https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68272
Bug ID: 68272 Summary: Unwanted out-of-line instances for C inline functions that are also GCC builtins. Product: gcc Version: 4.9.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: sorganov at gmail dot com Target Milestone: --- When compiling C code, GCC generates out-of-line copy of any inline function that also happens to be a GCC builtin, in every compilation unit that gets inline definition, resulting in link errors (see a test-case below). This violates C standard, as according to the standard, an out-of-line copy of inline function should only be put in those compilation unit(s) where the function is declared 'extern' as well. To reproduce (notice no 'extern' declaration ever): $ cat inl.h inline int abs(int i) { return (i >= 0) ? i : -i; } $ cat a.c #include "inl.h" int main() { return 1; } $ cat b.c #include "inl.h" $ gcc a.c b.c /tmp/ccyZFKSx.o: In function `abs': b.c:(.text+0x0): multiple definition of `abs' /tmp/ccijz638.o:a.c:(.text+0x0): first defined here collect2: error: ld returned 1 exit status $ gcc -v Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/lib/gcc/i586-linux-gnu/4.9/lto-wrapper Target: i586-linux-gnu Configured with: [...] Thread model: posix gcc version 4.9.2 (Debian 4.9.2-10) $