On 2013-02-18 01:52, Kevin Wolf wrote:
On Fri, Feb 15, 2013 at 10:16:11PM +0100, Stefan Weil wrote:
It looks like most (but not all) versions of gcc emit built-in code
for ffs() even for compilations without optimisation. I have to provide
additional compiler options (e.g. -fno-builtin-ffs) to get a real
function call.
Only then I get the linker errors which you see.
Obviously your compiler behaves different (or did you add extra
compiler options?).
Try this short test.c code:
int ffs(unsigned n);
int main(int argc, char *argv[])
{
return ffs(argc);
}
On Debian, I compiled and tested like this:
amd64-mingw32msvc-gcc -c -g -O0 test.c
amd64-mingw32msvc-nm test.o
There is no ffs function call in the resulting binary.
If your compiler creates a function call, we have to know
why and whether there is a simple rule which versions of
gcc behave like that. If there is no simple rule, we need
a configure check.
A configure check would require that a compiler either creates always a
function call, or never. I'm not sure if you can rely on that.
Almost certainly best to stop using a system ffs and use the ctz
for which we have plain old arithmetic fallback support. It would also
clean up the subtraction in e.g.
hw/pci/pci.h: return (val & mask) >> (ffs(mask) - 1);
hw/strongarm.c: bit = ffs(diff) - 1;
target-ppc/cpu.h: int tlb_bits = ffs(booke206_tlb_size(env, tlbn)) - 1;
i.e. almost every place that we actually use ffs today.
r~