Bug 3666 - Comdat/linkonce doesn't merge symbol visibility
Summary: Comdat/linkonce doesn't merge symbol visibility
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.18
: P2 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-12-06 14:39 UTC by H.J. Lu
Modified: 2006-12-12 13:08 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description H.J. Lu 2006-12-06 14:39:28 UTC
When a symbol in a comdat/linkonce section has different visibility in different
files, linker doesn't merge symbol visibility:

bash-3.1$ cat foo.c
int foo __attribute__ ((section (".gnu.linkonce.d.1"))) = 1;
int
__attribute__ ((section (".gnu.linkonce.t.1")))
bar ()
{
  return 1;
}
bash-3.1$ cat bar.c
int foo __attribute__ ((section (".gnu.linkonce.d.1"),
                        visibility ("hidden"))) = 1;
int
__attribute__ ((section (".gnu.linkonce.t.1"), visibility ("hidden")))
bar ()
{
  return 1;
}
int
get_foo ()
{
  return foo;
}
int
get_bar ()
{
  return bar ();
}
bash-3.1$ make
gcc -fPIC -O   -c -o bar.o bar.c
gcc -fPIC -O   -c -o foo.o foo.c
ld -shared -o lib1.so bar.o foo.o
ld -shared -o lib2.so foo.o bar.o
ld: bar.o: relocation R_X86_64_PC32 against `foo' can not be used when making a
shared object; recompile with -fPIC
ld: final link failed: Bad value
make: *** [lib2.so] Error 1
bash-3.1$ 

Should we handle this case?
Comment 1 H.J. Lu 2006-12-06 15:15:34 UTC
A patch is posted at

http://sourceware.org/ml/binutils/2006-12/msg00059.html
Comment 2 H.J. Lu 2006-12-12 13:08:27 UTC
Fixed.