Skip to content

Commit aa288fd

Browse files
committed
[lld-macho] Emit map file entries for more synthetic sections
We now handle the GOT, TLV, and stubs/lazy pointer sections. Reviewed By: #lld-macho, thevinster, thakis Differential Revision: https://reviews.llvm.org/D139762
1 parent c774fd5 commit aa288fd

File tree

4 files changed

+158
-70
lines changed

4 files changed

+158
-70
lines changed

lld/MachO/MapFile.cpp

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,11 @@ struct MapInfo {
6363

6464
static MapInfo gatherMapInfo() {
6565
MapInfo info;
66-
for (InputFile *file : inputFiles)
66+
for (InputFile *file : inputFiles) {
67+
bool isReferencedFile = false;
68+
6769
if (isa<ObjFile>(file) || isa<BitcodeFile>(file)) {
6870
uint32_t fileIndex = info.files.size() + 1;
69-
bool isReferencedFile = false;
7071

7172
// Gather the dead symbols. We don't have to bother with the live ones
7273
// because we will pick them up as we iterate over the OutputSections
@@ -104,11 +105,14 @@ static MapInfo gatherMapInfo() {
104105
}
105106
}
106107
}
107-
108-
if (isReferencedFile)
109-
info.files.push_back(file);
108+
} else if (const auto *dylibFile = dyn_cast<DylibFile>(file)) {
109+
isReferencedFile = dylibFile->isReferenced();
110110
}
111111

112+
if (isReferencedFile)
113+
info.files.push_back(file);
114+
}
115+
112116
// cstrings are not stored in sorted order in their OutputSections, so we sort
113117
// them here.
114118
for (auto &liveCStrings : info.liveCStringsForSection)
@@ -118,6 +122,30 @@ static MapInfo gatherMapInfo() {
118122
return info;
119123
}
120124

125+
// For printing the contents of the __stubs and __la_symbol_ptr sections.
126+
void printStubsEntries(
127+
raw_fd_ostream &os,
128+
const DenseMap<lld::macho::InputFile *, uint32_t> &readerToFileOrdinal,
129+
const OutputSection *osec, size_t entrySize) {
130+
for (const Symbol *sym : in.stubs->getEntries())
131+
os << format("0x%08llX\t0x%08zX\t[%3u] %s\n",
132+
osec->addr + sym->stubsIndex * entrySize, entrySize,
133+
readerToFileOrdinal.lookup(sym->getFile()),
134+
sym->getName().str().data());
135+
}
136+
137+
void printNonLazyPointerSection(raw_fd_ostream &os,
138+
NonLazyPointerSectionBase *osec) {
139+
// ld64 considers stubs to belong to particular files, but considers GOT
140+
// entries to be linker-synthesized. Not sure why they made that decision, but
141+
// I think we can follow suit unless there's demand for better symbol-to-file
142+
// associations.
143+
for (const Symbol *sym : osec->getEntries())
144+
os << format("0x%08llX\t0x%08zX\t[ 0] non-lazy-pointer-to-local: %s\n",
145+
osec->addr + sym->gotIndex * target->wordSize,
146+
target->wordSize, sym->getName().str().data());
147+
}
148+
121149
void macho::writeMapFile() {
122150
if (config->mapFile.empty())
123151
return;
@@ -185,6 +213,18 @@ void macho::writeMapFile() {
185213
} else if (osec == (void *)in.unwindInfo) {
186214
os << format("0x%08llX\t0x%08llX\t[ 0] compact unwind info\n",
187215
osec->addr, osec->getSize());
216+
} else if (osec == in.stubs) {
217+
printStubsEntries(os, readerToFileOrdinal, osec, target->stubSize);
218+
} else if (osec == in.lazyPointers) {
219+
printStubsEntries(os, readerToFileOrdinal, osec, target->wordSize);
220+
} else if (osec == in.stubHelper) {
221+
// yes, ld64 calls it "helper helper"...
222+
os << format("0x%08llX\t0x%08llX\t[ 0] helper helper\n", osec->addr,
223+
osec->getSize());
224+
} else if (osec == in.got) {
225+
printNonLazyPointerSection(os, in.got);
226+
} else if (osec == in.tlvPointers) {
227+
printNonLazyPointerSection(os, in.tlvPointers);
188228
}
189229
// TODO print other synthetic sections
190230
}

lld/test/MachO/dead-strip.s

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,12 @@
4848

4949
# MAP: _main
5050
# MAP-LABEL: Dead Stripped Symbols
51-
# MAP-DAG: <<dead>> 0x00000001 [ 1] _unref_com
52-
# MAP-DAG: <<dead>> 0x00000008 [ 1] _unref_data
53-
# MAP-DAG: <<dead>> 0x00000006 [ 1] _unref_extern
54-
# MAP-DAG: <<dead>> 0x00000001 [ 1] _unref_local
55-
# MAP-DAG: <<dead>> 0x00000007 [ 1] _unref_private_extern
56-
# MAP-DAG: <<dead>> 0x00000008 [ 1] l_unref_data
51+
# MAP-DAG: <<dead>> 0x00000001 [ 2] _unref_com
52+
# MAP-DAG: <<dead>> 0x00000008 [ 2] _unref_data
53+
# MAP-DAG: <<dead>> 0x00000006 [ 2] _unref_extern
54+
# MAP-DAG: <<dead>> 0x00000001 [ 2] _unref_local
55+
# MAP-DAG: <<dead>> 0x00000007 [ 2] _unref_private_extern
56+
# MAP-DAG: <<dead>> 0x00000008 [ 2] l_unref_data
5757

5858
## Run dead stripping on code without any dead symbols.
5959
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos \
@@ -347,7 +347,7 @@
347347
# RUN: FileCheck --check-prefix=DUPMAP %s < %t/stripped-duplicate-map
348348
# DUPMAP: _main
349349
# DUPMAP-LABEL: Dead Stripped Symbols
350-
# DUPMAP: <<dead>> 0x00000001 [ 2] _foo
350+
# DUPMAP: <<dead>> 0x00000001 [ 3] _foo
351351

352352
#--- duplicate1.s
353353
.text

lld/test/MachO/map-file.ll

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,40 +27,43 @@
2727
; FOOBAR-NEXT: # Arch: x86_64
2828
; FOOBAR-NEXT: # Object files:
2929
; FOOBAR-NEXT: [ 0] linker synthesized
30-
; FOOBAR-NEXT: [ 1] {{.*}}{{/|\\}}map-file.ll.tmp/foo.thinlto.o
31-
; FOOBAR-NEXT: [ 2] {{.*}}{{/|\\}}map-file.ll.tmp/bar.thinlto.o
30+
; FOOBAR-NEXT: [ 1] {{.*}}{{/|\\}}usr/lib{{/|\\}}libSystem.tbd
31+
; FOOBAR-NEXT: [ 2] {{.*}}{{/|\\}}map-file.ll.tmp/foo.thinlto.o
32+
; FOOBAR-NEXT: [ 3] {{.*}}{{/|\\}}map-file.ll.tmp/bar.thinlto.o
3233
; FOOBAR-NEXT: # Sections:
3334
; FOOBAR: # Symbols:
3435
; FOOBAR-NEXT: # Address Size File Name
35-
; FOOBAR-NEXT: 0x{{[0-9A-F]+}} 0x{{[0-9A-F]+}} [ 1] _foo
36-
; FOOBAR-NEXT: 0x{{[0-9A-F]+}} 0x{{[0-9A-F]+}} [ 2] _bar
37-
; FOOBAR-NEXT: 0x{{[0-9A-F]+}} 0x{{[0-9A-F]+}} [ 2] _maybe_weak
36+
; FOOBAR-NEXT: 0x{{[0-9A-F]+}} 0x{{[0-9A-F]+}} [ 2] _foo
37+
; FOOBAR-NEXT: 0x{{[0-9A-F]+}} 0x{{[0-9A-F]+}} [ 3] _bar
38+
; FOOBAR-NEXT: 0x{{[0-9A-F]+}} 0x{{[0-9A-F]+}} [ 3] _maybe_weak
3839

3940
; BARFOO: # Path: {{.*}}{{/|\\}}map-file.ll.tmp/barfoo.thinlto
4041
; BARFOO-NEXT: # Arch: x86_64
4142
; BARFOO-NEXT: # Object files:
4243
; BARFOO-NEXT: [ 0] linker synthesized
43-
; BARFOO-NEXT: [ 1] {{.*}}{{/|\\}}map-file.ll.tmp/bar.thinlto.o
44-
; BARFOO-NEXT: [ 2] {{.*}}{{/|\\}}map-file.ll.tmp/foo.thinlto.o
44+
; BARFOO-NEXT: [ 1] {{.*}}{{/|\\}}usr/lib{{/|\\}}libSystem.tbd
45+
; BARFOO-NEXT: [ 2] {{.*}}{{/|\\}}map-file.ll.tmp/bar.thinlto.o
46+
; BARFOO-NEXT: [ 3] {{.*}}{{/|\\}}map-file.ll.tmp/foo.thinlto.o
4547
; BARFOO-NEXT: # Sections:
4648
; BARFOO: # Symbols:
4749
; BARFOO-NEXT: # Address Size File Name
48-
; BARFOO-NEXT: 0x{{[0-9A-F]+}} 0x{{[0-9A-F]+}} [ 1] _bar
49-
; BARFOO-NEXT: 0x{{[0-9A-F]+}} 0x{{[0-9A-F]+}} [ 1] _maybe_weak
50-
; BARFOO-NEXT: 0x{{[0-9A-F]+}} 0x{{[0-9A-F]+}} [ 2] _foo
50+
; BARFOO-NEXT: 0x{{[0-9A-F]+}} 0x{{[0-9A-F]+}} [ 2] _bar
51+
; BARFOO-NEXT: 0x{{[0-9A-F]+}} 0x{{[0-9A-F]+}} [ 2] _maybe_weak
52+
; BARFOO-NEXT: 0x{{[0-9A-F]+}} 0x{{[0-9A-F]+}} [ 3] _foo
5153

5254
; LTO: # Path: {{.*}}{{/|\\}}map-file.ll.tmp/foobar
5355
; LTO-NEXT: # Arch: x86_64
5456
; LTO-NEXT: # Object files:
5557
; LTO-NEXT: [ 0] linker synthesized
56-
; LTO-NEXT: [ 1] {{.*}}{{/|\\}}map-file.ll.tmp/foo.o
57-
; LTO-NEXT: [ 2] {{.*}}{{/|\\}}map-file.ll.tmp/bar.o
58+
; LTO-NEXT: [ 1] {{.*}}{{/|\\}}usr/lib{{/|\\}}libSystem.tbd
59+
; LTO-NEXT: [ 2] {{.*}}{{/|\\}}map-file.ll.tmp/foo.o
60+
; LTO-NEXT: [ 3] {{.*}}{{/|\\}}map-file.ll.tmp/bar.o
5861
; LTO-NEXT: # Sections:
5962
; LTO: # Symbols:
6063
; LTO-NEXT: # Address Size File Name
61-
; LTO-NEXT: 0x{{[0-9A-F]+}} 0x{{[0-9A-F]+}} [ 1] _foo
62-
; LTO-NEXT: 0x{{[0-9A-F]+}} 0x{{[0-9A-F]+}} [ 2] _bar
63-
; LTO-NEXT: 0x{{[0-9A-F]+}} 0x{{[0-9A-F]+}} [ 2] _maybe_weak
64+
; LTO-NEXT: 0x{{[0-9A-F]+}} 0x{{[0-9A-F]+}} [ 2] _foo
65+
; LTO-NEXT: 0x{{[0-9A-F]+}} 0x{{[0-9A-F]+}} [ 3] _bar
66+
; LTO-NEXT: 0x{{[0-9A-F]+}} 0x{{[0-9A-F]+}} [ 3] _maybe_weak
6467

6568
;--- foo.ll
6669
target triple = "x86_64-apple-darwin"

lld/test/MachO/map-file.s

Lines changed: 88 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,37 @@
33
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/foo.s -o %t/foo.o
44
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/test.s -o %t/test.o
55
# 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
67

8+
# RUN: %lld -dylib %t/baz.o -o %t/libbaz.dylib
79
# RUN: %lld -demangle -map %t/map %t/test.o %t/foo.o %t/c-string-literal.o \
8-
# RUN: --time-trace -o %t/test
10+
# RUN: %t/libbaz.dylib --time-trace -o %t/test
911
# RUN: llvm-objdump --syms --section-headers %t/test > %t/objdump
1012
## Check that symbols in cstring sections aren't emitted
1113
## Also check that we don't have redundant EH_Frame symbols (regression test)
1214
# RUN: cat %t/objdump %t/map | FileCheck %s --implicit-check-not _hello_world \
1315
# RUN: --implicit-check-not EH_Frame
1416
# RUN: FileCheck %s --check-prefix=MAPFILE < %t/test.time-trace
1517

16-
# CHECK: Sections:
17-
# CHECK-NEXT: Idx Name Size VMA Type
18-
# CHECK-NEXT: 0 __text {{[0-9a-f]+}} [[#%x,TEXT:]] TEXT
19-
# CHECK-NEXT: 1 __cstring {{[0-9a-f]+}} [[#%x,CSTR:]] DATA
20-
# CHECK-NEXT: 2 __unwind_info {{[0-9a-f]+}} [[#%x,UNWIND:]] DATA
21-
# CHECK-NEXT: 3 __eh_frame {{[0-9a-f]+}} [[#%x,EH_FRAME:]] DATA
22-
# CHECK-NEXT: 4 __common {{[0-9a-f]+}} [[#%x,BSS:]] BSS
18+
# CHECK: Sections:
19+
# CHECK-NEXT: Idx Name Size VMA Type
20+
# CHECK-NEXT: 0 __text 0000001b [[#%x,TEXT:]] TEXT
21+
# CHECK-NEXT: 1 __stubs 0000000c [[#%x,STUBS:]] TEXT
22+
# CHECK-NEXT: 2 __stub_helper 0000001a [[#%x,HELPER:]] TEXT
23+
# CHECK-NEXT: 3 __cstring 0000002b [[#%x,CSTR:]] DATA
24+
# CHECK-NEXT: 4 __unwind_info 0000103c [[#%x,UNWIND:]] DATA
25+
# CHECK-NEXT: 5 __eh_frame 00000038 [[#%x,EH_FRAME:]] DATA
26+
# CHECK-NEXT: 6 __got 00000010 [[#%x,GOT:]] DATA
27+
# CHECK-NEXT: 7 __la_symbol_ptr 00000010 [[#%x,LAZY:]] DATA
28+
# CHECK-NEXT: 8 __data 00000008 [[#%x,DATA:]] DATA
29+
# CHECK-NEXT: 9 __thread_ptrs 00000008 [[#%x,TLVP:]] DATA
30+
# CHECK-NEXT: 10 __common 00000001 [[#%x,BSS:]] BSS
2331

2432
# CHECK: SYMBOL TABLE:
33+
# CHECK-DAG: [[#%x,DYLD:]] l O __DATA,__data __dyld_private
2534
# CHECK-DAG: [[#%x,MAIN:]] g F __TEXT,__text _main
2635
# CHECK-DAG: [[#%x,NUMBER:]] g O __DATA,__common _number
27-
# CHECK-DAG: [[#%x,BAR:]] g F __TEXT,__text _bar
36+
# CHECK-DAG: [[#%x,BAR:]] w F __TEXT,__text _bar
2837
# CHECK-DAG: [[#%x,FOO:]] g F __TEXT,__text __ZTIN3foo3bar4MethE
2938
# CHECK-DAG: [[#%x,HIWORLD:]] g O __TEXT,__cstring _hello_world
3039
# CHECK-DAG: [[#%x,HIITSME:]] g O __TEXT,__cstring _hello_its_me
@@ -33,57 +42,74 @@
3342
# CHECK-NEXT: # Arch: x86_64
3443
# CHECK-NEXT: # Object files:
3544
# CHECK-NEXT: [ 0] linker synthesized
36-
# CHECK-NEXT: [ 1] {{.*}}{{/|\\}}map-file.s.tmp/test.o
37-
# CHECK-NEXT: [ 2] {{.*}}{{/|\\}}map-file.s.tmp/foo.o
38-
# CHECK-NEXT: [ 3] {{.*}}{{/|\\}}map-file.s.tmp/c-string-literal.o
45+
# CHECK-NEXT: [ 1] {{.*}}{{/|\\}}usr/lib{{/|\\}}libSystem.tbd
46+
# CHECK-NEXT: [ 2] {{.*}}{{/|\\}}map-file.s.tmp/test.o
47+
# CHECK-NEXT: [ 3] {{.*}}{{/|\\}}map-file.s.tmp/foo.o
48+
# CHECK-NEXT: [ 4] {{.*}}{{/|\\}}map-file.s.tmp/c-string-literal.o
49+
# CHECK-NEXT: [ 5] {{.*}}{{/|\\}}map-file.s.tmp/libbaz.dylib
3950

4051
# CHECK-NEXT: # Sections:
41-
# CHECK-NEXT: # Address Size Segment Section
42-
# CHECK-NEXT: 0x[[#%X,TEXT]] 0x{{[0-9A-F]+}} __TEXT __text
43-
# CHECK-NEXT: 0x[[#%X,CSTR]] 0x{{[0-9A-F]+}} __TEXT __cstring
44-
# CHECK-NEXT: 0x[[#%X,UNWIND]] 0x{{[0-9A-F]+}} __TEXT __unwind_info
45-
# CHECK-NEXT: 0x[[#%X,EH_FRAME]] 0x{{[0-9A-F]+}} __TEXT __eh_frame
46-
# CHECK-NEXT: 0x[[#%X,BSS]] 0x{{[0-9A-F]+}} __DATA __common
52+
# CHECK-NEXT: # Address Size Segment Section
53+
# CHECK-NEXT: 0x[[#%X,TEXT]] 0x{{[0-9A-F]+}} __TEXT __text
54+
# CHECK-NEXT: 0x[[#%X,STUBS]] 0x{{[0-9A-F]+}} __TEXT __stubs
55+
# CHECK-NEXT: 0x[[#%X,HELPER]] 0x{{[0-9A-F]+}} __TEXT __stub_helper
56+
# CHECK-NEXT: 0x[[#%X,CSTR]] 0x{{[0-9A-F]+}} __TEXT __cstring
57+
# CHECK-NEXT: 0x[[#%X,UNWIND]] 0x{{[0-9A-F]+}} __TEXT __unwind_info
58+
# CHECK-NEXT: 0x[[#%X,EH_FRAME]] 0x{{[0-9A-F]+}} __TEXT __eh_frame
59+
# CHECK-NEXT: 0x[[#%X,GOT]] 0x{{[0-9A-F]+}} __DATA_CONST __got
60+
# CHECK-NEXT: 0x[[#%X,LAZY]] 0x{{[0-9A-F]+}} __DATA __la_symbol_ptr
61+
# CHECK-NEXT: 0x[[#%X,DATA]] 0x{{[0-9A-F]+}} __DATA __data
62+
# CHECK-NEXT: 0x[[#%X,TLVP]] 0x{{[0-9A-F]+}} __DATA __thread_ptrs
63+
# CHECK-NEXT: 0x[[#%X,BSS]] 0x{{[0-9A-F]+}} __DATA __common
4764

4865
# CHECK-NEXT: # Symbols:
49-
# CHECK-NEXT: # Address Size File Name
50-
# CHECK-DAG: 0x[[#%X,MAIN]] 0x00000001 [ 1] _main
51-
# CHECK-DAG: 0x[[#%X,BAR]] 0x00000001 [ 1] _bar
52-
# CHECK-DAG: 0x[[#%X,FOO]] 0x00000001 [ 2] __ZTIN3foo3bar4MethE
53-
# CHECK-DAG: 0x[[#%X,HIWORLD]] 0x0000000E [ 3] literal string: Hello world!\n
54-
# CHECK-DAG: 0x[[#%X,HIITSME]] 0x0000000F [ 3] literal string: Hello, it's me
55-
# CHECK-DAG: 0x[[#%X,HIITSME + 0xf]] 0x0000000E [ 3] literal string: Hello world!\n
56-
# CHECK-DAG: 0x[[#%X,NUMBER]] 0x00000001 [ 1] _number
57-
# CHECK-DAG: 0x[[#%X,UNWIND]] 0x0000103C [ 0] compact unwind info
66+
# CHECK-NEXT: # Address Size File Name
67+
# CHECK-NEXT: 0x[[#%X,MAIN]] 0x00000019 [ 2] _main
68+
# CHECK-NEXT: 0x[[#%X,BAR]] 0x00000001 [ 2] _bar
69+
# CHECK-NEXT: 0x[[#%X,FOO]] 0x00000001 [ 3] __ZTIN3foo3bar4MethE
70+
# CHECK-NEXT: 0x[[#%X,STUBS]] 0x00000006 [ 5] _baz
71+
# CHECK-NEXT: 0x[[#%X,STUBS+6]] 0x00000006 [ 2] _bar
72+
# CHECK-NEXT: 0x[[#%X,HELPER]] 0x0000001A [ 0] helper helper
73+
# CHECK-NEXT: 0x[[#%X,HIWORLD]] 0x0000000E [ 4] literal string: Hello world!\n
74+
# CHECK-NEXT: 0x[[#%X,HIITSME]] 0x0000000F [ 4] literal string: Hello, it's me
75+
# CHECK-NEXT: 0x[[#%X,HIITSME+0xf]] 0x0000000E [ 4] literal string: Hello world!\n
76+
# CHECK-NEXT: 0x[[#%X,UNWIND]] 0x0000103C [ 0] compact unwind info
5877
## Note: ld64 prints "CIE" and "FDE for: <function>" instead of "EH_Frame".
59-
# CHECK-DAG: 0x[[#%X,EH_FRAME]] 0x00000018 [ 1] EH_Frame
60-
# CHECK-DAG: 0x[[#%X,EH_FRAME + 0x18]] 0x00000020 [ 1] EH_Frame
78+
# CHECK-NEXT: 0x[[#%X,EH_FRAME]] 0x00000018 [ 2] EH_Frame
79+
# CHECK-NEXT: 0x[[#%X,EH_FRAME+0x18]] 0x00000020 [ 2] EH_Frame
80+
# CHECK-NEXT: 0x[[#%X,GOT]] 0x00000008 [ 0] non-lazy-pointer-to-local: _baz2
81+
# CHECK-NEXT: 0x[[#%X,GOT+8]] 0x00000008 [ 0] non-lazy-pointer-to-local: dyld_stub_binder
82+
# CHECK-NEXT: 0x[[#%X,LAZY]] 0x00000008 [ 5] _baz
83+
# CHECK-NEXT: 0x[[#%X,LAZY+8]] 0x00000008 [ 2] _bar
84+
# CHECK-NEXT: 0x[[#%X,DYLD]] 0x00000000 [ 0] __dyld_private
85+
# CHECK-NEXT: 0x[[#%X,TLVP]] 0x00000008 [ 0] non-lazy-pointer-to-local: _baz_tlv
86+
# CHECK-NEXT: 0x[[#%X,BSS]] 0x00000001 [ 2] _number
6187

6288
# MAPFILE: "name":"Total Write map file"
6389

64-
# RUN: %lld -demangle -dead_strip -map %t/stripped-map %t/test.o %t/foo.o %t/c-string-literal.o -o %t/stripped
90+
# RUN: %lld -demangle -dead_strip -map %t/stripped-map %t/test.o %t/foo.o \
91+
# RUN: %t/c-string-literal.o %t/libbaz.dylib -o %t/stripped
6592
# RUN: FileCheck --check-prefix=STRIPPED %s < %t/stripped-map
6693

67-
## C-string literals should be printed as "literal string: <C string literal>"
6894
# STRIPPED-LABEL: Dead Stripped Symbols:
69-
# STRIPPED-DAG: <<dead>> 0x00000001 [ 1] _bar
70-
# STRIPPED-DAG: <<dead>> 0x00000001 [ 1] _number
71-
# STRIPPED-DAG: <<dead>> 0x00000001 [ 2] __ZTIN3foo3bar4MethE
72-
# STRIPPED-DAG: <<dead>> 0x0000000E [ 3] literal string: Hello world!\n
73-
# STRIPPED-DAG: <<dead>> 0x0000000F [ 3] literal string: Hello, it's me
74-
# STRIPPED-DAG: <<dead>> 0x0000000E [ 3] literal string: Hello world!\n
75-
76-
# RUN: %lld --icf=all -map %t/icf-map %t/test.o %t/foo.o %t/c-string-literal.o -o %t/icf
95+
# STRIPPED-DAG: <<dead>> 0x00000001 [ 2] _number
96+
# STRIPPED-DAG: <<dead>> 0x00000001 [ 3] __ZTIN3foo3bar4MethE
97+
# STRIPPED-DAG: <<dead>> 0x0000000E [ 4] literal string: Hello world!\n
98+
# STRIPPED-DAG: <<dead>> 0x0000000F [ 4] literal string: Hello, it's me
99+
# STRIPPED-DAG: <<dead>> 0x0000000E [ 4] literal string: Hello world!\n
100+
101+
# RUN: %lld --icf=all -map %t/icf-map %t/test.o %t/foo.o %t/c-string-literal.o \
102+
# RUN: %t/libbaz.dylib -o /dev/null
77103
# RUN: FileCheck --check-prefix=ICF %s < %t/icf-map
78104

79105
## Verify that folded symbols and cstrings have size zero. Note that ld64 prints
80106
## folded symbols but not folded cstrings; we print both.
81107

82108
# ICF: Symbols:
83-
# ICF-DAG: 0x[[#%X,FOO:]] 0x00000000 [ 2] __ZTIN3foo3bar4MethE
84-
# ICF-DAG: 0x[[#FOO]] 0x00000001 [ 1] _bar
85-
# ICF-DAG: 0x[[#%X,HIWORLD:]] 0x0000000E [ 3] literal string: Hello world!\n
86-
# ICF-DAG: 0x[[#%X,HIWORLD]] 0x00000000 [ 3] literal string: Hello world!\n
109+
# ICF-DAG: 0x[[#%X,FOO:]] 0x00000000 [ 3] __ZTIN3foo3bar4MethE
110+
# ICF-DAG: 0x[[#FOO]] 0x00000001 [ 2] _bar
111+
# ICF-DAG: 0x[[#%X,HIWORLD:]] 0x0000000E [ 4] literal string: Hello world!\n
112+
# ICF-DAG: 0x[[#%X,HIWORLD]] 0x00000000 [ 4] literal string: Hello world!\n
87113

88114
#--- foo.s
89115
.globl __ZTIN3foo3bar4MethE
@@ -97,10 +123,15 @@ __ZTIN3foo3bar4MethE:
97123
#--- test.s
98124
.comm _number, 1
99125
.globl _main, _bar
126+
.weak_definition _bar
100127

101128
_main:
102129
.cfi_startproc
103130
.cfi_def_cfa_offset 16
131+
callq _bar
132+
callq _baz
133+
movq _baz2@GOTPCREL(%rip), %rax
134+
mov _baz_tlv@TLVP(%rip), %rax
104135
ret
105136
.cfi_endproc
106137

@@ -123,3 +154,17 @@ _hello_its_me:
123154
.asciz "Hello world!\n"
124155

125156
.subsections_via_symbols
157+
158+
#--- baz.s
159+
.globl _baz, _baz2
160+
161+
_baz:
162+
nop
163+
164+
_baz2:
165+
nop
166+
167+
.section __DATA,__thread_vars,thread_local_variables
168+
.globl _baz_tlv
169+
_baz_tlv:
170+
nop

0 commit comments

Comments
 (0)