bug-binutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

ld: once multiple symbol definitions are allowed, both definitions end u


From: Pavel Shishpor
Subject: ld: once multiple symbol definitions are allowed, both definitions end up in the executable
Date: Wed, 11 Jan 2017 10:49:00 +0100

Hello,

Could please someone advice is it
a bug or a feature when we get both bodies of the functions with the same name in the executable once multiple symbol definitions are allowed? Here is the example showing the behavior:

$ cat main.c

int f() {return 6;}
int main() { return f();}

$ cat a.c

int f() {return 4;}

$ gcc -c a.c main.c
$ gcc -Wl,--allow-multiple-definition a.o main.o

# From objdump we can see that the bodies of both functions "f" end up in the executable:
$ objdump -d a.out

00000000004004f6 <f>:
  4004f6:    55                       push   %rbp
  4004f7:    48 89 e5                 mov    %rsp,%rbp
  4004fa:    b8 04 00 00 00           mov    $0x4,%eax
  4004ff:    5d                       pop    %rbp
  400500:    c3                       retq  
  400501:    55                       push   %rbp
  400502:    48 89 e5                 mov    %rsp,%rbp
  400505:    b8 06 00 00 00           mov    $0x6,%eax
  40050a:    5d                       pop    %rbp
  40050b:    c3                       retq  

# The behavior is more or less as specified in the documentation with only the first definition executed:
$ ./a.out
$ echo $?
4
$


In my (more complex) setup I saw issues coming from this behavior since not only we get the second definition but the relocations needed by it.

Just in case some more information on my setup (though the behavior is the same on one more Linux host and the issue looks to be there on more recent ld also):
$ gcc --version
gcc (GCC) 5.3.1 20160406 (Red Hat 5.3.1-6)
$ ld --version
GNU ld version 2.25-9.fc22

Best regards,
Pavel

reply via email to

[Prev in Thread] Current Thread [Next in Thread]