[lld] r243560 - COFF: ARM: Fix relocations to thumb code.

Rui Ueyama ruiu at google.com
Wed Jul 29 12:25:01 PDT 2015


Author: ruiu
Date: Wed Jul 29 14:25:00 2015
New Revision: 243560

URL: http://llvm.org/viewvc/llvm-project?rev=243560&view=rev
Log:
COFF: ARM: Fix relocations to thumb code.

Windows ARM is the thumb ARM environment, and pointers to thumb code
needs to have its LSB set. When we apply relocations, we need to
adjust the LSB if it points to an executable section.

Modified:
    lld/trunk/COFF/Chunks.cpp
    lld/trunk/COFF/Symbols.h
    lld/trunk/COFF/Writer.cpp
    lld/trunk/test/COFF/armnt-mov32t-exec.test

Modified: lld/trunk/COFF/Chunks.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Chunks.cpp?rev=243560&r1=243559&r2=243560&view=diff
==============================================================================
--- lld/trunk/COFF/Chunks.cpp (original)
+++ lld/trunk/COFF/Chunks.cpp Wed Jul 29 14:25:00 2015
@@ -105,6 +105,9 @@ static void applyBranchImm(uint8_t *Off,
 void SectionChunk::applyRelARM(uint8_t *Off, uint16_t Type, Defined *Sym,
                                uint64_t P) {
   uint64_t S = Sym->getRVA();
+  // Pointer to thumb code must have the LSB set.
+  if (Sym->isExecutable())
+    S |= 1;
   switch (Type) {
   case IMAGE_REL_ARM_ADDR32:    add32(Off, S + Config->ImageBase); break;
   case IMAGE_REL_ARM_ADDR32NB:  add32(Off, S); break;

Modified: lld/trunk/COFF/Symbols.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Symbols.h?rev=243560&r1=243559&r2=243560&view=diff
==============================================================================
--- lld/trunk/COFF/Symbols.h (original)
+++ lld/trunk/COFF/Symbols.h Wed Jul 29 14:25:00 2015
@@ -138,6 +138,10 @@ public:
   // Returns the output section index.
   // Used to implement SECTION relocation type.
   uint64_t getSectionIndex();
+
+  // Returns true if this symbol points to an executable (e.g. .text) section.
+  // Used to implement ARM relocations.
+  bool isExecutable();
 };
 
 // Symbols defined via a COFF object file.

Modified: lld/trunk/COFF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Writer.cpp?rev=243560&r1=243559&r2=243560&view=diff
==============================================================================
--- lld/trunk/COFF/Writer.cpp (original)
+++ lld/trunk/COFF/Writer.cpp Wed Jul 29 14:25:00 2015
@@ -690,5 +690,12 @@ uint64_t Defined::getSectionIndex() {
   llvm::report_fatal_error("SECTION relocation points to a non-regular symbol");
 }
 
+bool Defined::isExecutable() {
+  const auto X = IMAGE_SCN_MEM_EXECUTE;
+  if (auto *D = dyn_cast<DefinedRegular>(this))
+    return D->getChunk()->getOutputSection()->getPermissions() & X;
+  return isa<DefinedImportThunk>(this);
+}
+
 } // namespace coff
 } // namespace lld

Modified: lld/trunk/test/COFF/armnt-mov32t-exec.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/armnt-mov32t-exec.test?rev=243560&r1=243559&r2=243560&view=diff
==============================================================================
--- lld/trunk/test/COFF/armnt-mov32t-exec.test (original)
+++ lld/trunk/test/COFF/armnt-mov32t-exec.test Wed Jul 29 14:25:00 2015
@@ -2,7 +2,7 @@
 
 # RUN: yaml2obj < %s > %t.obj
 # RUN: llvm-objdump -d %t.obj | FileCheck %s -check-prefix BEFORE
-# RUN: lld -flavor link /out:%t.exe /subsystem:console /entry:get_function %t.obj
+# RUN: lld -flavor link2 /out:%t.exe /subsystem:console /entry:get_function %t.obj
 # RUN: llvm-objdump -d %t.exe | FileCheck %s -check-prefix AFTER
 
 # BEFORE: Disassembly of section .text:





More information about the llvm-commits mailing list