[llvm-bugs] [Bug 44594] New: clang++ cannot compile an executable with -fPIE because of possibly incorrect linking of
via llvm-bugs
llvm-bugs at lists.llvm.org
Mon Jan 20 03:17:14 PST 2020
https://bugs.llvm.org/show_bug.cgi?id=44594
Bug ID: 44594
Summary: clang++ cannot compile an executable with -fPIE
because of possibly incorrect linking of
Product: clang
Version: 10.0
Hardware: PC
OS: Linux
Status: NEW
Severity: enhancement
Priority: P
Component: C++
Assignee: unassignedclangbugs at nondot.org
Reporter: kolan_n at mail.ru
CC: blitzrakete at gmail.com, dgregor at apple.com,
erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
richard-llvm at metafoo.co.uk
```
clang++-10 ./hw.cpp -o hw -fPIE -Wl,-pie -Wl,-O1 -Wl,--sort-common
-Wl,--as-needed -Wl,-z,relro -Wl,-z,now -Wl,-z,shstk -Wl,-z,notext
-Wl,--verbose
GNU ld (GNU Binutils for Ubuntu) 2.33
...
/usr/bin/ld: mode elf_x86_64
....
attempt to open /usr/bin/../lib/gcc/x86_64-linux-gnu/9/crtbegin.o succeeded
/usr/bin/../lib/gcc/x86_64-linux-gnu/9/crtbegin.o
.....
/usr/bin/ld: /usr/bin/../lib/gcc/x86_64-linux-gnu/9/crtbegin.o: relocation
R_X86_64_32 against hidden symbol `__TMC_END__' can not be used when making a
PIE object
/usr/bin/ld: final link failed: nonrepresentable section on output
clang: error: linker command failed with exit code 1 (use -v to see invocation)
```
```
clang++-10 ./hw.cpp -o hw -fPIE -Wl,-pie -Wl,-O1 -Wl,--sort-common
-Wl,--as-needed -Wl,-z,relro -Wl,-z,now -Wl,-z,shstk -Wl,-z,notext -fuse-ld=lld
-Wl,--verbose
...
ld.lld: /usr/bin/../lib/gcc/x86_64-linux-gnu/9/crtbegin.o
....
ld.lld: error: cannot preempt symbol: __TMC_END__
>>> defined in /usr/bin/../lib/gcc/x86_64-linux-gnu/9/crtend.o
>>> referenced by crtstuff.c
>>> /usr/bin/../lib/gcc/x86_64-linux-gnu/9/crtbegin.o:(.text+0x1)
ld.lld: error: relocation R_X86_64_32S cannot be used against local symbol;
recompile with -fPIC
>>> defined in /usr/bin/../lib/gcc/x86_64-linux-gnu/9/crtbegin.o
>>> referenced by crtstuff.c
>>> /usr/bin/../lib/gcc/x86_64-linux-gnu/9/crtbegin.o:(.text+0x7)
ld.lld: error: relocation R_X86_64_32 cannot be used against local symbol;
recompile with -fPIC
>>> defined in /usr/bin/../lib/gcc/x86_64-linux-gnu/9/crtbegin.o
>>> referenced by crtstuff.c
>>> /usr/bin/../lib/gcc/x86_64-linux-gnu/9/crtbegin.o:(.text+0x18)
ld.lld: error: cannot preempt symbol: __TMC_END__
>>> defined in /usr/bin/../lib/gcc/x86_64-linux-gnu/9/crtend.o
>>> referenced by crtstuff.c
>>> /usr/bin/../lib/gcc/x86_64-linux-gnu/9/crtbegin.o:(.text+0x31)
ld.lld: error: relocation R_X86_64_32S cannot be used against local symbol;
recompile with -fPIC
>>> defined in /usr/bin/../lib/gcc/x86_64-linux-gnu/9/crtbegin.o
>>> referenced by crtstuff.c
>>> /usr/bin/../lib/gcc/x86_64-linux-gnu/9/crtbegin.o:(.text+0x38)
ld.lld: error: relocation R_X86_64_32 cannot be used against local symbol;
recompile with -fPIC
>>> defined in /usr/bin/../lib/gcc/x86_64-linux-gnu/9/crtbegin.o
>>> referenced by crtstuff.c
>>> /usr/bin/../lib/gcc/x86_64-linux-gnu/9/crtbegin.o:(.text+0x5A)
clang: error: linker command failed with exit code 1 (use -v to see invocation)
```
```
g++-9 ./hw.cpp -o hw -fPIE -Wl,-pic -Wl,-O1 -Wl,--sort-common -Wl,--as-needed
-Wl,-flto -Wl,-z,relro -Wl,-z,now -Wl,-z,ibtplt -Wl,-z,ibt -Wl,-z,shstk
-Wl,--verbose
GNU ld (GNU Binutils for Ubuntu) 2.33
....
/usr/bin/ld: mode elf_x86_64
....
attempt to open /usr/lib/gcc/x86_64-linux-gnu/9/crtbeginS.o succeeded
/usr/lib/gcc/x86_64-linux-gnu/9/crtbeginS.o
```
compiles and links OK
https://dev.gentoo.org/~vapier/crt.txt says:
>crtbegin.o
> GCC uses this to find the start of the constructors.
>crtbeginS.o
> Used in place of crtbegin.o when generating shared objects/PIEs.
>crtend.o
> GCC uses this to find the start of the destructors.
>crtendS.o
> Used in place of crtend.o when generating shared objects/PIEs.
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20200120/8aec4f4d/attachment.html>
More information about the llvm-bugs
mailing list