[PATCH] D54361: [ELF] .gdb_index: fix CuOff when a .debug_info section more than 1 CU

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 9 16:05:25 PST 2018


MaskRay updated this revision to Diff 173463.
MaskRay retitled this revision from "[ELF] .gdb_index: fix CuOff when a .debug_info section more than 1 CU

This fixes a .gdb_index issue linking Scrt1.o with debug information, as Scrt1.o has two DW_tag_compile_unit." to "[ELF] .gdb_index: fix CuOff when a .debug_info section more than 1 CU".
MaskRay edited the summary of this revision.
MaskRay added a reviewer: ruiu.
MaskRay added a comment.

.


Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D54361

Files:
  ELF/SyntheticSections.cpp


Index: ELF/SyntheticSections.cpp
===================================================================
--- ELF/SyntheticSections.cpp
+++ ELF/SyntheticSections.cpp
@@ -2414,6 +2414,8 @@
 
 static std::vector<GdbIndexSection::NameTypeEntry>
 readPubNamesAndTypes(DWARFContext &Dwarf, uint32_t Idx) {
+  // Idx is chunk/section offset which should be converted to CU offset later.
+
   StringRef Sec1 = Dwarf.getDWARFObj().getGnuPubNamesSection();
   StringRef Sec2 = Dwarf.getDWARFObj().getGnuPubTypesSection();
 
@@ -2548,14 +2550,17 @@
   Hdr->CuTypesOff = Buf - Start;
   Hdr->AddressAreaOff = Buf - Start;
   uint32_t CuOff = 0;
+  std::vector<uint32_t> ChunkOffToCuOff;
+  ChunkOffToCuOff.reserve(Chunks.size());
   for (GdbChunk &Chunk : Chunks) {
     for (AddressEntry &E : Chunk.AddressAreas) {
       uint64_t BaseAddr = E.Section->getVA(0);
       write64le(Buf, BaseAddr + E.LowAddress);
       write64le(Buf + 8, BaseAddr + E.HighAddress);
       write32le(Buf + 16, E.CuIndex + CuOff);
       Buf += 20;
     }
+    ChunkOffToCuOff.push_back(CuOff);
     CuOff += Chunk.CompilationUnits.size();
   }
 
@@ -2585,11 +2590,12 @@
   });
 
   // Write the CU vectors.
+  constexpr uint32_t CuOffMask = (1 << 24) - 1;
   for (GdbSymbol &Sym : Symbols) {
     write32le(Buf, Sym.CuVector.size());
     Buf += 4;
     for (uint32_t Val : Sym.CuVector) {
-      write32le(Buf, Val);
+      write32le(Buf, (Val & ~CuOffMask) | ChunkOffToCuOff[Val & CuOffMask]);
       Buf += 4;
     }
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D54361.173463.patch
Type: text/x-patch
Size: 1491 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181110/b21fe8bc/attachment.bin>


More information about the llvm-commits mailing list