Skip to content

Commit 4d64fcd

Browse files
committed
[DWARF][GDB INDEX] Fix to deal with constant pool de-dupliation Summary:
GDB 11.2 generates V8 version of gdb-index where it de-duplicates entries in constant pool based on cu indices. Changed how constant pool entries are counted to account for this. Differential Revision: https://reviews.llvm.org/D146852
1 parent e3b6b92 commit 4d64fcd

File tree

3 files changed

+76
-6
lines changed

3 files changed

+76
-6
lines changed

llvm/lib/DebugInfo/DWARF/DWARFGdbIndex.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <cassert>
1717
#include <cinttypes>
1818
#include <cstdint>
19+
#include <set>
1920
#include <utility>
2021

2122
using namespace llvm;
@@ -114,9 +115,9 @@ void DWARFGdbIndex::dump(raw_ostream &OS) {
114115
bool DWARFGdbIndex::parseImpl(DataExtractor Data) {
115116
uint64_t Offset = 0;
116117

117-
// Only version 7 is supported at this moment.
118+
// Only version 7 and 8 are supported at this moment.
118119
Version = Data.getU32(&Offset);
119-
if (Version != 7)
120+
if (Version != 7 && Version != 8)
120121
return false;
121122

122123
CuListOffset = Data.getU32(&Offset);
@@ -166,25 +167,26 @@ bool DWARFGdbIndex::parseImpl(DataExtractor Data) {
166167
// for both a string and a CU vector.
167168
uint32_t SymTableSize = (ConstantPoolOffset - SymbolTableOffset) / 8;
168169
SymbolTable.reserve(SymTableSize);
169-
uint32_t CuVectorsTotal = 0;
170+
std::set<uint32_t> CUOffsets;
170171
for (uint32_t i = 0; i < SymTableSize; ++i) {
171172
uint32_t NameOffset = Data.getU32(&Offset);
172173
uint32_t CuVecOffset = Data.getU32(&Offset);
173174
SymbolTable.push_back({NameOffset, CuVecOffset});
174175
if (NameOffset || CuVecOffset)
175-
++CuVectorsTotal;
176+
CUOffsets.insert(CuVecOffset);
176177
}
177178

178179
// The constant pool. CU vectors are stored first, followed by strings.
179180
// The first value is the number of CU indices in the vector. Each subsequent
180181
// value is the index and symbol attributes of a CU in the CU list.
181-
for (uint32_t i = 0; i < CuVectorsTotal; ++i) {
182+
for (auto CUOffset : CUOffsets) {
183+
Offset = ConstantPoolOffset + CUOffset;
182184
ConstantPoolVectors.emplace_back(0, SmallVector<uint32_t, 0>());
183185
auto &Vec = ConstantPoolVectors.back();
184186
Vec.first = Offset - ConstantPoolOffset;
185187

186188
uint32_t Num = Data.getU32(&Offset);
187-
for (uint32_t j = 0; j < Num; ++j)
189+
for (uint32_t J = 0; J < Num; ++J)
188190
Vec.second.push_back(Data.getU32(&Offset));
189191
}
190192

Binary file not shown.
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
RUN: llvm-dwarfdump -gdb-index %p/Inputs/dwarfdump-gdbindex-v8.elf-x86-64 | FileCheck %s
2+
3+
; main.cpp:
4+
; typedef struct
5+
; {
6+
; unsigned a;
7+
; unsigned b;
8+
; } S;
9+
;
10+
; int main() {
11+
; S s;
12+
; s.a = 0x64A40101;
13+
; }
14+
; helper.cpp:
15+
; typedef struct
16+
; {
17+
; unsigned a;
18+
; unsigned b;
19+
; } S2;
20+
;
21+
; int foo() {
22+
; S2 s;
23+
; s.a = 0x64A40101;
24+
; }
25+
; Compiled with:
26+
; clang++ -ggnu-pubnames -g2 -gdwarf-4 -fdebug-types-section -c test.cpp test2.cpp
27+
; ld.lld main.o helper.o -o dwarfdump-gdbindex-v8.elf-x86-64
28+
; gdb-11/bin/gdb-add-index dwarfdump-gdbindex-v8.elf-x86-64
29+
; clang version 17.0.0 (https://github.com/llvm/llvm-project.git 128b050d3c234c7238966349f8878884123a0030)
30+
; GNU gdb (GDB) 11.2
31+
; Info about gdb-index: https://sourceware.org/gdb/onlinedocs/gdb/Index-Section-Format.html
32+
33+
; CHECK-LABEL: .gdb_index contents:
34+
; CHECK: Version = 8
35+
36+
; CHECK: CU list offset = 0x18, has 2 entries:
37+
; CHECK-NEXT: 0: Offset = 0x0, Length = 0x6e
38+
; CHECK-NEXT: 1: Offset = 0x6e, Length = 0x72
39+
40+
; CHECK: Types CU list offset = 0x38, has 2 entries:
41+
; CHECK-NEXT: 0: offset = 0x00000000, type_offset = 0x0000001e, type_signature = 0x418503b8111e9a7b
42+
; CHECK-NEXT; 1: offset = 0x00000044, type_offset = 0x0000001e, type_signature = 0x00f6cca4e3a15118
43+
44+
; CHECK: Address area offset = 0x68, has 2 entries:
45+
; CHECK-NEXT: Low/High address = [0x201180, 0x20118f) (Size: 0xf), CU id = 0
46+
; CHECK-NEXT: Low/High address = [0x201190, 0x20119d) (Size: 0xd), CU id = 1
47+
48+
; CHECK: Symbol table offset = 0x90, size = 1024, filled slots:
49+
; CHECK-NEXT: 2: Name offset = 0x28, CU vector offset = 0x0
50+
; CHECK-NEXT: String name: S, CU vector index: 0
51+
; CHECK-NEXT: 71: Name offset = 0x2a, CU vector offset = 0x8
52+
; CHECK-NEXT: String name: S2, CU vector index: 1
53+
; CHECK-NEXT: 489: Name offset = 0x2d, CU vector offset = 0x10
54+
; CHECK-NEXT: String name: main, CU vector index: 2
55+
; CHECK-NEXT: 661: Name offset = 0x32, CU vector offset = 0x18
56+
; CHECK-NEXT: String name: foo, CU vector index: 3
57+
; CHECK-NEXT: 732: Name offset = 0x36, CU vector offset = 0x20
58+
; CHECK-NEXT: String name: unsigned int, CU vector index: 4
59+
; CHECK-NEXT: 754: Name offset = 0x43, CU vector offset = 0x0
60+
; CHECK-NEXT: String name: int, CU vector index: 0
61+
62+
63+
; CHECK: Constant pool offset = 0x2090, has 5 CU vectors:
64+
; CHECK-NEXT: 0(0x0): 0x90000000
65+
; CHECK-NEXT: 1(0x8): 0x90000001
66+
; CHECK-NEXT: 2(0x10): 0x30000000
67+
; CHECK-NEXT: 3(0x18): 0x30000001
68+
; CHECK-NEXT: 4(0x20): 0x90000002

0 commit comments

Comments
 (0)