[PATCH] D22990: [ELF] Implement R_ARM_TARGET1

Davide Italiano via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 29 18:57:00 PDT 2016


davide created this revision.
davide added a reviewer: ruiu.
davide added a subscriber: llvm-commits.
Herald added subscribers: samparker, rengolin, aemerson.

I hit this relocation while building some software for ARM and realized the support for that is a little bit weird. In fact, TARGET1 is interpreted as REL32 or ABS32 depending on if --target1-rel or --target1-abs is passed on the cmdline. The default behaviour seems to interpret the relocation as ABS if no option is passed.

https://reviews.llvm.org/D22990

Files:
  ELF/Config.h
  ELF/Driver.cpp
  ELF/Options.td
  ELF/Relocations.cpp
  ELF/Target.cpp
  ELF/Target.h

Index: ELF/Target.h
===================================================================
--- ELF/Target.h
+++ ELF/Target.h
@@ -27,6 +27,7 @@
   virtual bool isTlsLocalDynamicRel(uint32_t Type) const;
   virtual bool isTlsGlobalDynamicRel(uint32_t Type) const;
   virtual uint32_t getDynRel(uint32_t Type) const { return Type; }
+  virtual uint32_t modifyReloc(uint32_t Type) const { return Type; }
   virtual void writeGotPltHeader(uint8_t *Buf) const {}
   virtual void writeGotPlt(uint8_t *Buf, const SymbolBody &S) const {};
   virtual uint64_t getImplicitAddend(const uint8_t *Buf, uint32_t Type) const;
Index: ELF/Target.cpp
===================================================================
--- ELF/Target.cpp
+++ ELF/Target.cpp
@@ -177,6 +177,7 @@
   ARMTargetInfo();
   RelExpr getRelExpr(uint32_t Type, const SymbolBody &S) const override;
   uint32_t getDynRel(uint32_t Type) const override;
+  uint32_t modifyReloc(uint32_t Type) const override;
   uint64_t getImplicitAddend(const uint8_t *Buf, uint32_t Type) const override;
   bool isTlsLocalDynamicRel(uint32_t Type) const override;
   bool isTlsGlobalDynamicRel(uint32_t Type) const override;
@@ -1502,6 +1503,12 @@
   NeedsThunks = true;
 }
 
+uint32_t ARMTargetInfo::modifyReloc(uint32_t Type) const {
+  if (Type == R_ARM_TARGET1)
+    return (Config->Target1Rel) ? R_ARM_REL32 : R_ARM_ABS32;
+  return Type;
+}
+
 RelExpr ARMTargetInfo::getRelExpr(uint32_t Type, const SymbolBody &S) const {
   switch (Type) {
   default:
Index: ELF/Relocations.cpp
===================================================================
--- ELF/Relocations.cpp
+++ ELF/Relocations.cpp
@@ -535,7 +535,7 @@
   for (auto I = Rels.begin(), E = Rels.end(); I != E; ++I) {
     const RelTy &RI = *I;
     SymbolBody &Body = File.getRelocTargetSym(RI);
-    uint32_t Type = RI.getType(Config->Mips64EL);
+    uint32_t Type = Target->modifyReloc(RI.getType(Config->Mips64EL));
 
     RelExpr Expr = Target->getRelExpr(Type, Body);
     bool Preemptible = isPreemptible(Body, Type);
Index: ELF/Options.td
===================================================================
--- ELF/Options.td
+++ ELF/Options.td
@@ -146,6 +146,10 @@
 
 def sysroot: J<"sysroot=">, HelpText<"Set the system root">;
 
+def target1_rel: F<"target1-rel">, HelpText<"Interpret R_ARM_TARGET1 as R_ARM_REL32">;
+
+def target1_abs: F<"target1-abs">, HelpText<"Interpret R_ARM_TARGET1 as R_ARM_ABS32">;
+
 def threads: F<"threads">, HelpText<"Enable use of threads">;
 
 def trace: F<"trace">, HelpText<"Print the names of the input files">;
Index: ELF/Driver.cpp
===================================================================
--- ELF/Driver.cpp
+++ ELF/Driver.cpp
@@ -364,6 +364,7 @@
   Config->Shared = Args.hasArg(OPT_shared);
   Config->StripAll = Args.hasArg(OPT_strip_all);
   Config->StripDebug = Args.hasArg(OPT_strip_debug);
+  Config->Target1Rel = Args.hasArg(OPT_target1_rel);
   Config->Threads = Args.hasArg(OPT_threads);
   Config->Trace = Args.hasArg(OPT_trace);
   Config->Verbose = Args.hasArg(OPT_verbose);
Index: ELF/Config.h
===================================================================
--- ELF/Config.h
+++ ELF/Config.h
@@ -1,3 +1,4 @@
+
 //===- Config.h -------------------------------------------------*- C++ -*-===//
 //
 //                             The LLVM Linker
@@ -103,6 +104,7 @@
   bool StripAll;
   bool StripDebug;
   bool SysvHash = true;
+  bool Target1Rel;
   bool Threads;
   bool Trace;
   bool Verbose;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D22990.66211.patch
Type: text/x-patch
Size: 3471 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160730/f8065590/attachment.bin>


More information about the llvm-commits mailing list