[PATCH] D42960: [ELF] DEMO: Example for adding .eh_frame pieces to map file
Rafael Avila de Espindola via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 22 13:32:11 PST 2018
The changes are isolated to MapFile.cpp, so I would be OK with this.
Could you please rebase and add a testcase?
Thanks,
Rafael
James Henderson via Phabricator via llvm-commits
<llvm-commits at lists.llvm.org> writes:
> jhenderson created this revision.
> jhenderson added a reviewer: ruiu.
> Herald added a subscriber: emaste.
>
> This is an example implementation for adding .eh_frame pieces to the map file. See the RFC on the mailing list: http://lists.llvm.org/pipermail/llvm-dev/2018-February/120993.html. Credit to @andrewng for this.
>
> I wouldn't expect to check this in as-is. It's intended only as a demonstration of how this might be achieved. I imagine a similar approach would work for meregeable section pieces.
>
>
> Repository:
> rLLD LLVM Linker
>
> https://reviews.llvm.org/D42960
>
> Files:
> ELF/MapFile.cpp
> ELF/SyntheticSections.h
>
>
> Index: ELF/SyntheticSections.h
> ===================================================================
> --- ELF/SyntheticSections.h
> +++ ELF/SyntheticSections.h
> @@ -83,6 +83,7 @@
> };
>
> std::vector<FdeData> getFdeData() const;
> + std::vector<CieRecord *> const &getCieRecords() const { return CieRecords; }
>
> private:
> uint64_t Size = 0;
> Index: ELF/MapFile.cpp
> ===================================================================
> --- ELF/MapFile.cpp
> +++ ELF/MapFile.cpp
> @@ -142,6 +142,58 @@
> if (!ISD)
> continue;
> for (InputSection *IS : ISD->Sections) {
> + if (IS == InX::EhFrame) {
> + uint64_t InputStart = 0, InputEnd = 0, OutputStart = 0, OutputEnd = 0;
> +
> + auto AddEntry = [&](InputSectionBase *IS) {
> + writeHeader(OS, (OSec->Addr + OutputStart),
> + (OutputEnd - OutputStart), IS->Alignment);
> +
> + std::string InputName = toString(IS);
> + if (InputStart) {
> + auto Pos = InputName.size();
> + if (Pos && (InputName.back() == ')'))
> + --Pos;
> + InputName.insert(Pos, "+" + std::to_string(InputStart));
> + }
> +
> + OS << indent(1) << InputName << '\n';
> + };
> +
> + InputSectionBase *IS = nullptr;
> +
> + auto ProcessPiece = [&](const EhSectionPiece *P) {
> + uint64_t InputOff = P->InputOff;
> + uint64_t OutputOff = P->OutputOff;
> + if (P->Sec != IS || (OutputOff != OutputEnd) ||
> + (InputOff != InputEnd)) {
> + if (IS)
> + AddEntry(IS);
> + InputStart = InputOff;
> + OutputStart = OutputOff;
> + IS = P->Sec;
> + }
> +
> + auto Size = P->Size;
> + OutputEnd = OutputOff + Size;
> + InputEnd = InputOff + Size;
> + };
> +
> + auto CieRecords = InX::EhFrame->getCieRecords();
> + for (const auto *Rec : CieRecords) {
> + ProcessPiece(Rec->Cie);
> +
> + const auto &Fdes = Rec->Fdes;
> + for (const auto *Fde : Fdes)
> + ProcessPiece(Fde);
> + }
> +
> + if (IS)
> + AddEntry(IS);
> +
> + continue;
> + }
> +
> writeHeader(OS, OSec->Addr + IS->OutSecOff, IS->getSize(),
> IS->Alignment);
> OS << indent(1) << toString(IS) << '\n';
>
>
> Index: ELF/SyntheticSections.h
> ===================================================================
> --- ELF/SyntheticSections.h
> +++ ELF/SyntheticSections.h
> @@ -83,6 +83,7 @@
> };
>
> std::vector<FdeData> getFdeData() const;
> + std::vector<CieRecord *> const &getCieRecords() const { return CieRecords; }
>
> private:
> uint64_t Size = 0;
> Index: ELF/MapFile.cpp
> ===================================================================
> --- ELF/MapFile.cpp
> +++ ELF/MapFile.cpp
> @@ -142,6 +142,58 @@
> if (!ISD)
> continue;
> for (InputSection *IS : ISD->Sections) {
> + if (IS == InX::EhFrame) {
> + uint64_t InputStart = 0, InputEnd = 0, OutputStart = 0, OutputEnd = 0;
> +
> + auto AddEntry = [&](InputSectionBase *IS) {
> + writeHeader(OS, (OSec->Addr + OutputStart),
> + (OutputEnd - OutputStart), IS->Alignment);
> +
> + std::string InputName = toString(IS);
> + if (InputStart) {
> + auto Pos = InputName.size();
> + if (Pos && (InputName.back() == ')'))
> + --Pos;
> + InputName.insert(Pos, "+" + std::to_string(InputStart));
> + }
> +
> + OS << indent(1) << InputName << '\n';
> + };
> +
> + InputSectionBase *IS = nullptr;
> +
> + auto ProcessPiece = [&](const EhSectionPiece *P) {
> + uint64_t InputOff = P->InputOff;
> + uint64_t OutputOff = P->OutputOff;
> + if (P->Sec != IS || (OutputOff != OutputEnd) ||
> + (InputOff != InputEnd)) {
> + if (IS)
> + AddEntry(IS);
> + InputStart = InputOff;
> + OutputStart = OutputOff;
> + IS = P->Sec;
> + }
> +
> + auto Size = P->Size;
> + OutputEnd = OutputOff + Size;
> + InputEnd = InputOff + Size;
> + };
> +
> + auto CieRecords = InX::EhFrame->getCieRecords();
> + for (const auto *Rec : CieRecords) {
> + ProcessPiece(Rec->Cie);
> +
> + const auto &Fdes = Rec->Fdes;
> + for (const auto *Fde : Fdes)
> + ProcessPiece(Fde);
> + }
> +
> + if (IS)
> + AddEntry(IS);
> +
> + continue;
> + }
> +
> writeHeader(OS, OSec->Addr + IS->OutSecOff, IS->getSize(),
> IS->Alignment);
> OS << indent(1) << toString(IS) << '\n';
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list