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/82723] New: Collisions with standard library not detected by linker


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82723

            Bug ID: 82723
           Summary: Collisions with standard library not detected by
                    linker
           Product: gcc
           Version: 7.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: berck.nash at wdc dot com
  Target Milestone: ---

If the standard library calls a function with the same name as a function that
happens to appear locally, the linker will happily plug in the local function
instead of the standard library function.  I found the resulting runtime
failure rather difficult to debug.

The obvious case is detected by the compiler as a redefinition, but the
troublesome case is one where standard library call and the conflicting
definition are in different objects.  In this case, I believe the linker should
detect that there are, in fact, multiple symbols with the same name and throw
an error.  Instead, it seems happy to link with whatever the first thing it
finds.

Here's an example triggered by calling getaddrinfo() which apparently calls
connect().  The linker has incorrectly linked the standard library call to
connect() to my connect() without a single warning or error.

Note that the example requires two source files:
First:

#include <stdio.h>
#include <netdb.h>
#include <errno.h>
#include <string.h>

int main(int argc, char **argv)
{
        struct addrinfo *addr;
        int error;
        char addr_str[INET6_ADDRSTRLEN];

        error = getaddrinfo(argv[1], NULL, NULL, &addr);
        if (error) {
                fprintf(stderr, "Error resolving address (%s): %s\n",
                                argv[1], gai_strerror(error));
        }

        freeaddrinfo(addr);
}

Second:
#include <stdio.h>

int connect(void)
{
        printf("Should never get here!\n");
        return -1;
}

Output from running the compiled binary:

./bug google.com
Should never get here!
Should never get here!
Should never get here!
Should never get here!
Should never get here!
Should never get here!
Should never get here!
Should never get here!
Should never get here!
Should never get here!
Should never get here!
Should never get here!
Error resolving address (google.com): Temporary failure in name resolution
*** Error in `./bug': munmap_chunk(): invalid pointer: 0x00007fff46e2736c ***
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x70bfb)[0x7fdf16cd7bfb]
/lib/x86_64-linux-gnu/libc.so.6(+0x76fc6)[0x7fdf16cddfc6]
/lib/x86_64-linux-gnu/libc.so.6(freeaddrinfo+0x1d)[0x7fdf16d3c1ad]
./bug(+0x86c)[0x5625543fa86c]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf1)[0x7fdf16c872e1]
./bug(+0x6fa)[0x5625543fa6fa]
======= Memory map: ========
5625543fa000-5625543fb000 r-xp 00000000 08:02 5393861                   
/home/berck/work/gcc_bug/bug
5625545fa000-5625545fb000 r--p 00000000 08:02 5393861                   
/home/berck/work/gcc_bug/bug
5625545fb000-5625545fc000 rw-p 00001000 08:02 5393861                   
/home/berck/work/gcc_bug/bug
562554cc2000-562554ce3000 rw-p 00000000 00:00 0                          [heap]
7fdf1621e000-7fdf16234000 r-xp 00000000 08:02 11012524                  
/lib/x86_64-linux-gnu/libgcc_s.so.1
7fdf16234000-7fdf16433000 ---p 00016000 08:02 11012524                  
/lib/x86_64-linux-gnu/libgcc_s.so.1
7fdf16433000-7fdf16434000 r--p 00015000 08:02 11012524                  
/lib/x86_64-linux-gnu/libgcc_s.so.1
7fdf16434000-7fdf16435000 rw-p 00016000 08:02 11012524                  
/lib/x86_64-linux-gnu/libgcc_s.so.1
7fdf16435000-7fdf16449000 r-xp 00000000 08:02 11012621                  
/lib/x86_64-linux-gnu/libresolv-2.24.so
7fdf16449000-7fdf16648000 ---p 00014000 08:02 11012621                  
/lib/x86_64-linux-gnu/libresolv-2.24.so
7fdf16648000-7fdf16649000 r--p 00013000 08:02 11012621                  
/lib/x86_64-linux-gnu/libresolv-2.24.so
7fdf16649000-7fdf1664a000 rw-p 00014000 08:02 11012621                  
/lib/x86_64-linux-gnu/libresolv-2.24.so
7fdf1664a000-7fdf1664c000 rw-p 00000000 00:00 0
7fdf1664c000-7fdf16651000 r-xp 00000000 08:02 11012613                  
/lib/x86_64-linux-gnu/libnss_dns-2.24.so
7fdf16651000-7fdf16850000 ---p 00005000 08:02 11012613                  
/lib/x86_64-linux-gnu/libnss_dns-2.24.so
7fdf16850000-7fdf16851000 r--p 00004000 08:02 11012613                  
/lib/x86_64-linux-gnu/libnss_dns-2.24.so
7fdf16851000-7fdf16852000 rw-p 00005000 08:02 11012613                  
/lib/x86_64-linux-gnu/libnss_dns-2.24.so
7fdf16852000-7fdf16854000 r-xp 00000000 08:02 11012473                  
/lib/x86_64-linux-gnu/libnss_mdns4_minimal.so.2
7fdf16854000-7fdf16a53000 ---p 00002000 08:02 11012473                  
/lib/x86_64-linux-gnu/libnss_mdns4_minimal.so.2
7fdf16a53000-7fdf16a54000 r--p 00001000 08:02 11012473                  
/lib/x86_64-linux-gnu/libnss_mdns4_minimal.so.2
7fdf16a54000-7fdf16a55000 rw-p 00002000 08:02 11012473                  
/lib/x86_64-linux-gnu/libnss_mdns4_minimal.so.2
7fdf16a55000-7fdf16a5f000 r-xp 00000000 08:02 11012614                  
/lib/x86_64-linux-gnu/libnss_files-2.24.so
7fdf16a5f000-7fdf16c5f000 ---p 0000a000 08:02 11012614                  
/lib/x86_64-linux-gnu/libnss_files-2.24.so
7fdf16c5f000-7fdf16c60000 r--p 0000a000 08:02 11012614                  
/lib/x86_64-linux-gnu/libnss_files-2.24.so
7fdf16c60000-7fdf16c61000 rw-p 0000b000 08:02 11012614                  
/lib/x86_64-linux-gnu/libnss_files-2.24.so
7fdf16c61000-7fdf16c67000 rw-p 00000000 00:00 0
7fdf16c67000-7fdf16dfa000 r-xp 00000000 08:02 11012588                  
/lib/x86_64-linux-gnu/libc-2.24.so
7fdf16dfa000-7fdf16ffa000 ---p 00193000 08:02 11012588                  
/lib/x86_64-linux-gnu/libc-2.24.so
7fdf16ffa000-7fdf16ffe000 r--p 00193000 08:02 11012588                  
/lib/x86_64-linux-gnu/libc-2.24.so
7fdf16ffe000-7fdf17000000 rw-p 00197000 08:02 11012588                  
/lib/x86_64-linux-gnu/libc-2.24.so
7fdf17000000-7fdf17004000 rw-p 00000000 00:00 0
7fdf17004000-7fdf17027000 r-xp 00000000 08:02 11012582                  
/lib/x86_64-linux-gnu/ld-2.24.so
7fdf171ea000-7fdf171ec000 rw-p 00000000 00:00 0
7fdf17223000-7fdf17227000 rw-p 00000000 00:00 0
7fdf17227000-7fdf17228000 r--p 00023000 08:02 11012582                  
/lib/x86_64-linux-gnu/ld-2.24.so
7fdf17228000-7fdf17229000 rw-p 00024000 08:02 11012582                  
/lib/x86_64-linux-gnu/ld-2.24.so
7fdf17229000-7fdf1722a000 rw-p 00000000 00:00 0
7fff46e07000-7fff46e28000 rw-p 00000000 00:00 0                         
[stack]
7fff46e5d000-7fff46e60000 r--p 00000000 00:00 0                          [vvar]
7fff46e60000-7fff46e62000 r-xp 00000000 00:00 0                          [vdso]
Aborted (core dumped)

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