llvm-project/lld/test/MachO/map-file.s

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

94 lines
3.1 KiB
ArmAsm
Raw Normal View History

# REQUIRES: x86
# RUN: rm -rf %t; split-file %s %t
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/foo.s -o %t/foo.o
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/test.s -o %t/test.o
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/c-string-literal.s -o %t/c-string-literal.o
# RUN: %lld -map %t/map %t/test.o %t/foo.o --time-trace -o %t/test-map
# RUN: llvm-objdump --syms --section-headers %t/test-map > %t/objdump
# RUN: cat %t/objdump %t/map > %t/out
# RUN: FileCheck %s < %t/out
# RUN: FileCheck %s --check-prefix=MAPFILE < %t/test-map.time-trace
# CHECK: Sections:
# CHECK-NEXT: Idx Name Size VMA Type
# CHECK-NEXT: 0 __text {{[0-9a-f]+}} [[#%x,TEXT:]] TEXT
# CHECK-NEXT: 1 obj {{[0-9a-f]+}} [[#%x,DATA:]] DATA
# CHECK-NEXT: 2 __common {{[0-9a-f]+}} [[#%x,BSS:]] BSS
# CHECK: SYMBOL TABLE:
# CHECK-NEXT: [[#%x,MAIN:]] g F __TEXT,__text _main
# CHECK-NEXT: [[#%x,NUMBER:]] g O __DATA,__common _number
# CHECK-NEXT: [[#%x,FOO:]] g O __TEXT,obj _foo
# CHECK-NEXT: [[#%x,HEADER:]] g F __TEXT,__text __mh_execute_header
# CHECK-NEXT: # Path: {{.*}}{{/|\\}}map-file.s.tmp/test-map
# CHECK-NEXT: # Arch: x86_64
# CHECK-NEXT: # Object files:
# CHECK-NEXT: [ 0] linker synthesized
# CHECK-NEXT: [ 1] {{.*}}{{/|\\}}map-file.s.tmp/test.o
# CHECK-NEXT: [ 2] {{.*}}{{/|\\}}map-file.s.tmp/foo.o
# CHECK-NEXT: # Sections:
# CHECK-NEXT: # Address Size Segment Section
# CHECK-NEXT: 0x[[#TEXT]] 0x{{[0-9a-f]+}} __TEXT __text
# CHECK-NEXT: 0x[[#DATA]] 0x{{[0-9a-f]+}} __TEXT obj
# CHECK-NEXT: 0x[[#BSS]] 0x{{[0-9a-f]+}} __DATA __common
# CHECK-NEXT: # Symbols:
# CHECK-NEXT: # Address File Name
# CHECK-NEXT: 0x[[#MAIN]] [ 1] _main
# CHECK-NEXT: 0x[[#FOO]] [ 2] _foo
[lld][macho] Stop grouping symbols by sections in mapfile. As per [Bug 50689](https://bugs.llvm.org/show_bug.cgi?id=50689), ``` 2. getSectionSyms() puts all the symbols into a map of section -> symbols, but this seems unnecessary. This was likely copied from the ELF port, which prints a section header before the list of symbols it contains. But the Mach-O map file doesn't print these headers. ``` This diff removes `getSectionSyms()` and keeps all symbols in a flat vector. What does ld64's mapfile look like? ``` $ llvm-mc -filetype=obj -triple=x86_64-apple-darwin test.s -o test.o $ llvm-mc -filetype=obj -triple=x86_64-apple-darwin foo.s -o foo.o $ ld -map map test.o foo.o -o out -L/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib -lSystem ``` ``` [ 0] linker synthesized [ 1] test.o [ 2] foo.o 0x100003FB7 0x00000001 __TEXT __text 0x100003FB8 0x00000000 __TEXT obj 0x100003FB8 0x00000048 __TEXT __unwind_info 0x100004000 0x00000001 __DATA __common 0x100003FB7 0x00000001 [ 1] _main 0x100003FB8 0x00000000 [ 2] _foo 0x100003FB8 0x00000048 [ 0] compact unwind info 0x100004000 0x00000001 [ 1] _number ``` Perf numbers when linking chromium framework on a 16-Core Intel Xeon W Mac Pro: ``` base diff difference (95% CI) sys_time 1.406 ± 0.020 1.388 ± 0.019 [ -1.9% .. -0.6%] user_time 5.557 ± 0.023 5.914 ± 0.020 [ +6.2% .. +6.6%] wall_time 4.455 ± 0.041 4.436 ± 0.035 [ -0.8% .. -0.0%] samples 35 35 ``` Reviewed By: #lld-macho, int3 Differential Revision: https://reviews.llvm.org/D114735
2022-01-21 04:13:04 +08:00
# CHECK-NEXT: 0x[[#NUMBER]] [ 1] _number
# RUN: %lld -map %t/c-string-literal-map %t/c-string-literal.o -o %t/c-string-literal-out
# RUN: FileCheck --check-prefix=CSTRING %s < %t/c-string-literal-map
## C-string literals should be printed as "literal string: <C string literal>"
# CSTRING-LABEL: Symbols:
# CSTRING-DAG: _main
# CSTRING-DAG: literal string: Hello world!\n
# CSTRING-DAG: literal string: Hello, it's me
# RUN: %lld -dead_strip -map %t/dead-c-string-literal-map %t/c-string-literal.o -o %t/dead-c-string-literal-out
# RUN: FileCheck --check-prefix=DEADCSTRING %s < %t/dead-c-string-literal-map
## C-string literals should be printed as "literal string: <C string literal>"
# DEADCSTRING-LABEL: Symbols:
# DEADCSTRING-DAG: _main
# DEADCSTRING-DAG: literal string: Hello world!\n
# DEADCSTRING-LABEL: Dead Stripped Symbols:
# DEADCSTRING-DAG: literal string: Hello, it's me
# MAPFILE: "name":"Total Write map file"
#--- foo.s
.section __TEXT,obj
.globl _foo
_foo:
#--- test.s
.comm _number, 1
.globl _main
_main:
ret
#--- c-string-literal.s
.section __TEXT,__cstring
.globl _hello_world, _hello_its_me, _main
_hello_world:
.asciz "Hello world!\n"
_hello_its_me:
.asciz "Hello, it's me"
.text
_main:
movl $0x2000004, %eax # write() syscall
mov $1, %rdi # stdout
leaq _hello_world(%rip), %rsi
mov $13, %rdx # length of str
syscall
ret