Bug 24218 - [2.32 Regression] ld.bfd fails to link shared library built by clang (x86_64)
Summary: [2.32 Regression] ld.bfd fails to link shared library built by clang (x86_64)
Status: RESOLVED DUPLICATE of bug 24151
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.32
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-02-13 14:20 UTC by Matthias Klose
Modified: 2019-02-13 14:50 UTC (History)
1 user (show)

See Also:
Host:
Target: x86_64-linux-gnu
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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 ***