diff --git a/lld/MachO/MapFile.cpp b/lld/MachO/MapFile.cpp --- a/lld/MachO/MapFile.cpp +++ b/lld/MachO/MapFile.cpp @@ -31,6 +31,7 @@ #include "OutputSection.h" #include "OutputSegment.h" #include "Symbols.h" +#include "SyntheticSections.h" #include "Target.h" #include "llvm/Support/Parallel.h" #include "llvm/Support/TimeProfiler.h" @@ -161,4 +162,13 @@ os << "# Dead Stripped Symbols:\n"; writeSymbols(deadSymbols, false); } + + assert(in.cStringSection != nullptr); + auto &cStringSection = *in.cStringSection; + + auto buffer = std::make_unique(cStringSection.getSize()); + cStringSection.writeTo(buffer.get()); + os << "C-Strings:\n"; + os << StringRef(reinterpret_cast(buffer.get()), + cStringSection.getSize()); } diff --git a/lld/test/MachO/Inputs/hello.s b/lld/test/MachO/Inputs/hello.s new file mode 100644 --- /dev/null +++ b/lld/test/MachO/Inputs/hello.s @@ -0,0 +1,17 @@ +.section __TEXT,__cstring +.globl _hello_world, _hello_its_me, _main + +_hello_world: +.asciz "Hello world!\n" + +_hello_its_me: +.asciz "Hello, it's me\n" + +.text +_main: + movl $0x2000004, %eax # write() syscall + mov $1, %rdi # stdout + leaq _hello_world(%rip), %rsi + mov $13, %rdx # length of str + syscall + ret 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 @@ -49,3 +49,13 @@ # CHECK-NEXT: 0x[[#MAIN]] [ 1] _main # CHECK-NEXT: 0x[[#FOO]] [ 2] _foo # CHECK-NEXT: 0x[[#NUMBER]] [ 1] _number + +# RUN: mkdir -p %t +# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %p/Inputs/hello.s \ +# RUN: -o %t/hello.o +# RUN: %lld -map %t/hello-map %t/hello.o -o %t/hello-out +# RUN: cat %t/hello-map +# RUN: FileCheck --check-prefix=CSTRING %s < %t/hello-map + +# CSTRING: none +