Index: ELF/MapFile.cpp =================================================================== --- ELF/MapFile.cpp +++ ELF/MapFile.cpp @@ -27,9 +27,11 @@ #include "SymbolTable.h" #include "SyntheticSections.h" #include "lld/Common/Threads.h" +#include "llvm/BinaryFormat/ELF.h" #include "llvm/Support/raw_ostream.h" using namespace llvm; +using namespace llvm::ELF; using namespace llvm::object; using namespace lld; @@ -132,6 +134,15 @@ OS << indent(1) << toString(IS) << '\n'; for (Defined *Sym : SectionSyms[IS]) OS << SymStr[Sym] << '\n'; + + // Dump synthetic mergeable sections layout. + if (!isa(IS) || !(IS->Flags & SHF_MERGE)) + continue; + MergeSyntheticSection *MS = static_cast(IS); + for (MergeInputSection *Sec : MS->getSections()) { + writeHeader(OS, 0, Sec->getSize(), Sec->Alignment); + OS << indent(2) << toString(Sec) << '\n'; + } } } } Index: ELF/SyntheticSections.h =================================================================== --- ELF/SyntheticSections.h +++ ELF/SyntheticSections.h @@ -682,6 +682,8 @@ public: void addSection(MergeInputSection *MS); + ArrayRef getSections() { return Sections; } + protected: MergeSyntheticSection(StringRef Name, uint32_t Type, uint64_t Flags, uint32_t Alignment) Index: test/ELF/Inputs/map-file2.s =================================================================== --- test/ELF/Inputs/map-file2.s +++ test/ELF/Inputs/map-file2.s @@ -6,3 +6,7 @@ .section .text.zed,"ax",@progbits .global zed zed: +.section .strings,"MS",@progbits,1 +.align 2 +.asciz "AAA" +.asciz "AAA" Index: test/ELF/map-file.s =================================================================== --- test/ELF/map-file.s +++ test/ELF/map-file.s @@ -29,6 +29,9 @@ abs = 0xAB5 labs = 0x1AB5 +.section .strings,"MS",@progbits,1 +.asciz "AAA" + // CHECK: Address Size Align Out In Symbol // CHECK-NEXT: 0000000000200158 0000000000000030 8 .eh_frame // CHECK-NEXT: 0000000000200158 0000000000000030 8 :(.eh_frame) @@ -49,12 +52,18 @@ // CHECK-NEXT: 0000000000202000 0000000000000004 16 .bss // CHECK-NEXT: 0000000000202000 0000000000000004 16 {{.*}}{{/|\\}}map-file.s.tmp1.o:(COMMON) // CHECK-NEXT: 0000000000202000 0000000000000004 0 common +// CHECK-NEXT: 0000000000000000 0000000000000008 2 .strings +// CHECK-NEXT: 0000000000000000 0000000000000004 1 :(.strings) +// CHECK-NEXT: 0000000000000000 0000000000000004 1 {{.*}}{{/|\\}}map-file.s.tmp1.o:(.strings) +// CHECK-NEXT: 0000000000000004 0000000000000004 2 :(.strings) +// CHECK-NEXT: 0000000000000000 0000000000000008 2 {{.*}}{{/|\\}}map-file.s.tmp2.o:(.strings) // CHECK-NEXT: 0000000000000000 0000000000000008 1 .comment // CHECK-NEXT: 0000000000000000 0000000000000008 1 :(.comment) +// CHECK-NEXT: 0000000000000000 0000000000000008 1 :(.comment) // CHECK-NEXT: 0000000000000000 0000000000000120 8 .symtab // CHECK-NEXT: 0000000000000000 0000000000000120 8 :(.symtab) -// CHECK-NEXT: 0000000000000000 0000000000000039 1 .shstrtab -// CHECK-NEXT: 0000000000000000 0000000000000039 1 :(.shstrtab) +// CHECK-NEXT: 0000000000000000 0000000000000042 1 .shstrtab +// CHECK-NEXT: 0000000000000000 0000000000000042 1 :(.shstrtab) // CHECK-NEXT: 0000000000000000 0000000000000038 1 .strtab // CHECK-NEXT: 0000000000000000 0000000000000038 1 :(.strtab)