[PATCH] D21184: [ELF] - Properly check that R_X86_64_PC32 and R_X86_64_32 relocations are disallowed in DSO.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 9 07:55:52 PDT 2016


grimar created this revision.
grimar added reviewers: ruiu, rafael.
grimar added subscribers: llvm-commits, grimar.

getDynRel() contains the next code:

```
uint32_t X86_64TargetInfo::getDynRel(uint32_t Type) const {
  if (Config->Shared && (Type == R_X86_64_PC32 || Type == R_X86_64_32))
    error(getRelName(Type) + " cannot be a dynamic relocation");
  return Type;
}
```

where error was never thown/catched previously when running testcases because adjustExpr() method 
consumed that error check. adjustExpr() errors out if dynamic relocations happens against the readonly segment. 

I think initially we wanted to check that these two relocations are not present when linking DSO because of 
possible overflow in runtime. Patch moves them to writable segment in testcases to allow
error check above to trigger.

http://reviews.llvm.org/D21184

Files:
  test/ELF/x86-64-reloc-32-fpic.s
  test/ELF/x86-64-reloc-pc32-fpic.s

Index: test/ELF/x86-64-reloc-pc32-fpic.s
===================================================================
--- test/ELF/x86-64-reloc-pc32-fpic.s
+++ test/ELF/x86-64-reloc-pc32-fpic.s
@@ -1,6 +1,7 @@
 # REQUIRES: x86
 # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
 # RUN: not ld.lld -shared %t.o -o %t.so 2>&1 | FileCheck %s
-# CHECK: relocation R_X86_64_PC32 cannot be used when making a shared object; recompile with -fPIC.
+# CHECK: R_X86_64_PC32 cannot be a dynamic relocation
 
+.data
 call _shared
Index: test/ELF/x86-64-reloc-32-fpic.s
===================================================================
--- test/ELF/x86-64-reloc-32-fpic.s
+++ test/ELF/x86-64-reloc-32-fpic.s
@@ -1,6 +1,7 @@
 # REQUIRES: x86
 # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
 # RUN: not ld.lld -shared %t.o -o %t.so 2>&1 | FileCheck %s
-# CHECK: relocation R_X86_64_32 cannot be used when making a shared object; recompile with -fPIC.
+# CHECK: R_X86_64_32 cannot be a dynamic relocation
 
+.data
 .long _shared


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D21184.60178.patch
Type: text/x-patch
Size: 1047 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160609/72c2ff3f/attachment.bin>


More information about the llvm-commits mailing list