Skip to content

[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

Merged
merged 1 commit into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lld/COFF/Chunks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Copy link
Member

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?

Copy link
Contributor Author

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).

}

void CHPERedirectionChunk::writeTo(uint8_t *buf) const {
Expand Down
10 changes: 5 additions & 5 deletions lld/test/COFF/arm64ec-altnames.s
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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.

Expand Down
74 changes: 37 additions & 37 deletions lld/test/COFF/arm64ec-codemap.test
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.

Expand All @@ -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
Expand All @@ -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.

Expand Down Expand Up @@ -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
Expand All @@ -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.

Expand All @@ -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.

Expand All @@ -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
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions lld/test/COFF/arm64ec-delayimport.test
Original file line number Diff line number Diff line change
Expand Up @@ -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>:
Expand Down
11 changes: 8 additions & 3 deletions lld/test/COFF/arm64ec-export-thunks.test
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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

Expand Down Expand Up @@ -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: }


Expand Down
16 changes: 8 additions & 8 deletions lld/test/COFF/arm64ec-import.test
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lld/test/COFF/arm64ec-lib.test
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion lld/test/COFF/arm64ec-loadcfg.s
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading
Loading