1# REQUIRES: x86 2# RUN: rm -rf %t; split-file %s %t 3# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/foo.s -o %t/foo.o 4# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/test.s -o %t/test.o 5# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/c-string-literal.s -o %t/c-string-literal.o 6# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/baz.s -o %t/baz.o 7 8# RUN: llvm-ar --format=darwin crs %t/libfoo.a %t/foo.o 9# RUN: %lld -dylib %t/baz.o -o %t/libbaz.dylib 10# RUN: %lld -demangle -map %t/map %t/test.o -force_load %t/libfoo.a \ 11# RUN: %t/c-string-literal.o %t/libbaz.dylib --time-trace -o %t/test \ 12# RUN: --no-deduplicate-strings 13# RUN: llvm-objdump --syms --section-headers %t/test > %t/objdump 14## Check that symbols in cstring sections aren't emitted 15## Also check that we don't have redundant EH_Frame symbols (regression test) 16# RUN: cat %t/objdump %t/map | FileCheck %s --implicit-check-not _hello_world \ 17# RUN: --implicit-check-not EH_Frame 18# RUN: FileCheck %s --check-prefix=MAPFILE < %t/test.time-trace 19 20# CHECK: Sections: 21# CHECK-NEXT: Idx Name Size VMA Type 22# CHECK-NEXT: 0 __text 0000001c [[#%x,TEXT:]] TEXT 23# CHECK-NEXT: 1 __stubs 0000000c [[#%x,STUBS:]] TEXT 24# CHECK-NEXT: 2 __stub_helper 0000001a [[#%x,HELPER:]] TEXT 25# CHECK-NEXT: 3 __cstring 0000002b [[#%x,CSTR:]] DATA 26# CHECK-NEXT: 4 __unwind_info 0000103c [[#%x,UNWIND:]] DATA 27# CHECK-NEXT: 5 __eh_frame 00000038 [[#%x,EH_FRAME:]] DATA 28# CHECK-NEXT: 6 __got 00000010 [[#%x,GOT:]] DATA 29# CHECK-NEXT: 7 __la_symbol_ptr 00000010 [[#%x,LAZY:]] DATA 30# CHECK-NEXT: 8 __data 00000008 [[#%x,DATA:]] DATA 31# CHECK-NEXT: 9 __thread_ptrs 00000008 [[#%x,TLVP:]] DATA 32# CHECK-NEXT: 10 __common 00000001 [[#%x,BSS:]] BSS 33 34# CHECK: SYMBOL TABLE: 35# CHECK-DAG: [[#%x,DYLD:]] l O __DATA,__data __dyld_private 36# CHECK-DAG: [[#%x,MAIN:]] g F __TEXT,__text _main 37# CHECK-DAG: [[#%x,NUMBER:]] g O __DATA,__common _number 38# CHECK-DAG: [[#%x,BAR:]] w F __TEXT,__text _bar 39# CHECK-DAG: [[#%x,FOO:]] g F __TEXT,__text __ZTIN3foo3bar4MethE 40# CHECK-DAG: [[#%x,HIWORLD:]] g O __TEXT,__cstring _hello_world 41# CHECK-DAG: [[#%x,HIITSME:]] g O __TEXT,__cstring _hello_its_me 42 43# CHECK: # Path: {{.*}}{{/|\\}}map-file.s.tmp/test 44# CHECK-NEXT: # Arch: x86_64 45# CHECK-NEXT: # Object files: 46# CHECK-NEXT: [ 0] linker synthesized 47# CHECK-NEXT: [ 1] {{.*}}{{/|\\}}usr/lib{{/|\\}}libSystem.tbd{{$}} 48# CHECK-NEXT: [ 2] {{.*}}{{/|\\}}map-file.s.tmp/test.o{{$}} 49# CHECK-NEXT: [ 3] {{.*}}{{/|\\}}map-file.s.tmp/libfoo.a(foo.o){{$}} 50# CHECK-NEXT: [ 4] {{.*}}{{/|\\}}map-file.s.tmp/c-string-literal.o{{$}} 51# CHECK-NEXT: [ 5] {{.*}}{{/|\\}}map-file.s.tmp/libbaz.dylib{{$}} 52 53# CHECK-NEXT: # Sections: 54# CHECK-NEXT: # Address Size Segment Section 55# CHECK-NEXT: 0x[[#%X,TEXT]] 0x{{[0-9A-F]+}} __TEXT __text 56# CHECK-NEXT: 0x[[#%X,STUBS]] 0x{{[0-9A-F]+}} __TEXT __stubs 57# CHECK-NEXT: 0x[[#%X,HELPER]] 0x{{[0-9A-F]+}} __TEXT __stub_helper 58# CHECK-NEXT: 0x[[#%X,CSTR]] 0x{{[0-9A-F]+}} __TEXT __cstring 59# CHECK-NEXT: 0x[[#%X,UNWIND]] 0x{{[0-9A-F]+}} __TEXT __unwind_info 60# CHECK-NEXT: 0x[[#%X,EH_FRAME]] 0x{{[0-9A-F]+}} __TEXT __eh_frame 61# CHECK-NEXT: 0x[[#%X,GOT]] 0x{{[0-9A-F]+}} __DATA_CONST __got 62# CHECK-NEXT: 0x[[#%X,LAZY]] 0x{{[0-9A-F]+}} __DATA __la_symbol_ptr 63# CHECK-NEXT: 0x[[#%X,DATA]] 0x{{[0-9A-F]+}} __DATA __data 64# CHECK-NEXT: 0x[[#%X,TLVP]] 0x{{[0-9A-F]+}} __DATA __thread_ptrs 65# CHECK-NEXT: 0x[[#%X,BSS]] 0x{{[0-9A-F]+}} __DATA __common 66 67# CHECK-NEXT: # Symbols: 68# CHECK-NEXT: # Address Size File Name 69# CHECK-NEXT: 0x[[#%X,MAIN]] 0x00000019 [ 2] _main 70# CHECK-NEXT: 0x[[#%X,BAR]] 0x00000001 [ 2] _bar 71# CHECK-NEXT: 0x[[#%X,FOO]] 0x00000001 [ 3] __ZTIN3foo3bar4MethE 72# CHECK-NEXT: 0x[[#%X,FOO+1]] 0x00000001 [ 3] ltmp1 73# CHECK-NEXT: 0x[[#%X,STUBS]] 0x00000006 [ 5] _baz 74# CHECK-NEXT: 0x[[#%X,STUBS+6]] 0x00000006 [ 2] _bar 75# CHECK-NEXT: 0x[[#%X,HELPER]] 0x0000001A [ 0] helper helper 76# CHECK-NEXT: 0x[[#%X,HIWORLD]] 0x0000000E [ 4] literal string: Hello world!\n 77# CHECK-NEXT: 0x[[#%X,HIITSME]] 0x0000000F [ 4] literal string: Hello, it's me 78# CHECK-NEXT: 0x[[#%X,HIITSME+0xf]] 0x0000000E [ 4] literal string: Hello world!\n 79# CHECK-NEXT: 0x[[#%X,UNWIND]] 0x0000103C [ 0] compact unwind info 80## Note: ld64 prints "CIE" and "FDE for: <function>" instead of "EH_Frame". 81# CHECK-NEXT: 0x[[#%X,EH_FRAME]] 0x00000018 [ 2] EH_Frame 82# CHECK-NEXT: 0x[[#%X,EH_FRAME+0x18]] 0x00000020 [ 2] EH_Frame 83# CHECK-NEXT: 0x[[#%X,GOT]] 0x00000008 [ 0] non-lazy-pointer-to-local: _baz2 84# CHECK-NEXT: 0x[[#%X,GOT+8]] 0x00000008 [ 0] non-lazy-pointer-to-local: dyld_stub_binder 85# CHECK-NEXT: 0x[[#%X,LAZY]] 0x00000008 [ 5] _baz 86# CHECK-NEXT: 0x[[#%X,LAZY+8]] 0x00000008 [ 2] _bar 87# CHECK-NEXT: 0x[[#%X,DYLD]] 0x00000000 [ 0] __dyld_private 88# CHECK-NEXT: 0x[[#%X,TLVP]] 0x00000008 [ 0] non-lazy-pointer-to-local: _baz_tlv 89# CHECK-NEXT: 0x[[#%X,BSS]] 0x00000001 [ 2] _number 90# CHECK-EMPTY: 91 92# MAPFILE: "name":"Total Write map file" 93 94# RUN: %lld -demangle -dead_strip -map %t/stripped-map %t/test.o -force_load \ 95# RUN: %t/libfoo.a %t/c-string-literal.o %t/libbaz.dylib -o %t/stripped 96# RUN: FileCheck --check-prefix=STRIPPED %s < %t/stripped-map 97 98# STRIPPED-LABEL: Dead Stripped Symbols: 99# STRIPPED-DAG: <<dead>> 0x00000001 [ 2] _number 100# STRIPPED-DAG: <<dead>> 0x00000001 [ 3] __ZTIN3foo3bar4MethE 101# STRIPPED-DAG: <<dead>> 0x0000000E [ 4] literal string: Hello world!\n 102# STRIPPED-DAG: <<dead>> 0x0000000F [ 4] literal string: Hello, it's me 103# STRIPPED-DAG: <<dead>> 0x0000000E [ 4] literal string: Hello world!\n 104 105# RUN: %lld --icf=all -map %t/icf-map %t/test.o -force_load %t/libfoo.a \ 106# RUN: %t/c-string-literal.o %t/libbaz.dylib -o /dev/null 107# RUN: FileCheck --check-prefix=ICF %s < %t/icf-map 108 109## Verify that folded symbols and cstrings have size zero. Note that ld64 prints 110## folded symbols but not folded cstrings; we print both. 111 112# ICF: Symbols: 113# ICF-DAG: 0x[[#%X,FOO:]] 0x00000000 [ 3] __ZTIN3foo3bar4MethE 114# ICF-DAG: 0x[[#FOO]] 0x00000001 [ 2] _bar 115# ICF-DAG: 0x[[#%X,HIWORLD:]] 0x0000000E [ 4] literal string: Hello world!\n 116# ICF-DAG: 0x[[#%X,HIWORLD]] 0x00000000 [ 4] literal string: Hello world!\n 117 118#--- foo.s 119.globl __ZTIN3foo3bar4MethE 120## This should not appear in the map file since it is a zero-size private label 121## symbol. 122ltmp0: 123## This C++ symbol makes it clear that we do not print the demangled name in 124## the map file, even if `-demangle` is passed. 125__ZTIN3foo3bar4MethE: 126 nop 127 128## This private label symbol will appear in the map file since it has nonzero 129## size. 130ltmp1: 131 nop 132 133.subsections_via_symbols 134 135#--- test.s 136.comm _number, 1 137.globl _main, _bar 138.weak_definition _bar 139 140_main: 141.cfi_startproc 142.cfi_def_cfa_offset 16 143 callq _bar 144 callq _baz 145 movq _baz2@GOTPCREL(%rip), %rax 146 mov _baz_tlv@TLVP(%rip), %rax 147 ret 148.cfi_endproc 149 150_bar: 151 nop 152 153.subsections_via_symbols 154 155#--- c-string-literal.s 156.globl _hello_world, _hello_its_me 157 158.cstring 159 160_hello_world: 161.asciz "Hello world!\n" 162 163_hello_its_me: 164.asciz "Hello, it's me" 165 166.asciz "Hello world!\n" 167 168.subsections_via_symbols 169 170#--- baz.s 171.globl _baz, _baz2 172 173_baz: 174 nop 175 176_baz2: 177 nop 178 179.section __DATA,__thread_vars,thread_local_variables 180.globl _baz_tlv 181_baz_tlv: 182 nop 183