Index: ELF/MapFile.cpp =================================================================== --- ELF/MapFile.cpp +++ ELF/MapFile.cpp @@ -137,11 +137,37 @@ OS << OSec->Name << '\n'; // Dump symbols for each input section. - for (InputSection *IS : getInputSections(OSec)) { - writeHeader(OS, OSec->Addr + IS->OutSecOff, IS->getSize(), IS->Alignment); - OS << indent(1) << toString(IS) << '\n'; - for (Symbol *Sym : SectionSyms[IS]) - OS << SymStr[Sym] << '\n'; + for (BaseCommand *Base : OSec->SectionCommands) { + if (auto *ISD = dyn_cast(Base)) { + for (InputSection *IS : ISD->Sections) { + writeHeader(OS, OSec->Addr + IS->OutSecOff, IS->getSize(), + IS->Alignment); + OS << indent(1) << toString(IS) << '\n'; + for (Symbol *Sym : SectionSyms[IS]) + OS << SymStr[Sym] << '\n'; + } + continue; + } + + if (auto *Cmd = dyn_cast(Base)) { + auto Print = [&](StringRef Name) { + writeHeader(OS, OSec->Addr + Cmd->Offset, Cmd->Size, Cmd->Size); + OS << indent(1) << Name << ' ' + << format("0x%0*llx", Cmd->Size, Cmd->Expression().getValue()) + << '\n'; + }; + if (Cmd->Size == 1) + Print("BYTE"); + else if (Cmd->Size == 2) + Print("SHORT"); + else if (Cmd->Size == 4) + Print("LONG"); + else if (Cmd->Size == 8) + Print("QUAD"); + else + llvm_unreachable("invalid data command size"); + continue; + } } } } Index: test/ELF/linkerscript/map-file.test =================================================================== --- test/ELF/linkerscript/map-file.test +++ test/ELF/linkerscript/map-file.test @@ -0,0 +1,28 @@ +# REQUIRES: x86 + +# RUN: echo ".section .foo.1,\"a\"" > %t.s +# RUN: echo ".quad 1" >> %t.s +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %t.s -o %t.o + +# RUN: ld.lld -o %t %t.o -Map=%t.map --script %s + +SECTIONS { + . = 0x1000; + .foo : { + BYTE(0x11) + SHORT(0x1122) + LONG(0x11223344) + QUAD(0x1122334455667788) + *(.foo.1) + } +} + +# CHECK: Address Size Align Out In Symbol +# CHECK-NEXT: 0000000000001000 0000000000000117 1 .foo +# CHECK-NEXT: 0000000000001000 0000000000000001 1 BYTE 0x11 +# CHECK-NEXT: 0000000000001001 0000000000000002 2 SHORT 0x1122 +# CHECK-NEXT: 0000000000001003 0000000000000004 4 LONG 0x11223344 +# CHECK-NEXT: 0000000000001007 0000000000000008 8 QUAD 0x1122334455667788 +# CHECK-NEXT: 000000000000100f 0000000000000008 1 {{.*}}{{/|\\}}map-file.test.tmp.o:(.foo.1) +# CHECK-NEXT: 0000000000001118 0000000000000000 4 .text +# CHECK-NEXT: 0000000000001118 0000000000000000 4 {{.*}}{{/|\\}}map-file.test.tmp.o:(.text)