[lld] r226246 - PE/COFF: use dyn_cast for the check of the target

Saleem Abdulrasool compnerd at compnerd.org
Thu Jan 15 20:14:34 PST 2015


Author: compnerd
Date: Thu Jan 15 22:14:33 2015
New Revision: 226246

URL: http://llvm.org/viewvc/llvm-project?rev=226246&view=rev
Log:
PE/COFF: use dyn_cast for the check of the target

The target may be a synthetic symbol like __ImageBase.  cast_or_null will ensure
that the atom is a DefinedAtom, which is not guaranteed, which was the original
reason for the cast_or_null.  Switch this to dyn_cast, which should enable
building of executables for WoA.  Unfortunately, the issue of missing base
relocations still needs to be investigated.

Added:
    lld/trunk/test/pecoff/Inputs/armnt-ImageBase.obj.yaml
    lld/trunk/test/pecoff/Inputs/armnt-ImageBase.s
    lld/trunk/test/pecoff/armnt-ImageBase.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=226246&r1=226245&r2=226246&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp Thu Jan 15 22:14:33 2015
@@ -588,7 +588,7 @@ void AtomChunk::applyRelocationsARM(uint
         continue;
 
       bool AssumeTHUMBCode = false;
-      if (auto Target = cast_or_null<DefinedAtom>(R->target()))
+      if (auto Target = dyn_cast<DefinedAtom>(R->target()))
         AssumeTHUMBCode = Target->permissions() == DefinedAtom::permR_X ||
                           Target->permissions() == DefinedAtom::permRWX;
 

Added: lld/trunk/test/pecoff/Inputs/armnt-ImageBase.obj.yaml
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/pecoff/Inputs/armnt-ImageBase.obj.yaml?rev=226246&view=auto
==============================================================================
--- lld/trunk/test/pecoff/Inputs/armnt-ImageBase.obj.yaml (added)
+++ lld/trunk/test/pecoff/Inputs/armnt-ImageBase.obj.yaml Thu Jan 15 22:14:33 2015
@@ -0,0 +1,39 @@
+---
+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:     7047FEDE00000000
+    Relocations:
+      - VirtualAddress:  4
+        SymbolName:      __ImageBase
+        Type:            1
+symbols:
+  - Name:            .text
+    Value:           0
+    SectionNumber:   1
+    SimpleType:      IMAGE_SYM_TYPE_NULL
+    ComplexType:     IMAGE_SYM_DTYPE_NULL
+    StorageClass:    IMAGE_SYM_CLASS_STATIC
+    SectionDefinition:
+      Length:          8
+      NumberOfRelocations: 1
+      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
+  - Name:            __ImageBase
+    Value:           0
+    SectionNumber:   0
+    SimpleType:      IMAGE_SYM_TYPE_NULL
+    ComplexType:     IMAGE_SYM_DTYPE_NULL
+    StorageClass:    IMAGE_SYM_CLASS_EXTERNAL
+...

Added: lld/trunk/test/pecoff/Inputs/armnt-ImageBase.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/pecoff/Inputs/armnt-ImageBase.s?rev=226246&view=auto
==============================================================================
--- lld/trunk/test/pecoff/Inputs/armnt-ImageBase.s (added)
+++ lld/trunk/test/pecoff/Inputs/armnt-ImageBase.s Thu Jan 15 22:14:33 2015
@@ -0,0 +1,16 @@
+
+	.syntax unified
+	.thumb
+	.text
+
+	.def mainCRTStartup
+		.type 32
+		.scl 2
+	.endef
+	.align 2
+	.thumb_func
+mainCRTStartup:
+	bx lr
+	trap
+	.long __ImageBase
+

Added: lld/trunk/test/pecoff/armnt-ImageBase.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/pecoff/armnt-ImageBase.test?rev=226246&view=auto
==============================================================================
--- lld/trunk/test/pecoff/armnt-ImageBase.test (added)
+++ lld/trunk/test/pecoff/armnt-ImageBase.test Thu Jan 15 22:14:33 2015
@@ -0,0 +1,14 @@
+# RUN: yaml2obj -format coff -o %t.obj %p/Inputs/armnt-ImageBase.obj.yaml
+# RUN: llvm-readobj -r %t.obj | FileCheck %s -check-prefix BEFORE
+# RUN: lld -flavor link /out:%t.exe %t.obj /subsystem:console
+# RUN: llvm-readobj -r %t.exe | FileCheck %s -check-prefix AFTER
+
+BEFORE: Relocations [
+BEFORE:   Section {{.*}} .text {
+BEFORE:     0x4 IMAGE_REL_ARM_ADDR32 __ImageBase
+BEFORE:   }
+BEFORE: ]
+
+AFTER: Relocations [
+AFTER-NEXT: ]
+





More information about the llvm-commits mailing list