Skip to content

Commit 95ccc73

Browse files
author
git apple-llvm automerger
committed
Merge commit '28d81a2bfa0a' from llvm.org/release/17.x into stable/20230725
2 parents 7059b0a + 28d81a2 commit 95ccc73

File tree

3 files changed

+55
-187
lines changed

3 files changed

+55
-187
lines changed

lld/COFF/Writer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1796,7 +1796,7 @@ void Writer::createGuardCFTables() {
17961796
// Add the ehcont target table unless the user told us not to.
17971797
if (config->guardCF & GuardCFLevel::EHCont)
17981798
maybeAddRVATable(std::move(ehContTargets), "__guard_eh_cont_table",
1799-
"__guard_eh_cont_count", true);
1799+
"__guard_eh_cont_count");
18001800

18011801
// Set __guard_flags, which will be used in the load config to indicate that
18021802
// /guard:cf was enabled.

lld/test/COFF/guard-ehcont.s

Lines changed: 40 additions & 170 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# CHECK: GuardCFCheckFunction: 0x0
1111
# CHECK: GuardCFCheckDispatch: 0x0
1212
# CHECK: GuardCFFunctionTable: 0x14000{{.*}}
13-
# CHECK: GuardCFFunctionCount: 4
13+
# CHECK: GuardCFFunctionCount: 1
1414
# CHECK: GuardFlags [ (0x400500)
1515
# CHECK: CF_FUNCTION_TABLE_PRESENT (0x400)
1616
# CHECK: CF_INSTRUMENTED (0x100)
@@ -19,25 +19,13 @@
1919
# CHECK: GuardAddressTakenIatEntryTable: 0x0
2020
# CHECK: GuardAddressTakenIatEntryCount: 0
2121
# CHECK: GuardEHContinuationTable: 0x14000{{.*}}
22-
# CHECK: GuardEHContinuationCount: 1
22+
# CHECK: GuardEHContinuationCount: 2
2323
# CHECK: ]
2424
# CHECK: GuardEHContTable [
2525
# CHECK-NEXT: 0x14000{{.*}}
26+
# CHECK-NEXT: 0x14000{{.*}}
2627
# CHECK-NEXT: ]
2728

28-
29-
# This assembly is reduced from C code like:
30-
# int main()
31-
# {
32-
# try {
33-
# throw 3;
34-
# }
35-
# catch (int e) {
36-
# return e != 3;
37-
# }
38-
# return 2;
39-
# }
40-
4129
# We need @feat.00 to have 0x4000 to indicate /guard:ehcont.
4230
.def @feat.00;
4331
.scl 3;
@@ -48,168 +36,50 @@
4836
.def main; .scl 2; .type 32; .endef
4937
.globl main # -- Begin function main
5038
.p2align 4, 0x90
51-
main: # @main
52-
.Lfunc_begin0:
39+
main:
5340
.seh_proc main
54-
.intel_syntax
55-
.seh_handler __CxxFrameHandler3, @unwind, @except
56-
# %bb.0: # %entry
57-
push rbp
58-
.seh_pushreg rbp
59-
sub rsp, 64
60-
.seh_stackalloc 64
61-
lea rbp, [rsp + 64]
62-
.seh_setframe rbp, 64
63-
.seh_endprologue
64-
mov qword ptr [rbp - 16], -2
65-
mov dword ptr [rbp - 20], 0
66-
mov dword ptr [rbp - 24], 3
67-
.Ltmp0:
68-
lea rdx, [rip + _TI1H]
69-
lea rcx, [rbp - 24]
70-
call _CxxThrowException
71-
.Ltmp1:
72-
jmp .LBB0_3
73-
.LBB0_2: # Block address taken
74-
# %catchret.dest
75-
$ehgcr_0_2:
76-
mov eax, dword ptr [rbp - 20]
77-
add rsp, 64
78-
pop rbp
79-
ret
80-
.LBB0_3: # %unreachable
81-
int3
82-
.seh_handlerdata
83-
.long ($cppxdata$main)@IMGREL
84-
.text
85-
.seh_endproc
86-
.def "?catch$1@?0?main@4HA";
87-
.scl 3;
88-
.type 32;
89-
.endef
90-
.p2align 4, 0x90
91-
"?catch$1@?0?main@4HA":
92-
.seh_proc "?catch$1@?0?main@4HA"
93-
.seh_handler __CxxFrameHandler3, @unwind, @except
94-
.LBB0_1: # %catch
95-
mov qword ptr [rsp + 16], rdx
96-
push rbp
97-
.seh_pushreg rbp
98-
sub rsp, 32
99-
.seh_stackalloc 32
100-
lea rbp, [rdx + 64]
101-
.seh_endprologue
102-
mov eax, dword ptr [rbp - 4]
103-
sub eax, 3
104-
setne al
105-
movzx eax, al
106-
mov dword ptr [rbp - 20], eax
107-
lea rax, [rip + .LBB0_2]
108-
add rsp, 32
109-
pop rbp
110-
ret # CATCHRET
111-
.def free; .scl 2; .type 32; .endef
112-
.globl free
113-
free:
114-
ret
115-
.def __CxxFrameHandler3; .scl 2; .type 32; .endef
116-
.globl __CxxFrameHandler3
117-
__CxxFrameHandler3:
118-
ret
119-
.def _CxxThrowException; .scl 2; .type 32; .endef
120-
.globl _CxxThrowException
121-
_CxxThrowException:
122-
ret
123-
.Lfunc_end0:
41+
.seh_handler __C_specific_handler, @unwind, @except
12442
.seh_handlerdata
125-
.long ($cppxdata$main)@IMGREL
43+
.long 2
44+
.long (seh_begin)@IMGREL
45+
.long (seh_end)@IMGREL
46+
.long 1
47+
.long (seh_except)@IMGREL
48+
.long (seh2_begin)@IMGREL
49+
.long (seh2_end)@IMGREL
50+
.long 1
51+
.long (seh2_except)@IMGREL
12652
.text
127-
.seh_endproc
128-
.section .xdata,"dr"
129-
.p2align 2
130-
$cppxdata$main:
131-
.long 429065506 # MagicNumber
132-
.long 2 # MaxState
133-
.long ($stateUnwindMap$main)@IMGREL # UnwindMap
134-
.long 1 # NumTryBlocks
135-
.long ($tryMap$main)@IMGREL # TryBlockMap
136-
.long 4 # IPMapEntries
137-
.long ($ip2state$main)@IMGREL # IPToStateXData
138-
.long 48 # UnwindHelp
139-
.long 0 # ESTypeList
140-
.long 1 # EHFlags
141-
$stateUnwindMap$main:
142-
.long -1 # ToState
143-
.long 0 # Action
144-
.long -1 # ToState
145-
.long 0 # Action
146-
$tryMap$main:
147-
.long 0 # TryLow
148-
.long 0 # TryHigh
149-
.long 1 # CatchHigh
150-
.long 1 # NumCatches
151-
.long ($handlerMap$0$main)@IMGREL # HandlerArray
152-
$handlerMap$0$main:
153-
.long 0 # Adjectives
154-
.long "??_R0H@8"@IMGREL # Type
155-
.long 60 # CatchObjOffset
156-
.long "?catch$1@?0?main@4HA"@IMGREL # Handler
157-
.long 56 # ParentFrameOffset
158-
$ip2state$main:
159-
.long .Lfunc_begin0@IMGREL # IP
160-
.long -1 # ToState
161-
.long .Ltmp0@IMGREL+1 # IP
162-
.long 0 # ToState
163-
.long .Ltmp1@IMGREL+1 # IP
164-
.long -1 # ToState
165-
.long "?catch$1@?0?main@4HA"@IMGREL # IP
166-
.long 1 # ToState
167-
.text
168-
# -- End function
169-
.section .data,"dw",discard,"??_R0H@8"
170-
.globl "??_R0H@8" # @"??_R0H@8"
171-
.p2align 4
172-
"??_R0H@8":
173-
.quad 0
174-
.quad 0
175-
.asciz ".H"
176-
.zero 5
53+
seh_begin:
54+
nop
55+
int3
56+
nop
57+
seh_end:
58+
nop
59+
seh_except:
60+
nop
17761

178-
.section .xdata,"dr",discard,"_CT??_R0H@84"
179-
.globl "_CT??_R0H@84" # @"_CT??_R0H@84"
180-
.p2align 4
181-
"_CT??_R0H@84":
182-
.long 1 # 0x1
183-
.long "??_R0H@8"@IMGREL
184-
.long 0 # 0x0
185-
.long 4294967295 # 0xffffffff
186-
.long 0 # 0x0
187-
.long 4 # 0x4
188-
.long 0 # 0x0
62+
seh2_begin:
63+
nop
64+
int3
65+
nop
66+
seh2_end:
67+
nop
68+
seh2_except:
69+
nop
70+
71+
xor %eax, %eax
72+
ret
73+
.seh_endproc
18974

190-
.section .xdata,"dr",discard,_CTA1H
191-
.globl _CTA1H # @_CTA1H
192-
.p2align 3
193-
_CTA1H:
194-
.long 1 # 0x1
195-
.long "_CT??_R0H@84"@IMGREL
75+
__C_specific_handler:
76+
ret
19677

197-
.section .xdata,"dr",discard,_TI1H
198-
.globl _TI1H # @_TI1H
199-
.p2align 3
200-
_TI1H:
201-
.long 0 # 0x0
202-
.long 0 # 0x0
203-
.long 0 # 0x0
204-
.long _CTA1H@IMGREL
78+
.section .gehcont$y,"dr"
79+
.symidx seh_except
80+
.symidx seh2_except
20581

206-
.section .gehcont$y,"dr"
207-
.symidx $ehgcr_0_2
208-
.addrsig_sym _CxxThrowException
209-
.addrsig_sym __CxxFrameHandler3
210-
.addrsig_sym "??_R0H@8"
211-
.addrsig_sym __ImageBase
212-
.section .rdata,"dr"
82+
.section .rdata,"dr"
21383
.globl _load_config_used
21484
_load_config_used:
21585
.long 312

llvm/tools/llvm-readobj/COFFDumper.cpp

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -940,36 +940,34 @@ void COFFDumper::printCOFFLoadConfig() {
940940
OS << " flags " << utohexstr(Flags);
941941
};
942942

943+
// The stride gives the number of extra bytes in addition to the 4-byte
944+
// RVA of each entry in the table. As of writing only a 1-byte extra flag
945+
// has been defined.
946+
uint32_t Stride = Tables.GuardFlags >> 28;
947+
PrintExtraCB PrintExtra = Stride == 1 ? PrintGuardFlags : nullptr;
948+
943949
if (Tables.GuardFidTableVA) {
944950
ListScope LS(W, "GuardFidTable");
945-
if (uint32_t Size =
946-
Tables.GuardFlags &
947-
uint32_t(COFF::GuardFlags::CF_FUNCTION_TABLE_SIZE_MASK)) {
948-
// The size mask gives the number of extra bytes in addition to the 4-byte
949-
// RVA of each entry in the table. As of writing only a 1-byte extra flag
950-
// has been defined.
951-
Size = (Size >> 28) + 4;
952-
printRVATable(Tables.GuardFidTableVA, Tables.GuardFidTableCount, Size,
953-
PrintGuardFlags);
954-
} else {
955-
printRVATable(Tables.GuardFidTableVA, Tables.GuardFidTableCount, 4);
956-
}
951+
printRVATable(Tables.GuardFidTableVA, Tables.GuardFidTableCount,
952+
4 + Stride, PrintExtra);
957953
}
958954

959955
if (Tables.GuardIatTableVA) {
960956
ListScope LS(W, "GuardIatTable");
961-
printRVATable(Tables.GuardIatTableVA, Tables.GuardIatTableCount, 4);
957+
printRVATable(Tables.GuardIatTableVA, Tables.GuardIatTableCount,
958+
4 + Stride, PrintExtra);
962959
}
963960

964961
if (Tables.GuardLJmpTableVA) {
965962
ListScope LS(W, "GuardLJmpTable");
966-
printRVATable(Tables.GuardLJmpTableVA, Tables.GuardLJmpTableCount, 4);
963+
printRVATable(Tables.GuardLJmpTableVA, Tables.GuardLJmpTableCount,
964+
4 + Stride, PrintExtra);
967965
}
968966

969967
if (Tables.GuardEHContTableVA) {
970968
ListScope LS(W, "GuardEHContTable");
971-
printRVATable(Tables.GuardEHContTableVA, Tables.GuardEHContTableCount, 5,
972-
PrintGuardFlags);
969+
printRVATable(Tables.GuardEHContTableVA, Tables.GuardEHContTableCount,
970+
4 + Stride, PrintExtra);
973971
}
974972
}
975973

0 commit comments

Comments
 (0)