Index: ELF/MapFile.cpp =================================================================== --- ELF/MapFile.cpp +++ ELF/MapFile.cpp @@ -44,10 +44,10 @@ static const std::string Indent16 = " "; // 16 spaces // Print out the first three columns of a line. -static void writeHeader(raw_ostream &OS, uint64_t Addr, uint64_t Size, - uint64_t Align) { +static void writeHeader(raw_ostream &OS, uint64_t VA, uint64_t LMA, + uint64_t Size, uint64_t Align) { int W = Config->Is64 ? 16 : 8; - OS << format("%0*llx %0*llx %5lld ", W, Addr, W, Size, Align); + OS << format("%0*llx %0*llx %0*llx %5lld ", W, VA, W, LMA, W, Size, Align); } // Returns a list of all symbols that we want to print out. @@ -94,6 +94,12 @@ return Ret; } +static uint64_t getLMA(OutputSection *OSec) { + if (OSec && OSec->PtLoad) + return OSec->PtLoad->p_paddr + OSec->Addr - OSec->PtLoad->p_vaddr; + return 0; +} + // Construct a map from symbols to their stringified representations. // Demangling symbols (which is what toString() does) is slow, so // we do that in batch using parallel-for. @@ -102,7 +108,10 @@ std::vector Str(Syms.size()); parallelForEachN(0, Syms.size(), [&](size_t I) { raw_string_ostream OS(Str[I]); - writeHeader(OS, Syms[I]->getVA(), Syms[I]->getSize(), 0); + OutputSection *OSec = Syms[I]->getOutputSection(); + uint64_t VA = Syms[I]->getVA(); + uint64_t LMA = OSec ? getLMA(OSec) + VA - OSec->getVA(0) : 0; + writeHeader(OS, VA, LMA, Syms[I]->getSize(), 0); OS << Indent16 << toString(*Syms[I]); }); @@ -143,7 +152,8 @@ // Print out section pieces. for (EhSectionPiece &P : Pieces) { - writeHeader(OS, OSec->Addr + P.OutputOff, P.Size, 0); + writeHeader(OS, OSec->Addr + P.OutputOff, getLMA(OSec) + P.OutputOff, + P.Size, 0); OS << Indent8 << toString(P.Sec->File) << ":(" << P.Sec->Name << "+0x" << Twine::utohexstr(P.InputOff) + ")\n"; } @@ -168,12 +178,12 @@ // Print out the header line. int W = Config->Is64 ? 16 : 8; - OS << left_justify("Address", W) << ' ' << left_justify("Size", W) - << " Align Out In Symbol\n"; + OS << left_justify("VA", W) << ' ' << left_justify("LMA", W) << ' ' + << left_justify("Size", W) << " Align Out In Symbol\n"; // Print out file contents. for (OutputSection *OSec : OutputSections) { - writeHeader(OS, OSec->Addr, OSec->Size, OSec->Alignment); + writeHeader(OS, OSec->Addr, getLMA(OSec), OSec->Size, OSec->Alignment); OS << OSec->Name << '\n'; // Dump symbols for each input section. @@ -185,7 +195,8 @@ continue; } - writeHeader(OS, IS->getVA(0), IS->getSize(), IS->Alignment); + writeHeader(OS, IS->getVA(0), getLMA(OSec) + IS->getOffset(0), + IS->getSize(), IS->Alignment); OS << Indent8 << toString(IS) << '\n'; for (Symbol *Sym : SectionSyms[IS]) OS << SymStr[Sym] << '\n'; @@ -194,13 +205,15 @@ } if (auto *Cmd = dyn_cast(Base)) { - writeHeader(OS, OSec->Addr + Cmd->Offset, Cmd->Size, 1); + writeHeader(OS, OSec->Addr + Cmd->Offset, getLMA(OSec) + Cmd->Offset, + Cmd->Size, 1); OS << Indent8 << Cmd->CommandString << '\n'; continue; } if (auto *Cmd = dyn_cast(Base)) { - writeHeader(OS, OSec->Addr + Cmd->Offset, Cmd->Size, 1); + writeHeader(OS, OSec->Addr + Cmd->Offset, getLMA(OSec) + Cmd->Offset, + Cmd->Size, 1); OS << Indent8 << Cmd->CommandString << '\n'; continue; } Index: test/ELF/linkerscript/Inputs/map-file2.s =================================================================== --- test/ELF/linkerscript/Inputs/map-file2.s +++ test/ELF/linkerscript/Inputs/map-file2.s @@ -0,0 +1,19 @@ +.global _start +_start: +.global _Z1fi +_Z1fi: +.cfi_startproc +nop +.cfi_endproc + +.section .aaa, "a"; +.quad 1; + +.section .bbb, "a"; +.quad 2; + +.section .ccc, "a"; +.quad 3; + +.section .ddd, "a"; +.quad 4 Index: test/ELF/linkerscript/map-file.test =================================================================== --- test/ELF/linkerscript/map-file.test +++ test/ELF/linkerscript/map-file.test @@ -22,16 +22,16 @@ } } -# CHECK: Address Size Align Out In Symbol -# CHECK-NEXT: 0000000000001000 000000000000125d 1 .foo -# CHECK-NEXT: 0000000000001000 0000000000000001 1 BYTE ( 0x11 ) -# CHECK-NEXT: 0000000000001001 0000000000000002 1 SHORT ( 0x1122 ) -# CHECK-NEXT: 0000000000001003 0000000000000004 1 LONG ( 0x11223344 ) -# CHECK-NEXT: 0000000000001007 0000000000000008 1 QUAD ( 0x1122334455667788 ) -# CHECK-NEXT: 000000000000100f 0000000000001000 1 . += 0x1000 -# CHECK-NEXT: 000000000000200f 0000000000000008 1 {{.*}}{{/|\\}}map-file.test.tmp.o:(.foo.1) -# CHECK-NEXT: 0000000000002017 0000000000000246 1 . += 0x123 * ( 1 + 1 ) -# CHECK-NEXT: 000000000000225d 0000000000000000 1 foo = . -# CHECK-NEXT: 000000000000225d 0000000000000000 1 bar = 0x42 - 0x26 -# CHECK-NEXT: 0000000000002260 0000000000000000 4 .text -# CHECK-NEXT: 0000000000002260 0000000000000000 4 {{.*}}{{/|\\}}map-file.test.tmp.o:(.text) +# CHECK: VA LMA Size Align Out In Symbol +# CHECK-NEXT: 0000000000001000 0000000000001000 000000000000125d 1 .foo +# CHECK-NEXT: 0000000000001000 0000000000001000 0000000000000001 1 BYTE ( 0x11 ) +# CHECK-NEXT: 0000000000001001 0000000000001001 0000000000000002 1 SHORT ( 0x1122 ) +# CHECK-NEXT: 0000000000001003 0000000000001003 0000000000000004 1 LONG ( 0x11223344 ) +# CHECK-NEXT: 0000000000001007 0000000000001007 0000000000000008 1 QUAD ( 0x1122334455667788 ) +# CHECK-NEXT: 000000000000100f 000000000000100f 0000000000001000 1 . += 0x1000 +# CHECK-NEXT: 000000000000200f 000000000000200f 0000000000000008 1 {{.*}}{{/|\\}}map-file.test.tmp.o:(.foo.1) +# CHECK-NEXT: 0000000000002017 0000000000002017 0000000000000246 1 . += 0x123 * ( 1 + 1 ) +# CHECK-NEXT: 000000000000225d 000000000000225d 0000000000000000 1 foo = . +# CHECK-NEXT: 000000000000225d 000000000000225d 0000000000000000 1 bar = 0x42 - 0x26 +# CHECK-NEXT: 0000000000002260 0000000000002260 0000000000000000 4 .text +# CHECK-NEXT: 0000000000002260 0000000000002260 0000000000000000 4 {{.*}}{{/|\\}}map-file.test.tmp.o:(.text) Index: test/ELF/linkerscript/map-file2.test =================================================================== --- test/ELF/linkerscript/map-file2.test +++ test/ELF/linkerscript/map-file2.test @@ -0,0 +1,35 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %p/Inputs/map-file2.s -o %t.o +# RUN: ld.lld -o %t %t.o -Map=%t.map --script %s +# RUN: FileCheck -strict-whitespace %s < %t.map + +SECTIONS { + . = 0x1000; + .aaa : { *(.aaa.*) } + .bbb : AT(0x2000) { *(.bbb.*) } + .ccc : AT(0x3000) { *(.ccc.*) } + .ddd : { + BYTE(0x11) + . += 0x100; + *(.ddd.*) + } + .text : { *(.text.*) } +} + +# CHECK: VA LMA Size Align Out In Symbol +# CHECK-NEXT: 0000000000001000 0000000000001000 0000000000000008 1 .aaa +# CHECK-NEXT: 0000000000001000 0000000000001000 0000000000000008 1 {{.*}}{{/|\\}}map-file2.test.tmp.o:(.aaa) +# CHECK-NEXT: 0000000000001008 0000000000002000 0000000000000008 1 .bbb +# CHECK-NEXT: 0000000000001008 0000000000002000 0000000000000008 1 {{.*}}{{/|\\}}map-file2.test.tmp.o:(.bbb) +# CHECK-NEXT: 0000000000001010 0000000000003000 0000000000000008 1 .ccc +# CHECK-NEXT: 0000000000001010 0000000000003000 0000000000000008 1 {{.*}}{{/|\\}}map-file2.test.tmp.o:(.ccc) +# CHECK-NEXT: 0000000000001018 0000000000003008 0000000000000109 1 .ddd +# CHECK-NEXT: 0000000000001018 0000000000003008 0000000000000001 1 BYTE ( 0x11 ) +# CHECK-NEXT: 0000000000001019 0000000000003009 0000000000000100 1 . += 0x100 +# CHECK-NEXT: 0000000000001119 0000000000003109 0000000000000008 1 {{.*}}{{/|\\}}map-file2.test.tmp.o:(.ddd) +# CHECK-NEXT: 0000000000001124 0000000000003114 0000000000000001 4 .text +# CHECK-NEXT: 0000000000001124 0000000000003114 0000000000000001 4 {{.*}}{{/|\\}}map-file2.test.tmp.o:(.text) +# CHECK-NEXT: 0000000000001124 0000000000003114 0000000000000000 0 f(int) +# CHECK-NEXT: 0000000000001124 0000000000003114 0000000000000000 0 _start +# CHECK-NEXT: 0000000000001128 0000000000003118 0000000000000030 8 .eh_frame +# CHECK-NEXT: 0000000000001128 0000000000003118 0000000000000030 0 {{.*}}{{/|\\}}map-file2.test.tmp.o:(.eh_frame+0x0) Index: test/ELF/map-file.s =================================================================== --- test/ELF/map-file.s +++ test/ELF/map-file.s @@ -40,60 +40,60 @@ abs = 0xAB5 labs = 0x1AB5 -// CHECK: Address Size Align Out In Symbol -// CHECK-NEXT: 00000000002001c8 0000000000000078 8 .dynsym -// CHECK-NEXT: 00000000002001c8 0000000000000078 8 :(.dynsym) -// CHECK-NEXT: 0000000000200240 000000000000002c 8 .gnu.hash -// CHECK-NEXT: 0000000000200240 000000000000002c 8 :(.gnu.hash) -// CHECK-NEXT: 000000000020026c 0000000000000030 4 .hash -// CHECK-NEXT: 000000000020026c 0000000000000030 4 :(.hash) -// CHECK-NEXT: 000000000020029c 0000000000000031 1 .dynstr -// CHECK-NEXT: 000000000020029c 0000000000000031 1 :(.dynstr) -// CHECK-NEXT: 00000000002002d0 0000000000000030 8 .rela.dyn -// CHECK-NEXT: 00000000002002d0 0000000000000030 8 :(.rela.dyn) -// CHECK-NEXT: 0000000000200300 0000000000000030 8 .rela.plt -// CHECK-NEXT: 0000000000200300 0000000000000030 8 :(.rela.plt) -// CHECK-NEXT: 0000000000200330 0000000000000060 8 .eh_frame -// CHECK-NEXT: 0000000000200330 000000000000002c 0 {{.*}}{{/|\\}}map-file.s.tmp1.o:(.eh_frame+0x0) -// CHECK-NEXT: 0000000000200360 0000000000000014 0 {{.*}}{{/|\\}}map-file.s.tmp1.o:(.eh_frame+0x2c) -// CHECK-NEXT: 0000000000200378 0000000000000018 0 {{.*}}{{/|\\}}map-file.s.tmp2.o:(.eh_frame+0x18) -// CHECK-NEXT: 0000000000201000 000000000000002d 4 .text -// CHECK-NEXT: 0000000000201000 0000000000000028 4 {{.*}}{{/|\\}}map-file.s.tmp1.o:(.text) -// CHECK-NEXT: 0000000000201000 0000000000000000 0 _start -// CHECK-NEXT: 000000000020101f 0000000000000000 0 f(int) -// CHECK-NEXT: 0000000000201028 0000000000000000 0 local -// CHECK-NEXT: 0000000000201028 0000000000000002 4 {{.*}}{{/|\\}}map-file.s.tmp2.o:(.text) -// CHECK-NEXT: 0000000000201028 0000000000000000 0 foo -// CHECK-NEXT: 0000000000201029 0000000000000000 0 bar -// CHECK-NEXT: 000000000020102a 0000000000000000 1 {{.*}}{{/|\\}}map-file.s.tmp2.o:(.text.zed) -// CHECK-NEXT: 000000000020102a 0000000000000000 0 zed -// CHECK-NEXT: 000000000020102c 0000000000000000 4 {{.*}}{{/|\\}}map-file.s.tmp3.o:(.text) -// CHECK-NEXT: 000000000020102c 0000000000000000 0 bah -// CHECK-NEXT: 000000000020102c 0000000000000001 4 {{.*}}{{/|\\}}map-file.s.tmp4.a(map-file.s.tmp4.o):(.text) -// CHECK-NEXT: 000000000020102c 0000000000000000 0 baz -// CHECK-NEXT: 0000000000201030 0000000000000030 16 .plt -// CHECK-NEXT: 0000000000201030 0000000000000030 16 :(.plt) -// CHECK-NEXT: 0000000000201040 0000000000000000 0 sharedFunc1 -// CHECK-NEXT: 0000000000201050 0000000000000000 0 sharedFunc2 -// CHECK-NEXT: 0000000000202000 0000000000000028 8 .got.plt -// CHECK-NEXT: 0000000000202000 0000000000000028 8 :(.got.plt) -// CHECK-NEXT: 0000000000203000 0000000000000100 8 .dynamic -// CHECK-NEXT: 0000000000203000 0000000000000100 8 :(.dynamic) -// CHECK-NEXT: 0000000000204000 0000000000000010 16 .bss -// CHECK-NEXT: 0000000000204000 0000000000000004 16 {{.*}}{{/|\\}}map-file.s.tmp1.o:(COMMON) -// CHECK-NEXT: 0000000000204000 0000000000000004 0 common -// CHECK-NEXT: 0000000000204004 0000000000000004 1 :(.bss) -// CHECK-NEXT: 0000000000204004 0000000000000004 0 sharedFoo -// CHECK-NEXT: 0000000000204008 0000000000000008 1 :(.bss) -// CHECK-NEXT: 0000000000204008 0000000000000008 0 sharedBar -// CHECK-NEXT: 0000000000000000 0000000000000008 1 .comment -// CHECK-NEXT: 0000000000000000 0000000000000008 1 :(.comment) -// CHECK-NEXT: 0000000000000000 0000000000000198 8 .symtab -// CHECK-NEXT: 0000000000000000 0000000000000198 8 :(.symtab) -// CHECK-NEXT: 0000000000000000 0000000000000084 1 .shstrtab -// CHECK-NEXT: 0000000000000000 0000000000000084 1 :(.shstrtab) -// CHECK-NEXT: 0000000000000000 000000000000006d 1 .strtab -// CHECK-NEXT: 0000000000000000 000000000000006d 1 :(.strtab) +// CHECK: VA LMA Size Align Out In Symbol +// CHECK-NEXT: 00000000002001c8 00000000002001c8 0000000000000078 8 .dynsym +// CHECK-NEXT: 00000000002001c8 00000000002001c8 0000000000000078 8 :(.dynsym) +// CHECK-NEXT: 0000000000200240 0000000000200240 000000000000002c 8 .gnu.hash +// CHECK-NEXT: 0000000000200240 0000000000200240 000000000000002c 8 :(.gnu.hash) +// CHECK-NEXT: 000000000020026c 000000000020026c 0000000000000030 4 .hash +// CHECK-NEXT: 000000000020026c 000000000020026c 0000000000000030 4 :(.hash) +// CHECK-NEXT: 000000000020029c 000000000020029c 0000000000000031 1 .dynstr +// CHECK-NEXT: 000000000020029c 000000000020029c 0000000000000031 1 :(.dynstr) +// CHECK-NEXT: 00000000002002d0 00000000002002d0 0000000000000030 8 .rela.dyn +// CHECK-NEXT: 00000000002002d0 00000000002002d0 0000000000000030 8 :(.rela.dyn) +// CHECK-NEXT: 0000000000200300 0000000000200300 0000000000000030 8 .rela.plt +// CHECK-NEXT: 0000000000200300 0000000000200300 0000000000000030 8 :(.rela.plt) +// CHECK-NEXT: 0000000000200330 0000000000200330 0000000000000060 8 .eh_frame +// CHECK-NEXT: 0000000000200330 0000000000200330 000000000000002c 0 {{.*}}{{/|\\}}map-file.s.tmp1.o:(.eh_frame+0x0) +// CHECK-NEXT: 0000000000200360 0000000000200360 0000000000000014 0 {{.*}}{{/|\\}}map-file.s.tmp1.o:(.eh_frame+0x2c) +// CHECK-NEXT: 0000000000200378 0000000000200378 0000000000000018 0 {{.*}}{{/|\\}}map-file.s.tmp2.o:(.eh_frame+0x18) +// CHECK-NEXT: 0000000000201000 0000000000201000 000000000000002d 4 .text +// CHECK-NEXT: 0000000000201000 0000000000201000 0000000000000028 4 {{.*}}{{/|\\}}map-file.s.tmp1.o:(.text) +// CHECK-NEXT: 0000000000201000 0000000000201000 0000000000000000 0 _start +// CHECK-NEXT: 000000000020101f 000000000020101f 0000000000000000 0 f(int) +// CHECK-NEXT: 0000000000201028 0000000000201028 0000000000000000 0 local +// CHECK-NEXT: 0000000000201028 0000000000201028 0000000000000002 4 {{.*}}{{/|\\}}map-file.s.tmp2.o:(.text) +// CHECK-NEXT: 0000000000201028 0000000000201028 0000000000000000 0 foo +// CHECK-NEXT: 0000000000201029 0000000000201029 0000000000000000 0 bar +// CHECK-NEXT: 000000000020102a 000000000020102a 0000000000000000 1 {{.*}}{{/|\\}}map-file.s.tmp2.o:(.text.zed) +// CHECK-NEXT: 000000000020102a 000000000020102a 0000000000000000 0 zed +// CHECK-NEXT: 000000000020102c 000000000020102c 0000000000000000 4 {{.*}}{{/|\\}}map-file.s.tmp3.o:(.text) +// CHECK-NEXT: 000000000020102c 000000000020102c 0000000000000000 0 bah +// CHECK-NEXT: 000000000020102c 000000000020102c 0000000000000001 4 {{.*}}{{/|\\}}map-file.s.tmp4.a(map-file.s.tmp4.o):(.text) +// CHECK-NEXT: 000000000020102c 000000000020102c 0000000000000000 0 baz +// CHECK-NEXT: 0000000000201030 0000000000201030 0000000000000030 16 .plt +// CHECK-NEXT: 0000000000201030 0000000000201030 0000000000000030 16 :(.plt) +// CHECK-NEXT: 0000000000201040 0000000000000000 0000000000000000 0 sharedFunc1 +// CHECK-NEXT: 0000000000201050 0000000000000000 0000000000000000 0 sharedFunc2 +// CHECK-NEXT: 0000000000202000 0000000000202000 0000000000000028 8 .got.plt +// CHECK-NEXT: 0000000000202000 0000000000202000 0000000000000028 8 :(.got.plt) +// CHECK-NEXT: 0000000000203000 0000000000203000 0000000000000100 8 .dynamic +// CHECK-NEXT: 0000000000203000 0000000000203000 0000000000000100 8 :(.dynamic) +// CHECK-NEXT: 0000000000204000 0000000000204000 0000000000000010 16 .bss +// CHECK-NEXT: 0000000000204000 0000000000204000 0000000000000004 16 {{.*}}{{/|\\}}map-file.s.tmp1.o:(COMMON) +// CHECK-NEXT: 0000000000204000 0000000000204000 0000000000000004 0 common +// CHECK-NEXT: 0000000000204004 0000000000204004 0000000000000004 1 :(.bss) +// CHECK-NEXT: 0000000000204004 0000000000204004 0000000000000004 0 sharedFoo +// CHECK-NEXT: 0000000000204008 0000000000204008 0000000000000008 1 :(.bss) +// CHECK-NEXT: 0000000000204008 0000000000204008 0000000000000008 0 sharedBar +// CHECK-NEXT: 0000000000000000 0000000000000000 0000000000000008 1 .comment +// CHECK-NEXT: 0000000000000000 0000000000000000 0000000000000008 1 :(.comment) +// CHECK-NEXT: 0000000000000000 0000000000000000 0000000000000198 8 .symtab +// CHECK-NEXT: 0000000000000000 0000000000000000 0000000000000198 8 :(.symtab) +// CHECK-NEXT: 0000000000000000 0000000000000000 0000000000000084 1 .shstrtab +// CHECK-NEXT: 0000000000000000 0000000000000000 0000000000000084 1 :(.shstrtab) +// CHECK-NEXT: 0000000000000000 0000000000000000 000000000000006d 1 .strtab +// CHECK-NEXT: 0000000000000000 0000000000000000 000000000000006d 1 :(.strtab) // RUN: not ld.lld %t1.o %t2.o %t3.o %t4.a -o %t -Map=/ 2>&1 \ // RUN: | FileCheck -check-prefix=FAIL %s