[lld] r241658 - COFF: Fix AMD64_SECTION relocation.

Rui Ueyama ruiu at google.com
Tue Jul 7 18:47:28 PDT 2015


Author: ruiu
Date: Tue Jul  7 20:47:28 2015
New Revision: 241658

URL: http://llvm.org/viewvc/llvm-project?rev=241658&view=rev
Log:
COFF: Fix AMD64_SECTION relocation.

Added:
    lld/trunk/test/COFF/reloc-x64.test
Modified:
    lld/trunk/COFF/Chunks.cpp

Modified: lld/trunk/COFF/Chunks.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Chunks.cpp?rev=241658&r1=241657&r2=241658&view=diff
==============================================================================
--- lld/trunk/COFF/Chunks.cpp (original)
+++ lld/trunk/COFF/Chunks.cpp Tue Jul  7 20:47:28 2015
@@ -60,7 +60,7 @@ void SectionChunk::applyRelX64(uint8_t *
   case IMAGE_REL_AMD64_REL32_3:  add32(Off, S - P - 7); break;
   case IMAGE_REL_AMD64_REL32_4:  add32(Off, S - P - 8); break;
   case IMAGE_REL_AMD64_REL32_5:  add32(Off, S - P - 9); break;
-  case IMAGE_REL_AMD64_SECTION:  add16(Off, Out->getSectionIndex()); break;
+  case IMAGE_REL_AMD64_SECTION:  add16(Off, Out->getSectionIndex() + 1); break;
   case IMAGE_REL_AMD64_SECREL:   add32(Off, S - Out->getRVA()); break;
   default:
     llvm::report_fatal_error("Unsupported relocation type");

Added: lld/trunk/test/COFF/reloc-x64.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/reloc-x64.test?rev=241658&view=auto
==============================================================================
--- lld/trunk/test/COFF/reloc-x64.test (added)
+++ lld/trunk/test/COFF/reloc-x64.test Tue Jul  7 20:47:28 2015
@@ -0,0 +1,79 @@
+# RUN: yaml2obj < %s > %t.obj
+# RUN: lld -flavor link2 /out:%t.exe /entry:main %t.obj
+# RUN: llvm-objdump -d %t.exe | FileCheck %s
+
+# CHECK: .text:
+# CHECK: 1000: a1 00 10 00 40 00 00 00 00
+# CHECK: 1009: a1 00 10 00 40 01 00 00 00
+# CHECK: 1012: a1 00 10 00 00 00 00 00 00
+# CHECK: 101b: a1 e0 ff ff ff 00 00 00 00
+# CHECK: 1024: a1 d6 ff ff ff 00 00 00 00
+# CHECK: 102d: a1 cc ff ff ff 00 00 00 00
+# CHECK: 1036: a1 c2 ff ff ff 00 00 00 00
+# CHECK: 103f: a1 b8 ff ff ff 00 00 00 00
+# CHECK: 1048: a1 ae ff ff ff 00 00 00 00
+# CHECK: 1051: a1 01 00 00 00 00 00 00 00
+
+---
+header:
+  Machine:         IMAGE_FILE_MACHINE_AMD64
+  Characteristics: []
+sections:
+  - Name:            .text
+    Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
+    Alignment:       4096
+    SectionData:     A10000000000000000A10000000000000000A10000000000000000A10000000000000000A10000000000000000A10000000000000000A10000000000000000A10000000000000000A10000000000000000A10000000000000000
+    Relocations:
+      - VirtualAddress:  1
+        SymbolName:      main
+        Type:            IMAGE_REL_AMD64_ADDR32
+      - VirtualAddress:  10
+        SymbolName:      main
+        Type:            IMAGE_REL_AMD64_ADDR64
+      - VirtualAddress:  19
+        SymbolName:      main
+        Type:            IMAGE_REL_AMD64_ADDR32NB
+      - VirtualAddress:  28
+        SymbolName:      main
+        Type:            IMAGE_REL_AMD64_REL32
+      - VirtualAddress:  37
+        SymbolName:      main
+        Type:            IMAGE_REL_AMD64_REL32_1
+      - VirtualAddress:  46
+        SymbolName:      main
+        Type:            IMAGE_REL_AMD64_REL32_2
+      - VirtualAddress:  55
+        SymbolName:      main
+        Type:            IMAGE_REL_AMD64_REL32_3
+      - VirtualAddress:  64
+        SymbolName:      main
+        Type:            IMAGE_REL_AMD64_REL32_4
+      - VirtualAddress:  73
+        SymbolName:      main
+        Type:            IMAGE_REL_AMD64_REL32_5
+      - VirtualAddress:  82
+        SymbolName:      main
+        Type:            IMAGE_REL_AMD64_SECTION
+      - VirtualAddress:  91
+        SymbolName:      main
+        Type:            IMAGE_REL_AMD64_SECREL
+symbols:
+  - Name:            .text
+    Value:           0
+    SectionNumber:   1
+    SimpleType:      IMAGE_SYM_TYPE_NULL
+    ComplexType:     IMAGE_SYM_DTYPE_NULL
+    StorageClass:    IMAGE_SYM_CLASS_STATIC
+    SectionDefinition:
+      Length:          6
+      NumberOfRelocations: 0
+      NumberOfLinenumbers: 0
+      CheckSum:        0
+      Number:          0
+  - Name:            main
+    Value:           0
+    SectionNumber:   1
+    SimpleType:      IMAGE_SYM_TYPE_NULL
+    ComplexType:     IMAGE_SYM_DTYPE_NULL
+    StorageClass:    IMAGE_SYM_CLASS_EXTERNAL
+...





More information about the llvm-commits mailing list