Bug 32615 - Source file with extern inline function fails to link with -O0
Summary: Source file with extern inline function fails to link with -O0
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 4.1.2
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
Depends on:
Reported: 2007-07-03 18:28 UTC by Kris Van Hees
Modified: 2007-07-03 18:40 UTC (History)
1 user (show)

See Also:
Known to work:
Known to fail:
Last reconfirmed:


Note You need to log in before you can comment on or make changes to this bug.
Description Kris Van Hees 2007-07-03 18:28:34 UTC
Output of the gcc command:
Using built-in specs.
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/u
sr/share/info --enable-shared --enable-threads=posix --enable-checking=release -
-with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-
languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-ds
si --enable-plugin --with-java-home=/usr/lib/jvm/java-1.5.0-gcj- --en
able-libgcj-multifile --enable-java-maintainer-mode --with-ecj-jar=/usr/share/ja
va/eclipse-ecj.jar --with-cpu=generic --host=x86_64-redhat-linux
Thread model: posix
gcc version 4.1.2 20070502 (Red Hat 4.1.2-12)
 /usr/libexec/gcc/x86_64-redhat-linux/4.1.2/cc1 -E -quiet -v tt.c -mtune=generic
 -O0 -fpch-preprocess -o tt.i
ignoring nonexistent directory "/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../
#include "..." search starts here:
#include <...> search starts here:
End of search list.
 /usr/libexec/gcc/x86_64-redhat-linux/4.1.2/cc1 -fpreprocessed tt.i -quiet -dump
base tt.c -mtune=generic -auxbase tt -O0 -version -o tt.s
GNU C version 4.1.2 20070502 (Red Hat 4.1.2-12) (x86_64-redhat-linux)
        compiled by GNU C version 4.1.2 20070502 (Red Hat 4.1.2-12).
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: cdc0c9646615f6ebf987f895cd040dc2
 as -V -Qy -o tt.o tt.s
GNU assembler version (x86_64-redhat-linux) using BFD version versi
on 20070511
 /usr/libexec/gcc/x86_64-redhat-linux/4.1.2/collect2 --eh-frame-hdr -m elf_x86_6
4 --hash-style=gnu -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o tt /usr/lib/gc
c/x86_64-redhat-linux/4.1.2/../../../../lib64/crt1.o /usr/lib/gcc/x86_64-redhat-
linux/4.1.2/../../../../lib64/crti.o /usr/lib/gcc/x86_64-redhat-linux/4.1.2/crtb
egin.o -L/usr/lib/gcc/x86_64-redhat-linux/4.1.2 -L/usr/lib/gcc/x86_64-redhat-lin
ux/4.1.2 -L/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../lib64 -L/lib/../li
b64 -L/usr/lib/../lib64 tt.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc
--as-needed -lgcc_s --no-as-needed /usr/lib/gcc/x86_64-redhat-linux/4.1.2/crtend
.o /usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../lib64/crtn.o
tt.o: In function `first':
tt.c:(.text+0x22): undefined reference to `second'
collect2: ld returned 1 exit status

Preprocessed source file (tt.i):
# 1 "tt.c"
# 1 "<built-in>"
# 1 "<command line>"
# 1 "tt.c"
void crash(){
  int* a = 0;
  a[0] = 0;

extern inline void second(){

void first(){

int main(){


  return 0;

    This compiles and links fine with -O (and any higher degree of optimization) instead of -O0.  The problem is also present in GCC 4.1.1.
Comment 1 Andrew Pinski 2007-07-03 18:33:28 UTC
extern inline is not what you think it is.  The "extern inline" GNU C90 implementes (except for 4.3 with -std=c99/-std=gnu99 which is the standard C99 extern inline) means the function is extern but don't create a definition if the function was not inlined.  This is different from C99's extern inline.
Comment 2 Kris Van Hees 2007-07-03 18:40:38 UTC
Thanks for the explanation - that does explain why -O0 causes an error (since there is no inlining being done as far as I understand), whereas any other optimization setting results in success due to inlining of the function (avoiding the error that way).