Skip to content

Commit fab91e9

Browse files
committed
Revert "[Reland][DWARFLinkerParallel] Add limited functionality to DWARFLinkerParallel."
This reverts commit 0229dd0. This introduces two test failures on s390x. tools/dsymutil/X86/location-expression.test: warning: cann't load line table. note: while processing CU1 /builddir/build/BUILD/llvm-18.0.0.src/test/tools/dsymutil/X86/location-expression.test:20:10: error: CHECK: expected string not found in input # CHECK: DW_AT_name{{.*}}"CU1" ^ <stdin>:34:32: note: scanning from here 0x0000000b: DW_TAG_compile_unit [1] * ^ <stdin>:37:2: note: possible intended match here DW_AT_name [DW_FORM_strp] ( .debug_str[0x09000000] = ) ^ tools/dsymutil/X86/tls-variable.test: warning: cann't load line table. note: while processing CU1 /builddir/build/BUILD/llvm-18.0.0.src/test/tools/dsymutil/X86/tls-variable.test:19:10: error: CHECK: expected string not found in input # CHECK: DW_AT_name{{.*}}"CU1" ^ <stdin>:26:32: note: scanning from here 0x0000000b: DW_TAG_compile_unit ^ <stdin>:29:2: note: possible intended match here DW_AT_name () ^
1 parent 23c8d38 commit fab91e9

File tree

133 files changed

+1007
-8485
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

133 files changed

+1007
-8485
lines changed

llvm/include/llvm/CodeGen/DwarfStringPoolEntry.h

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,34 +27,29 @@ struct DwarfStringPoolEntry {
2727
bool isIndexed() const { return Index != NotIndexed; }
2828
};
2929

30-
/// DwarfStringPoolEntry with string keeping externally.
31-
struct DwarfStringPoolEntryWithExtString : public DwarfStringPoolEntry {
32-
StringRef String;
33-
};
34-
3530
/// DwarfStringPoolEntryRef: Dwarf string pool entry reference.
3631
///
3732
/// Dwarf string pool entry keeps string value and its data.
3833
/// There are two variants how data are represented:
3934
///
40-
/// 1. String data in pool - StringMapEntry<DwarfStringPoolEntry>.
41-
/// 2. External string data - DwarfStringPoolEntryWithExtString.
35+
/// 1. By value - StringMapEntry<DwarfStringPoolEntry>.
36+
/// 2. By pointer - StringMapEntry<DwarfStringPoolEntry *>.
4237
///
43-
/// The external data variant allows reducing memory usage for the case
44-
/// when string pool entry does not have data: string entry does not
45-
/// keep any data and so no need to waste space for the full
46-
/// DwarfStringPoolEntry. It is recommended to use external variant if not all
47-
/// entries of dwarf string pool have corresponding DwarfStringPoolEntry.
38+
/// The "By pointer" variant allows for reducing memory usage for the case
39+
/// when string pool entry does not have data: it keeps the null pointer
40+
/// and so no need to waste space for the full DwarfStringPoolEntry.
41+
/// It is recommended to use "By pointer" variant if not all entries
42+
/// of dwarf string pool have corresponding DwarfStringPoolEntry.
4843

4944
class DwarfStringPoolEntryRef {
5045
/// Pointer type for "By value" string entry.
5146
using ByValStringEntryPtr = const StringMapEntry<DwarfStringPoolEntry> *;
5247

53-
/// Pointer type for external string entry.
54-
using ExtStringEntryPtr = const DwarfStringPoolEntryWithExtString *;
48+
/// Pointer type for "By pointer" string entry.
49+
using ByPtrStringEntryPtr = const StringMapEntry<DwarfStringPoolEntry *> *;
5550

5651
/// Pointer to the dwarf string pool Entry.
57-
PointerUnion<ByValStringEntryPtr, ExtStringEntryPtr> MapEntry = nullptr;
52+
PointerUnion<ByValStringEntryPtr, ByPtrStringEntryPtr> MapEntry = nullptr;
5853

5954
public:
6055
DwarfStringPoolEntryRef() = default;
@@ -66,8 +61,10 @@ class DwarfStringPoolEntryRef {
6661

6762
/// ASSUMPTION: DwarfStringPoolEntryRef keeps pointer to \p Entry,
6863
/// thus specified entry mustn`t be reallocated.
69-
DwarfStringPoolEntryRef(const DwarfStringPoolEntryWithExtString &Entry)
70-
: MapEntry(&Entry) {}
64+
DwarfStringPoolEntryRef(const StringMapEntry<DwarfStringPoolEntry *> &Entry)
65+
: MapEntry(&Entry) {
66+
assert(cast<ByPtrStringEntryPtr>(MapEntry)->second != nullptr);
67+
}
7168

7269
explicit operator bool() const { return !MapEntry.isNull(); }
7370

@@ -91,15 +88,15 @@ class DwarfStringPoolEntryRef {
9188
if (isa<ByValStringEntryPtr>(MapEntry))
9289
return cast<ByValStringEntryPtr>(MapEntry)->first();
9390

94-
return cast<ExtStringEntryPtr>(MapEntry)->String;
91+
return cast<ByPtrStringEntryPtr>(MapEntry)->first();
9592
}
9693

9794
/// \returns the entire string pool entry for convenience.
9895
const DwarfStringPoolEntry &getEntry() const {
9996
if (isa<ByValStringEntryPtr>(MapEntry))
10097
return cast<ByValStringEntryPtr>(MapEntry)->second;
10198

102-
return *cast<ExtStringEntryPtr>(MapEntry);
99+
return *cast<ByPtrStringEntryPtr>(MapEntry)->second;
103100
}
104101

105102
bool operator==(const DwarfStringPoolEntryRef &X) const {

llvm/include/llvm/DWARFLinker/DWARFLinker.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,11 +270,9 @@ using UnitListTy = std::vector<std::unique_ptr<CompileUnit>>;
270270
/// and its address map.
271271
class DWARFFile {
272272
public:
273-
using UnloadCallbackTy = std::function<void(StringRef FileName)>;
274273
DWARFFile(StringRef Name, std::unique_ptr<DWARFContext> Dwarf,
275274
std::unique_ptr<AddressesMap> Addresses,
276-
const std::vector<std::string> &Warnings,
277-
UnloadCallbackTy = nullptr)
275+
const std::vector<std::string> &Warnings)
278276
: FileName(Name), Dwarf(std::move(Dwarf)),
279277
Addresses(std::move(Addresses)), Warnings(Warnings) {}
280278

llvm/include/llvm/DWARFLinkerParallel/AddressesMap.h

Lines changed: 0 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@
1010
#define LLVM_DWARFLINKERPARALLEL_ADDRESSESMAP_H
1111

1212
#include "llvm/ADT/AddressRanges.h"
13-
#include "llvm/DebugInfo/DWARF/DWARFContext.h"
1413
#include "llvm/DebugInfo/DWARF/DWARFDie.h"
1514
#include "llvm/DebugInfo/DWARF/DWARFExpression.h"
16-
#include "llvm/DebugInfo/DWARF/DWARFUnit.h"
1715
#include <cstdint>
1816

1917
namespace llvm {
@@ -64,108 +62,6 @@ class AddressesMap {
6462

6563
/// Erases all data.
6664
virtual void clear() = 0;
67-
68-
/// This function checks whether variable has DWARF expression containing
69-
/// operation referencing live address(f.e. DW_OP_addr, DW_OP_addrx...).
70-
/// \returns first is true if the expression has an operation referencing an
71-
/// address.
72-
/// second is the relocation adjustment value if the live address is
73-
/// referenced.
74-
std::pair<bool, std::optional<int64_t>>
75-
getVariableRelocAdjustment(const DWARFDie &DIE) {
76-
assert((DIE.getTag() == dwarf::DW_TAG_variable ||
77-
DIE.getTag() == dwarf::DW_TAG_constant) &&
78-
"Wrong type of input die");
79-
80-
const auto *Abbrev = DIE.getAbbreviationDeclarationPtr();
81-
82-
// Check if DIE has DW_AT_location attribute.
83-
DWARFUnit *U = DIE.getDwarfUnit();
84-
std::optional<uint32_t> LocationIdx =
85-
Abbrev->findAttributeIndex(dwarf::DW_AT_location);
86-
if (!LocationIdx)
87-
return std::make_pair(false, std::nullopt);
88-
89-
// Get offset to the DW_AT_location attribute.
90-
uint64_t AttrOffset =
91-
Abbrev->getAttributeOffsetFromIndex(*LocationIdx, DIE.getOffset(), *U);
92-
93-
// Get value of the DW_AT_location attribute.
94-
std::optional<DWARFFormValue> LocationValue =
95-
Abbrev->getAttributeValueFromOffset(*LocationIdx, AttrOffset, *U);
96-
if (!LocationValue)
97-
return std::make_pair(false, std::nullopt);
98-
99-
// Check that DW_AT_location attribute is of 'exprloc' class.
100-
// Handling value of location expressions for attributes of 'loclist'
101-
// class is not implemented yet.
102-
std::optional<ArrayRef<uint8_t>> Expr = LocationValue->getAsBlock();
103-
if (!Expr)
104-
return std::make_pair(false, std::nullopt);
105-
106-
// Parse 'exprloc' expression.
107-
DataExtractor Data(toStringRef(*Expr), U->getContext().isLittleEndian(),
108-
U->getAddressByteSize());
109-
DWARFExpression Expression(Data, U->getAddressByteSize(),
110-
U->getFormParams().Format);
111-
112-
bool HasLocationAddress = false;
113-
uint64_t CurExprOffset = 0;
114-
for (DWARFExpression::iterator It = Expression.begin();
115-
It != Expression.end(); ++It) {
116-
DWARFExpression::iterator NextIt = It;
117-
++NextIt;
118-
119-
const DWARFExpression::Operation &Op = *It;
120-
switch (Op.getCode()) {
121-
case dwarf::DW_OP_const2u:
122-
case dwarf::DW_OP_const4u:
123-
case dwarf::DW_OP_const8u:
124-
case dwarf::DW_OP_const2s:
125-
case dwarf::DW_OP_const4s:
126-
case dwarf::DW_OP_const8s:
127-
if (NextIt == Expression.end() || !isTlsAddressCode(NextIt->getCode()))
128-
break;
129-
[[fallthrough]];
130-
case dwarf::DW_OP_addr: {
131-
HasLocationAddress = true;
132-
// Check relocation for the address.
133-
if (std::optional<int64_t> RelocAdjustment =
134-
getExprOpAddressRelocAdjustment(*U, Op,
135-
AttrOffset + CurExprOffset,
136-
AttrOffset + Op.getEndOffset()))
137-
return std::make_pair(HasLocationAddress, *RelocAdjustment);
138-
} break;
139-
case dwarf::DW_OP_constx:
140-
case dwarf::DW_OP_addrx: {
141-
HasLocationAddress = true;
142-
if (std::optional<uint64_t> AddressOffset =
143-
DIE.getDwarfUnit()->getIndexedAddressOffset(
144-
Op.getRawOperand(0))) {
145-
// Check relocation for the address.
146-
if (std::optional<int64_t> RelocAdjustment =
147-
getExprOpAddressRelocAdjustment(
148-
*U, Op, *AddressOffset,
149-
*AddressOffset +
150-
DIE.getDwarfUnit()->getAddressByteSize()))
151-
return std::make_pair(HasLocationAddress, *RelocAdjustment);
152-
}
153-
} break;
154-
default: {
155-
// Nothing to do.
156-
} break;
157-
}
158-
CurExprOffset = Op.getEndOffset();
159-
}
160-
161-
return std::make_pair(HasLocationAddress, std::nullopt);
162-
}
163-
164-
protected:
165-
inline bool isTlsAddressCode(uint8_t DW_OP_Code) {
166-
return DW_OP_Code == dwarf::DW_OP_form_tls_address ||
167-
DW_OP_Code == dwarf::DW_OP_GNU_push_tls_address;
168-
}
16965
};
17066

17167
} // end of namespace dwarflinker_parallel

llvm/include/llvm/DWARFLinkerParallel/DWARFFile.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,14 @@ class DWARFFile {
3030
DWARFFile(StringRef Name, std::unique_ptr<DWARFContext> Dwarf,
3131
std::unique_ptr<AddressesMap> Addresses,
3232
const std::vector<std::string> &Warnings,
33-
UnloadCallbackTy UnloadFunc = nullptr);
33+
UnloadCallbackTy UnloadFunc = nullptr)
34+
: FileName(Name), Dwarf(std::move(Dwarf)),
35+
Addresses(std::move(Addresses)), Warnings(Warnings),
36+
UnloadFunc(UnloadFunc) {
37+
if (this->Dwarf)
38+
Endianess = this->Dwarf->isLittleEndian() ? support::endianness::little
39+
: support::endianness::big;
40+
}
3441

3542
/// Object file name.
3643
StringRef FileName;
@@ -44,6 +51,9 @@ class DWARFFile {
4451
/// Warnings for object file.
4552
const std::vector<std::string> &Warnings;
4653

54+
/// Endiannes of source DWARF information.
55+
support::endianness Endianess = support::endianness::little;
56+
4757
/// Callback to the module keeping object file to unload.
4858
UnloadCallbackTy UnloadFunc;
4959

llvm/include/llvm/DWARFLinkerParallel/StringPool.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace dwarflinker_parallel {
2121

2222
/// StringEntry keeps data of the string: the length, external offset
2323
/// and a string body which is placed right after StringEntry.
24-
using StringEntry = StringMapEntry<std::nullopt_t>;
24+
using StringEntry = StringMapEntry<DwarfStringPoolEntry *>;
2525

2626
class StringPoolEntryInfo {
2727
public:
@@ -64,8 +64,6 @@ class StringPool
6464

6565
parallel::PerThreadBumpPtrAllocator &getAllocatorRef() { return Allocator; }
6666

67-
void clear() { Allocator.Reset(); }
68-
6967
private:
7068
parallel::PerThreadBumpPtrAllocator Allocator;
7169
};
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
//===- StringTable.h --------------------------------------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_DWARFLINKERPARALLEL_STRINGTABLE_H
10+
#define LLVM_DWARFLINKERPARALLEL_STRINGTABLE_H
11+
12+
#include "llvm/ADT/SmallVector.h"
13+
#include "llvm/DWARFLinkerParallel/StringPool.h"
14+
15+
namespace llvm {
16+
namespace dwarflinker_parallel {
17+
18+
using StringsVector = SmallVector<StringEntry *>;
19+
20+
/// This class prepares strings for emission into .debug_str table:
21+
/// translates string if necessary, assigns index and offset, keeps in order.
22+
class StringTable {
23+
public:
24+
StringTable(StringPool &Strings,
25+
std::function<StringRef(StringRef)> StringsTranslator)
26+
: Strings(Strings), StringsTranslator(StringsTranslator) {}
27+
~StringTable() {}
28+
29+
/// Add string to the vector of strings which should be emitted.
30+
/// Translate input string if neccessary, assign index and offset.
31+
/// \returns updated string entry.
32+
StringEntry *add(StringEntry *String) {
33+
// Translate string if necessary.
34+
if (StringsTranslator)
35+
String = Strings.insert(StringsTranslator(String->first())).first;
36+
37+
// Store String for emission and assign index and offset.
38+
if (String->getValue() == nullptr) {
39+
DwarfStringPoolEntry *NewEntry =
40+
Strings.getAllocatorRef().Allocate<DwarfStringPoolEntry>();
41+
42+
NewEntry->Symbol = nullptr;
43+
NewEntry->Index = StringEntriesForEmission.size();
44+
45+
if (StringEntriesForEmission.empty())
46+
NewEntry->Offset = 0;
47+
else {
48+
StringEntry *PrevString = StringEntriesForEmission.back();
49+
NewEntry->Offset =
50+
PrevString->getValue()->Offset + PrevString->getKeyLength() + 1;
51+
}
52+
53+
String->getValue() = NewEntry;
54+
StringEntriesForEmission.push_back(String);
55+
}
56+
57+
return String;
58+
}
59+
60+
/// Erase contents of StringsForEmission.
61+
void clear() { StringEntriesForEmission.clear(); }
62+
63+
/// Enumerate all strings in sequential order and call \p Handler for each
64+
/// string.
65+
void forEach(function_ref<void(DwarfStringPoolEntryRef)> Handler) const {
66+
for (const StringEntry *Entry : StringEntriesForEmission)
67+
Handler(*Entry);
68+
}
69+
70+
std::function<StringRef(StringRef)> getTranslator() {
71+
return StringsTranslator;
72+
}
73+
74+
protected:
75+
/// List of strings for emission.
76+
StringsVector StringEntriesForEmission;
77+
78+
/// String pool for the translated strings.
79+
StringPool &Strings;
80+
81+
/// Translator for the strings.
82+
std::function<StringRef(StringRef)> StringsTranslator;
83+
};
84+
85+
} // end of namespace dwarflinker_parallel
86+
} // end namespace llvm
87+
88+
#endif // LLVM_DWARFLINKERPARALLEL_STRINGTABLE_H

llvm/include/llvm/DebugInfo/DWARF/DWARFDebugMacro.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ class DwarfStreamer;
2222

2323
class DWARFDebugMacro {
2424
friend DwarfStreamer;
25-
friend dwarflinker_parallel::CompileUnit;
2625

2726
/// DWARFv5 section 6.3.1 Macro Information Header.
2827
enum HeaderFlagMask {

llvm/lib/DWARFLinker/DWARFLinker.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -444,10 +444,8 @@ DWARFLinker::getVariableRelocAdjustment(AddressesMap &RelocMgr,
444444

445445
const DWARFExpression::Operation &Op = *It;
446446
switch (Op.getCode()) {
447-
case dwarf::DW_OP_const2u:
448447
case dwarf::DW_OP_const4u:
449448
case dwarf::DW_OP_const8u:
450-
case dwarf::DW_OP_const2s:
451449
case dwarf::DW_OP_const4s:
452450
case dwarf::DW_OP_const8s:
453451
if (NextIt == Expression.end() || !isTlsAddressCode(NextIt->getCode()))

llvm/lib/DWARFLinker/DWARFLinkerCompileUnit.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,8 @@ void CompileUnit::markEverythingAsKept() {
9797
++NextIt;
9898

9999
switch (It->getCode()) {
100-
case dwarf::DW_OP_const2u:
101100
case dwarf::DW_OP_const4u:
102101
case dwarf::DW_OP_const8u:
103-
case dwarf::DW_OP_const2s:
104102
case dwarf::DW_OP_const4s:
105103
case dwarf::DW_OP_const8s:
106104
if (NextIt == Expression.end() ||

0 commit comments

Comments
 (0)