Skip to content

[lld-macho] Fix duplicate GOT entries for personality functions #95054

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
Jun 11, 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
34 changes: 23 additions & 11 deletions lld/MachO/UnwindInfoSection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,19 +298,31 @@ void UnwindInfoSectionImpl::prepareRelocations(ConcatInputSection *isec) {
assert(!isCoalescedWeak(referentIsec));
// Personality functions can be referenced via section relocations
// if they live in the same object file. Create placeholder synthetic
// symbols for them in the GOT.
// symbols for them in the GOT. If the corresponding symbol is already
// in the GOT, use that to avoid creating a duplicate entry. All GOT
// entries needed by non-unwind sections will have already been added
// by this point.
Symbol *&s = personalityTable[{referentIsec, r.addend}];
if (s == nullptr) {
// This runs after dead stripping, so the noDeadStrip argument does not
// matter.
s = make<Defined>("<internal>", /*file=*/nullptr, referentIsec,
r.addend, /*size=*/0, /*isWeakDef=*/false,
/*isExternal=*/false, /*isPrivateExtern=*/false,
/*includeInSymtab=*/true,
/*isReferencedDynamically=*/false,
/*noDeadStrip=*/false);
s->used = true;
in.got->addEntry(s);
Defined *const *gotEntry =
llvm::find_if(referentIsec->symbols, [&](Defined const *d) {
return d->value == static_cast<uint64_t>(r.addend) &&
d->isInGot();
});
if (gotEntry != referentIsec->symbols.end()) {
s = *gotEntry;
} else {
// This runs after dead stripping, so the noDeadStrip argument does
// not matter.
s = make<Defined>("<internal>", /*file=*/nullptr, referentIsec,
r.addend, /*size=*/0, /*isWeakDef=*/false,
/*isExternal=*/false, /*isPrivateExtern=*/false,
/*includeInSymtab=*/true,
/*isReferencedDynamically=*/false,
/*noDeadStrip=*/false);
s->used = true;
in.got->addEntry(s);
}
}
r.referent = s;
r.addend = 0;
Expand Down
15 changes: 8 additions & 7 deletions lld/test/MachO/compact-unwind-both-local-and-dylib-personality.s
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,20 @@

# RUN: llvm-objdump --macho --indirect-symbols --unwind-info --bind %t/d.out | FileCheck %s --check-prefixes=D -D#%x,OFF=0x100000000

# A: Indirect symbols for (__DATA_CONST,__got)
# A: Indirect symbols for (__DATA_CONST,__got) 4 entries
# A-NEXT: address index name
# A: 0x[[#%x,GXX_PERSONALITY_LO:]] [[#]] ___gxx_personality_v0
# A: 0x[[#%x,PERSONALITY_1:]] [[#]] _personality_1
# A: 0x[[#%x,PERSONALITY_2:]] [[#]] _personality_2
# A: 0x[[#%x,GXX_PERSONALITY_HI:]] [[#]] ___gxx_personality_v0
# A: 0x[[#%x,PERSONALITY_1:]] LOCAL
# A: 0x[[#%x,PERSONALITY_2:]] LOCAL

# BC: Indirect symbols for (__DATA_CONST,__got)
# BC-NEXT: address index name
# C: 0x[[#%x,GXX_PERSONALITY_HI:]] LOCAL
# BC: 0x[[#%x,GXX_PERSONALITY_LO:]] LOCAL
# BC: 0x[[#%x,PERSONALITY_1:]] LOCAL
# BC: 0x[[#%x,PERSONALITY_2:]] LOCAL
# C: 0x[[#%x,GXX_PERSONALITY_HI:]] [[#]] ___gxx_personality_v0
# BC: 0x[[#%x,PERSONALITY_1:]] [[#]] _personality_1
# BC: 0x[[#%x,PERSONALITY_2:]] [[#]] _personality_2
# BC-EMPTY:

# CHECK: Personality functions: (count = 3)
# CHECK-DAG: personality[{{[0-9]+}}]: 0x{{0*}}[[#GXX_PERSONALITY_LO-OFF]]
Expand All @@ -66,7 +67,7 @@
# A-NEXT: __DATA_CONST __got 0x[[#GXX_PERSONALITY_LO-0]] pointer 0 libc++abi ___gxx_personality_v0


# D: Indirect symbols for (__DATA_CONST,__got)
# D: Indirect symbols for (__DATA_CONST,__got) 6 entries
# D-NEXT: address index name
# D: 0x[[#%x,GXX_PERSONALITY_HI:]] [[#]] ___gxx_personality_v0
# D: 0x[[#%x,PERSONALITY_1:]] [[#]] _personality_1
Expand Down
2 changes: 1 addition & 1 deletion lld/test/MachO/compact-unwind.s
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
# FIRST: Indirect symbols for (__DATA_CONST,__got)
# FIRST-NEXT: address index name
# FIRST-DAG: 0x[[#%x,GXX_PERSONALITY:]] [[#]] ___gxx_personality_v0
# FIRST-DAG: 0x[[#%x,MY_PERSONALITY:]] LOCAL
# FIRST-DAG: 0x[[#%x,MY_PERSONALITY:]]

# SECOND: Indirect symbols for (__DATA_CONST,__got)
# SECOND-NEXT: address index name
Expand Down
Loading