Skip to contentSkip to conversation

Git head build problem (popcountl vs. system headers)

Qemu-devel Martin Husemann 6 participants 9 messages Apr 25, 2013 – May 5, 2013

lore
Share & tools
lore
#0 lore raw

I just tried building git HEAD on NetBSD-current and gcc chokes on a prototype mismatch for popcountl:

util/hbitmap.c has:

static inline int popcountl(unsigned long l)

{
    return BITS_PER_LONG == 32 ? ctpop32(l) : ctpop64(l);
}

while NetBSD's strings.h uses:

unsigned int popcountl(unsigned long) __constfunc;

"unsigned" looks better to me for a non negative count, but maybe a configure test and using the system libs would be preferable?

Martin

#1 lore raw
Quoted 5 lines · Martin Husemann

I just tried building git HEAD on NetBSD-current and gcc chokes on a prototype mismatch for popcountl:

util/hbitmap.c has:

Quoted 8 lines

static inline int popcountl(unsigned long l)

{
     return BITS_PER_LONG == 32 ? ctpop32(l) : ctpop64(l);
}

while NetBSD's strings.h uses:

unsigned int popcountl(unsigned long) __constfunc;

<strings.h> is the K&R header supplanted by ISO <string.h>. Is there any good reason that we're including it at all?

r~

#2 lore raw
Quoted 11 lines · Richard Henderson
Quoted 10 lines · Martin Husemann

I just tried building git HEAD on NetBSD-current and gcc chokes on a prototype mismatch for popcountl:

util/hbitmap.c has:

static inline int popcountl(unsigned long l)

{
     return BITS_PER_LONG == 32 ? ctpop32(l) : ctpop64(l);
}
Quoted 6 lines
Quoted 3 lines

while NetBSD's strings.h uses:

unsigned int popcountl(unsigned long) __constfunc;

<strings.h> is the K&R header supplanted by ISO <string.h>. Is there any good reason that we're including it at all?

- <strings.h> is a portable SUS/POSIX header:

http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/strings.h.html

- "popcountl()" in NetBSD's <strings.h> is either a standards-nonconformance issue, or the the qemu build system doesn't set up the right SUS/POSIX environment for compilation on NetBSD. (If that's possible at all, I don't know.)

Laszlo

#4 lore raw
Quoted 10 lines · Richard Henderson
Quoted 6 lines · Laszlo Ersek
Quoted 2 lines

<strings.h> is the K&R header supplanted by ISO <string.h>. Is there any good reason that we're including it at all?

- <strings.h> is a portable SUS/POSIX header:

http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/strings.h.html

Huh. Ok, fine, but what do we think we're using out of it that isn't in <string.h>?

strcasecmp(). Just because some (many) systems pollute <string.h> with strcasecmp() without you having to explicitly include <strings.h> (and POSIX allows but not requires this:
http://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_02_02
says that the str* prefix is reserved in <string.h>), a strictly-conforming implementation cannot rely on this extension, and there are systems where you have to get strcasecmp() from <strings.h>, just as POSIX requires.

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#5 lore raw
In reply to Richard Henderson
Quoted 10 lines · Richard Henderson
Quoted 6 lines · Laszlo Ersek
Quoted 2 lines

<strings.h> is the K&R header supplanted by ISO <string.h>. Is there any good reason that we're including it at all?

- <strings.h> is a portable SUS/POSIX header:

http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/strings.h.html

Huh. Ok, fine, but what do we think we're using out of it that isn't in <string.h>?

Ok, I can fix the namespace issue (which is real) easily. But this still leaves two questions open:

- why not use an unsigned return value for your homegrown version?
- would it be preferable to use official/optimized versions if available?

Thanks,

Martin

#6 lore raw
Quoted 3 lines · Martin Husemann

But this still leaves two questions open:

- why not use an unsigned return value for your homegrown version?

We follow gcc's API, which returns int for __builtin_popcountl.

Quoted 2 lines

- would it be preferable to use official/optimized versions if available?

We will -- assuming a reasonably recent gcc we will end up compiling this to __builtin_popcount() and friends.

(We could maybe do with a bit more rationalisation in this area, though.)

thanks
-- PMM

#7 lore raw
In reply to Martin Husemann
Quoted 1 line · Martin Husemann

Ok, I can fix the namespace issue (which is real) easily.

Turns out to be a bit harder: qemu does not define (as far as I can tell) any restricting macro (_POSIX_C_SOURCE or whatever).

Should it?

Martin

#8 lore raw
Quoted 7 lines · Martin Husemann
Quoted 1 line · Martin Husemann

Ok, I can fix the namespace issue (which is real) easily.

Turns out to be a bit harder: qemu does not define (as far as I can tell) any restricting macro (_POSIX_C_SOURCE or whatever).

Should it?

I think the easiest fix is to stop QEMU from reusing a reserved identifier. So popcountl() in util/hbitmap.c should be renamed to qemu_popcountl().

Quoted 3 lines

Martin