Bug 24218

Summary: [2.32 Regression] ld.bfd fails to link shared library built by clang (x86_64)
Product: binutils Reporter: Matthias Klose <doko>
Component: ldAssignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED DUPLICATE    
Severity: normal CC: hjl
Priority: P2    
Version: 2.32   
Target Milestone: ---   
Host: Target: x86_64-linux-gnu
Build: Last reconfirmed:

Description Matthias Klose 2019-02-13 14:20:54 UTC
seen when using ld.bfd 2.32 with clang 7 or 8, works with GCC:

# Segfault https://bugs.llvm.org/show_bug.cgi?id=26580
echo '
extern int a;
extern void bar (void);
int main() {
  bar ();
  if (a != 30)
    __builtin_abort();
  return 0;
}' > x.c

echo 'int a;
__attribute__((visibility("protected"))) int a;
void bar () {
  a = 30;
}
' > bar.c

# reported in https://bugs.llvm.org/show_bug.cgi?id=26580#c18
if [ $DEB_HOST_ARCH != "i386" ]; then
    clang-$VERSION -O3 -c -o x.o x.c
    clang-$VERSION -O3 -fpic -c -o bar.o bar.c
    clang-$VERSION -fuse-ld=bfd -shared -o libfoo.so bar.o
    clang-$VERSION -fuse-ld=bfd -o y x.o libfoo.so -Wl,-R,.
    # Still failing, commenting
    ./y || true
fi
/usr/bin/ld.bfd: bar.o: relocation R_X86_64_PC32 against protected symbol `a' can not be used when making a shared object
/usr/bin/ld.bfd: final link failed: nonrepresentable section on output
clang: error: linker command failed with exit code 1 (use -v to see invocation)

The failing command is:
    clang-$VERSION -fuse-ld=bfd -shared -o libfoo.so bar.o
Comment 1 Matthias Klose 2019-02-13 14:24:44 UTC
LLVM issue? https://bugs.llvm.org/show_bug.cgi?id=26580
Comment 2 H.J. Lu 2019-02-13 14:50:05 UTC
This is a clang bug.

*** This bug has been marked as a duplicate of bug 24151 ***