[lld] aa288fd - [lld-macho] Emit map file entries for more synthetic sections
Jez Ng via llvm-commits
llvm-commits at lists.llvm.org
Wed Dec 21 14:29:40 PST 2022
Author: Jez Ng
Date: 2022-12-21T17:28:18-05:00
New Revision: aa288fd9847ce4982058fda8bfd9a127bab339b8
URL: https://github.com/llvm/llvm-project/commit/aa288fd9847ce4982058fda8bfd9a127bab339b8
DIFF: https://github.com/llvm/llvm-project/commit/aa288fd9847ce4982058fda8bfd9a127bab339b8.diff
LOG: [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
Added:
Modified:
lld/MachO/MapFile.cpp
lld/test/MachO/dead-strip.s
lld/test/MachO/map-file.ll
lld/test/MachO/map-file.s
Removed:
################################################################################
diff --git a/lld/MachO/MapFile.cpp b/lld/MachO/MapFile.cpp
index 351c435e110d2..c16e046dcd1f7 100644
--- a/lld/MachO/MapFile.cpp
+++ b/lld/MachO/MapFile.cpp
@@ -63,10 +63,11 @@ struct MapInfo {
static MapInfo gatherMapInfo() {
MapInfo info;
- for (InputFile *file : inputFiles)
+ for (InputFile *file : inputFiles) {
+ bool isReferencedFile = false;
+
if (isa<ObjFile>(file) || isa<BitcodeFile>(file)) {
uint32_t fileIndex = info.files.size() + 1;
- bool isReferencedFile = false;
// Gather the dead symbols. We don't have to bother with the live ones
// because we will pick them up as we iterate over the OutputSections
@@ -104,11 +105,14 @@ static MapInfo gatherMapInfo() {
}
}
}
-
- if (isReferencedFile)
- info.files.push_back(file);
+ } else if (const auto *dylibFile = dyn_cast<DylibFile>(file)) {
+ isReferencedFile = dylibFile->isReferenced();
}
+ if (isReferencedFile)
+ info.files.push_back(file);
+ }
+
// cstrings are not stored in sorted order in their OutputSections, so we sort
// them here.
for (auto &liveCStrings : info.liveCStringsForSection)
@@ -118,6 +122,30 @@ static MapInfo gatherMapInfo() {
return info;
}
+// For printing the contents of the __stubs and __la_symbol_ptr sections.
+void printStubsEntries(
+ raw_fd_ostream &os,
+ const DenseMap<lld::macho::InputFile *, uint32_t> &readerToFileOrdinal,
+ const OutputSection *osec, size_t entrySize) {
+ for (const Symbol *sym : in.stubs->getEntries())
+ os << format("0x%08llX\t0x%08zX\t[%3u] %s\n",
+ osec->addr + sym->stubsIndex * entrySize, entrySize,
+ readerToFileOrdinal.lookup(sym->getFile()),
+ sym->getName().str().data());
+}
+
+void printNonLazyPointerSection(raw_fd_ostream &os,
+ NonLazyPointerSectionBase *osec) {
+ // ld64 considers stubs to belong to particular files, but considers GOT
+ // entries to be linker-synthesized. Not sure why they made that decision, but
+ // I think we can follow suit unless there's demand for better symbol-to-file
+ // associations.
+ for (const Symbol *sym : osec->getEntries())
+ os << format("0x%08llX\t0x%08zX\t[ 0] non-lazy-pointer-to-local: %s\n",
+ osec->addr + sym->gotIndex * target->wordSize,
+ target->wordSize, sym->getName().str().data());
+}
+
void macho::writeMapFile() {
if (config->mapFile.empty())
return;
@@ -185,6 +213,18 @@ void macho::writeMapFile() {
} else if (osec == (void *)in.unwindInfo) {
os << format("0x%08llX\t0x%08llX\t[ 0] compact unwind info\n",
osec->addr, osec->getSize());
+ } else if (osec == in.stubs) {
+ printStubsEntries(os, readerToFileOrdinal, osec, target->stubSize);
+ } else if (osec == in.lazyPointers) {
+ printStubsEntries(os, readerToFileOrdinal, osec, target->wordSize);
+ } else if (osec == in.stubHelper) {
+ // yes, ld64 calls it "helper helper"...
+ os << format("0x%08llX\t0x%08llX\t[ 0] helper helper\n", osec->addr,
+ osec->getSize());
+ } else if (osec == in.got) {
+ printNonLazyPointerSection(os, in.got);
+ } else if (osec == in.tlvPointers) {
+ printNonLazyPointerSection(os, in.tlvPointers);
}
// TODO print other synthetic sections
}
diff --git a/lld/test/MachO/dead-strip.s b/lld/test/MachO/dead-strip.s
index 88b15382602f8..a8996cd59e0b8 100644
--- a/lld/test/MachO/dead-strip.s
+++ b/lld/test/MachO/dead-strip.s
@@ -48,12 +48,12 @@
# MAP: _main
# MAP-LABEL: Dead Stripped Symbols
-# MAP-DAG: <<dead>> 0x00000001 [ 1] _unref_com
-# MAP-DAG: <<dead>> 0x00000008 [ 1] _unref_data
-# MAP-DAG: <<dead>> 0x00000006 [ 1] _unref_extern
-# MAP-DAG: <<dead>> 0x00000001 [ 1] _unref_local
-# MAP-DAG: <<dead>> 0x00000007 [ 1] _unref_private_extern
-# MAP-DAG: <<dead>> 0x00000008 [ 1] l_unref_data
+# MAP-DAG: <<dead>> 0x00000001 [ 2] _unref_com
+# MAP-DAG: <<dead>> 0x00000008 [ 2] _unref_data
+# MAP-DAG: <<dead>> 0x00000006 [ 2] _unref_extern
+# MAP-DAG: <<dead>> 0x00000001 [ 2] _unref_local
+# MAP-DAG: <<dead>> 0x00000007 [ 2] _unref_private_extern
+# MAP-DAG: <<dead>> 0x00000008 [ 2] l_unref_data
## Run dead stripping on code without any dead symbols.
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos \
@@ -347,7 +347,7 @@
# RUN: FileCheck --check-prefix=DUPMAP %s < %t/stripped-duplicate-map
# DUPMAP: _main
# DUPMAP-LABEL: Dead Stripped Symbols
-# DUPMAP: <<dead>> 0x00000001 [ 2] _foo
+# DUPMAP: <<dead>> 0x00000001 [ 3] _foo
#--- duplicate1.s
.text
diff --git a/lld/test/MachO/map-file.ll b/lld/test/MachO/map-file.ll
index 83824667612e0..2f8332a2a3732 100644
--- a/lld/test/MachO/map-file.ll
+++ b/lld/test/MachO/map-file.ll
@@ -27,40 +27,43 @@
; FOOBAR-NEXT: # Arch: x86_64
; FOOBAR-NEXT: # Object files:
; FOOBAR-NEXT: [ 0] linker synthesized
-; FOOBAR-NEXT: [ 1] {{.*}}{{/|\\}}map-file.ll.tmp/foo.thinlto.o
-; FOOBAR-NEXT: [ 2] {{.*}}{{/|\\}}map-file.ll.tmp/bar.thinlto.o
+; FOOBAR-NEXT: [ 1] {{.*}}{{/|\\}}usr/lib{{/|\\}}libSystem.tbd
+; FOOBAR-NEXT: [ 2] {{.*}}{{/|\\}}map-file.ll.tmp/foo.thinlto.o
+; FOOBAR-NEXT: [ 3] {{.*}}{{/|\\}}map-file.ll.tmp/bar.thinlto.o
; FOOBAR-NEXT: # Sections:
; FOOBAR: # Symbols:
; FOOBAR-NEXT: # Address Size File Name
-; FOOBAR-NEXT: 0x{{[0-9A-F]+}} 0x{{[0-9A-F]+}} [ 1] _foo
-; FOOBAR-NEXT: 0x{{[0-9A-F]+}} 0x{{[0-9A-F]+}} [ 2] _bar
-; FOOBAR-NEXT: 0x{{[0-9A-F]+}} 0x{{[0-9A-F]+}} [ 2] _maybe_weak
+; FOOBAR-NEXT: 0x{{[0-9A-F]+}} 0x{{[0-9A-F]+}} [ 2] _foo
+; FOOBAR-NEXT: 0x{{[0-9A-F]+}} 0x{{[0-9A-F]+}} [ 3] _bar
+; FOOBAR-NEXT: 0x{{[0-9A-F]+}} 0x{{[0-9A-F]+}} [ 3] _maybe_weak
; BARFOO: # Path: {{.*}}{{/|\\}}map-file.ll.tmp/barfoo.thinlto
; BARFOO-NEXT: # Arch: x86_64
; BARFOO-NEXT: # Object files:
; BARFOO-NEXT: [ 0] linker synthesized
-; BARFOO-NEXT: [ 1] {{.*}}{{/|\\}}map-file.ll.tmp/bar.thinlto.o
-; BARFOO-NEXT: [ 2] {{.*}}{{/|\\}}map-file.ll.tmp/foo.thinlto.o
+; BARFOO-NEXT: [ 1] {{.*}}{{/|\\}}usr/lib{{/|\\}}libSystem.tbd
+; BARFOO-NEXT: [ 2] {{.*}}{{/|\\}}map-file.ll.tmp/bar.thinlto.o
+; BARFOO-NEXT: [ 3] {{.*}}{{/|\\}}map-file.ll.tmp/foo.thinlto.o
; BARFOO-NEXT: # Sections:
; BARFOO: # Symbols:
; BARFOO-NEXT: # Address Size File Name
-; BARFOO-NEXT: 0x{{[0-9A-F]+}} 0x{{[0-9A-F]+}} [ 1] _bar
-; BARFOO-NEXT: 0x{{[0-9A-F]+}} 0x{{[0-9A-F]+}} [ 1] _maybe_weak
-; BARFOO-NEXT: 0x{{[0-9A-F]+}} 0x{{[0-9A-F]+}} [ 2] _foo
+; BARFOO-NEXT: 0x{{[0-9A-F]+}} 0x{{[0-9A-F]+}} [ 2] _bar
+; BARFOO-NEXT: 0x{{[0-9A-F]+}} 0x{{[0-9A-F]+}} [ 2] _maybe_weak
+; BARFOO-NEXT: 0x{{[0-9A-F]+}} 0x{{[0-9A-F]+}} [ 3] _foo
; LTO: # Path: {{.*}}{{/|\\}}map-file.ll.tmp/foobar
; LTO-NEXT: # Arch: x86_64
; LTO-NEXT: # Object files:
; LTO-NEXT: [ 0] linker synthesized
-; LTO-NEXT: [ 1] {{.*}}{{/|\\}}map-file.ll.tmp/foo.o
-; LTO-NEXT: [ 2] {{.*}}{{/|\\}}map-file.ll.tmp/bar.o
+; LTO-NEXT: [ 1] {{.*}}{{/|\\}}usr/lib{{/|\\}}libSystem.tbd
+; LTO-NEXT: [ 2] {{.*}}{{/|\\}}map-file.ll.tmp/foo.o
+; LTO-NEXT: [ 3] {{.*}}{{/|\\}}map-file.ll.tmp/bar.o
; LTO-NEXT: # Sections:
; LTO: # Symbols:
; LTO-NEXT: # Address Size File Name
-; LTO-NEXT: 0x{{[0-9A-F]+}} 0x{{[0-9A-F]+}} [ 1] _foo
-; LTO-NEXT: 0x{{[0-9A-F]+}} 0x{{[0-9A-F]+}} [ 2] _bar
-; LTO-NEXT: 0x{{[0-9A-F]+}} 0x{{[0-9A-F]+}} [ 2] _maybe_weak
+; LTO-NEXT: 0x{{[0-9A-F]+}} 0x{{[0-9A-F]+}} [ 2] _foo
+; LTO-NEXT: 0x{{[0-9A-F]+}} 0x{{[0-9A-F]+}} [ 3] _bar
+; LTO-NEXT: 0x{{[0-9A-F]+}} 0x{{[0-9A-F]+}} [ 3] _maybe_weak
;--- foo.ll
target triple = "x86_64-apple-darwin"
diff --git a/lld/test/MachO/map-file.s b/lld/test/MachO/map-file.s
index 7fe00fa0d99d2..85f5d504ccf32 100644
--- a/lld/test/MachO/map-file.s
+++ b/lld/test/MachO/map-file.s
@@ -3,9 +3,11 @@
# 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: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/baz.s -o %t/baz.o
+# RUN: %lld -dylib %t/baz.o -o %t/libbaz.dylib
# RUN: %lld -demangle -map %t/map %t/test.o %t/foo.o %t/c-string-literal.o \
-# RUN: --time-trace -o %t/test
+# RUN: %t/libbaz.dylib --time-trace -o %t/test
# RUN: llvm-objdump --syms --section-headers %t/test > %t/objdump
## Check that symbols in cstring sections aren't emitted
## Also check that we don't have redundant EH_Frame symbols (regression test)
@@ -13,18 +15,25 @@
# RUN: --implicit-check-not EH_Frame
# RUN: FileCheck %s --check-prefix=MAPFILE < %t/test.time-trace
-# CHECK: Sections:
-# CHECK-NEXT: Idx Name Size VMA Type
-# CHECK-NEXT: 0 __text {{[0-9a-f]+}} [[#%x,TEXT:]] TEXT
-# CHECK-NEXT: 1 __cstring {{[0-9a-f]+}} [[#%x,CSTR:]] DATA
-# CHECK-NEXT: 2 __unwind_info {{[0-9a-f]+}} [[#%x,UNWIND:]] DATA
-# CHECK-NEXT: 3 __eh_frame {{[0-9a-f]+}} [[#%x,EH_FRAME:]] DATA
-# CHECK-NEXT: 4 __common {{[0-9a-f]+}} [[#%x,BSS:]] BSS
+# CHECK: Sections:
+# CHECK-NEXT: Idx Name Size VMA Type
+# CHECK-NEXT: 0 __text 0000001b [[#%x,TEXT:]] TEXT
+# CHECK-NEXT: 1 __stubs 0000000c [[#%x,STUBS:]] TEXT
+# CHECK-NEXT: 2 __stub_helper 0000001a [[#%x,HELPER:]] TEXT
+# CHECK-NEXT: 3 __cstring 0000002b [[#%x,CSTR:]] DATA
+# CHECK-NEXT: 4 __unwind_info 0000103c [[#%x,UNWIND:]] DATA
+# CHECK-NEXT: 5 __eh_frame 00000038 [[#%x,EH_FRAME:]] DATA
+# CHECK-NEXT: 6 __got 00000010 [[#%x,GOT:]] DATA
+# CHECK-NEXT: 7 __la_symbol_ptr 00000010 [[#%x,LAZY:]] DATA
+# CHECK-NEXT: 8 __data 00000008 [[#%x,DATA:]] DATA
+# CHECK-NEXT: 9 __thread_ptrs 00000008 [[#%x,TLVP:]] DATA
+# CHECK-NEXT: 10 __common 00000001 [[#%x,BSS:]] BSS
# CHECK: SYMBOL TABLE:
+# CHECK-DAG: [[#%x,DYLD:]] l O __DATA,__data __dyld_private
# CHECK-DAG: [[#%x,MAIN:]] g F __TEXT,__text _main
# CHECK-DAG: [[#%x,NUMBER:]] g O __DATA,__common _number
-# CHECK-DAG: [[#%x,BAR:]] g F __TEXT,__text _bar
+# CHECK-DAG: [[#%x,BAR:]] w F __TEXT,__text _bar
# CHECK-DAG: [[#%x,FOO:]] g F __TEXT,__text __ZTIN3foo3bar4MethE
# CHECK-DAG: [[#%x,HIWORLD:]] g O __TEXT,__cstring _hello_world
# CHECK-DAG: [[#%x,HIITSME:]] g O __TEXT,__cstring _hello_its_me
@@ -33,57 +42,74 @@
# 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: [ 3] {{.*}}{{/|\\}}map-file.s.tmp/c-string-literal.o
+# CHECK-NEXT: [ 1] {{.*}}{{/|\\}}usr/lib{{/|\\}}libSystem.tbd
+# CHECK-NEXT: [ 2] {{.*}}{{/|\\}}map-file.s.tmp/test.o
+# CHECK-NEXT: [ 3] {{.*}}{{/|\\}}map-file.s.tmp/foo.o
+# CHECK-NEXT: [ 4] {{.*}}{{/|\\}}map-file.s.tmp/c-string-literal.o
+# CHECK-NEXT: [ 5] {{.*}}{{/|\\}}map-file.s.tmp/libbaz.dylib
# CHECK-NEXT: # Sections:
-# CHECK-NEXT: # Address Size Segment Section
-# CHECK-NEXT: 0x[[#%X,TEXT]] 0x{{[0-9A-F]+}} __TEXT __text
-# CHECK-NEXT: 0x[[#%X,CSTR]] 0x{{[0-9A-F]+}} __TEXT __cstring
-# CHECK-NEXT: 0x[[#%X,UNWIND]] 0x{{[0-9A-F]+}} __TEXT __unwind_info
-# CHECK-NEXT: 0x[[#%X,EH_FRAME]] 0x{{[0-9A-F]+}} __TEXT __eh_frame
-# CHECK-NEXT: 0x[[#%X,BSS]] 0x{{[0-9A-F]+}} __DATA __common
+# CHECK-NEXT: # Address Size Segment Section
+# CHECK-NEXT: 0x[[#%X,TEXT]] 0x{{[0-9A-F]+}} __TEXT __text
+# CHECK-NEXT: 0x[[#%X,STUBS]] 0x{{[0-9A-F]+}} __TEXT __stubs
+# CHECK-NEXT: 0x[[#%X,HELPER]] 0x{{[0-9A-F]+}} __TEXT __stub_helper
+# CHECK-NEXT: 0x[[#%X,CSTR]] 0x{{[0-9A-F]+}} __TEXT __cstring
+# CHECK-NEXT: 0x[[#%X,UNWIND]] 0x{{[0-9A-F]+}} __TEXT __unwind_info
+# CHECK-NEXT: 0x[[#%X,EH_FRAME]] 0x{{[0-9A-F]+}} __TEXT __eh_frame
+# CHECK-NEXT: 0x[[#%X,GOT]] 0x{{[0-9A-F]+}} __DATA_CONST __got
+# CHECK-NEXT: 0x[[#%X,LAZY]] 0x{{[0-9A-F]+}} __DATA __la_symbol_ptr
+# CHECK-NEXT: 0x[[#%X,DATA]] 0x{{[0-9A-F]+}} __DATA __data
+# CHECK-NEXT: 0x[[#%X,TLVP]] 0x{{[0-9A-F]+}} __DATA __thread_ptrs
+# CHECK-NEXT: 0x[[#%X,BSS]] 0x{{[0-9A-F]+}} __DATA __common
# CHECK-NEXT: # Symbols:
-# CHECK-NEXT: # Address Size File Name
-# CHECK-DAG: 0x[[#%X,MAIN]] 0x00000001 [ 1] _main
-# CHECK-DAG: 0x[[#%X,BAR]] 0x00000001 [ 1] _bar
-# CHECK-DAG: 0x[[#%X,FOO]] 0x00000001 [ 2] __ZTIN3foo3bar4MethE
-# CHECK-DAG: 0x[[#%X,HIWORLD]] 0x0000000E [ 3] literal string: Hello world!\n
-# CHECK-DAG: 0x[[#%X,HIITSME]] 0x0000000F [ 3] literal string: Hello, it's me
-# CHECK-DAG: 0x[[#%X,HIITSME + 0xf]] 0x0000000E [ 3] literal string: Hello world!\n
-# CHECK-DAG: 0x[[#%X,NUMBER]] 0x00000001 [ 1] _number
-# CHECK-DAG: 0x[[#%X,UNWIND]] 0x0000103C [ 0] compact unwind info
+# CHECK-NEXT: # Address Size File Name
+# CHECK-NEXT: 0x[[#%X,MAIN]] 0x00000019 [ 2] _main
+# CHECK-NEXT: 0x[[#%X,BAR]] 0x00000001 [ 2] _bar
+# CHECK-NEXT: 0x[[#%X,FOO]] 0x00000001 [ 3] __ZTIN3foo3bar4MethE
+# CHECK-NEXT: 0x[[#%X,STUBS]] 0x00000006 [ 5] _baz
+# CHECK-NEXT: 0x[[#%X,STUBS+6]] 0x00000006 [ 2] _bar
+# CHECK-NEXT: 0x[[#%X,HELPER]] 0x0000001A [ 0] helper helper
+# CHECK-NEXT: 0x[[#%X,HIWORLD]] 0x0000000E [ 4] literal string: Hello world!\n
+# CHECK-NEXT: 0x[[#%X,HIITSME]] 0x0000000F [ 4] literal string: Hello, it's me
+# CHECK-NEXT: 0x[[#%X,HIITSME+0xf]] 0x0000000E [ 4] literal string: Hello world!\n
+# CHECK-NEXT: 0x[[#%X,UNWIND]] 0x0000103C [ 0] compact unwind info
## Note: ld64 prints "CIE" and "FDE for: <function>" instead of "EH_Frame".
-# CHECK-DAG: 0x[[#%X,EH_FRAME]] 0x00000018 [ 1] EH_Frame
-# CHECK-DAG: 0x[[#%X,EH_FRAME + 0x18]] 0x00000020 [ 1] EH_Frame
+# CHECK-NEXT: 0x[[#%X,EH_FRAME]] 0x00000018 [ 2] EH_Frame
+# CHECK-NEXT: 0x[[#%X,EH_FRAME+0x18]] 0x00000020 [ 2] EH_Frame
+# CHECK-NEXT: 0x[[#%X,GOT]] 0x00000008 [ 0] non-lazy-pointer-to-local: _baz2
+# CHECK-NEXT: 0x[[#%X,GOT+8]] 0x00000008 [ 0] non-lazy-pointer-to-local: dyld_stub_binder
+# CHECK-NEXT: 0x[[#%X,LAZY]] 0x00000008 [ 5] _baz
+# CHECK-NEXT: 0x[[#%X,LAZY+8]] 0x00000008 [ 2] _bar
+# CHECK-NEXT: 0x[[#%X,DYLD]] 0x00000000 [ 0] __dyld_private
+# CHECK-NEXT: 0x[[#%X,TLVP]] 0x00000008 [ 0] non-lazy-pointer-to-local: _baz_tlv
+# CHECK-NEXT: 0x[[#%X,BSS]] 0x00000001 [ 2] _number
# MAPFILE: "name":"Total Write map file"
-# RUN: %lld -demangle -dead_strip -map %t/stripped-map %t/test.o %t/foo.o %t/c-string-literal.o -o %t/stripped
+# RUN: %lld -demangle -dead_strip -map %t/stripped-map %t/test.o %t/foo.o \
+# RUN: %t/c-string-literal.o %t/libbaz.dylib -o %t/stripped
# RUN: FileCheck --check-prefix=STRIPPED %s < %t/stripped-map
-## C-string literals should be printed as "literal string: <C string literal>"
# STRIPPED-LABEL: Dead Stripped Symbols:
-# STRIPPED-DAG: <<dead>> 0x00000001 [ 1] _bar
-# STRIPPED-DAG: <<dead>> 0x00000001 [ 1] _number
-# STRIPPED-DAG: <<dead>> 0x00000001 [ 2] __ZTIN3foo3bar4MethE
-# STRIPPED-DAG: <<dead>> 0x0000000E [ 3] literal string: Hello world!\n
-# STRIPPED-DAG: <<dead>> 0x0000000F [ 3] literal string: Hello, it's me
-# STRIPPED-DAG: <<dead>> 0x0000000E [ 3] literal string: Hello world!\n
-
-# RUN: %lld --icf=all -map %t/icf-map %t/test.o %t/foo.o %t/c-string-literal.o -o %t/icf
+# STRIPPED-DAG: <<dead>> 0x00000001 [ 2] _number
+# STRIPPED-DAG: <<dead>> 0x00000001 [ 3] __ZTIN3foo3bar4MethE
+# STRIPPED-DAG: <<dead>> 0x0000000E [ 4] literal string: Hello world!\n
+# STRIPPED-DAG: <<dead>> 0x0000000F [ 4] literal string: Hello, it's me
+# STRIPPED-DAG: <<dead>> 0x0000000E [ 4] literal string: Hello world!\n
+
+# RUN: %lld --icf=all -map %t/icf-map %t/test.o %t/foo.o %t/c-string-literal.o \
+# RUN: %t/libbaz.dylib -o /dev/null
# RUN: FileCheck --check-prefix=ICF %s < %t/icf-map
## Verify that folded symbols and cstrings have size zero. Note that ld64 prints
## folded symbols but not folded cstrings; we print both.
# ICF: Symbols:
-# ICF-DAG: 0x[[#%X,FOO:]] 0x00000000 [ 2] __ZTIN3foo3bar4MethE
-# ICF-DAG: 0x[[#FOO]] 0x00000001 [ 1] _bar
-# ICF-DAG: 0x[[#%X,HIWORLD:]] 0x0000000E [ 3] literal string: Hello world!\n
-# ICF-DAG: 0x[[#%X,HIWORLD]] 0x00000000 [ 3] literal string: Hello world!\n
+# ICF-DAG: 0x[[#%X,FOO:]] 0x00000000 [ 3] __ZTIN3foo3bar4MethE
+# ICF-DAG: 0x[[#FOO]] 0x00000001 [ 2] _bar
+# ICF-DAG: 0x[[#%X,HIWORLD:]] 0x0000000E [ 4] literal string: Hello world!\n
+# ICF-DAG: 0x[[#%X,HIWORLD]] 0x00000000 [ 4] literal string: Hello world!\n
#--- foo.s
.globl __ZTIN3foo3bar4MethE
@@ -97,10 +123,15 @@ __ZTIN3foo3bar4MethE:
#--- test.s
.comm _number, 1
.globl _main, _bar
+.weak_definition _bar
_main:
.cfi_startproc
.cfi_def_cfa_offset 16
+ callq _bar
+ callq _baz
+ movq _baz2 at GOTPCREL(%rip), %rax
+ mov _baz_tlv at TLVP(%rip), %rax
ret
.cfi_endproc
@@ -123,3 +154,17 @@ _hello_its_me:
.asciz "Hello world!\n"
.subsections_via_symbols
+
+#--- baz.s
+.globl _baz, _baz2
+
+_baz:
+ nop
+
+_baz2:
+ nop
+
+.section __DATA,__thread_vars,thread_local_variables
+.globl _baz_tlv
+_baz_tlv:
+ nop
More information about the llvm-commits
mailing list