-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[LLD][COFF] Append a terminator entry to redirection metadata #115202
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
For MSVC compatibility.
@llvm/pr-subscribers-lld-coff @llvm/pr-subscribers-lld Author: Jacek Caban (cjacek) ChangesFor MSVC compatibility. Patch is 22.41 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/115202.diff 10 Files Affected:
diff --git a/lld/COFF/Chunks.cpp b/lld/COFF/Chunks.cpp
index 33fb20ffeaf321..a82e37ff052303 100644
--- a/lld/COFF/Chunks.cpp
+++ b/lld/COFF/Chunks.cpp
@@ -1083,7 +1083,8 @@ void CHPECodeRangesChunk::writeTo(uint8_t *buf) const {
}
size_t CHPERedirectionChunk::getSize() const {
- return exportThunks.size() * sizeof(chpe_redirection_entry);
+ // Add an extra +1 for a terminator entry.
+ return (exportThunks.size() + 1) * sizeof(chpe_redirection_entry);
}
void CHPERedirectionChunk::writeTo(uint8_t *buf) const {
diff --git a/lld/test/COFF/arm64ec-altnames.s b/lld/test/COFF/arm64ec-altnames.s
index fb28ae15895f98..b2abb24efe4c32 100644
--- a/lld/test/COFF/arm64ec-altnames.s
+++ b/lld/test/COFF/arm64ec-altnames.s
@@ -17,7 +17,7 @@ DISASM-NEXT: 180001004: d65f03c0 ret
DISASM-NOT: .thnk
RUN: llvm-readobj --hex-dump=.test out1.dll | FileCheck --check-prefix=TESTSEC %s
-TESTSEC: 0x180004000 00100000 00100000
+TESTSEC: 0x180005000 00100000 00100000
# Ensure -alternatename can change a demangled function symbol aliasing an anti-dependency symbol.
@@ -32,12 +32,12 @@ DISASM2-NEXT: 180001004: d65f03c0 ret
DISASM2-EMPTY:
DISASM2-NEXT: Disassembly of section .thnk:
DISASM2-EMPTY:
-DISASM2-NEXT: 0000000180005000 <.thnk>:
-DISASM2-NEXT: 180005000: 52800040 mov w0, #0x2 // =2
-DISASM2-NEXT: 180005004: d65f03c0 ret
+DISASM2-NEXT: 0000000180006000 <.thnk>:
+DISASM2-NEXT: 180006000: 52800040 mov w0, #0x2 // =2
+DISASM2-NEXT: 180006004: d65f03c0 ret
RUN: llvm-readobj --hex-dump=.test out2.dll | FileCheck --check-prefix=TESTSEC2 %s
-TESTSEC2: 0x180004000 00100000 00500000
+TESTSEC2: 0x180005000 00100000 00600000
# Ensure -alternatename cannot modify a demangled function symbol aliasing a defined symbol.
diff --git a/lld/test/COFF/arm64ec-codemap.test b/lld/test/COFF/arm64ec-codemap.test
index 7f4d5d84b458e1..6e97c14e87d862 100644
--- a/lld/test/COFF/arm64ec-codemap.test
+++ b/lld/test/COFF/arm64ec-codemap.test
@@ -20,8 +20,8 @@ RUN: llvm-readobj --coff-load-config test.dll | FileCheck -check-prefix=CODEMAP
CODEMAP: CodeMap [
CODEMAP-NEXT: 0x1000 - 0x1008 ARM64EC
CODEMAP-NEXT: 0x2000 - 0x2006 X64
-CODEMAP-NEXT: 0x5000 - 0x5008 ARM64EC
-CODEMAP-NEXT: 0x6000 - 0x6006 X64
+CODEMAP-NEXT: 0x6000 - 0x6008 ARM64EC
+CODEMAP-NEXT: 0x7000 - 0x7006 X64
CODEMAP-NEXT: ]
RUN: llvm-objdump -d test.dll | FileCheck -check-prefix=DISASM %s
@@ -36,12 +36,12 @@ DISASM-NEXT: 180002005: c3 retq
DISASM-EMPTY:
DISASM-NEXT: Disassembly of section test:
DISASM-EMPTY:
-DISASM-NEXT: 0000000180005000 <test>:
-DISASM-NEXT: 180005000: 528000a0 mov w0, #0x5
-DISASM-NEXT: 180005004: d65f03c0 ret
+DISASM-NEXT: 0000000180006000 <test>:
+DISASM-NEXT: 180006000: 528000a0 mov w0, #0x5
+DISASM-NEXT: 180006004: d65f03c0 ret
DISASM-NEXT: ...
-DISASM-NEXT: 180006000: b8 06 00 00 00 movl $0x6, %eax
-DISASM-NEXT: 180006005: c3 retq
+DISASM-NEXT: 180007000: b8 06 00 00 00 movl $0x6, %eax
+DISASM-NEXT: 180007005: c3 retq
Order of arguments doesn't matter in this case, chunks are sorted by target type anyway.
@@ -66,8 +66,8 @@ CODEMAPX: CodeMap [
CODEMAPX-NEXT: 0x1000 - 0x1008 ARM64
CODEMAPX-NEXT: 0x2000 - 0x2008 ARM64EC
CODEMAPX-NEXT: 0x3000 - 0x3006 X64
-CODEMAPX-NEXT: 0x6000 - 0x6008 ARM64EC
-CODEMAPX-NEXT: 0x7000 - 0x7006 X64
+CODEMAPX-NEXT: 0x7000 - 0x7008 ARM64EC
+CODEMAPX-NEXT: 0x8000 - 0x8006 X64
CODEMAPX-NEXT: ]
RUN: llvm-objdump -d testx.dll | FileCheck -check-prefix=DISASMX %s
@@ -85,12 +85,12 @@ DISASMX-NEXT: 180003005: c3 retq
DISASMX-EMPTY:
DISASMX-NEXT: Disassembly of section test:
DISASMX-EMPTY:
-DISASMX-NEXT: 0000000180006000 <test>:
-DISASMX-NEXT: 180006000: 528000a0 mov w0, #0x5
-DISASMX-NEXT: 180006004: d65f03c0 ret
+DISASMX-NEXT: 0000000180007000 <test>:
+DISASMX-NEXT: 180007000: 528000a0 mov w0, #0x5
+DISASMX-NEXT: 180007004: d65f03c0 ret
DISASMX-NEXT: ...
-DISASMX-NEXT: 180007000: b8 06 00 00 00 movl $0x6, %eax
-DISASMX-NEXT: 180007005: c3 retq
+DISASMX-NEXT: 180008000: b8 06 00 00 00 movl $0x6, %eax
+DISASMX-NEXT: 180008005: c3 retq
Test merged sections.
@@ -127,8 +127,8 @@ RUN: llvm-readobj --coff-load-config testdm.dll | FileCheck -check-prefix=CODEMA
CODEMAPDM: CodeMap [
CODEMAPDM-NEXT: 0x2000 - 0x2008 ARM64EC
CODEMAPDM-NEXT: 0x3000 - 0x3006 X64
-CODEMAPDM-NEXT: 0x6000 - 0x6008 ARM64EC
-CODEMAPDM-NEXT: 0x7000 - 0x7006 X64
+CODEMAPDM-NEXT: 0x7000 - 0x7008 ARM64EC
+CODEMAPDM-NEXT: 0x8000 - 0x8006 X64
CODEMAPDM-NEXT: ]
RUN: llvm-objdump -d testdm.dll | FileCheck -check-prefix=DISASMDM %s
@@ -147,12 +147,12 @@ DISASMDM-NEXT: 180003005: c3 retq
DISASMDM-EMPTY:
DISASMDM-NEXT: Disassembly of section test:
DISASMDM-EMPTY:
-DISASMDM-NEXT: 0000000180005000 <test>:
-DISASMDM: 180006000: 528000a0 mov w0, #0x5
-DISASMDM-NEXT: 180006004: d65f03c0 ret
+DISASMDM-NEXT: 0000000180006000 <test>:
+DISASMDM: 180007000: 528000a0 mov w0, #0x5
+DISASMDM-NEXT: 180007004: d65f03c0 ret
DISASMDM-NEXT: ...
-DISASMDM-NEXT: 180007000: b8 06 00 00 00 movl $0x6, %eax
-DISASMDM-NEXT: 180007005: c3 retq
+DISASMDM-NEXT: 180008000: b8 06 00 00 00 movl $0x6, %eax
+DISASMDM-NEXT: 180008005: c3 retq
Merging a code section into data section produces a valid code map.
@@ -161,20 +161,20 @@ RUN: loadconfig-arm64ec.obj -dll -noentry -merge:test=.testdata -merge:
RUN: llvm-readobj --coff-load-config testcm.dll | FileCheck -check-prefix=CODEMAPCM %s
CODEMAPCM: CodeMap [
-CODEMAPCM-NEXT: 0x3008 - 0x3016 X64
+CODEMAPCM-NEXT: 0x4008 - 0x4016 X64
CODEMAPCM-NEXT: ]
RUN: llvm-objdump -d testcm.dll | FileCheck -check-prefix=DISASMCM %s
DISASMCM: Disassembly of section .testdat:
DISASMCM-EMPTY:
-DISASMCM-NEXT: 0000000180003000 <.testdat>:
-DISASMCM-NEXT: 180003000: 00000001 udf #0x1
-DISASMCM-NEXT: 180003004: 00000000 udf #0x0
-DISASMCM-NEXT: 180003008: b8 03 00 00 00 movl $0x3, %eax
-DISASMCM-NEXT: 18000300d: c3 retq
-DISASMCM-NEXT: 18000300e: 00 00 addb %al, (%rax)
-DISASMCM-NEXT: 180003010: b8 06 00 00 00 movl $0x6, %eax
-DISASMCM-NEXT: 180003015: c3
+DISASMCM-NEXT: 0000000180004000 <.testdat>:
+DISASMCM-NEXT: 180004000: 00000001 udf #0x1
+DISASMCM-NEXT: 180004004: 00000000 udf #0x0
+DISASMCM-NEXT: 180004008: b8 03 00 00 00 movl $0x3, %eax
+DISASMCM-NEXT: 18000400d: c3 retq
+DISASMCM-NEXT: 18000400e: 00 00 addb %al, (%rax)
+DISASMCM-NEXT: 180004010: b8 06 00 00 00 movl $0x6, %eax
+DISASMCM-NEXT: 180004015: c3
Test code map range entry spanning over multiple sections.
@@ -184,7 +184,7 @@ RUN: loadconfig-arm64ec.obj -dll -noentry
RUN: llvm-readobj --coff-load-config testms.dll | FileCheck -check-prefix=CODEMAPMS %s
CODEMAPMS: CodeMap [
CODEMAPMS-NEXT: 0x1000 - 0x1008 ARM64EC
-CODEMAPMS-NEXT: 0x4000 - 0x5008 ARM64EC
+CODEMAPMS-NEXT: 0x5000 - 0x6008 ARM64EC
CODEMAPMS-NEXT: ]
RUN: llvm-objdump -d testms.dll | FileCheck -check-prefix=DISASMMS %s
@@ -196,15 +196,15 @@ DISASMMS-NEXT: 180001004: d65f03c0 ret
DISASMMS-EMPTY:
DISASMMS-NEXT: Disassembly of section test:
DISASMMS-EMPTY:
-DISASMMS-NEXT: 0000000180004000 <test>:
-DISASMMS-NEXT: 180004000: 528000a0 mov w0, #0x5 // =5
-DISASMMS-NEXT: 180004004: d65f03c0 ret
+DISASMMS-NEXT: 0000000180005000 <test>:
+DISASMMS-NEXT: 180005000: 528000a0 mov w0, #0x5 // =5
+DISASMMS-NEXT: 180005004: d65f03c0 ret
DISASMMS-EMPTY:
DISASMMS-NEXT: Disassembly of section test2:
DISASMMS-EMPTY:
-DISASMMS-NEXT: 0000000180005000 <test2>:
-DISASMMS-NEXT: 180005000: 528000a0 mov w0, #0x5 // =5
-DISASMMS-NEXT: 180005004: d65f03c0 ret
+DISASMMS-NEXT: 0000000180006000 <test2>:
+DISASMMS-NEXT: 180006000: 528000a0 mov w0, #0x5 // =5
+DISASMMS-NEXT: 180006004: d65f03c0 ret
#--- arm64-func-sym.s
diff --git a/lld/test/COFF/arm64ec-delayimport.test b/lld/test/COFF/arm64ec-delayimport.test
index 6797d84e088686..0c8009362f80e7 100644
--- a/lld/test/COFF/arm64ec-delayimport.test
+++ b/lld/test/COFF/arm64ec-delayimport.test
@@ -12,9 +12,9 @@ RUN: lld-link -machine:arm64ec -dll -noentry -out:out.dll loadconfig-arm64ec.obj
RUN: helper-mangled.obj test-arm64ec.lib test2-arm64ec.lib -delayload:test.dll -map
RUN: llvm-readobj --hex-dump=.test out.dll | FileCheck --check-prefix=TESTSEC %s
-TESTSEC: 0x180008000 00600000 88700000 00200000 10100000
-TESTSEC-NEXT: 0x180008010 08600000 90700000 10200000 30100000
-TESTSEC-NEXT: 0x180008020 1c100000 3c100000 00300000
+TESTSEC: 0x180009000 00600000 88700000 00200000 10100000
+TESTSEC-NEXT: 0x180009010 08600000 90700000 10200000 30100000
+TESTSEC-NEXT: 0x180009020 1c100000 3c100000 00300000
RUN: llvm-objdump -d out.dll | FileCheck --check-prefix=DISASM %s
DISASM: 0000000180001000 <.text>:
diff --git a/lld/test/COFF/arm64ec-export-thunks.test b/lld/test/COFF/arm64ec-export-thunks.test
index 809fac1f24a7dc..f84d21d27e9a6c 100644
--- a/lld/test/COFF/arm64ec-export-thunks.test
+++ b/lld/test/COFF/arm64ec-export-thunks.test
@@ -70,7 +70,7 @@ EXP-CHPE-NEXT: ]
RUN: llvm-readobj --sections exports.dll | FileCheck --check-prefix=A64XRM %s
A64XRM: Name: .a64xrm (2E 61 36 34 78 72 6D 00)
-A64XRM-NEXT: VirtualSize: 0x10
+A64XRM-NEXT: VirtualSize: 0x18
A64XRM-NEXT: VirtualAddress: 0x6000
A64XRM-NEXT: RawDataSize: 512
A64XRM-NEXT: PointerToRawData:
@@ -83,6 +83,11 @@ A64XRM-NEXT: IMAGE_SCN_CNT_INITIALIZED_DATA (0x40)
A64XRM-NEXT: IMAGE_SCN_MEM_READ (0x40000000)
A64XRM-NEXT: ]
+RUN: llvm-readobj --hex-dump=.a64xrm exports.dll | FileCheck --check-prefix=A64XRM-DUMP %s
+
+A64XRM-DUMP: 0x180006000 00300000 00100000 10300000 00100000
+A64XRM-DUMP-NEXT: 0x180006010 00000000 00000000
+
RUN: llvm-objdump -s --section=.test exports.dll | FileCheck --check-prefix=EXP-DATA %s
EXP-DATA: 180007000 00300000 10300000
@@ -138,13 +143,13 @@ RUN: lld-link -out:data-func.dll -machine:arm64ec arm64ec-data-sym.obj loadconfi
RUN: llvm-readobj --hex-dump=.test data-func.dll | FileCheck --check-prefix=DATAFUNC-TEST %s
DATAFUNC-TEST: Hex dump of section '.test':
-DATAFUNC-TEST-NEXT: 0x180003000 00000000 ....
+DATAFUNC-TEST-NEXT: 0x180004000 00000000 ....
RUN: llvm-readobj --coff-exports --hex-dump=.test data-func.dll | FileCheck --check-prefix=DATAFUNC-EXP %s
DATAFUNC-EXP: Export {
DATAFUNC-EXP-NEXT: Ordinal: 1
DATAFUNC-EXP-NEXT: Name: data_sym
-DATAFUNC-EXP-NEXT: RVA: 0x3000
+DATAFUNC-EXP-NEXT: RVA: 0x4000
DATAFUNC-EXP-NEXT: }
diff --git a/lld/test/COFF/arm64ec-import.test b/lld/test/COFF/arm64ec-import.test
index 9cf09143229410..033c27884be02c 100644
--- a/lld/test/COFF/arm64ec-import.test
+++ b/lld/test/COFF/arm64ec-import.test
@@ -76,16 +76,16 @@ DISASM-NEXT: 180002000: ff 25 02 10 00 00 jmpq *0x1002(%rip)
RUN: llvm-readobj --hex-dump=.test out.dll | FileCheck --check-prefix=TESTSEC %s
RUN: llvm-readobj --hex-dump=.test out2.dll | FileCheck --check-prefix=TESTSEC %s
-TESTSEC: 0x180007000 08500000 00300000 10500000 20500000
-TESTSEC-NEXT: 0x180007010 08300000 00500000 10300000 20300000
-TESTSEC-NEXT: 0x180007020 14100000 28100000 00200000 08100000
-TESTSEC-NEXT: 0x180007030 3c100000 88420000
+TESTSEC: 0x180008000 08500000 00300000 10500000 20500000
+TESTSEC-NEXT: 0x180008010 08300000 00500000 10300000 20300000
+TESTSEC-NEXT: 0x180008020 14100000 28100000 00200000 08100000
+TESTSEC-NEXT: 0x180008030 3c100000 88420000
RUN: llvm-readobj --hex-dump=.test out3.dll | FileCheck -check-prefix=TESTSEC-X64 %s
-TESTSEC-X64: 0x180007000 08300000 00300000 10300000 20300000
-TESTSEC-X64-NEXT: 0x180007010 08300000 00500000 10300000 20300000
-TESTSEC-X64-NEXT: 0x180007020 14100000 28100000 00200000 08100000
-TESTSEC-X64-NEXT: 0x180007030 3c100000 88420000
+TESTSEC-X64: 0x180008000 08300000 00300000 10300000 20300000
+TESTSEC-X64-NEXT: 0x180008010 08300000 00500000 10300000 20300000
+TESTSEC-X64-NEXT: 0x180008020 14100000 28100000 00200000 08100000
+TESTSEC-X64-NEXT: 0x180008030 3c100000 88420000
RUN: FileCheck --check-prefix=MAP %s < out.map
RUN: FileCheck --check-prefix=MAP %s < out2.map
diff --git a/lld/test/COFF/arm64ec-lib.test b/lld/test/COFF/arm64ec-lib.test
index 075854f62d5d42..9dff23022f9eef 100644
--- a/lld/test/COFF/arm64ec-lib.test
+++ b/lld/test/COFF/arm64ec-lib.test
@@ -41,7 +41,7 @@ DISASM-NEXT: 180001000: d65f03c0 ret
DISASM-EMPTY:
RUN: llvm-readobj --hex-dump=.test ref-alias-1.dll | FileCheck -check-prefix=TESTSEC %s
-TESTSEC: 0x180004000 00100000
+TESTSEC: 0x180005000 00100000
The same test, but with a different input order.
RUN: lld-link -machine:arm64ec -dll -noentry -out:ref-alias-2.dll func.lib ref-alias.obj loadconfig-arm64ec.obj
diff --git a/lld/test/COFF/arm64ec-loadcfg.s b/lld/test/COFF/arm64ec-loadcfg.s
index d7df96334313d5..65a0e52bd86524 100644
--- a/lld/test/COFF/arm64ec-loadcfg.s
+++ b/lld/test/COFF/arm64ec-loadcfg.s
@@ -30,7 +30,10 @@
# LOADCFG-NEXT: ]
# RUN: llvm-readobj --hex-dump=.test %t.dll | FileCheck --check-prefix=TEST %s
-# TEST: 0x180003000 00000000 00000000 00000000
+# TEST: 0x180004000 00000000 00000000 00000000
+
+# RUN: llvm-readobj --hex-dump=.a64xrm %t.dll | FileCheck --check-prefix=A64XRM %s
+# A64XRM: 0x180003000 00000000 00000000 ........
.section .test,"dr"
.rva __arm64x_native_entrypoint
diff --git a/lld/test/COFF/arm64ec-range-thunks.s b/lld/test/COFF/arm64ec-range-thunks.s
index 71bf0e34bd70e3..f170349d7965d1 100644
--- a/lld/test/COFF/arm64ec-range-thunks.s
+++ b/lld/test/COFF/arm64ec-range-thunks.s
@@ -19,41 +19,41 @@
# DISASM: Disassembly of section .code1:
# DISASM-EMPTY:
-# DISASM-NEXT: 0000000180003000 <.code1>:
-# DISASM-NEXT: 180003000: 36000040 tbz w0, #0x0, 0x180003008 <.code1+0x8>
-# DISASM-NEXT: 180003004: d65f03c0 ret
-# DISASM-NEXT: 180003008: b0000050 adrp x16, 0x18000c000
-# DISASM-NEXT: 18000300c: 91000210 add x16, x16, #0x0
-# DISASM-NEXT: 180003010: d61f0200 br x16
+# DISASM-NEXT: 0000000180004000 <.code1>:
+# DISASM-NEXT: 180004000: 36000040 tbz w0, #0x0, 0x180004008 <.code1+0x8>
+# DISASM-NEXT: 180004004: d65f03c0 ret
+# DISASM-NEXT: 180004008: b0000050 adrp x16, 0x18000d000
+# DISASM-NEXT: 18000400c: 91000210 add x16, x16, #0x0
+# DISASM-NEXT: 180004010: d61f0200 br x16
# DISASM-EMPTY:
# DISASM-NEXT: Disassembly of section .code2:
# DISASM-EMPTY:
-# DISASM-NEXT: 0000000180004000 <.code2>:
+# DISASM-NEXT: 0000000180005000 <.code2>:
# DISASM-NEXT: ...
# DISASM-EMPTY:
# DISASM-NEXT: Disassembly of section .code3:
# DISASM-EMPTY:
-# DISASM-NEXT: 0000000180005000 <.code3>:
+# DISASM-NEXT: 0000000180006000 <.code3>:
# DISASM-NEXT: ...
-# DISASM-NEXT: 18000c000: 36000060 tbz w0, #0x0, 0x18000c00c <.code3+0x700c>
-# DISASM-NEXT: 18000c004: d65f03c0 ret
-# DISASM-NEXT: 18000c008: 00000000 udf #0x0
-# DISASM-NEXT: 18000c00c: 90000050 adrp x16, 0x180014000 <.code3+0xf000>
-# DISASM-NEXT: 18000c010: 91006210 add x16, x16, #0x18
-# DISASM-NEXT: 18000c014: d61f0200 br x16
+# DISASM-NEXT: 18000d000: 36000060 tbz w0, #0x0, 0x18000d00c <.code3+0x700c>
+# DISASM-NEXT: 18000d004: d65f03c0 ret
+# DISASM-NEXT: 18000d008: 00000000 udf #0x0
+# DISASM-NEXT: 18000d00c: 90000050 adrp x16, 0x180015000 <.code3+0xf000>
+# DISASM-NEXT: 18000d010: 91006210 add x16, x16, #0x18
+# DISASM-NEXT: 18000d014: d61f0200 br x16
# DISASM-NEXT: ...
-# DISASM-NEXT: 180014018: 36000040 tbz w0, #0x0, 0x180014020 <.code3+0xf020>
-# DISASM-NEXT: 18001401c: d65f03c0 ret
-# DISASM-NEXT: 180014020: f0ffff70 adrp x16, 0x180003000 <.code1>
-# DISASM-NEXT: 180014024: 91000210 add x16, x16, #0x0
-# DISASM-NEXT: 180014028: d61f0200 br x16
+# DISASM-NEXT: 180015018: 36000040 tbz w0, #0x0, 0x180015020 <.code3+0xf020>
+# DISASM-NEXT: 18001501c: d65f03c0 ret
+# DISASM-NEXT: 180015020: f0ffff70 adrp x16, 0x180004000 <.code1>
+# DISASM-NEXT: 180015024: 91000210 add x16, x16, #0x0
+# DISASM-NEXT: 180015028: d61f0200 br x16
# RUN: llvm-readobj --coff-load-config test.dll | FileCheck --check-prefix=LOADCFG %s
# LOADCFG: CodeMap [
-# LOADCFG-NEXT: 0x3000 - 0x3014 ARM64EC
-# LOADCFG-NEXT: 0x4000 - 0x4300 X64
-# LOADCFG-NEXT: 0x5000 - 0x1402C ARM64EC
+# LOADCFG-NEXT: 0x4000 - 0x4014 ARM64EC
+# LOADCFG-NEXT: 0x5000 - 0x5300 X64
+# LOADCFG-NEXT: 0x6000 - 0x1502C ARM64EC
# LOADCFG-NEXT: ]
@@ -66,9 +66,9 @@
# RUN: llvm-readobj --coff-load-config testx.dll | FileCheck --check-prefix=LOADCFGX %s
# LOADCFGX: CodeMap [
-# LOADCFGX-NEXT: 0x3000 - 0x3014 ARM64EC
-# LOADCFGX-NEXT: 0x4000 - 0x4300 ARM64
-# LOADCFGX-NEXT: 0x5000 - 0x1402C ARM64EC
+# LOADCFGX-NEXT: 0x4000 - 0x4014 ARM64EC
+# LOADCFGX-NEXT: 0x5000 - 0x5300 ARM64
+# LOADCFGX-NEXT: 0x6000 - 0x1502C ARM64EC
# LOADCFGX-NEXT: ]
@@ -82,55 +82,55 @@
# DISASMX: Disassembly of section .code1:
# DISASMX-EMPTY:
-# DISASMX-NEXT: 0000000180003000 <.code1>:
-# DISASMX-NEXT: 180003000: 36000040 tbz w0, #0x0, 0x180003008 <.code1+0x8>
-# DISASMX-NEXT: 180003004: d65f03c0 ret
-# DISASMX-NEXT: 180003008: b0000050 adrp x16, 0x18000c000
-# DISASMX-NEXT: 18000300c: 91000210 add x16, x16, #0x0
-# DISASMX-NEXT: 180003010: d61f0200 br x16
-# DISASMX-EMPTY:
-# DISASMX-NEXT: Disassembly of section .code2:
-# DISASMX-EMPTY:
-# DISASMX-NEXT: 0000000180004000 <.code2>:
-# DISASMX-NEXT: 180004000: 36000040 tbz w0, #0x0, 0x180004008 <.code2+0x8>
+# DISASMX-NEXT: 0000000180004000 <.code1>:
+# DISASMX-NEXT: 180004000: 36000040 tbz w0, #0x0, 0x180004008 <.code1+0x8>
# DISASMX-NEXT: 180004004: d65f03c0 ret
-# DISASMX-NEXT: 180004008: b0000090 adrp x16, 0x180015000
+# DISASMX-NEXT: 180004008: b0000050 adrp x16, 0x18000d000
# DISASMX-NEXT: 18000400c: 91000210 add x16, x16, #0x0
# DISASMX-NEXT: 180004010: d61f0200 br x16
# DISASMX-EMPTY:
+# DISASMX-NEXT: Disassembly of section .code2:
+# DISASMX-EMPTY:
+# DISASMX-NEXT: 0000000180005000 <.code2>:
+# DISASMX-NEXT: 180005000: 36000040 tbz w0, #0x0, 0x180005008 <.code2+0x8>
+# DISASMX-NEXT: 180005004: d65f03c0 ret
+# DISASMX-NEXT: 180005008: b0000090 adrp x16, 0x180016000
+# DISASMX-NEXT: 18000500c: 91000210 add x16, x16, #0x0
+# DISASMX-NEXT: 180005010: d61f0200 br x16
+# DISASMX-EMPTY:
# DISASMX-NEXT: Disassembly of section .code3:
# DISASMX-EMPTY:
-# DISASMX-NEXT: 0000000180005000 <.code3>:
+# DISASMX-NEXT: 0000000180006000 <.code3>:
# DISASMX-NEXT: ...
-# DISASMX-NEXT: 18000c000: 36000060 tbz w0, #0x0, 0x18000c00c <.code3+0x700c>
-# DISASMX-NEXT: 18000c004: d65f03c0 ret
-# DISASMX-NEXT: 18000c008: 00000000 udf #0x0
-# DISASMX-NEXT: 18000c00c: 90000050 adrp x16, 0x180014000 <.code3+0xf000>
-# DISASMX-NEXT: 18000c010: 91006210 add x16, x16, #0x18
-# DISASMX-NEXT: 18000c014: d61f0200 br x16
+# DISASMX-NEXT: 18000d000: 36000060 tbz w0, #0x0, 0x18000d00c <.code3+0x700c>
+# DISASMX-NEXT: 18000d004: d65f03c0 ret
+# DISASMX-NEXT: 18000d008: 00000000 udf #0x0
+# DISASMX-NEXT: 18000d00c: 90000050 adrp x16, 0x180015000 <.code3+0xf000>
+# DISASMX-NEXT: 18000d010: 91006210 add x16, x16, #0x18
+# DISASMX-NEXT: 18000d014: d61f0200 br x16
# DISASMX-NEXT: ...
-# DISASMX-NEXT: 180014018: 36000040 tbz w0, #0x0, 0x180014020 <.code3+0xf020>
-# DISASMX-NEXT: 18001401c: d65f...
[truncated]
|
I noticed that the In my testing, skipping the terminator works fine, though this may be coincidental, as it is typically followed by section padding at runtime. Since adding it is straightforward, it seems reasonable to follow MSVC’s approach. One notable side effect is that when the redirection metadata is empty, MSVC still emits an |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, sounds reasonable
@@ -1083,7 +1083,8 @@ void CHPECodeRangesChunk::writeTo(uint8_t *buf) const { | |||
} | |||
|
|||
size_t CHPERedirectionChunk::getSize() const { | |||
return exportThunks.size() * sizeof(chpe_redirection_entry); | |||
// Add an extra +1 for a terminator entry. | |||
return (exportThunks.size() + 1) * sizeof(chpe_redirection_entry); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this allocates a larger section for this, which gets zero initialized, while we only write the same area of it as before?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. I assumed that it's fine to depend on the buffer being initialized to zero (we already do in other places, as mentioned in #72138).
For MSVC compatibility.