@@ -2062,177 +2062,6 @@ void DWARFRewriter::writeDWOFiles(
2062
2062
TempOut->keep ();
2063
2063
}
2064
2064
2065
- void DWARFRewriter::addGDBTypeUnitEntry (const GDBIndexTUEntry &&Entry) {
2066
- std::lock_guard<std::mutex> Lock (DWARFRewriterMutex);
2067
- if (!BC.getGdbIndexSection ())
2068
- return ;
2069
- GDBIndexTUEntryVector.emplace_back (Entry);
2070
- }
2071
-
2072
- void DWARFRewriter::updateGdbIndexSection (CUOffsetMap &CUMap, uint32_t NumCUs) {
2073
- if (!BC.getGdbIndexSection ())
2074
- return ;
2075
-
2076
- // See https://sourceware.org/gdb/onlinedocs/gdb/Index-Section-Format.html
2077
- // for .gdb_index section format.
2078
-
2079
- StringRef GdbIndexContents = BC.getGdbIndexSection ()->getContents ();
2080
-
2081
- const char *Data = GdbIndexContents.data ();
2082
-
2083
- // Parse the header.
2084
- const uint32_t Version = read32le (Data);
2085
- if (Version != 7 && Version != 8 ) {
2086
- errs () << " BOLT-ERROR: can only process .gdb_index versions 7 and 8\n " ;
2087
- exit (1 );
2088
- }
2089
-
2090
- // Some .gdb_index generators use file offsets while others use section
2091
- // offsets. Hence we can only rely on offsets relative to each other,
2092
- // and ignore their absolute values.
2093
- const uint32_t CUListOffset = read32le (Data + 4 );
2094
- const uint32_t CUTypesOffset = read32le (Data + 8 );
2095
- const uint32_t AddressTableOffset = read32le (Data + 12 );
2096
- const uint32_t SymbolTableOffset = read32le (Data + 16 );
2097
- const uint32_t ConstantPoolOffset = read32le (Data + 20 );
2098
- Data += 24 ;
2099
-
2100
- // Map CUs offsets to indices and verify existing index table.
2101
- std::map<uint32_t , uint32_t > OffsetToIndexMap;
2102
- const uint32_t CUListSize = CUTypesOffset - CUListOffset;
2103
- const uint32_t TUListSize = AddressTableOffset - CUTypesOffset;
2104
- const unsigned NUmCUsEncoded = CUListSize / 16 ;
2105
- unsigned MaxDWARFVersion = BC.DwCtx ->getMaxVersion ();
2106
- unsigned NumDWARF5TUs =
2107
- getGDBIndexTUEntryVector ().size () - BC.DwCtx ->getNumTypeUnits ();
2108
- bool SkipTypeUnits = false ;
2109
- // For DWARF5 Types are in .debug_info.
2110
- // LLD doesn't generate Types CU List, and in CU list offset
2111
- // only includes CUs.
2112
- // GDB 11+ includes only CUs in CU list and generates Types
2113
- // list.
2114
- // GDB 9 includes CUs and TUs in CU list and generates TYpes
2115
- // list. The NumCUs is CUs + TUs, so need to modify the check.
2116
- // For split-dwarf
2117
- // GDB-11, DWARF5: TU units from dwo are not included.
2118
- // GDB-11, DWARF4: TU units from dwo are included.
2119
- if (MaxDWARFVersion >= 5 )
2120
- SkipTypeUnits = !TUListSize ? true
2121
- : ((NUmCUsEncoded + NumDWARF5TUs) ==
2122
- BC.DwCtx ->getNumCompileUnits ());
2123
-
2124
- if (!((CUListSize == NumCUs * 16 ) ||
2125
- (CUListSize == (NumCUs + NumDWARF5TUs) * 16 ))) {
2126
- errs () << " BOLT-ERROR: .gdb_index: CU count mismatch\n " ;
2127
- exit (1 );
2128
- }
2129
- DenseSet<uint64_t > OriginalOffsets;
2130
- for (unsigned Index = 0 , Units = BC.DwCtx ->getNumCompileUnits ();
2131
- Index < Units; ++Index) {
2132
- const DWARFUnit *CU = BC.DwCtx ->getUnitAtIndex (Index);
2133
- if (SkipTypeUnits && CU->isTypeUnit ())
2134
- continue ;
2135
- const uint64_t Offset = read64le (Data);
2136
- Data += 16 ;
2137
- if (CU->getOffset () != Offset) {
2138
- errs () << " BOLT-ERROR: .gdb_index CU offset mismatch\n " ;
2139
- exit (1 );
2140
- }
2141
-
2142
- OriginalOffsets.insert (Offset);
2143
- OffsetToIndexMap[Offset] = Index;
2144
- }
2145
-
2146
- // Ignore old address table.
2147
- const uint32_t OldAddressTableSize = SymbolTableOffset - AddressTableOffset;
2148
- // Move Data to the beginning of symbol table.
2149
- Data += SymbolTableOffset - CUTypesOffset;
2150
-
2151
- // Calculate the size of the new address table.
2152
- uint32_t NewAddressTableSize = 0 ;
2153
- for (const auto &CURangesPair : ARangesSectionWriter->getCUAddressRanges ()) {
2154
- const SmallVector<DebugAddressRange, 2 > &Ranges = CURangesPair.second ;
2155
- NewAddressTableSize += Ranges.size () * 20 ;
2156
- }
2157
-
2158
- // Difference between old and new table (and section) sizes.
2159
- // Could be negative.
2160
- int32_t Delta = NewAddressTableSize - OldAddressTableSize;
2161
-
2162
- size_t NewGdbIndexSize = GdbIndexContents.size () + Delta;
2163
-
2164
- // Free'd by ExecutableFileMemoryManager.
2165
- auto *NewGdbIndexContents = new uint8_t [NewGdbIndexSize];
2166
- uint8_t *Buffer = NewGdbIndexContents;
2167
-
2168
- write32le (Buffer, Version);
2169
- write32le (Buffer + 4 , CUListOffset);
2170
- write32le (Buffer + 8 , CUTypesOffset);
2171
- write32le (Buffer + 12 , AddressTableOffset);
2172
- write32le (Buffer + 16 , SymbolTableOffset + Delta);
2173
- write32le (Buffer + 20 , ConstantPoolOffset + Delta);
2174
- Buffer += 24 ;
2175
-
2176
- using MapEntry = std::pair<uint32_t , CUInfo>;
2177
- std::vector<MapEntry> CUVector (CUMap.begin (), CUMap.end ());
2178
- // Need to sort since we write out all of TUs in .debug_info before CUs.
2179
- std::sort (CUVector.begin (), CUVector.end (),
2180
- [](const MapEntry &E1 , const MapEntry &E2 ) -> bool {
2181
- return E1 .second .Offset < E2 .second .Offset ;
2182
- });
2183
- // Writing out CU List <Offset, Size>
2184
- for (auto &CUInfo : CUVector) {
2185
- // Skipping TU for DWARF5 when they are not included in CU list.
2186
- if (!OriginalOffsets.count (CUInfo.first ))
2187
- continue ;
2188
- write64le (Buffer, CUInfo.second .Offset );
2189
- // Length encoded in CU doesn't contain first 4 bytes that encode length.
2190
- write64le (Buffer + 8 , CUInfo.second .Length + 4 );
2191
- Buffer += 16 ;
2192
- }
2193
-
2194
- // Rewrite TU CU List, since abbrevs can be different.
2195
- // Entry example:
2196
- // 0: offset = 0x00000000, type_offset = 0x0000001e, type_signature =
2197
- // 0x418503b8111e9a7b Spec says " triplet, the first value is the CU offset,
2198
- // the second value is the type offset in the CU, and the third value is the
2199
- // type signature" Looking at what is being generated by gdb-add-index. The
2200
- // first entry is TU offset, second entry is offset from it, and third entry
2201
- // is the type signature.
2202
- if (TUListSize)
2203
- for (const GDBIndexTUEntry &Entry : getGDBIndexTUEntryVector ()) {
2204
- write64le (Buffer, Entry.UnitOffset );
2205
- write64le (Buffer + 8 , Entry.TypeDIERelativeOffset );
2206
- write64le (Buffer + 16 , Entry.TypeHash );
2207
- Buffer += sizeof (GDBIndexTUEntry);
2208
- }
2209
-
2210
- // Generate new address table.
2211
- for (const std::pair<const uint64_t , DebugAddressRangesVector> &CURangesPair :
2212
- ARangesSectionWriter->getCUAddressRanges ()) {
2213
- const uint32_t CUIndex = OffsetToIndexMap[CURangesPair.first ];
2214
- const DebugAddressRangesVector &Ranges = CURangesPair.second ;
2215
- for (const DebugAddressRange &Range : Ranges) {
2216
- write64le (Buffer, Range.LowPC );
2217
- write64le (Buffer + 8 , Range.HighPC );
2218
- write32le (Buffer + 16 , CUIndex);
2219
- Buffer += 20 ;
2220
- }
2221
- }
2222
-
2223
- const size_t TrailingSize =
2224
- GdbIndexContents.data () + GdbIndexContents.size () - Data;
2225
- assert (Buffer + TrailingSize == NewGdbIndexContents + NewGdbIndexSize &&
2226
- " size calculation error" );
2227
-
2228
- // Copy over the rest of the original data.
2229
- memcpy (Buffer, Data, TrailingSize);
2230
-
2231
- // Register the new section.
2232
- BC.registerOrUpdateNoteSection (" .gdb_index" , NewGdbIndexContents,
2233
- NewGdbIndexSize);
2234
- }
2235
-
2236
2065
std::unique_ptr<DebugBufferVector>
2237
2066
DWARFRewriter::makeFinalLocListsSection (DWARFVersion Version) {
2238
2067
auto LocBuffer = std::make_unique<DebugBufferVector>();
0 commit comments