[PATCH] ELF/ARM: Ignore R_ARM_V4BX but allow linking

Adhemerval Zanella adhemerval.zanella at linaro.org
Tue Apr 14 11:59:56 PDT 2015


Hi ruiu, shankar.easwaran,

This patch allow the ARM relocation R_ARM_V4BX to be processed by lld,
although it is not really handled in the static relocation code.  The
relocation is in the form:

Relocation section '.rel.text' at offset 0x428 contains 4 entries:
 Offset     Info    Type            Sym.Value  Sym. Name
00000014  00000028 R_ARM_V4BX

Meaning it does have a direct target, but rather references to an absolute
section *ABS* (in this exemple to the .text segment itself).  It makes the
target Atom after file parse to not have a associated pointer and thus
generating a derrefence NULL point in ELFFile<ELFT>::findAtom.  Current
approach is just ignore and return nullptr in such cases.

With this patch I can dynamically link an application against a GLIBC
arm-linux-gnueabi system.

I am not certainly that it is the right approach to handle this cases in arch-neutral
code, so I am more than willing to hear better suggestions.

http://reviews.llvm.org/D9020

Files:
  lib/ReaderWriter/ELF/ARM/ARMRelocationHandler.cpp
  lib/ReaderWriter/ELF/ELFFile.cpp
  lib/ReaderWriter/ELF/SectionChunks.h

Index: lib/ReaderWriter/ELF/ARM/ARMRelocationHandler.cpp
===================================================================
--- lib/ReaderWriter/ELF/ARM/ARMRelocationHandler.cpp
+++ lib/ReaderWriter/ELF/ARM/ARMRelocationHandler.cpp
@@ -514,7 +514,7 @@
 
   // Flags that the relocation addresses Thumb instruction
   bool thumb = false;
-  if (const auto *definedAtom = dyn_cast<DefinedAtom>(ref.target())) {
+  if (const auto *definedAtom = dyn_cast_or_null<DefinedAtom>(ref.target())) {
     thumb = isThumbCode(definedAtom);
   }
 
@@ -596,6 +596,9 @@
   case R_ARM_IRELATIVE:
     // Runtime only relocations. Ignore here.
     break;
+  case R_ARM_V4BX:
+    // TODO implement
+    break;
   default:
     return make_unhandled_reloc_error();
   }
Index: lib/ReaderWriter/ELF/ELFFile.cpp
===================================================================
--- lib/ReaderWriter/ELF/ELFFile.cpp
+++ lib/ReaderWriter/ELF/ELFFile.cpp
@@ -38,7 +38,7 @@
                               const Elf_Sym *targetSym) {
   // Return the atom for targetSym if we can do so.
   Atom *target = _symbolToAtomMapping.lookup(targetSym);
-  if (target->definition() != Atom::definitionRegular)
+  if (!target || target->definition() != Atom::definitionRegular)
     return target;
   Atom::Scope scope = llvm::cast<DefinedAtom>(target)->scope();
   if (scope == DefinedAtom::scopeTranslationUnit)
Index: lib/ReaderWriter/ELF/SectionChunks.h
===================================================================
--- lib/ReaderWriter/ELF/SectionChunks.h
+++ lib/ReaderWriter/ELF/SectionChunks.h
@@ -286,11 +286,14 @@
       kindValStr = "unknown";
     }
 
+    StringRef targetName = "undefined";
+    if (ref.target())
+      targetName = ref.target()->name();
     std::string errStr = (Twine(errorStr) + " in file " +
                           atom._atom->file().path() +
                           ": reference from " + atom._atom->name() +
                           "+" + Twine(ref.offsetInAtom()) +
-                          " to " + ref.target()->name() +
+                          " to " + targetName +
                           "+" + Twine(ref.addend()) +
                           " of type " + Twine(ref.kindValue()) +
                           " (" + kindValStr + ")\n").str();

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D9020.23739.patch
Type: text/x-patch
Size: 2280 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150414/1e5091a4/attachment.bin>


More information about the llvm-commits mailing list