Bug 41194 - __attribute__ ((__gnu_inline__)) yields undefined reference when compiled with -O0, but not with -O1
Summary: __attribute__ ((__gnu_inline__)) yields undefined reference when compiled wit...
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.4.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-08-30 20:22 UTC by Hugh Daschbach
Modified: 2010-05-31 23:46 UTC (History)
1 user (show)

See Also:
Host: x86_64-unknown-linux-gnu
Target: x86_64-unknown-linux-gnu
Build: x86_64-unknown-linux-gnu
Known to work:
Known to fail:
Last reconfirmed:


Attachments
Preprocessed test case. (86.63 KB, text/plain)
2009-08-30 20:25 UTC, Hugh Daschbach
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Hugh Daschbach 2009-08-30 20:22:48 UTC
Error messages:

/tmp/ccgtrVyI.o: In function `Color':
/home/chromium/chromium/src/third_party/WebKit/WebCore/platform/ColorData.gperf:254: undefined reference to `findColor(char const*, unsigned int)'
/home/chromium/chromium/src/third_party/WebKit/WebCore/platform/ColorData.gperf:254: undefined reference to `findColor(char const*, unsigned int)'
collect2: ld returned 1 exit status


Command line:

g++  -O0 -g  Color-stripped.ii

Compiler build configuration:
  ../configure --prefix=/usr --enable-shared \
      --enable-languages=c,c++,fortran,objc,obj-c++ \
      --enable-threads=posix --mandir=/usr/share/man \
      --infodir=/usr/share/info \
      --enable-__cxa_atexit  --disable-multilib --libdir=/usr/lib \
      --libexecdir=/usr/lib --enable-clocale=gnu \
      --disable-libstdcxx-pch \
      --with-tune=generic

The symbols resolve correctly if compiled with "-O1" or if "__attribute__ ((__gnu_inline__))" is removed from function definition.
Comment 1 Hugh Daschbach 2009-08-30 20:25:05 UTC
Created attachment 18452 [details]
Preprocessed test case.
Comment 2 Jakub Jelinek 2009-08-31 08:05:35 UTC
That's correct.  In C++ gnu_inline attribute always means the GNU C extern inline function, i.e. it is inlined if deemed desirable and otherwise you must provide an external definition of the function.
If you don't do this, don't use gnu_inline attribute...
Comment 3 Jon Wilkes 2010-05-31 23:41:46 UTC
For clarity, a smaller test is:  __inline __attribute__ ((gnu_inline)) void func () { } int main() { func(); return 0; }  $ g++ foo.cpp /tmp/cc31L8fw.o: In function `main': foo.cpp:(.text+0x5): undefined reference to `func()' collect2: ld returned 1 exit status  Most people who hit this bug are likely using gperf.  $ gperf -N func  . . . #ifdef __GNUC__ __inline #if defined __GNUC_STDC_INLINE__ || defined __GNUC_GNU_INLINE__ __attribute__ ((__gnu_inline__)) #endif #endif const char * func (str, len) . . .  $ gperf -N func -L C++ # will and avoid this bug :-) but also renames func to Perfect_Hash::func :-(
Comment 4 Jon Wilkes 2010-05-31 23:46:25 UTC
Same as comment 3, hopefully in pre tags this time.

For clarity, a smaller test is:

__inline __attribute__ ((gnu_inline)) void func () { }
int main() { func(); return 0; }

$ g++ foo.cpp
/tmp/cc31L8fw.o: In function `main':
foo.cpp:(.text+0x5): undefined reference to `func()'
collect2: ld returned 1 exit status

Most people who hit this bug are likely using gperf.

$ gperf -N func

. . .
#ifdef __GNUC__
__inline
#if defined __GNUC_STDC_INLINE__ || defined __GNUC_GNU_INLINE__
__attribute__ ((__gnu_inline__))
#endif
#endif
const char * func (str, len)
. . .

$ gperf -N func -L C++ # will and avoid this bug :-) but also renames func to Perfect_Hash::func :-(