[lld] r349024 - [ELF][AArch64] Fix adrp to undefined weak reference.

Peter Smith via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 13 03:13:02 PST 2018


Author: psmith
Date: Thu Dec 13 03:13:01 2018
New Revision: 349024

URL: http://llvm.org/viewvc/llvm-project?rev=349024&view=rev
Log:
[ELF][AArch64] Fix adrp to undefined weak reference.

In the ABI for the 64-bit Arm architecture the section on weak references
states:
During linking, the symbol value of an undefined weak reference is:
- Zero if the relocation type is absolute
- The address of the place if the relocation type is pc-relative.

The relocations associated with an ADRP are relative so we should resolve
the undefined weak reference to the place instead of 0. This matches GNU
ld.bfd behaviour.

fixes pr34928

Differential Revision: https://reviews.llvm.org/D55599


Modified:
    lld/trunk/ELF/InputSection.cpp
    lld/trunk/test/ELF/aarch64-undefined-weak.s

Modified: lld/trunk/ELF/InputSection.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.cpp?rev=349024&r1=349023&r2=349024&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.cpp (original)
+++ lld/trunk/ELF/InputSection.cpp Thu Dec 13 03:13:01 2018
@@ -671,11 +671,11 @@ static uint64_t getRelocTargetVA(const I
     return In.MipsGot->getVA() + In.MipsGot->getTlsIndexOffset(File) -
            In.MipsGot->getGp(File);
   case R_AARCH64_PAGE_PC: {
-    uint64_t Val = Sym.isUndefWeak() ? A : Sym.getVA(A);
+    uint64_t Val = Sym.isUndefWeak() ? P + A : Sym.getVA(A);
     return getAArch64Page(Val) - getAArch64Page(P);
   }
   case R_AARCH64_PLT_PAGE_PC: {
-    uint64_t Val = Sym.isUndefWeak() ? A : Sym.getPltVA() + A;
+    uint64_t Val = Sym.isUndefWeak() ? P + A : Sym.getPltVA() + A;
     return getAArch64Page(Val) - getAArch64Page(P);
   }
   case R_RISCV_PC_INDIRECT: {

Modified: lld/trunk/test/ELF/aarch64-undefined-weak.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/aarch64-undefined-weak.s?rev=349024&r1=349023&r2=349024&view=diff
==============================================================================
--- lld/trunk/test/ELF/aarch64-undefined-weak.s (original)
+++ lld/trunk/test/ELF/aarch64-undefined-weak.s Thu Dec 13 03:13:01 2018
@@ -40,7 +40,7 @@ _start:
 // CHECK-NEXT:    210008: {{.*}} b.eq    #4
 // CHECK-NEXT:    21000c: {{.*}} cbz     x1, #4
 // CHECK-NEXT:    210010: {{.*}} adr     x0, #0
-// CHECK-NEXT:    210014: {{.*}} adrp    x0, #-2162688
+// CHECK-NEXT:    210014: {{.*}} adrp    x0, #0
 // CHECK:         210018: {{.*}} .word   0x00000000
 // CHECK-NEXT:    21001c: {{.*}} .word   0x00000000
 // CHECK-NEXT:    210020: {{.*}} .word   0x00000000




More information about the llvm-commits mailing list