Skip to content

Commit 3d9e686

Browse files
committed
Update comment and test
1 parent 35082de commit 3d9e686

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

lld/MachO/Arch/ARM64.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,13 @@ void ARM64::populateThunk(InputSection *thunk, Symbol *funcSym) {
173173
/*offset=*/0, /*addend=*/0,
174174
/*referent=*/funcSym);
175175
}
176-
// Just a single direct branch to the target function.
176+
// Just a single direct branch to the target function and a nop.
177+
// The nop will improve the debuggability.
178+
//
179+
// Debug lines in DWARF does not recognize one-instruction sequence, and this
180+
// thunk will be merged into other sequences if it only had one instruction.
181+
// Adding a nop after the branch has no runtime cost, and little size impact,
182+
// but it would make DWARF linker and debuggers happier.
177183
static constexpr uint32_t icfSafeThunkCode[] = {
178184
0x14000000, // 08: b target
179185
0xD503201F, // 0c: nop

lld/test/MachO/icf-safe-thunks.ll

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,15 @@
3939
;
4040
; CHECK-ARM64: _func_2identical_v2:
4141
; CHECK-ARM64-NEXT: b _func_2identical_v1
42+
; CHECK-ARM64-NEXT: nop
4243
; CHECK-ARM64-NEXT: _func_3identical_v2:
4344
; CHECK-ARM64-NEXT: b _func_3identical_v1
45+
; CHECK-ARM64-NEXT: nop
4446
; CHECK-ARM64-NEXT: _func_3identical_v3:
4547
; CHECK-ARM64-NEXT: b _func_3identical_v1
48+
; CHECK-ARM64-NEXT: nop
4649

47-
50+
; Check the size of each functions. Thunks' size will change from 4-> 8 because of added nop.
4851
; CHECK-ARM64-MAP: 0x00000010 [ 2] _func_unique_1
4952
; CHECK-ARM64-MAP-NEXT: 0x00000010 [ 2] _func_2identical_v1
5053
; CHECK-ARM64-MAP-NEXT: 0x00000000 [ 2] _func_unique_2_canmerge
@@ -57,9 +60,9 @@
5760
; CHECK-ARM64-MAP-NEXT: 0x00000000 [ 2] _func_call_thunked_2_merge
5861
; CHECK-ARM64-MAP-NEXT: 0x00000034 [ 2] _call_all_funcs
5962
; CHECK-ARM64-MAP-NEXT: 0x00000050 [ 2] _take_func_addr
60-
; CHECK-ARM64-MAP-NEXT: 0x00000004 [ 2] _func_2identical_v2
61-
; CHECK-ARM64-MAP-NEXT: 0x00000004 [ 2] _func_3identical_v2
62-
; CHECK-ARM64-MAP-NEXT: 0x00000004 [ 2] _func_3identical_v3
63+
; CHECK-ARM64-MAP-NEXT: 0x00000008 [ 2] _func_2identical_v2
64+
; CHECK-ARM64-MAP-NEXT: 0x00000008 [ 2] _func_3identical_v2
65+
; CHECK-ARM64-MAP-NEXT: 0x00000008 [ 2] _func_3identical_v3
6366

6467
;--- a.cpp
6568
#define ATTR __attribute__((noinline)) extern "C"

0 commit comments

Comments
 (0)