[PATCH] D28516: [ELF] - Explicitly list supported relocations for x86 target.

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 10 07:40:10 PST 2017


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

Previously some value was returned by default for relocations by getRelExpr(),
even if relocation actually was not supported.

This is orthogonal alternative to https://reviews.llvm.org/D28094.
Instead of implementing probably useless R_386_PC8/R_386_8 relocations,
this patch uses them in a testcase to demonstrate what happens
when LLD mets unsupported relocations.

Patch passes all testcases and changes logic only for x86.
Patches for other targets can be posted separatelly.


https://reviews.llvm.org/D28516

Files:
  ELF/Target.cpp
  test/ELF/Inputs/unknown-reloc.s
  test/ELF/unknown-reloc.s


Index: test/ELF/unknown-reloc.s
===================================================================
--- test/ELF/unknown-reloc.s
+++ test/ELF/unknown-reloc.s
@@ -0,0 +1,14 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=i386-pc-linux-gnu %s -o %t1.o
+# RUN: llvm-mc -filetype=obj -triple=i386-pc-linux-gnu %S/Inputs/unknown-reloc.s -o %t2.o
+# RUN: not ld.lld %t1.o %t2.o -o %t.out 2>&1 | FileCheck %s
+
+# CHECK: do not know how to handle relocation R_386_PC8(23)
+# CHECK: do not know how to handle relocation R_386_8(22)
+
+.text
+.global foo
+foo:
+
+.byte und-foo
+.byte foo
Index: test/ELF/Inputs/unknown-reloc.s
===================================================================
--- test/ELF/Inputs/unknown-reloc.s
+++ test/ELF/Inputs/unknown-reloc.s
@@ -0,0 +1,2 @@
+.global und
+und:
Index: ELF/Target.cpp
===================================================================
--- ELF/Target.cpp
+++ ELF/Target.cpp
@@ -356,7 +356,9 @@
 
 RelExpr X86TargetInfo::getRelExpr(uint32_t Type, const SymbolBody &S) const {
   switch (Type) {
-  default:
+  case R_386_16:
+  case R_386_32:
+  case R_386_TLS_LDO_32:
     return R_ABS;
   case R_386_TLS_GD:
     return R_TLSGD;
@@ -381,6 +383,10 @@
     return R_TLS;
   case R_386_TLS_LE_32:
     return R_NEG_TLS;
+  default:
+    error("do not know how to handle relocation " + toString(Type) + "(" +
+          Twine(Type) + ")");
+    return R_HINT;
   }
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D28516.83807.patch
Type: text/x-patch
Size: 1425 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170110/9df8b44b/attachment.bin>


More information about the llvm-commits mailing list