brintos

brintos / llvm-project-archived public Read only

0
0
Text · 14.6 KiB · a10f0f4 Raw
480 lines · plain
1# REQUIRES: x862# RUN: rm -rf %t; split-file %s %t3 4## This tests that if two input files define the same weak symbol, we only5## write it to the output once (...assuming both input files use6## .subsections_via_symbols).7 8# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/weak-sub.s -o %t/weak-sub.o9# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/weak-nosub.s -o %t/weak-nosub.o10 11## Test that weak symbols are emitted just once with .subsections_via_symbols12# RUN: %lld -dylib -o %t/out.dylib %t/weak-sub.o %t/weak-sub.o13# RUN: llvm-otool -jtV %t/out.dylib | FileCheck --check-prefix=SUB %s14# RUN: %lld -dylib -o %t/out.dylib %t/weak-nosub.o %t/weak-sub.o15# RUN: llvm-otool -jtV %t/out.dylib | FileCheck --check-prefix=SUB %s16# RUN: %lld -dylib -o %t/out.dylib %t/weak-sub.o %t/weak-nosub.o17# RUN: llvm-otool -jtV %t/out.dylib | FileCheck --check-prefix=SUB %s18# SUB:      _foo19# SUB-NEXT: retq20# SUB-NOT:  retq21# SUB:      _bar22# SUB-NEXT: retq23# SUB-NOT:  retq24 25## We can even strip weak symbols without subsections_via_symbols as long26## as none of the weak symbols in a section are needed.27# RUN: %lld -dylib -o %t/out.dylib %t/weak-nosub.o %t/weak-nosub.o28# RUN: llvm-otool -jtV %t/out.dylib | FileCheck --check-prefix=SUB %s29 30## Test that omitted weak symbols don't add entries to the compact unwind table.31# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin19.0.0 %t/weak-sub-lsda.s -o %t/weak-sub-lsda.o32# RUN: %lld -dylib -lc++ -o %t/out.dylib %t/weak-sub-lsda.o %t/weak-sub-lsda.o33# RUN: llvm-objdump --macho --unwind-info --syms %t/out.dylib | FileCheck %s --check-prefix=ONE-UNWIND34# RUN: %lld -dylib -lc++ -o %t/out.dylib %t/weak-sub.o %t/weak-sub-lsda.o35# RUN: llvm-objdump --macho --unwind-info --syms %t/out.dylib | FileCheck %s --check-prefix=NO-UNWIND36# RUN: yaml2obj %t/weak-sub-lsda-r.yaml -o %t/weak-sub-lsda-r.o37# RUN: %lld -dylib -lc++ -o %t/out.dylib %t/weak-sub.o %t/weak-sub-lsda-r.o38# RUN: llvm-objdump --macho --unwind-info --syms %t/out.dylib | FileCheck %s --check-prefix=NO-UNWIND39 40# ONE-UNWIND:      SYMBOL TABLE:41# ONE-UNWIND-DAG:  [[#%x,FOO:]]       w  F __TEXT,__text _foo42# ONE-UNWIND-NOT:                          __TEXT,__text _foo43 44# ONE-UNWIND:      Contents of __unwind_info section:45# ONE-UNWIND:        LSDA descriptors:46# ONE-UNWIND:           [0]: function offset=0x[[#%.8x,FOO]]47# ONE-UNWIND-NOT:       [1]:48# ONE-UNWIND:        Second level indices:49# ONE-UNWIND-DAG:      [0]: function offset=0x[[#%.8x,FOO]]50# ONE-UNWIND-NOT:      [1]:51 52# NO-UNWIND:      SYMBOL TABLE:53# NO-UNWIND-DAG:  [[#%x,FOO:]]       w  F __TEXT,__text _foo54# NO-UNWIND-NOT:                          __TEXT,__text _foo55# NO-UNWIND-NOT:  Contents of __unwind_info section:56 57## Test interaction with .alt_entry58## FIXME: ld64 manages to strip both one copy of _foo and _bar each.59##        We only manage this if we're lucky and the object files are in60##        the right order. We're happy to not crash at link time for now.61# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin19.0.0 %t/weak-sub-alt.s -o %t/weak-sub-alt.o62# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin19.0.0 %t/weak-sub-alt2.s -o %t/weak-sub-alt2.o63# RUN: %lld -dylib -o %t/out.dylib %t/weak-sub-alt.o %t/weak-sub-alt2.o64# RUN: %lld -dylib -o %t/out.dylib %t/weak-sub-alt2.o %t/weak-sub-alt.o65 66# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin19.0.0 %t/weak-aligned-1.s -o %t/weak-aligned-1.o67# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin19.0.0 %t/weak-aligned-2.s -o %t/weak-aligned-2.o68# RUN: %lld -o %t/out -lSystem %t/weak-aligned-1.o %t/weak-aligned-2.o69# RUN: llvm-objdump --syms --section=__const --full-contents %t/out | FileCheck --check-prefixes=ALIGN,ALIGN2 %s70# RUN: %lld -o %t/out -lSystem %t/weak-aligned-1.o %t/weak-aligned-2.o -dead_strip71# RUN: llvm-objdump --syms --section=__const --full-contents %t/out | FileCheck --check-prefixes=ALIGN,ALIGN3 %s72# ALIGN:       SYMBOL TABLE:73# ALIGN-DAG:   [[#%x, ADDR:]]       l     O __DATA_CONST,__const .hidden _weak174# ALIGN2-DAG:  {{0*}}[[#ADDR+ 0x4]] l     O __DATA_CONST,__const .hidden _weak375# ALIGN3-DAG:  {{0*}}[[#ADDR+ 0x4]] l     O __DATA_CONST,__const .hidden _weak276# ALIGN2-DAG:  {{0*}}[[#ADDR+ 0x8]] l     O __DATA_CONST,__const .hidden _weak277# ALIGN-DAG:   {{0*}}[[#ADDR+0x10]] g     O __DATA_CONST,__const _aligned78# ALIGN:       Contents of section __DATA_CONST,__const:79# ALIGN2-NEXT: {{0*}}[[#ADDR]]      11111111 33333333 22222222 0000000080# ALIGN3-NEXT: {{0*}}[[#ADDR]]      11111111 22222222 00000000 0000000081# ALIGN-NEXT:  {{0*}}[[#ADDR+0x10]] 81818181 81818181 82828282 8282828282 83# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin19.0.0 %t/weak-def.s -o %t/weak-def.o84# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin19.0.0 %t/strong-def.s -o %t/strong-def.o85# RUN: %lld -dylib -lc++ -o %t/weak-strong-mixed.dylib %t/weak-def.o %t/strong-def.o86# RUN: %lld -dylib -lc++ -o %t/strong-weak-mixed.dylib %t/strong-def.o %t/weak-def.o87## Check that omitted weak symbols are not adding their section and unwind stuff.88 89# RUN: llvm-otool -jtV %t/weak-strong-mixed.dylib | FileCheck --check-prefix=MIXED %s90# RUN: llvm-otool -jtV %t/strong-weak-mixed.dylib | FileCheck --check-prefix=MIXED %s91# MIXED: (__TEXT,__text) section92# MIXED-NEXT: _foo:93# MIXED-NEXT: {{.+}} 	33 33            	xorl	(%rbx), %esi94# MIXED-NEXT: {{.+}} 	33 33            	xorl	(%rbx), %esi95# MIXED-NEXT: {{.+}}	c3              	retq96 97# RUN: llvm-objdump --macho --syms --unwind-info %t/weak-strong-mixed.dylib | FileCheck --check-prefix=MIXED-UNWIND %s98# RUN: llvm-objdump --macho --syms --unwind-info %t/strong-weak-mixed.dylib | FileCheck --check-prefix=MIXED-UNWIND %s99# MIXED-UNWIND: g     F __TEXT,__text _foo100# MIXED-UNWIND-NOT: Contents of __unwind_info section:101 102#--- weak-sub.s103.globl _foo, _bar104.weak_definition _foo, _bar105_foo:106  retq107_bar:108  retq109.subsections_via_symbols110 111#--- weak-nosub.s112.globl _foo, _bar113.weak_definition _foo, _bar114_foo:115  retq116_bar:117  retq118 119#--- weak-sub-lsda.s120.section __TEXT,__text,regular,pure_instructions121 122.globl _foo123.weak_definition _foo124_foo:125  .cfi_startproc126  .cfi_personality 155, ___gxx_personality_v0127  .cfi_lsda 16, Lexception128  pushq %rbp129  .cfi_def_cfa_offset 128130  .cfi_offset %rbp, 48131  movq %rsp, %rbp132  .cfi_def_cfa_register %rbp133  popq %rbp134  retq135  .cfi_endproc136 137.section __TEXT,__gcc_except_tab138Lexception:139    .space 0x10140 141.subsections_via_symbols142 143#--- weak-sub-alt.s144.globl _foo, _bar145.weak_definition _foo146_foo:147  retq148 149# Alternative entry point to _foo (strong)150.alt_entry _bar151_bar:152  retq153 154.globl _main, _ref155_main:156  callq _ref157  callq _bar158 159.subsections_via_symbols160 161#--- weak-sub-alt2.s162.globl _foo, _bar163.weak_definition _foo164_foo:165  retq166 167# Alternative entry point to _foo (weak)168.weak_definition _bar169.alt_entry _bar170_bar:171  retq172 173.globl _ref174_ref:175  callq _bar176 177.subsections_via_symbols178 179#--- weak-aligned-1.s180.section __DATA,__const181.p2align 3182.globl _weak1183.weak_def_can_be_hidden _weak1184_weak1:185  .4byte 0x11111111186 187.globl _weak3188.weak_def_can_be_hidden _weak3189_weak3:190  .4byte 0x33333333191 192.subsections_via_symbols193 194#--- weak-aligned-2.s195# _weak1 and _weak3 are already in weak-aligned-1,196# so from _weak1-3 in this file only _weak2 is used.197# However, _aligned still has to stay aligned to a 16-byte boundary.198.section __DATA,__const199.p2align 3200.globl _weak1201.weak_def_can_be_hidden _weak1202_weak1:203  .4byte 0x11111111204 205.globl _weak2206.weak_def_can_be_hidden _weak2207_weak2:208  .4byte 0x22222222209 210.globl _weak3211.weak_def_can_be_hidden _weak3212_weak3:213  .4byte 0x33333333214 215.section __DATA,__const216.p2align 4217.globl _aligned218_aligned:219  .8byte 0x8181818181818181220  .8byte 0x8282828282828282221 222.section __TEXT,__text223.globl _main224_main:225  movl _weak1(%rip), %eax226  movl _weak2(%rip), %ebx227  movaps _aligned(%rip), %xmm0228  retq229 230.subsections_via_symbols231 232#--- weak-def.s233.section __TEXT,__text,regular,pure_instructions234 235.globl _foo236.weak_definition _foo237_foo:238  .cfi_startproc239  .cfi_personality 155, ___gxx_personality_v0240  .cfi_lsda 16, Lexception241  pushq %rbp242  .cfi_def_cfa_offset 128243  .cfi_offset %rbp, 48244  movq %rsp, %rbp245  .cfi_def_cfa_register %rbp246  popq %rbp247  retq248  .cfi_endproc249 250.section __TEXT,__gcc_except_tab251Lexception:252    .space 0x10253 254.subsections_via_symbols255#--- strong-def.s256.globl _foo, _bar257 258_foo:259  .4byte 0x33333333260  retq261 262.subsections_via_symbols263 264#--- weak-sub-lsda-r.yaml265## This was generated from compiling weak-sub-lsda.s above at rev a2404f11c77e266## and then running it through `ld -r`. This converts a number of unwind-related267## relocations from section- to symbol-based ones.268--- !mach-o269FileHeader:270  magic:           0xFEEDFACF271  cputype:         0x1000007272  cpusubtype:      0x3273  filetype:        0x1274  ncmds:           2275  sizeofcmds:      464276  flags:           0x2000277  reserved:        0x0278LoadCommands:279  - cmd:             LC_SEGMENT_64280    cmdsize:         392281    segname:         ''282    vmaddr:          0283    vmsize:          152284    fileoff:         528285    filesize:        152286    maxprot:         7287    initprot:        7288    nsects:          3289    flags:           0290    Sections:291      - sectname:        __text292        segname:         __TEXT293        addr:            0x0294        size:            6295        offset:          0x210296        align:           0297        reloff:          0x0298        nreloc:          0299        flags:           0x80000400300        reserved1:       0x0301        reserved2:       0x0302        reserved3:       0x0303        content:         554889E55DC3304      - sectname:        __gcc_except_tab305        segname:         __TEXT306        addr:            0x6307        size:            32308        offset:          0x216309        align:           0310        reloff:          0x0311        nreloc:          0312        flags:           0x0313        reserved1:       0x0314        reserved2:       0x0315        reserved3:       0x0316        content:         '0000000000000000000000000000000000000000000000000000000000000000'317      - sectname:        __eh_frame318        segname:         __TEXT319        addr:            0x28320        size:            80321        offset:          0x238322        align:           3323        reloff:          0x2A8324        nreloc:          7325        flags:           0x0326        reserved1:       0x0327        reserved2:       0x0328        reserved3:       0x0329        content:         1C00000000000000017A504C5200017810079B0400000010100C0708900100002C00000004000000F8FFFFFFFFFFFFFF060000000000000008E7FFFFFFFFFFFFFF410E800111067A430D060000000000330        relocations:331          - address:         0x13332            symbolnum:       5333            pcrel:           true334            length:          2335            extern:          true336            type:            4337            scattered:       false338            value:           0339          - address:         0x24340            symbolnum:       2341            pcrel:           false342            length:          2343            extern:          true344            type:            5345            scattered:       false346            value:           0347          - address:         0x24348            symbolnum:       3349            pcrel:           false350            length:          2351            extern:          true352            type:            0353            scattered:       false354            value:           0355          - address:         0x28356            symbolnum:       3357            pcrel:           false358            length:          3359            extern:          true360            type:            5361            scattered:       false362            value:           0363          - address:         0x28364            symbolnum:       4365            pcrel:           false366            length:          3367            extern:          true368            type:            0369            scattered:       false370            value:           0371          - address:         0x39372            symbolnum:       3373            pcrel:           false374            length:          3375            extern:          true376            type:            5377            scattered:       false378            value:           0379          - address:         0x39380            symbolnum:       1381            pcrel:           false382            length:          3383            extern:          true384            type:            0385            scattered:       false386            value:           0387      - sectname:        __compact_unwind388        segname:         __LD389        addr:            0x78390        size:            32391        offset:          0x288392        align:           3393        reloff:          0x2E0394        nreloc:          4395        flags:           0x2000000396        reserved1:       0x0397        reserved2:       0x0398        reserved3:       0x0399        content:         '0000000000000000060000000000004100000000000000000000000000000000'400        relocations:401          - address:         0x0402            symbolnum:       4403            pcrel:           false404            length:          3405            extern:          true406            type:            0407            scattered:       false408            value:           0409          - address:         0x18410            symbolnum:       1411            pcrel:           false412            length:          3413            extern:          true414            type:            0415            scattered:       false416            value:           0417          - address:         0x10418            symbolnum:       5419            pcrel:           false420            length:          3421            extern:          true422            type:            0423            scattered:       false424            value:           0425          - address:         0x18426            symbolnum:       1427            pcrel:           false428            length:          3429            extern:          true430            type:            0431            scattered:       false432            value:           0433  - cmd:             LC_SYMTAB434    cmdsize:         24435    symoff:          768436    nsyms:           6437    stroff:          864438    strsize:         57439LinkEditData:440  NameList:441    - n_strx:          29442      n_type:          0xE443      n_sect:          2444      n_desc:          0445      n_value:         6446    - n_strx:          34447      n_type:          0xE448      n_sect:          2449      n_desc:          0450      n_value:         22451    - n_strx:          39452      n_type:          0xE453      n_sect:          3454      n_desc:          0455      n_value:         40456    - n_strx:          49457      n_type:          0xE458      n_sect:          3459      n_desc:          0460      n_value:         72461    - n_strx:          2462      n_type:          0xF463      n_sect:          1464      n_desc:          128465      n_value:         0466    - n_strx:          7467      n_type:          0x1468      n_sect:          0469      n_desc:          0470      n_value:         0471  StringTable:472    - ' '473    - _foo474    - ___gxx_personality_v0475    - l001476    - l002477    - EH_Frame1478    - func.eh479...480