Skip to content

Commit

Permalink
Merge branch 'llvm:main' into llvmgh-101657
Browse files Browse the repository at this point in the history
  • Loading branch information
DhruvSrivastavaX authored Aug 9, 2024
2 parents 50ad673 + 199d6f2 commit a2f162d
Show file tree
Hide file tree
Showing 981 changed files with 34,271 additions and 11,816 deletions.
3 changes: 0 additions & 3 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@
/clang/www/cxx_dr_status.html @Endilll
/clang/www/make_cxx_dr_status @Endilll

clang/lib/AST/Interp/ @tbaederr
clang/test/AST/Interp/ @tbaederr

/clang/include/clang/CIR @lanza @bcardosolopes
/clang/lib/CIR @lanza @bcardosolopes
/clang/tools/cir-* @lanza @bcardosolopes
Expand Down
6 changes: 0 additions & 6 deletions .github/workflows/libclang-python-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,6 @@ on:
- '.github/workflows/libclang-python-tests.yml'
- '.github/workflows/llvm-project-tests.yml'

concurrency:
# Skip intermediate builds: always.
# Cancel intermediate builds: only if it is a pull request build.
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }}

jobs:
check-clang-python:
# Build libclang and then run the libclang Python binding's unit tests.
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/llvm-project-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ concurrency:
# Cancel intermediate builds: only if it is a pull request build.
# If the group name here is the same as the group name in the workflow that includes
# this one, then the action will try to wait on itself and get stuck.
group: llvm-project-${{ github.workflow }}-${{ inputs.projects }}${{ github.ref }}
group: llvm-project-${{ github.workflow }}-${{ inputs.projects }}-${{ inputs.python_version }}${{ github.ref }}
cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }}

jobs:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/release-tasks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ jobs:
release-sources:
name: Package Release Sources
permissions:
contents: read
id-token: write
attestations: write
needs:
Expand Down
2 changes: 1 addition & 1 deletion bolt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ endforeach()

set(BOLT_ENABLE_RUNTIME_default OFF)
if ((CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64"
OR CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64")
OR CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm64|aarch64)$")
AND (CMAKE_SYSTEM_NAME STREQUAL "Linux"
OR CMAKE_SYSTEM_NAME STREQUAL "Darwin")
AND (NOT CMAKE_CROSSCOMPILING))
Expand Down
4 changes: 4 additions & 0 deletions bolt/docs/CommandLineArgumentReference.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@

Prints out offsets for abbrev and debug_info of Skeleton CUs that get patched.

- `--debug-thread-count=<uint>`

Specifies the number of threads to be used when processing DWO debug information.

- `--dot-tooltip-code`

Add basic block instructions as tool tips on nodes
Expand Down
2 changes: 1 addition & 1 deletion bolt/docs/OptimizingLinux.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Convert `perf` profile into a format suitable for BOLT passing the `vmlinux` bin


```bash
$ sudo chwon $USER perf.data
$ sudo chown $USER perf.data
$ perf2bolt -p perf.data -o perf.fdata vmlinux
```

Expand Down
3 changes: 2 additions & 1 deletion bolt/include/bolt/Core/ParallelUtilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ enum SchedulingPolicy {
};

/// Return the managed thread pool and initialize it if not initialized.
ThreadPoolInterface &getThreadPool();
ThreadPoolInterface &
getThreadPool(const unsigned ThreadsCount = opts::ThreadCount);

/// Perform the work on each BinaryFunction except those that are accepted
/// by SkipPredicate, scheduling heuristic is based on SchedPolicy.
Expand Down
3 changes: 2 additions & 1 deletion bolt/include/bolt/Rewrite/DWARFRewriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ class DWARFRewriter {
/// Output .dwo files.
void writeDWOFiles(DWARFUnit &, const OverriddenSectionsMap &,
const std::string &, DebugLocWriter &,
DebugStrOffsetsWriter &, DebugStrWriter &);
DebugStrOffsetsWriter &, DebugStrWriter &,
DebugRangesSectionWriter &);
using KnownSectionsEntry = std::pair<MCSection *, DWARFSectionKind>;
};

Expand Down
1 change: 0 additions & 1 deletion bolt/lib/Core/BinaryContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ BinaryContext::BinaryContext(std::unique_ptr<MCContext> Ctx,
InstPrinter(std::move(InstPrinter)), MIA(std::move(MIA)),
MIB(std::move(MIB)), MRI(std::move(MRI)), DisAsm(std::move(DisAsm)),
Logger(Logger), InitialDynoStats(isAArch64()) {
Relocation::Arch = this->TheTriple->getArch();
RegularPageSize = isAArch64() ? RegularPageSizeAArch64 : RegularPageSizeX86;
PageAlign = opts::NoHugePages ? RegularPageSize : HugePageSize;
}
Expand Down
11 changes: 7 additions & 4 deletions bolt/lib/Core/ParallelUtilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ namespace ParallelUtilities {

namespace {
/// A single thread pool that is used to run parallel tasks
std::unique_ptr<DefaultThreadPool> ThreadPoolPtr;
std::unique_ptr<ThreadPoolInterface> ThreadPoolPtr;

unsigned computeCostFor(const BinaryFunction &BF,
const PredicateTy &SkipPredicate,
Expand Down Expand Up @@ -102,12 +102,15 @@ inline unsigned estimateTotalCost(const BinaryContext &BC,

} // namespace

ThreadPoolInterface &getThreadPool() {
ThreadPoolInterface &getThreadPool(const unsigned ThreadsCount) {
if (ThreadPoolPtr.get())
return *ThreadPoolPtr;

ThreadPoolPtr = std::make_unique<DefaultThreadPool>(
llvm::hardware_concurrency(opts::ThreadCount));
if (ThreadsCount > 1)
ThreadPoolPtr = std::make_unique<DefaultThreadPool>(
llvm::hardware_concurrency(ThreadsCount));
else
ThreadPoolPtr = std::make_unique<SingleThreadExecutor>();
return *ThreadPoolPtr;
}

Expand Down
45 changes: 31 additions & 14 deletions bolt/lib/Rewrite/DWARFRewriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,12 @@ static cl::opt<bool> KeepARanges(
"keep or generate .debug_aranges section if .gdb_index is written"),
cl::Hidden, cl::cat(BoltCategory));

static cl::opt<unsigned>
DebugThreadCount("debug-thread-count",
cl::desc("specifies thread count for the multithreading "
"for updating DWO debug info"),
cl::init(1), cl::cat(BoltCategory));

static cl::opt<std::string> DwarfOutputPath(
"dwarf-output-path",
cl::desc("Path to where .dwo files will be written out to."), cl::init(""),
Expand Down Expand Up @@ -475,8 +481,8 @@ static void emitDWOBuilder(const std::string &DWOName,
DWARFUnit &SplitCU, DWARFUnit &CU,
DebugLocWriter &LocWriter,
DebugStrOffsetsWriter &StrOffstsWriter,
DebugStrWriter &StrWriter,
GDBIndex &GDBIndexSection) {
DebugStrWriter &StrWriter, GDBIndex &GDBIndexSection,
DebugRangesSectionWriter &TempRangesSectionWriter) {
// Populate debug_info and debug_abbrev for current dwo into StringRef.
DWODIEBuilder.generateAbbrevs();
DWODIEBuilder.finish();
Expand Down Expand Up @@ -532,7 +538,7 @@ static void emitDWOBuilder(const std::string &DWOName,
OverriddenSections[Kind] = Contents;
}
Rewriter.writeDWOFiles(CU, OverriddenSections, DWOName, LocWriter,
StrOffstsWriter, StrWriter);
StrOffstsWriter, StrWriter, TempRangesSectionWriter);
}

using DWARFUnitVec = std::vector<DWARFUnit *>;
Expand Down Expand Up @@ -646,7 +652,6 @@ void DWARFRewriter::updateDebugInfo() {
*StrWriter);
GDBIndex GDBIndexSection(BC);
auto processSplitCU = [&](DWARFUnit &Unit, DWARFUnit &SplitCU,
DIEBuilder &DIEBlder,
DebugRangesSectionWriter &TempRangesSectionWriter,
DebugAddrWriter &AddressWriter,
const std::string &DWOName,
Expand All @@ -669,7 +674,7 @@ void DWARFRewriter::updateDebugInfo() {

emitDWOBuilder(DWOName, DWODIEBuilder, *this, SplitCU, Unit,
DebugLocDWoWriter, DWOStrOffstsWriter, DWOStrWriter,
GDBIndexSection);
GDBIndexSection, TempRangesSectionWriter);
};
auto processMainBinaryCU = [&](DWARFUnit &Unit, DIEBuilder &DIEBlder) {
std::optional<DWARFUnit *> SplitCU;
Expand Down Expand Up @@ -716,9 +721,13 @@ void DWARFRewriter::updateDebugInfo() {
finalizeTypeSections(DIEBlder, *Streamer, GDBIndexSection);

CUPartitionVector PartVec = partitionCUs(*BC.DwCtx);
const unsigned int ThreadCount =
std::min(opts::DebugThreadCount, opts::ThreadCount);
for (std::vector<DWARFUnit *> &Vec : PartVec) {
DIEBlder.buildCompileUnits(Vec);
llvm::SmallVector<std::unique_ptr<DIEBuilder>, 72> DWODIEBuildersByCU;
ThreadPoolInterface &ThreadPool =
ParallelUtilities::getThreadPool(ThreadCount);
for (DWARFUnit *CU : DIEBlder.getProcessedCUs()) {
createRangeLocListAddressWriters(*CU);
std::optional<DWARFUnit *> SplitCU;
Expand All @@ -729,9 +738,9 @@ void DWARFRewriter::updateDebugInfo() {
continue;
DebugAddrWriter &AddressWriter =
*AddressWritersByCU[CU->getOffset()].get();
DebugRangesSectionWriter *TempRangesSectionWriter =
CU->getVersion() >= 5 ? RangeListsWritersByCU[*DWOId].get()
: LegacyRangesWritersByCU[*DWOId].get();
DebugRangesSectionWriter &TempRangesSectionWriter =
CU->getVersion() >= 5 ? *RangeListsWritersByCU[*DWOId].get()
: *LegacyRangesWritersByCU[*DWOId].get();
std::optional<std::string> DwarfOutputPath =
opts::DwarfOutputPath.empty()
? std::nullopt
Expand All @@ -744,9 +753,17 @@ void DWARFRewriter::updateDebugInfo() {
*DWODIEBuildersByCU.emplace_back(std::move(DWODIEBuilderPtr)).get();
if (CU->getVersion() >= 5)
StrOffstsWriter->finalizeSection(*CU, DIEBlder);
processSplitCU(*CU, **SplitCU, DIEBlder, *TempRangesSectionWriter,
AddressWriter, DWOName, DwarfOutputPath, DWODIEBuilder);
// Important to capture CU and SplitCU by value here, otherwise when the
// thread is executed at some point after the current iteration of the
// loop, dereferencing CU/SplitCU in the call to processSplitCU means it
// will dereference a different variable than the one intended, causing a
// seg fault.
ThreadPool.async([&, DwarfOutputPath, DWOName, CU, SplitCU] {
processSplitCU(*CU, **SplitCU, TempRangesSectionWriter, AddressWriter,
DWOName, DwarfOutputPath, DWODIEBuilder);
});
}
ThreadPool.wait();
for (std::unique_ptr<DIEBuilder> &DWODIEBuilderPtr : DWODIEBuildersByCU)
DWODIEBuilderPtr->updateDebugNamesTable();
for (DWARFUnit *CU : DIEBlder.getProcessedCUs())
Expand Down Expand Up @@ -1807,7 +1824,8 @@ std::optional<StringRef> updateDebugData(
void DWARFRewriter::writeDWOFiles(
DWARFUnit &CU, const OverriddenSectionsMap &OverridenSections,
const std::string &DWOName, DebugLocWriter &LocWriter,
DebugStrOffsetsWriter &StrOffstsWriter, DebugStrWriter &StrWriter) {
DebugStrOffsetsWriter &StrOffstsWriter, DebugStrWriter &StrWriter,
DebugRangesSectionWriter &TempRangesSectionWriter) {
// Setup DWP code once.
DWARFContext *DWOCtx = BC.getDWOContext();
const uint64_t DWOId = *CU.getDWOId();
Expand Down Expand Up @@ -1854,9 +1872,8 @@ void DWARFRewriter::writeDWOFiles(

DebugRangeListsSectionWriter *RangeListssWriter = nullptr;
if (CU.getVersion() == 5) {
assert(RangeListsWritersByCU.count(DWOId) != 0 &&
"No RangeListsWriter for DWO ID.");
RangeListssWriter = RangeListsWritersByCU[DWOId].get();
RangeListssWriter =
llvm::dyn_cast<DebugRangeListsSectionWriter>(&TempRangesSectionWriter);

// Handling .debug_rnglists.dwo separately. The original .o/.dwo might not
// have .debug_rnglists so won't be part of the loop below.
Expand Down
1 change: 1 addition & 0 deletions bolt/lib/Rewrite/MachORewriteInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ MachORewriteInstance::MachORewriteInstance(object::MachOObjectFile *InputFile,
StringRef ToolPath, Error &Err)
: InputFile(InputFile), ToolPath(ToolPath) {
ErrorAsOutParameter EAO(&Err);
Relocation::Arch = InputFile->makeTriple().getArch();
auto BCOrErr = BinaryContext::createBinaryContext(
InputFile->makeTriple(), InputFile->getFileName(), nullptr,
/* IsPIC */ true, DWARFContext::create(*InputFile),
Expand Down
3 changes: 2 additions & 1 deletion bolt/lib/Rewrite/RewriteInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ RewriteInstance::RewriteInstance(ELFObjectFileBase *File, const int Argc,
}
}

Relocation::Arch = TheTriple.getArch();
auto BCOrErr = BinaryContext::createBinaryContext(
TheTriple, File->getFileName(), Features.get(), IsPIC,
DWARFContext::create(*File, DWARFContext::ProcessDebugRelocations::Ignore,
Expand Down Expand Up @@ -2612,7 +2613,7 @@ void RewriteInstance::handleRelocation(const SectionRef &RelocatedSection,
Expected<StringRef> SectionName = Section->getName();
if (SectionName && !SectionName->empty())
ReferencedSection = BC->getUniqueSectionByName(*SectionName);
} else if (ReferencedSymbol && ContainingBF &&
} else if (BC->isRISCV() && ReferencedSymbol && ContainingBF &&
(cantFail(Symbol.getFlags()) & SymbolRef::SF_Absolute)) {
// This might be a relocation for an ABS symbols like __global_pointer$ on
// RISC-V
Expand Down
9 changes: 9 additions & 0 deletions bolt/test/AArch64/Inputs/build_id.ldscript
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
SECTIONS
{
PROVIDE (__executable_start = SEGMENT_START("text-segment", 0x400000)); . = SEGMENT_START("text-segment", 0x400000) + SIZEOF_HEADERS;
.note.gnu.build-id (0x400400):
{
build_id_note = ABSOLUTE(.);
*(.note.gnu.build-id)
}
}
25 changes: 25 additions & 0 deletions bolt/test/AArch64/build_id.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// This test checks that referencing build_id through GOT table
// would result in GOT access after disassembly, not directly
// to build_id address.

// RUN: %clang %cflags -fuse-ld=lld -Wl,-T,%S/Inputs/build_id.ldscript -Wl,-q \
// RUN: -Wl,--no-relax -Wl,--build-id=sha1 %s -o %t.exe
// RUN: llvm-bolt -print-disasm --print-only=get_build_id %t.exe -o %t.bolt | \
// RUN: FileCheck %s

// CHECK: adrp [[REG:x[0-28]+]], __BOLT_got_zero
// CHECK: ldr x{{.*}}, [[[REG]], :lo12:__BOLT_got_zero{{.*}}]

struct build_id_note {
char pad[16];
char hash[20];
};

extern const struct build_id_note build_id_note;

__attribute__((noinline)) char get_build_id() { return build_id_note.hash[0]; }

int main() {
get_build_id();
return 0;
}
Loading

0 comments on commit a2f162d

Please sign in to comment.