Skip to content

Commit c146bd4

Browse files
committed
Merge branch 'main' into ptrauth-constants-in-data
2 parents eb7cc2f + ac40463 commit c146bd4

File tree

2,353 files changed

+67640
-36975
lines changed

Some content is hidden

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

2,353 files changed

+67640
-36975
lines changed

.github/new-prs-labeler.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,16 @@ backend:AMDGPU:
717717
- '**/*amdgpu*/**'
718718
- '**/*AMDGPU*/**'
719719

720+
backend:NVPTX:
721+
- 'llvm/**/*nvvm*'
722+
- 'llvm/**/*NVVM*'
723+
- 'llvm/**/*nvptx*'
724+
- 'llvm/**/*NVPTX*'
725+
- 'llvm/**/*nvvm*/**'
726+
- 'llvm/**/*NVVM*/**'
727+
- 'llvm/**/*nvptx*/**'
728+
- 'llvm/**/*NVPTX*/**'
729+
720730
backend:RISC-V:
721731
- clang/**/*riscv*
722732
- clang/**/*RISCV*

.github/workflows/containers/github-action-ci/stage1.Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ RUN cmake -B ./build -G Ninja ./llvm \
3737
-DLLVM_ENABLE_RUNTIMES="compiler-rt" \
3838
-DCMAKE_INSTALL_PREFIX="$LLVM_SYSROOT" \
3939
-DLLVM_ENABLE_PROJECTS="bolt;clang;lld;clang-tools-extra" \
40-
-DLLVM_DISTRIBUTION_COMPONENTS="lld;compiler-rt;clang-format" \
40+
-DLLVM_DISTRIBUTION_COMPONENTS="lld;compiler-rt;clang-format;scan-build" \
4141
-DCLANG_DEFAULT_LINKER="lld" \
4242
-DBOOTSTRAP_CLANG_PGO_TRAINING_DATA_SOURCE_DIR=/llvm-project-llvmorg-$LLVM_VERSION/llvm
4343

.github/workflows/release-binaries.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ jobs:
156156
rm build.tar.zst
157157
158158
- name: Build Stage 2
159+
# Re-enable once PGO builds are supported.
160+
if: false
159161
run: |
160162
ninja -C /mnt/build stage2-instrumented
161163

bolt/include/bolt/Core/BinarySection.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ class BinarySection {
284284
return true;
285285
}
286286
}
287+
bool isNote() const { return isELF() && ELFType == ELF::SHT_NOTE; }
287288
bool isReordered() const { return IsReordered; }
288289
bool isAnonymous() const { return IsAnonymous; }
289290
bool isRelro() const { return IsRelro; }

bolt/include/bolt/Core/DIEBuilder.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,9 @@ class DIEBuilder {
215215
/// Along with current CU, and DIE being processed and the new DIE offset to
216216
/// be updated, it takes in Parents vector that can be empty if this DIE has
217217
/// no parents.
218-
uint32_t
219-
finalizeDIEs(DWARFUnit &CU, DIE &Die,
220-
std::vector<std::optional<BOLTDWARF5AccelTableData *>> &Parents,
221-
uint32_t &CurOffset);
218+
uint32_t finalizeDIEs(DWARFUnit &CU, DIE &Die,
219+
std::optional<BOLTDWARF5AccelTableData *> Parent,
220+
uint32_t NumberParentsInChain, uint32_t &CurOffset);
222221

223222
void registerUnit(DWARFUnit &DU, bool NeedSort);
224223

bolt/include/bolt/Core/DebugNames.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,25 @@ class BOLTDWARF5AccelTableData : public DWARF5AccelTableData {
2424
BOLTDWARF5AccelTableData(const uint64_t DieOffset,
2525
const std::optional<uint64_t> DefiningParentOffset,
2626
const unsigned DieTag, const unsigned UnitID,
27-
const bool IsTU,
27+
const bool IsParentRoot, const bool IsTU,
2828
const std::optional<unsigned> SecondUnitID)
2929
: DWARF5AccelTableData(DieOffset, DefiningParentOffset, DieTag, UnitID,
3030
IsTU),
31-
SecondUnitID(SecondUnitID) {}
31+
SecondUnitID(SecondUnitID), IsParentRoot(IsParentRoot) {}
3232

3333
uint64_t getDieOffset() const { return DWARF5AccelTableData::getDieOffset(); }
3434
unsigned getDieTag() const { return DWARF5AccelTableData::getDieTag(); }
3535
unsigned getUnitID() const { return DWARF5AccelTableData::getUnitID(); }
3636
bool isTU() const { return DWARF5AccelTableData::isTU(); }
37+
bool isParentRoot() const { return IsParentRoot; }
3738
std::optional<unsigned> getSecondUnitID() const { return SecondUnitID; }
3839

3940
void setPatchOffset(uint64_t PatchOffset) { OffsetVal = PatchOffset; }
4041
uint64_t getPatchOffset() const { return std::get<uint64_t>(OffsetVal); }
4142

4243
private:
4344
std::optional<unsigned> SecondUnitID;
45+
bool IsParentRoot;
4446
};
4547

4648
class DWARF5AcceleratorTable {
@@ -57,6 +59,7 @@ class DWARF5AcceleratorTable {
5759
std::optional<BOLTDWARF5AccelTableData *>
5860
addAccelTableEntry(DWARFUnit &Unit, const DIE &Die,
5961
const std::optional<uint64_t> &DWOID,
62+
const uint32_t NumberParentsInChain,
6063
std::optional<BOLTDWARF5AccelTableData *> &Parent);
6164
/// Set current unit being processed.
6265
void setCurrentUnit(DWARFUnit &Unit, const uint64_t UnitStartOffset);

bolt/include/bolt/Core/GDBIndex.h

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
//===-- bolt/Core/GDBIndex.h - GDB Index support ----------------*- 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+
/// This file contains declaration of classes required for generation of
10+
/// .gdb_index section.
11+
///
12+
//===----------------------------------------------------------------------===//
13+
14+
#ifndef BOLT_CORE_GDB_INDEX_H
15+
#define BOLT_CORE_GDB_INDEX_H
16+
17+
#include "bolt/Core/BinaryContext.h"
18+
#include <vector>
19+
20+
namespace llvm {
21+
namespace bolt {
22+
23+
class GDBIndex {
24+
public:
25+
/// Contains information about TU so we can write out correct entries in GDB
26+
/// index.
27+
struct GDBIndexTUEntry {
28+
uint64_t UnitOffset;
29+
uint64_t TypeHash;
30+
uint64_t TypeDIERelativeOffset;
31+
};
32+
33+
private:
34+
BinaryContext &BC;
35+
36+
/// Entries for GDB Index Types CU List.
37+
using GDBIndexTUEntryType = std::vector<GDBIndexTUEntry>;
38+
GDBIndexTUEntryType GDBIndexTUEntryVector;
39+
40+
public:
41+
GDBIndex(BinaryContext &BC) : BC(BC) {}
42+
43+
std::mutex GDBIndexMutex;
44+
45+
/// Adds an GDBIndexTUEntry if .gdb_index section exists.
46+
void addGDBTypeUnitEntry(const GDBIndexTUEntry &&Entry);
47+
48+
/// Rewrite .gdb_index section if present.
49+
void updateGdbIndexSection(const CUOffsetMap &CUMap, const uint32_t NumCUs,
50+
DebugARangesSectionWriter &ARangesSectionWriter);
51+
52+
/// Returns all entries needed for Types CU list.
53+
const GDBIndexTUEntryType &getGDBIndexTUEntryVector() const {
54+
return GDBIndexTUEntryVector;
55+
}
56+
};
57+
58+
} // namespace bolt
59+
} // namespace llvm
60+
61+
#endif

bolt/include/bolt/Rewrite/MetadataManager.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ class MetadataManager {
2828
/// Register a new \p Rewriter.
2929
void registerRewriter(std::unique_ptr<MetadataRewriter> Rewriter);
3030

31+
/// Run initializers after sections are discovered.
32+
void runSectionInitializers();
33+
3134
/// Execute initialization of rewriters while functions are disassembled, but
3235
/// CFG is not yet built.
3336
void runInitializersPreCFG();

bolt/include/bolt/Rewrite/MetadataRewriter.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ class MetadataRewriter {
4545
/// Return name for the rewriter.
4646
StringRef getName() const { return Name; }
4747

48+
/// Run initialization after the binary is read and sections are identified,
49+
/// but before functions are discovered.
50+
virtual Error sectionInitializer() { return Error::success(); }
51+
4852
/// Interface for modifying/annotating functions in the binary based on the
4953
/// contents of the section. Functions are in pre-cfg state.
5054
virtual Error preCFGInitializer() { return Error::success(); }

bolt/include/bolt/Rewrite/MetadataRewriters.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ class BinaryContext;
2121

2222
std::unique_ptr<MetadataRewriter> createLinuxKernelRewriter(BinaryContext &);
2323

24+
std::unique_ptr<MetadataRewriter> createBuildIDRewriter(BinaryContext &);
25+
2426
std::unique_ptr<MetadataRewriter> createPseudoProbeRewriter(BinaryContext &);
2527

2628
std::unique_ptr<MetadataRewriter> createSDTRewriter(BinaryContext &);

bolt/include/bolt/Rewrite/RewriteInstance.h

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,6 @@ class RewriteInstance {
7979
return InputFile->getFileName();
8080
}
8181

82-
/// Set the build-id string if we did not fail to parse the contents of the
83-
/// ELF note section containing build-id information.
84-
void parseBuildID();
85-
86-
/// The build-id is typically a stream of 20 bytes. Return these bytes in
87-
/// printable hexadecimal form if they are available, or std::nullopt
88-
/// otherwise.
89-
std::optional<std::string> getPrintableBuildID() const;
90-
9182
/// If this instance uses a profile, return appropriate profile reader.
9283
const ProfileReaderBase *getProfileReader() const {
9384
return ProfileReader.get();
@@ -184,6 +175,9 @@ class RewriteInstance {
184175
/// Link additional runtime code to support instrumentation.
185176
void linkRuntime();
186177

178+
/// Process metadata in sections before functions are discovered.
179+
void processSectionMetadata();
180+
187181
/// Process metadata in special sections before CFG is built for functions.
188182
void processMetadataPreCFG();
189183

@@ -368,11 +362,6 @@ class RewriteInstance {
368362
/// Loop over now emitted functions to write translation maps
369363
void encodeBATSection();
370364

371-
/// Update the ELF note section containing the binary build-id to reflect
372-
/// a new build-id, so tools can differentiate between the old and the
373-
/// rewritten binary.
374-
void patchBuildID();
375-
376365
/// Return file offset corresponding to a virtual \p Address.
377366
/// Return 0 if the address has no mapping in the file, including being
378367
/// part of .bss section.
@@ -562,18 +551,12 @@ class RewriteInstance {
562551
/// Exception handling and stack unwinding information in this binary.
563552
ErrorOr<BinarySection &> EHFrameSection{std::errc::bad_address};
564553

565-
/// .note.gnu.build-id section.
566-
ErrorOr<BinarySection &> BuildIDSection{std::errc::bad_address};
567-
568554
/// Helper for accessing sections by name.
569555
BinarySection *getSection(const Twine &Name) {
570556
ErrorOr<BinarySection &> ErrOrSection = BC->getUniqueSectionByName(Name);
571557
return ErrOrSection ? &ErrOrSection.get() : nullptr;
572558
}
573559

574-
/// A reference to the build-id bytes in the original binary
575-
StringRef BuildID;
576-
577560
/// Keep track of functions we fail to write in the binary. We need to avoid
578561
/// rewriting CFI info for these functions.
579562
std::vector<uint64_t> FailedAddresses;

bolt/lib/Core/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ add_llvm_library(LLVMBOLTCore
2525
DynoStats.cpp
2626
Exceptions.cpp
2727
FunctionLayout.cpp
28+
GDBIndex.cpp
2829
HashUtilities.cpp
2930
JumpTable.cpp
3031
MCPlusBuilder.cpp

bolt/lib/Core/DIEBuilder.cpp

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -461,32 +461,42 @@ getUnitForOffset(DIEBuilder &Builder, DWARFContext &DWCtx,
461461
return nullptr;
462462
}
463463

464-
uint32_t DIEBuilder::finalizeDIEs(
465-
DWARFUnit &CU, DIE &Die,
466-
std::vector<std::optional<BOLTDWARF5AccelTableData *>> &Parents,
467-
uint32_t &CurOffset) {
464+
uint32_t
465+
DIEBuilder::finalizeDIEs(DWARFUnit &CU, DIE &Die,
466+
std::optional<BOLTDWARF5AccelTableData *> Parent,
467+
uint32_t NumberParentsInChain, uint32_t &CurOffset) {
468468
getState().DWARFDieAddressesParsed.erase(Die.getOffset());
469469
uint32_t CurSize = 0;
470470
Die.setOffset(CurOffset);
471471
std::optional<BOLTDWARF5AccelTableData *> NameEntry =
472472
DebugNamesTable.addAccelTableEntry(
473473
CU, Die, SkeletonCU ? SkeletonCU->getDWOId() : std::nullopt,
474-
Parents.back());
474+
NumberParentsInChain, Parent);
475475
// It is possible that an indexed debugging information entry has a parent
476476
// that is not indexed (for example, if its parent does not have a name
477477
// attribute). In such a case, a parent attribute may point to a nameless
478478
// index entry (that is, one that cannot be reached from any entry in the name
479479
// table), or it may point to the nearest ancestor that does have an index
480480
// entry.
481+
// Skipping entry is not very useful for LLDB. This follows clang where
482+
// children of forward declaration won't have DW_IDX_parent.
483+
// https://github.com/llvm/llvm-project/pull/91808
484+
485+
// If Parent is nullopt and NumberParentsInChain is not zero, then forward
486+
// declaration was encountered in this DF traversal. Propagating nullopt for
487+
// Parent to children.
488+
if (!Parent && NumberParentsInChain)
489+
NameEntry = std::nullopt;
481490
if (NameEntry)
482-
Parents.push_back(std::move(NameEntry));
491+
++NumberParentsInChain;
483492
for (DIEValue &Val : Die.values())
484493
CurSize += Val.sizeOf(CU.getFormParams());
485494
CurSize += getULEB128Size(Die.getAbbrevNumber());
486495
CurOffset += CurSize;
487496

488497
for (DIE &Child : Die.children()) {
489-
uint32_t ChildSize = finalizeDIEs(CU, Child, Parents, CurOffset);
498+
uint32_t ChildSize =
499+
finalizeDIEs(CU, Child, NameEntry, NumberParentsInChain, CurOffset);
490500
CurSize += ChildSize;
491501
}
492502
// for children end mark.
@@ -496,9 +506,6 @@ uint32_t DIEBuilder::finalizeDIEs(
496506
}
497507

498508
Die.setSize(CurSize);
499-
if (NameEntry)
500-
Parents.pop_back();
501-
502509
return CurSize;
503510
}
504511

@@ -510,7 +517,7 @@ void DIEBuilder::finish() {
510517
DebugNamesTable.setCurrentUnit(CU, UnitStartOffset);
511518
std::vector<std::optional<BOLTDWARF5AccelTableData *>> Parents;
512519
Parents.push_back(std::nullopt);
513-
finalizeDIEs(CU, *UnitDIE, Parents, CurOffset);
520+
finalizeDIEs(CU, *UnitDIE, std::nullopt, 0, CurOffset);
514521

515522
DWARFUnitInfo &CurUnitInfo = getUnitInfoByDwarfUnit(CU);
516523
CurUnitInfo.UnitOffset = UnitStartOffset;

bolt/lib/Core/DebugNames.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ static uint64_t getEntryID(const BOLTDWARF5AccelTableData &Entry) {
220220
std::optional<BOLTDWARF5AccelTableData *>
221221
DWARF5AcceleratorTable::addAccelTableEntry(
222222
DWARFUnit &Unit, const DIE &Die, const std::optional<uint64_t> &DWOID,
223+
const uint32_t NumberParentsInChain,
223224
std::optional<BOLTDWARF5AccelTableData *> &Parent) {
224225
if (Unit.getVersion() < 5 || !NeedToCreate)
225226
return std::nullopt;
@@ -312,8 +313,14 @@ DWARF5AcceleratorTable::addAccelTableEntry(
312313
// Keeping memory footprint down.
313314
if (ParentOffset)
314315
EntryRelativeOffsets.insert({*ParentOffset, 0});
316+
bool IsParentRoot = false;
317+
// If there is no parent and no valid Entries in parent chain this is a root
318+
// to be marked with a flag.
319+
if (!Parent && !NumberParentsInChain)
320+
IsParentRoot = true;
315321
It.Values.push_back(new (Allocator) BOLTDWARF5AccelTableData(
316-
Die.getOffset(), ParentOffset, DieTag, UnitID, IsTU, SecondIndex));
322+
Die.getOffset(), ParentOffset, DieTag, UnitID, IsParentRoot, IsTU,
323+
SecondIndex));
317324
return It.Values.back();
318325
};
319326

@@ -462,7 +469,7 @@ void DWARF5AcceleratorTable::populateAbbrevsMap() {
462469
Abbrev.addAttribute({dwarf::DW_IDX_die_offset, dwarf::DW_FORM_ref4});
463470
if (std::optional<uint64_t> Offset = Value->getParentDieOffset())
464471
Abbrev.addAttribute({dwarf::DW_IDX_parent, dwarf::DW_FORM_ref4});
465-
else
472+
else if (Value->isParentRoot())
466473
Abbrev.addAttribute(
467474
{dwarf::DW_IDX_parent, dwarf::DW_FORM_flag_present});
468475
FoldingSetNodeID ID;

0 commit comments

Comments
 (0)