Index: ELF/InputSection.h =================================================================== --- ELF/InputSection.h +++ ELF/InputSection.h @@ -344,7 +344,7 @@ extern std::vector InputSections; } // namespace elf -std::string toString(const elf::InputSectionBase *); +std::string toString(const elf::InputSectionBase *, uint64_t SecOffset = 0); } // namespace lld #endif Index: ELF/InputSection.cpp =================================================================== --- ELF/InputSection.cpp +++ ELF/InputSection.cpp @@ -41,8 +41,10 @@ std::vector elf::InputSections; // Returns a string to construct an error message. -std::string lld::toString(const InputSectionBase *Sec) { - return (toString(Sec->File) + ":(" + Sec->Name + ")").str(); +std::string lld::toString(const InputSectionBase *Sec, uint64_t SecOffset) { + return (toString(Sec->File) + Twine(":(") + Sec->Name + + (SecOffset ? "+0x" + Twine::utohexstr(SecOffset) + ")" : ")")) + .str(); } template Index: ELF/MapFile.cpp =================================================================== --- ELF/MapFile.cpp +++ ELF/MapFile.cpp @@ -138,6 +138,41 @@ // Dump symbols for each input section. for (InputSection *IS : getInputSections(OSec)) { + if (IS == InX::EhFrame) { + InputSectionBase *ISec = nullptr; + uint64_t InputStart = 0, InputEnd = 0, OutputStart = 0, OutputEnd = 0; + + auto AddEntry = [&]() { + if (ISec) { + writeHeader(OS, OSec->Addr + OutputStart, OutputEnd - OutputStart, + ISec->Alignment); + OS << indent(1) << toString(ISec, InputStart) << '\n'; + } + }; + + auto ProcessPiece = [&](const EhSectionPiece *P) { + if (P->Sec != ISec || P->OutputOff != OutputEnd || + P->InputOff != InputEnd) { + AddEntry(); + InputStart = P->InputOff; + OutputStart = P->OutputOff; + ISec = P->Sec; + } + + OutputEnd = P->OutputOff + P->Size; + InputEnd = P->InputOff + P->Size; + }; + + for (const CieRecord *Rec : InX::EhFrame->getCieRecords()) { + ProcessPiece(Rec->Cie); + for (const EhSectionPiece *Fde : Rec->Fdes) + ProcessPiece(Fde); + } + + AddEntry(); + continue; + } + writeHeader(OS, OSec->Addr + IS->OutSecOff, IS->getSize(), IS->Alignment); OS << indent(1) << toString(IS) << '\n'; for (Symbol *Sym : SectionSyms[IS]) Index: ELF/SyntheticSections.h =================================================================== --- ELF/SyntheticSections.h +++ ELF/SyntheticSections.h @@ -83,6 +83,7 @@ }; std::vector getFdeData() const; + std::vector const &getCieRecords() const { return CieRecords; } private: uint64_t Size = 0; Index: test/ELF/Inputs/map-file2.s =================================================================== --- test/ELF/Inputs/map-file2.s +++ test/ELF/Inputs/map-file2.s @@ -1,5 +1,7 @@ foo: +.cfi_startproc nop +.cfi_endproc .global bar bar: nop Index: test/ELF/map-file.s =================================================================== --- test/ELF/map-file.s +++ test/ELF/map-file.s @@ -15,6 +15,8 @@ .global _start _start: +.cfi_startproc +.cfi_endproc .quad sharedFoo .quad sharedBar .byte 0xe8 @@ -26,8 +28,8 @@ .global _Z1fi _Z1fi: .cfi_startproc -.cfi_endproc nop +.cfi_endproc .weak bar bar: .long bar - . @@ -51,8 +53,10 @@ // CHECK-NEXT: 00000000002002d0 0000000000000030 8 :(.rela.dyn) // CHECK-NEXT: 0000000000200300 0000000000000030 8 .rela.plt // CHECK-NEXT: 0000000000200300 0000000000000030 8 :(.rela.plt) -// CHECK-NEXT: 0000000000200330 0000000000000030 8 .eh_frame -// CHECK-NEXT: 0000000000200330 0000000000000030 8 :(.eh_frame) +// CHECK-NEXT: 0000000000200330 0000000000000060 8 .eh_frame +// CHECK-NEXT: 0000000000200330 000000000000002c 8 {{.*}}{{/|\\}}map-file.s.tmp1.o:(.eh_frame) +// CHECK-NEXT: 0000000000200360 0000000000000014 8 {{.*}}{{/|\\}}map-file.s.tmp1.o:(.eh_frame+0x2c) +// CHECK-NEXT: 0000000000200378 0000000000000018 8 {{.*}}{{/|\\}}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