This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/14105] New: GCC over-optimisating extern


Sample code (x.c):

int main(void) {
  int return_pcap_debug(void) {
    extern int pcap_debug;

    return pcap_debug;
  }

  return 0;
}

Compiled with (-Os, -O1, -O2 are all the same):

gcc x.c -o x

Produces: 

/tmp/ccJy8Ead.o(.text+0xa): In function `return_pcap_debug.0':
: undefined reference to `pcap_debug'
collect2: ld returned 1 exit status

But, when compiled with:

gcc -O3 x.c -o x

The code compiles.

This is an over-optimisation, and is pretty silly, especially since the returned
value in the inlined block is an extern.

If you link the code against something that does export pcap_debug, it links
properly.

-- 
           Summary: GCC over-optimisating extern
           Product: gcc
           Version: 3.3.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: ok at mailcall dot com dot au
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: i586-trustix-linux
  GCC host triplet: i586-trustix-linux
GCC target triplet: i586-trustix-linux


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14105


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]