diff --git a/lld/MachO/MapFile.cpp b/lld/MachO/MapFile.cpp --- a/lld/MachO/MapFile.cpp +++ b/lld/MachO/MapFile.cpp @@ -122,8 +122,17 @@ return info; } +// We use this instead of `toString(const InputFile *)` as we don't want to +// include the dylib install name in our output. +static void printFileName(raw_fd_ostream &os, const InputFile *f) { + if (f->archiveName.empty()) + os << f->getName(); + else + os << f->archiveName << "(" << path::filename(f->getName()) + ")"; +} + // For printing the contents of the __stubs and __la_symbol_ptr sections. -void printStubsEntries( +static void printStubsEntries( raw_fd_ostream &os, const DenseMap &readerToFileOrdinal, const OutputSection *osec, size_t entrySize) { @@ -134,8 +143,8 @@ sym->getName().str().data()); } -void printNonLazyPointerSection(raw_fd_ostream &os, - NonLazyPointerSectionBase *osec) { +static 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 @@ -171,7 +180,9 @@ uint32_t fileIndex = 1; DenseMap readerToFileOrdinal; for (InputFile *file : info.files) { - os << format("[%3u] %s\n", fileIndex, file->getName().str().c_str()); + os << format("[%3u] ", fileIndex); + printFileName(os, file); + os << "\n"; readerToFileOrdinal[file] = fileIndex++; } diff --git a/lld/test/MachO/map-file.ll b/lld/test/MachO/map-file.ll --- a/lld/test/MachO/map-file.ll +++ b/lld/test/MachO/map-file.ll @@ -27,9 +27,9 @@ ; FOOBAR-NEXT: # Arch: x86_64 ; FOOBAR-NEXT: # Object files: ; FOOBAR-NEXT: [ 0] linker synthesized -; 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: [ 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 diff --git a/lld/test/MachO/map-file.s b/lld/test/MachO/map-file.s --- a/lld/test/MachO/map-file.s +++ b/lld/test/MachO/map-file.s @@ -5,9 +5,11 @@ # 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: llvm-ar --format=darwin crs %t/libfoo.a %t/foo.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: %t/libbaz.dylib --time-trace -o %t/test --no-deduplicate-strings +# RUN: %lld -demangle -map %t/map %t/test.o -force_load %t/libfoo.a \ +# RUN: %t/c-string-literal.o %t/libbaz.dylib --time-trace -o %t/test \ +# RUN: --no-deduplicate-strings # 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) @@ -42,11 +44,11 @@ # CHECK-NEXT: # Arch: x86_64 # CHECK-NEXT: # Object files: # CHECK-NEXT: [ 0] linker synthesized -# 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: [ 1] {{.*}}{{/|\\}}usr/lib{{/|\\}}libSystem.tbd{{$}} +# CHECK-NEXT: [ 2] {{.*}}{{/|\\}}map-file.s.tmp/test.o{{$}} +# CHECK-NEXT: [ 3] {{.*}}{{/|\\}}map-file.s.tmp/libfoo.a(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 @@ -87,8 +89,8 @@ # MAPFILE: "name":"Total Write map file" -# 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: %lld -demangle -dead_strip -map %t/stripped-map %t/test.o -force_load \ +# RUN: %t/libfoo.a %t/c-string-literal.o %t/libbaz.dylib -o %t/stripped # RUN: FileCheck --check-prefix=STRIPPED %s < %t/stripped-map # STRIPPED-LABEL: Dead Stripped Symbols: @@ -98,8 +100,8 @@ # STRIPPED-DAG: <> 0x0000000F [ 4] literal string: Hello, it's me # STRIPPED-DAG: <> 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: %lld --icf=all -map %t/icf-map %t/test.o -force_load %t/libfoo.a \ +# RUN: %t/c-string-literal.o %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