[lld] r265784 - [lld] [ELF/AARCH64] Fix dynamic relocation from PIC GOT access
Adhemerval Zanella via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 8 07:10:47 PDT 2016
Author: azanella
Date: Fri Apr 8 09:10:41 2016
New Revision: 265784
URL: http://llvm.org/viewvc/llvm-project?rev=265784&view=rev
Log:
[lld] [ELF/AARCH64] Fix dynamic relocation from PIC GOT access
This patch fixes dynamic relocation creation from GOT access in dynamic
objects on aarch64. Current code creates a plt relative one
(R_AARCH64_JUMP_SLOT) instead of a got relative (R_AARCH64_GLOB_DAT).
It leads the programs fails with:
$ cat t.cc
std::string test = "hello...\n";
int main ()
{
printf ("%s\n", test.c_str());
return 0;
}
$ clang++ t.cc -fpic -o t
$ ./t
hello...
Segmentation fault (core dumped)
Due the fact it will try to access the plt instead of the got for
__cxa_atexit registration for the std::string destruction. It will
lead in a bogus function address in atexit.
Added:
lld/trunk/test/ELF/aarch64-fpic-got.s
Modified:
lld/trunk/ELF/Target.cpp
Modified: lld/trunk/ELF/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.cpp?rev=265784&r1=265783&r2=265784&view=diff
==============================================================================
--- lld/trunk/ELF/Target.cpp (original)
+++ lld/trunk/ELF/Target.cpp Fri Apr 8 09:10:41 2016
@@ -170,6 +170,7 @@ public:
bool isRelRelative(uint32_t Type) const override;
bool needsCopyRelImpl(uint32_t Type) const override;
bool needsGot(uint32_t Type, const SymbolBody &S) const override;
+ bool refersToGotEntry(uint32_t Type) const override;
bool needsPltImpl(uint32_t Type) const override;
void relocateOne(uint8_t *Loc, uint8_t *BufEnd, uint32_t Type, uint64_t P,
uint64_t SA) const override;
@@ -1381,6 +1382,10 @@ bool AArch64TargetInfo::needsGot(uint32_
}
}
+bool AArch64TargetInfo::refersToGotEntry(uint32_t Type) const {
+ return Type == R_AARCH64_ADR_GOT_PAGE || Type == R_AARCH64_LD64_GOT_LO12_NC;
+}
+
bool AArch64TargetInfo::needsPltImpl(uint32_t Type) const {
switch (Type) {
default:
Added: lld/trunk/test/ELF/aarch64-fpic-got.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/aarch64-fpic-got.s?rev=265784&view=auto
==============================================================================
--- lld/trunk/test/ELF/aarch64-fpic-got.s (added)
+++ lld/trunk/test/ELF/aarch64-fpic-got.s Fri Apr 8 09:10:41 2016
@@ -0,0 +1,18 @@
+# REQUIRES: aarch64
+
+# RUN: llvm-mc -filetype=obj -triple=aarch64-none-linux %s -o %t.o
+# RUN: llvm-mc -filetype=obj -triple=aarch64-none-linux %p/Inputs/shared.s -o %t-lib.o
+# RUN: ld.lld -shared %t-lib.o -o %t-lib.so
+# RUN: ld.lld %t-lib.so %t.o -o %t.exe
+# RUN: llvm-readobj -dyn-relocations %t.exe | FileCheck %s
+
+## Checks if got access to dynamic objects is done through a got relative
+## dynamic relocation and not using plt relative (R_AARCH64_JUMP_SLOT).
+# CHECK: Dynamic Relocations {
+# CHECK-NEXT: 0x{{[0-9A-F]+}} R_AARCH64_GLOB_DAT bar 0x0
+# CHECK-NEXT: }
+
+.globl _start
+_start:
+ adrp x0, :got:bar
+ ldr x0, [x0, :got_lo12:bar]
More information about the llvm-commits
mailing list