qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] Undefined reference to 'ffs' when building for win64


From: Richard Henderson
Subject: Re: [Qemu-devel] Undefined reference to 'ffs' when building for win64
Date: Mon, 18 Feb 2013 10:47:57 -0800
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130110 Thunderbird/17.0.2

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~



reply via email to

[Prev in Thread] Current Thread [Next in Thread]