brintos

brintos / llvm-project-archived public Read only

0
0
Text · 5.8 KiB · feb4c0a Raw
150 lines · plain
1# REQUIRES: x862## This test checks that when we coalesce weak definitions, their local symbol3## aliases defs don't cause the coalesced data to be retained. This was4## motivated by MC's aarch64 backend which automatically creates `ltmp<N>`5## symbols at the start of each .text section. These symbols are frequently6## aliases of other symbols created by clang or other inputs to MC. I've chosen7## to explicitly create them here since we can then reference those symbols for8## a more complete test.9##10## Not retaining the data matters for more than just size -- we have a use case11## that depends on proper data coalescing to emit a valid file format. We also12## need this behavior to properly deduplicate the __objc_protolist section;13## failure to do this can result in dyld crashing on iOS 13.14##15## Finally, ld64 does all this regardless of whether .subsections_via_symbols is16## specified. We don't. But again, given how rare the lack of that directive is17## (I've only seen it from hand-written assembly inputs), I don't think we need18## to worry about it.19 20# RUN: rm -rf %t; split-file %s %t21# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/weak-then-local.s -o %t/weak-then-local.o22# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/local-then-weak.s -o %t/local-then-weak.o23# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/no-subsections.s -o %t/no-subsections.o24# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/no-dead-strip.s -o %t/no-dead-strip.o25 26# RUN: %lld -lSystem -dylib %t/weak-then-local.o %t/local-then-weak.o -o %t/test127# RUN: llvm-objdump --macho --syms --section="__DATA,__data" --weak-bind %t/test1 | FileCheck %s28# RUN: %lld -lSystem -dylib %t/local-then-weak.o %t/weak-then-local.o -o %t/test229# RUN: llvm-objdump --macho --syms --section="__DATA,__data" --weak-bind %t/test2 | FileCheck %s30 31## Check that we only have one copy of 0x123 in the data, not two.32# CHECK:       Contents of (__DATA,__data) section33# CHECK-NEXT:  0000000000001000  23 01 00 00 00 00 00 00 00 10 00 00 00 00 00 00 {{$}}34# CHECK-NEXT:  0000000000001010  00 10 00 00 00 00 00 00 {{$}}35# CHECK-EMPTY:36# CHECK-NEXT:  SYMBOL TABLE:37# CHECK-NEXT:  0000000000001000 l     O __DATA,__data _alias38# CHECK-NEXT:  0000000000001008 l     O __DATA,__data _ref39# CHECK-NEXT:  0000000000001000 l     O __DATA,__data _alias40# CHECK-NEXT:  0000000000001010 l     O __DATA,__data _ref41# CHECK-NEXT:  0000000000001000  w    O __DATA,__data _weak42# CHECK-NEXT:  0000000000000000         *UND* dyld_stub_binder43# CHECK-EMPTY:44## Even though the references were to the non-weak `_alias` symbols, ld64 still45## emits weak binds as if they were the `_weak` symbol itself. We do not. I46## don't know of any programs that rely on this behavior, so I'm just47## documenting it here.48# CHECK-NEXT:  Weak bind table:49# CHECK-NEXT:  segment  section            address     type       addend   symbol50# CHECK-EMPTY:51 52# RUN: %lld -lSystem -dylib %t/local-then-weak.o %t/no-subsections.o -o %t/sub-nosub53# RUN: llvm-objdump --macho --syms --section="__DATA,__data" %t/sub-nosub | FileCheck %s --check-prefix SUB-NOSUB54 55## This test case demonstrates a shortcoming of LLD: If .subsections_via_symbols56## isn't enabled, we don't elide the contents of coalesced weak symbols if they57## are part of a section that has other non-coalesced symbols. In contrast, LD6458## does elide the contents.59# SUB-NOSUB:       Contents of (__DATA,__data) section60# SUB-NOSUB-NEXT:  0000000000001000    23 01 00 00 00 00 00 00 00 10 00 00 00 00 00 0061# SUB-NOSUB-NEXT:  0000000000001010    00 00 00 00 00 00 00 00 23 01 00 00 00 00 00 0062# SUB-NOSUB-EMPTY:63# SUB-NOSUB-NEXT:  SYMBOL TABLE:64# SUB-NOSUB-NEXT:  0000000000001000 l     O __DATA,__data _alias65# SUB-NOSUB-NEXT:  0000000000001008 l     O __DATA,__data _ref66# SUB-NOSUB-NEXT:  0000000000001010 l     O __DATA,__data _zeros67# SUB-NOSUB-NEXT:  0000000000001000 l     O __DATA,__data _alias68# SUB-NOSUB-NEXT:  0000000000001000  w    O __DATA,__data _weak69# SUB-NOSUB-NEXT:  0000000000000000         *UND* dyld_stub_binder70 71# RUN: %lld -lSystem -dylib %t/no-subsections.o %t/local-then-weak.o -o %t/nosub-sub72# RUN: llvm-objdump --macho --syms --section="__DATA,__data" %t/nosub-sub | FileCheck %s --check-prefix NOSUB-SUB73 74# NOSUB-SUB:       Contents of (__DATA,__data) section75# NOSUB-SUB-NEXT:  0000000000001000    00 00 00 00 00 00 00 00 23 01 00 00 00 00 00 0076# NOSUB-SUB-NEXT:  0000000000001010    08 10 00 00 00 00 00 00 {{$}}77# NOSUB-SUB-EMPTY:78# NOSUB-SUB-NEXT:  SYMBOL TABLE:79# NOSUB-SUB-NEXT:  0000000000001000 l     O __DATA,__data _zeros80# NOSUB-SUB-NEXT:  0000000000001008 l     O __DATA,__data _alias81# NOSUB-SUB-NEXT:  0000000000001008 l     O __DATA,__data _alias82# NOSUB-SUB-NEXT:  0000000000001010 l     O __DATA,__data _ref83# NOSUB-SUB-NEXT:  0000000000001008  w    O __DATA,__data _weak84# NOSUB-SUB-NEXT:  0000000000000000         *UND* dyld_stub_binder85 86## Verify that we don't drop any flags that the aliases have (such as87## .no_dead_strip). This is a regression test. We previously had subsections88## that were mistakenly stripped.89 90# RUN: %lld -lSystem -dead_strip %t/no-dead-strip.o -o %t/no-dead-strip91# RUN: llvm-objdump --macho --section-headers %t/no-dead-strip | FileCheck %s \92# RUN:   --check-prefix=NO-DEAD-STRIP93# NO-DEAD-STRIP: __data        0000001094 95#--- weak-then-local.s96.globl _weak97.weak_definition _weak98.data99_weak:100_alias:101  .quad 0x123102 103_ref:104  .quad _alias105 106.subsections_via_symbols107 108#--- local-then-weak.s109.globl _weak110.weak_definition _weak111.data112_alias:113_weak:114  .quad 0x123115 116_ref:117  .quad _alias118 119.subsections_via_symbols120 121#--- no-subsections.s122.globl _weak123.weak_definition _weak124.data125_zeros:126.space 8127 128_weak:129_alias:130  .quad 0x123131 132#--- no-dead-strip.s133.globl _main134 135_main:136  ret137 138.data139.no_dead_strip l_foo, l_bar140 141_foo:142l_foo:143  .quad 0x123144 145l_bar:146_bar:147  .quad 0x123148 149.subsections_via_symbols150