Skip to content

Commit b5c850f

Browse files
authored
[lld-macho] Mark local personality functions as INDIRECT_SYMBOL_LOCAL (#95171)
This expands on the fix in 4e572db. The issue is pretty similar: we might put symbols in the GOT which don't need run-time binding, locally defined personality symbols in this case. We should set their indirect symbol table entries to `INDIRECT_SYMBOL_LOCAL` to help `strip` remove these local names from the symbol table. Checking if the symbol is private-extern doesn't cover all cases; it can also be a non-weak extern function too, for instance; use the `needsBinding()` helper to determine it. This was the case for the personality function in statically linked Rust executables. The extra non-`LOCAL` symbols triggered a bug in Apple's `strip` implementation. As the indirect value for the personality function was not set to the flag, but the symbol didn't require binding, it tried to make the symbol local, overwriting the GOT entry with the function's address in the process. This normally wouldn't be a problem, but if chained fixups are used, the fixup also encodes the offset to the next fixup, and it effectively zeroed this offset out, causing the remaining relocations on the page to not be performed by dyld. This caused the crash in https://issues.chromium.org/issues/325410295 The change in tests is a bit ugly, as a lot of symbol information is now removed by turning more symbols `LOCAL`.
1 parent 846103c commit b5c850f

File tree

6 files changed

+20
-23
lines changed

6 files changed

+20
-23
lines changed

lld/MachO/SyntheticSections.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1478,11 +1478,8 @@ void IndirectSymtabSection::finalizeContents() {
14781478
}
14791479

14801480
static uint32_t indirectValue(const Symbol *sym) {
1481-
if (sym->symtabIndex == UINT32_MAX)
1481+
if (sym->symtabIndex == UINT32_MAX || !needsBinding(sym))
14821482
return INDIRECT_SYMBOL_LOCAL;
1483-
if (auto *defined = dyn_cast<Defined>(sym))
1484-
if (defined->privateExtern)
1485-
return INDIRECT_SYMBOL_LOCAL;
14861483
return sym->symtabIndex;
14871484
}
14881485

lld/test/MachO/arm64-reloc-pointer-to-got.s

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
## POINTER_TO_GOT, we should still be able to relax this GOT_LOAD reference to
99
## it.
1010
# CHECK: _main:
11-
# CHECK-NEXT: adrp x8, [[#]] ;
12-
# CHECK-NEXT: ldr x8, [x8] ; literal pool symbol address: _foo
11+
# CHECK-NEXT: adrp x8, [[#]] ; 0x100004000
12+
# CHECK-NEXT: ldr x8, [x8]
1313
# CHECK-NEXT: ret
1414

1515
# CHECK: Idx Name Size VMA Type

lld/test/MachO/compact-unwind-both-local-and-dylib-personality.s

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,16 @@
4545
# A: Indirect symbols for (__DATA_CONST,__got) 4 entries
4646
# A-NEXT: address index name
4747
# A: 0x[[#%x,GXX_PERSONALITY_LO:]] [[#]] ___gxx_personality_v0
48-
# A: 0x[[#%x,PERSONALITY_1:]] [[#]] _personality_1
49-
# A: 0x[[#%x,PERSONALITY_2:]] [[#]] _personality_2
50-
# A: 0x[[#%x,GXX_PERSONALITY_HI:]] [[#]] ___gxx_personality_v0
48+
# A: 0x[[#%x,PERSONALITY_1:]] LOCAL
49+
# A: 0x[[#%x,PERSONALITY_2:]] LOCAL
50+
# A: 0x[[#%x,GXX_PERSONALITY_HI:]] LOCAL
5151

5252
# BC: Indirect symbols for (__DATA_CONST,__got)
5353
# BC-NEXT: address index name
5454
# BC: 0x[[#%x,GXX_PERSONALITY_LO:]] LOCAL
55-
# C: 0x[[#%x,GXX_PERSONALITY_HI:]] [[#]] ___gxx_personality_v0
56-
# BC: 0x[[#%x,PERSONALITY_1:]] [[#]] _personality_1
57-
# BC: 0x[[#%x,PERSONALITY_2:]] [[#]] _personality_2
55+
# C: 0x[[#%x,GXX_PERSONALITY_HI:]] LOCAL
56+
# BC: 0x[[#%x,PERSONALITY_1:]] LOCAL
57+
# BC: 0x[[#%x,PERSONALITY_2:]] LOCAL
5858
# BC-EMPTY:
5959

6060
# CHECK: Personality functions: (count = 3)
@@ -70,11 +70,11 @@
7070
# D: Indirect symbols for (__DATA_CONST,__got) 6 entries
7171
# D-NEXT: address index name
7272
# D: 0x[[#%x,GXX_PERSONALITY_HI:]] [[#]] ___gxx_personality_v0
73-
# D: 0x[[#%x,PERSONALITY_1:]] [[#]] _personality_1
74-
# D: 0x[[#%x,PERSONALITY_2:]] [[#]] _personality_2
75-
# D: 0x[[#%x,PERSONALITY_3:]] [[#]] _personality_3
76-
# D: 0x[[#%x,PERSONALITY_4:]] [[#]] _personality_4
77-
# D: 0x[[#%x,GXX_PERSONALITY_LO:]] [[#]] ___gxx_personality_v0
73+
# D: 0x[[#%x,PERSONALITY_1:]] LOCAL
74+
# D: 0x[[#%x,PERSONALITY_2:]] LOCAL
75+
# D: 0x[[#%x,PERSONALITY_3:]] LOCAL
76+
# D: 0x[[#%x,PERSONALITY_4:]] LOCAL
77+
# D: 0x[[#%x,GXX_PERSONALITY_LO:]] LOCAL
7878

7979
# D: Contents of __unwind_info section:
8080
# D: Personality functions: (count = 1)

lld/test/MachO/compact-unwind.s

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@
2929
# FIRST: Indirect symbols for (__DATA_CONST,__got)
3030
# FIRST-NEXT: address index name
3131
# FIRST-DAG: 0x[[#%x,GXX_PERSONALITY:]] [[#]] ___gxx_personality_v0
32-
# FIRST-DAG: 0x[[#%x,MY_PERSONALITY:]]
32+
# FIRST-DAG: 0x[[#%x,MY_PERSONALITY:]] LOCAL
3333

3434
# SECOND: Indirect symbols for (__DATA_CONST,__got)
3535
# SECOND-NEXT: address index name
3636
# SECOND-DAG: 0x[[#%x,GXX_PERSONALITY:]] [[#]] ___gxx_personality_v0
37-
# SECOND-DAG: 0x[[#%x,MY_PERSONALITY:]] [[#]] _my_personality
37+
# SECOND-DAG: 0x[[#%x,MY_PERSONALITY:]] LOCAL
3838

3939
# CHECK: SYMBOL TABLE:
4040
# CHECK-DAG: [[#%x,MAIN:]] g F __TEXT,__text _main

lld/test/MachO/dead-strip.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
# EXEC-DAG: g {{.*}} __mh_execute_header
3636
# EXECDATA-LABEL: Indirect symbols
3737
# EXECDATA-NEXT: name
38-
# EXECDATA-NEXT: _ref_com
38+
# EXECDATA-NEXT: LOCAL
3939
# EXECDATA-LABEL: Contents of (__DATA,__ref_section) section
4040
# EXECDATA-NEXT: 04 00 00 00 00 00 00 00 05 00 00 00 00 00 00 00
4141
# EXECDATA-LABEL: Exports trie:

lld/test/MachO/invalid/compact-unwind-personalities.s

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
# DWARF: Indirect symbols
1515
# DWARF: address index name
1616
# DWARF: 0x[[#%x,GXX_PERSONALITY:]] {{.*}} ___gxx_personality_v0
17-
# DWARF: 0x[[#%x,PERSONALITY_1:]] {{.*}} _personality_1
18-
# DWARF: 0x[[#%x,PERSONALITY_2:]] {{.*}} _personality_2
19-
# DWARF: 0x[[#%x,PERSONALITY_3:]] {{.*}} _personality_3
17+
# DWARF: 0x[[#%x,PERSONALITY_1:]] LOCAL
18+
# DWARF: 0x[[#%x,PERSONALITY_2:]] LOCAL
19+
# DWARF: 0x[[#%x,PERSONALITY_3:]] LOCAL
2020
# DWARF: .eh_frame contents:
2121
# DWARF: Personality Address: [[#%.16x,GXX_PERSONALITY]]
2222
# DWARF: Personality Address: [[#%.16x,PERSONALITY_1]]

0 commit comments

Comments
 (0)