Index: ELF/MapFile.cpp =================================================================== --- ELF/MapFile.cpp +++ ELF/MapFile.cpp @@ -110,6 +110,52 @@ return Ret; } +// Print .eh_frame contents. Since this section consists of EhSectionPieces, we +// need a specialized printer. +// +// .eh_frame tends to contain a lot of section pieces that are contiguous both +// in input file and output file. Such pieces are combined to make the output +// more compact. +static void printEhFrame(raw_ostream &OS, OutputSection *OSec) { + InputSectionBase *ISec = nullptr; + uint64_t InputStart = 0; + uint64_t InputEnd = 0; + uint64_t OutputStart = 0; + uint64_t OutputEnd = 0; + + auto PrintEntry = [&]() { + if (ISec) { + writeHeader(OS, OSec->Addr + OutputStart, OutputEnd - OutputStart, + ISec->Alignment); + OS << Indent1 << toString(ISec->File) << ":(" << ISec->Name; + if (InputStart) + OS << "+0x" << Twine::utohexstr(InputStart); + OS << ")\n"; + } + }; + + auto ProcessPiece = [&](const EhSectionPiece *P) { + if (P->Sec != ISec || P->OutputOff != OutputEnd || + P->InputOff != InputEnd) { + PrintEntry(); + 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); + } + + PrintEntry(); +} + void elf::writeMapFile() { if (Config->MapFile.empty()) return; @@ -139,6 +185,11 @@ // Dump symbols for each input section. for (InputSection *IS : getInputSections(OSec)) { + if (IS == InX::EhFrame) { + printEhFrame(OS, OSec); + continue; + } + writeHeader(OS, OSec->Addr + IS->OutSecOff, IS->getSize(), IS->Alignment); OS << Indent1 << 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