diff options
author | Daniel Bertalan <dani@danielbertalan.dev> | 2024-06-11 21:51:28 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-11 21:51:28 +0200 |
commit | 6afbda7130c343be34b2f3c765b9c4c1b251b671 (patch) | |
tree | d256442c26e14767581209d71c6193ca5cf26bcd /lld/test | |
parent | 57520985e09f3c098a5f5a6f72e3107a8a1d5446 (diff) | |
download | llvm-6afbda7130c343be34b2f3c765b9c4c1b251b671.zip llvm-6afbda7130c343be34b2f3c765b9c4c1b251b671.tar.gz llvm-6afbda7130c343be34b2f3c765b9c4c1b251b671.tar.bz2 |
[lld-macho] Fix duplicate GOT entries for personality functions (#95054)
As stated in `UnwindInfoSectionImpl::prepareRelocations`'s comments, the
unwind info uses section+addend relocations for personality functions
defined in the same file as the function itself. As personality
functions are always accessed via the GOT, we need to resolve those to a
symbol. Previously, we did this by keeping a map which resolves these to
symbols, creating a synthetic symbol if we didn't find it in the map.
This approach has an issue: if we process the object file containing the
personality function before any external uses, the entry in the map
remains unpopulated, so we create a synthetic symbol and a corresponding
GOT entry. If we encounter a relocation to it in a later file which
requires GOT (such as in `__eh_frame`), we add that symbol to the GOT,
too, effectively creating two entries which point to the same piece of
code.
This commit fixes that by searching the personality function's section
for a symbol at that offset which already has a GOT entry, and only
creating a synthetic symbol if there is none. As all non-unwind sections
are already processed by this point, it ensures no duplication.
This should only really affect our tests (and make them clearer), as
personality functions are usually defined in platform runtime libraries.
Or even if they are local, they are likely not in the first object file
to be linked.
Diffstat (limited to 'lld/test')
-rw-r--r-- | lld/test/MachO/compact-unwind-both-local-and-dylib-personality.s | 15 | ||||
-rw-r--r-- | lld/test/MachO/compact-unwind.s | 2 |
2 files changed, 9 insertions, 8 deletions
diff --git a/lld/test/MachO/compact-unwind-both-local-and-dylib-personality.s b/lld/test/MachO/compact-unwind-both-local-and-dylib-personality.s index 676577d..35f39ba 100644 --- a/lld/test/MachO/compact-unwind-both-local-and-dylib-personality.s +++ b/lld/test/MachO/compact-unwind-both-local-and-dylib-personality.s @@ -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]] @@ -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 diff --git a/lld/test/MachO/compact-unwind.s b/lld/test/MachO/compact-unwind.s index fa73ccb..27e4b44 100644 --- a/lld/test/MachO/compact-unwind.s +++ b/lld/test/MachO/compact-unwind.s @@ -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 |