Hi everyone, Although I'm seeing this on 3.3.3, it appears to be determined by the backend, so I think it's still reasonable to ask:
I have some code that calls __builtin_ffs, but entirely on compile-time constants. When I compile it (using an inhouse custom ELF-target backend) with -O2, it gets totally optimised away, but the compiler still emits an undefined symbol reference to the library ffs() function: ---------------------------------<snip!>--------------------------------- /tmp $ ${libexecdir}/3.3.3/cc1.exe -O2 - -o - int foo () { return __builtin_ffs (32); } .file "<stdin>" foo .global _ffs .text .align 2 .proc _foo .global _foo .type _foo, @function _foo: addi r1,r0,0x6 jr r15 .endproc _foo .size _foo, .-_foo .ident "GCC: (GNU) 3.3.3 (artimi-1.19)" ---------------------------------<snip!>--------------------------------- When I retarget the same gcc at x86/cygwin, no such reference is emitted: ---------------------------------<snip!>--------------------------------- /tmp $ /repository/gcc-build/gcc-x86/gcc/cc1.exe -O2 - -o - int foo () { return __builtin_ffs (32); } .file "<stdin>" foo .text .p2align 4,,15 .globl _foo .def _foo; .scl 2; .type 32; .endef _foo: pushl %ebp movl $6, %eax movl %esp, %ebp popl %ebp ret ---------------------------------<snip!>--------------------------------- Does anyone know off the top of their head if this is simply a side-effect of the fact that i386.md supplies an rtl insn for ffs, where my custom target doesn't? Or is it perhaps an elf-vs-PE difference? I couldn't find anything to explain this behaviour in the manual. I can kind-of work around it by tricking the compiler into thinking __builtin_ffs can be elided (as no body is ever required by a static inline[*]) ---------------------------------<snip!>--------------------------------- /tmp $ ./cc1.exe -O2 - -o - static inline int __builtin_ffs (int); int foo () { return __builtin_ffs (32); } .file "<stdin>" foo .text .align 2 .proc _foo .global _foo .type _foo, @function _foo: ; 010000000000000000000000000000000000000000000000000000000000000 ; frame size 0: local_vars_size 0 out_args_size 0 pretend_args_size 0 ; mul_save_size 0 gpr_save_size 0 lr_save_ 0 iar_save_ 0 fp_save_ 0 addi r1,r0,0x20 j ___builtin_ffs ; sibcall_value insn ; .endproc _foo .size _foo, .-_foo ? <stdin>:1: warning: `__builtin_ffs' used but never defined .ident "GCC: (GNU) 3.3.3 (artimi-1.19)" ---------------------------------<snip!>--------------------------------- but that leaves me with an ugly warning. Does anyone know a better way to eliminate the undefined reference? (I'm currently just supplying a dummy version of _ffs() in my source solely in order to satisfy the linker). cheers, DaveK [*] - before the recent changes for C99 compatibility, of course! -- Can't think of a witty .sigline today....