[lld] r225139 - PECOFF: adjust the entry point on ARM NT

Saleem Abdulrasool compnerd at compnerd.org
Sun Jan 4 12:26:46 PST 2015


Author: compnerd
Date: Sun Jan  4 14:26:45 2015
New Revision: 225139

URL: http://llvm.org/viewvc/llvm-project?rev=225139&view=rev
Log:
PECOFF: adjust the entry point on ARM NT

ARM NT assumes a purely THUMB execution, and as such requires that the address
of entry point is adjusted to indicate a thumb entry point.  Unconditionally
adjust the AddressOfEntryPoint in the PE header for PE/COFF ARM as we only
support ARM NT at the moment.

Added:
    lld/trunk/test/pecoff/Inputs/executable.obj.yaml
    lld/trunk/test/pecoff/Inputs/executable.s
    lld/trunk/test/pecoff/armnt-address-of-entry-point.test
Modified:
    lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp

Modified: lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp?rev=225139&r1=225138&r2=225139&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp Sun Jan  4 14:26:45 2015
@@ -1160,11 +1160,17 @@ void PECOFFWriter::build(const File &lin
       // says that entry point for dll images is optional, in which case it must
       // be set to 0.
       if (_ctx.hasEntry()) {
+        AtomChunk *atom = cast<AtomChunk>(section);
         uint64_t entryPointAddress =
-            dyn_cast<AtomChunk>(section)
-                ->getAtomVirtualAddress(_ctx.getEntrySymbolName());
-        if (entryPointAddress != 0)
+            atom->getAtomVirtualAddress(_ctx.getEntrySymbolName());
+
+        if (entryPointAddress) {
+          // NOTE: ARM NT assumes a pure THUMB execution, so adjust the entry
+          // point accordingly
+          if (_ctx.getMachineType() == llvm::COFF::IMAGE_FILE_MACHINE_ARMNT)
+            entryPointAddress |= 1;
           peHeader->setAddressOfEntryPoint(entryPointAddress);
+        }
       } else {
         peHeader->setAddressOfEntryPoint(0);
       }

Added: lld/trunk/test/pecoff/Inputs/executable.obj.yaml
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/pecoff/Inputs/executable.obj.yaml?rev=225139&view=auto
==============================================================================
--- lld/trunk/test/pecoff/Inputs/executable.obj.yaml (added)
+++ lld/trunk/test/pecoff/Inputs/executable.obj.yaml Sun Jan  4 14:26:45 2015
@@ -0,0 +1,29 @@
+---
+header:
+  Machine:         IMAGE_FILE_MACHINE_ARMNT
+  Characteristics: [  ]
+sections:
+  - Name:            .text
+    Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_PURGEABLE, IMAGE_SCN_MEM_16BIT, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
+    Alignment:       4
+    SectionData:     '7047'
+symbols:
+  - Name:            .text
+    Value:           0
+    SectionNumber:   1
+    SimpleType:      IMAGE_SYM_TYPE_NULL
+    ComplexType:     IMAGE_SYM_DTYPE_NULL
+    StorageClass:    IMAGE_SYM_CLASS_STATIC
+    SectionDefinition:
+      Length:          2
+      NumberOfRelocations: 0
+      NumberOfLinenumbers: 0
+      CheckSum:        0
+      Number:          1
+  - Name:            mainCRTStartup
+    Value:           0
+    SectionNumber:   1
+    SimpleType:      IMAGE_SYM_TYPE_NULL
+    ComplexType:     IMAGE_SYM_DTYPE_FUNCTION
+    StorageClass:    IMAGE_SYM_CLASS_EXTERNAL
+...

Added: lld/trunk/test/pecoff/Inputs/executable.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/pecoff/Inputs/executable.s?rev=225139&view=auto
==============================================================================
--- lld/trunk/test/pecoff/Inputs/executable.s (added)
+++ lld/trunk/test/pecoff/Inputs/executable.s Sun Jan  4 14:26:45 2015
@@ -0,0 +1,17 @@
+
+# void mainCRTStartup(){}
+
+	.syntax unified
+	.thumb
+	.text
+
+	.def mainCRTStartup
+		.scl 2
+		.type 32
+	.endef
+	.global mainCRTStartup
+	.align 2
+	.thumb_func
+mainCRTStartup:
+	bx lr
+

Added: lld/trunk/test/pecoff/armnt-address-of-entry-point.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/pecoff/armnt-address-of-entry-point.test?rev=225139&view=auto
==============================================================================
--- lld/trunk/test/pecoff/armnt-address-of-entry-point.test (added)
+++ lld/trunk/test/pecoff/armnt-address-of-entry-point.test Sun Jan  4 14:26:45 2015
@@ -0,0 +1,6 @@
+# RUN: yaml2obj -format coff -o %t.obj %p/Inputs/executable.obj.yaml
+# RUN: lld -flavor link /out:%t.exe %t.obj
+# RUN: llvm-readobj -file-headers %t.exe | FileCheck %s
+
+# CHECK: AddressOfEntryPoint: 0x1001
+





More information about the llvm-commits mailing list