[PATCH] D42960: [ELF] DEMO: Example for adding .eh_frame pieces to map file

James Henderson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 6 06:17:14 PST 2018


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';


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D42960.132984.patch
Type: text/x-patch
Size: 2369 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180206/f49b5de0/attachment.bin>


More information about the llvm-commits mailing list