[lld] r315936 - Add base relative relocation record that can be used for the following case (OpenCL example):

Tony Tye via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 16 13:46:53 PDT 2017


Author: t-tye
Date: Mon Oct 16 13:46:53 2017
New Revision: 315936

URL: http://llvm.org/viewvc/llvm-project?rev=315936&view=rev
Log:
Add base relative relocation record that can be used for the following case (OpenCL example):

static __global int Var = 0; 
__global int* Ptr[] = {&Var};
...

In this case Var is a non premptable symbol and so its address can be used as the value of Ptr, with a base relative relocation that will add the delta between the ELF address and the actual load address. Such relocations do not require a symbol.

This also fixes LLD which was incorrectly generating a PCREL64 for this case.

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

Modified:
    lld/trunk/ELF/Arch/AMDGPU.cpp
    lld/trunk/test/ELF/amdgpu-relocs.s

Modified: lld/trunk/ELF/Arch/AMDGPU.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Arch/AMDGPU.cpp?rev=315936&r1=315935&r2=315936&view=diff
==============================================================================
--- lld/trunk/ELF/Arch/AMDGPU.cpp (original)
+++ lld/trunk/ELF/Arch/AMDGPU.cpp Mon Oct 16 13:46:53 2017
@@ -32,7 +32,7 @@ public:
 } // namespace
 
 AMDGPU::AMDGPU() {
-  RelativeRel = R_AMDGPU_REL64;
+  RelativeRel = R_AMDGPU_RELATIVE64;
   GotRel = R_AMDGPU_ABS64;
   GotEntrySize = 8;
 }

Modified: lld/trunk/test/ELF/amdgpu-relocs.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/amdgpu-relocs.s?rev=315936&r1=315935&r2=315936&view=diff
==============================================================================
--- lld/trunk/test/ELF/amdgpu-relocs.s (original)
+++ lld/trunk/test/ELF/amdgpu-relocs.s Mon Oct 16 13:46:53 2017
@@ -65,10 +65,23 @@ ptr:
   .quad temp
   .size ptr, 8
 
+# R_AMDGPU_RELATIVE64:
+  .type temp2, @object
+  .local temp2
+  .size temp2, 4
+
+  .type ptr2, @object
+  .globl ptr2
+  .size ptr2, 8
+  .p2align 3
+ptr2:
+  .quad temp2
+
 # The relocation for local_var{0, 1, 2} and var should be resolved by the
 # linker.
 # CHECK: Relocations [
 # CHECK: .rela.dyn {
+# CHECK-NEXT: R_AMDGPU_RELATIVE64 - 0x0
 # CHECK-NEXT: R_AMDGPU_ABS64 common_var0 0x0
 # CHECK-NEXT: R_AMDGPU_ABS64 common_var1 0x0
 # CHECK-NEXT: R_AMDGPU_ABS64 common_var2 0x0




More information about the llvm-commits mailing list