Index: ELF/SyntheticSections.cpp =================================================================== --- ELF/SyntheticSections.cpp +++ ELF/SyntheticSections.cpp @@ -2414,6 +2414,8 @@ static std::vector 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,6 +2550,8 @@ Hdr->CuTypesOff = Buf - Start; Hdr->AddressAreaOff = Buf - Start; uint32_t CuOff = 0; + std::vector ChunkOffToCuOff; + ChunkOffToCuOff.reserve(Chunks.size()); for (GdbChunk &Chunk : Chunks) { for (AddressEntry &E : Chunk.AddressAreas) { uint64_t BaseAddr = E.Section->getVA(0); @@ -2556,6 +2560,7 @@ 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; } }