Skip to content

Commit

Permalink
Merge branch 'main' into compiler-rt-env_vars
Browse files Browse the repository at this point in the history
  • Loading branch information
Harini0924 authored Aug 7, 2024
2 parents d36c22e + a0ed7d6 commit b12ab0f
Show file tree
Hide file tree
Showing 2,616 changed files with 151,135 additions and 43,236 deletions.
5 changes: 5 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,8 @@ e2c2ffbe7a1b5d9e32a2ce64279475b50c4cba5b

# [lldb][nfc] Deindent ProcessGDBRemote::SetThreadStopInfo by two levels
b32931c5b32eb0d2cf37d688b34f8548c9674c19

# [libc++] Various consistency fixes to the CSV files that we use for tracking Standards Conformance
64946fdaf9864d8279da1c30e4d7214fe13d1427
b6262880b34629e9d7a72b5a42f315a3c9ed8139
39c7dc7207e76e72da21cf4fedda21b5311bf62d
3 changes: 3 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,6 @@ clang/test/AST/Interp/ @tbaederr
/llvm/**/DWARFLinker/ @JDevlieghere
/llvm/**/dsymutil/ @JDevlieghere
/llvm/**/llvm-dwarfutil/ @JDevlieghere

# libclang/Python bindings
/clang/bindings/python @DeinAlptraum
26 changes: 26 additions & 0 deletions .github/workflows/get-llvm-version/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Get LLVM Version
description: >-
Get the LLVM version from the llvm-project source tree. This action assumes
the llvm-project sources have already been checked out into GITHUB_WORKSPACE.
outputs:
major:
description: LLVM major version
value: ${{ steps.version.outputs.major }}
minor:
description: LLVM minor version
value: ${{ steps.version.outputs.minor }}
patch:
description: LLVM patch version
value: ${{ steps.version.outputs.patch }}

runs:
using: "composite"
steps:
- name: Get Version
shell: bash
id: version
run: |
for v in major minor patch; do
echo "$v=`llvm/utils/release/get-llvm-version.sh --$v`" >> $GITHUB_OUTPUT
done
16 changes: 8 additions & 8 deletions .github/workflows/libclang-abi-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ jobs:
ABI_HEADERS: ${{ steps.vars.outputs.ABI_HEADERS }}
ABI_LIBS: ${{ steps.vars.outputs.ABI_LIBS }}
BASELINE_VERSION_MAJOR: ${{ steps.vars.outputs.BASELINE_VERSION_MAJOR }}
LLVM_VERSION_MAJOR: ${{ steps.version.outputs.LLVM_VERSION_MAJOR }}
LLVM_VERSION_MINOR: ${{ steps.version.outputs.LLVM_VERSION_MINOR }}
LLVM_VERSION_PATCH: ${{ steps.version.outputs.LLVM_VERSION_PATCH }}
LLVM_VERSION_MAJOR: ${{ steps.version.outputs.major }}
LLVM_VERSION_MINOR: ${{ steps.version.outputs.minor }}
LLVM_VERSION_PATCH: ${{ steps.version.outputs.patch }}
steps:
- name: Checkout source
uses: actions/checkout@v4
Expand All @@ -44,14 +44,14 @@ jobs:

- name: Get LLVM version
id: version
uses: llvm/actions/get-llvm-version@main
uses: ./.github/workflows/get-llvm-version

- name: Setup Variables
id: vars
run: |
remote_repo='https://github.com/llvm/llvm-project'
if [ ${{ steps.version.outputs.LLVM_VERSION_PATCH }} -eq 0 ]; then
major_version=$(( ${{ steps.version.outputs.LLVM_VERSION_MAJOR }} - 1))
if [ ${{ steps.version.outputs.patch }} -eq 0 ]; then
major_version=$(( ${{ steps.version.outputs.major }} - 1))
baseline_ref="llvmorg-$major_version.1.0"
# If there is a minor release, we want to use that as the base line.
Expand All @@ -73,8 +73,8 @@ jobs:
} >> "$GITHUB_OUTPUT"
else
{
echo "BASELINE_VERSION_MAJOR=${{ steps.version.outputs.LLVM_VERSION_MAJOR }}"
echo "BASELINE_REF=llvmorg-${{ steps.version.outputs.LLVM_VERSION_MAJOR }}.1.0"
echo "BASELINE_VERSION_MAJOR=${{ steps.version.outputs.major }}"
echo "BASELINE_REF=llvmorg-${{ steps.version.outputs.major }}.1.0"
echo "ABI_HEADERS=."
echo "ABI_LIBS=libclang.so libclang-cpp.so"
} >> "$GITHUB_OUTPUT"
Expand Down
14 changes: 7 additions & 7 deletions .github/workflows/llvm-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ jobs:
ABI_HEADERS: ${{ steps.vars.outputs.ABI_HEADERS }}
BASELINE_VERSION_MAJOR: ${{ steps.vars.outputs.BASELINE_VERSION_MAJOR }}
BASELINE_VERSION_MINOR: ${{ steps.vars.outputs.BASELINE_VERSION_MINOR }}
LLVM_VERSION_MAJOR: ${{ steps.version.outputs.LLVM_VERSION_MAJOR }}
LLVM_VERSION_MINOR: ${{ steps.version.outputs.LLVM_VERSION_MINOR }}
LLVM_VERSION_PATCH: ${{ steps.version.outputs.LLVM_VERSION_PATCH }}
LLVM_VERSION_MAJOR: ${{ steps.version.outputs.major }}
LLVM_VERSION_MINOR: ${{ steps.version.outputs.minor }}
LLVM_VERSION_PATCH: ${{ steps.version.outputs.patch }}
steps:
- name: Checkout source
uses: actions/checkout@v4
Expand All @@ -54,7 +54,7 @@ jobs:

- name: Get LLVM version
id: version
uses: llvm/actions/get-llvm-version@main
uses: ./.github/workflows/get-llvm-version

- name: Setup Variables
id: vars
Expand All @@ -66,14 +66,14 @@ jobs:
# 18.1.0 We want to check 17.0.x
# 18.1.1 We want to check 18.1.0
echo "BASELINE_VERSION_MINOR=1" >> "$GITHUB_OUTPUT"
if [ ${{ steps.version.outputs.LLVM_VERSION_PATCH }} -eq 0 ]; then
if [ ${{ steps.version.outputs.patch }} -eq 0 ]; then
{
echo "BASELINE_VERSION_MAJOR=$(( ${{ steps.version.outputs.LLVM_VERSION_MAJOR }} - 1))"
echo "BASELINE_VERSION_MAJOR=$(( ${{ steps.version.outputs.major }} - 1))"
echo "ABI_HEADERS=llvm-c"
} >> "$GITHUB_OUTPUT"
else
{
echo "BASELINE_VERSION_MAJOR=${{ steps.version.outputs.LLVM_VERSION_MAJOR }}"
echo "BASELINE_VERSION_MAJOR=${{ steps.version.outputs.major }}"
echo "ABI_HEADERS=."
} >> "$GITHUB_OUTPUT"
fi
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/release-binaries-all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,8 @@ jobs:
release-version: "${{ needs.setup-variables.outputs.release-version }}"
upload: ${{ needs.setup-variables.outputs.upload == 'true'}}
runs-on: "${{ matrix.runs-on }}"

secrets:
# This will be empty for pull_request events, but that's fine, because
# the release-binaries workflow does not use this secret for the
# pull_request event.
RELEASE_TASKS_USER_TOKEN: ${{ secrets.RELEASE_TASKS_USER_TOKEN }}
13 changes: 12 additions & 1 deletion .github/workflows/release-binaries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ on:
description: "Runner to use for the build"
required: true
type: string
secrets:
RELEASE_TASKS_USER_TOKEN:
description: "Secret used to check user permissions."
required: false


permissions:
contents: read # Default everything to read-only
Expand All @@ -57,6 +62,12 @@ jobs:
release-binary-filename: ${{ steps.vars.outputs.release-binary-filename }}

steps:
# It's good practice to use setup-python, but this is also required on macos-14
# due to https://github.com/actions/runner-images/issues/10385
- uses: actions/setup-python@39cd14951b08e74b54015e9e001cdefcf80e669f
with:
python-version: '3.12'

- name: Checkout LLVM
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

Expand Down Expand Up @@ -436,7 +447,7 @@ jobs:
- name: Upload Build Provenance
uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 #v4.3.3
with:
name: ${{ runner.os }}-${{ runner.arch }}-release-binary-attestation
name: ${{ needs.prepare.outputs.release-binary-filename }}-attestation
path: ${{ needs.prepare.outputs.release-binary-filename }}.jsonl

- name: Upload Release
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/release-tasks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ jobs:
name: Build Release Binaries
permissions:
contents: write
id-token: write
attestations: write
needs:
- validate-tag
- release-create
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
3 changes: 2 additions & 1 deletion bolt/include/bolt/Core/BinaryContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,8 @@ class BinaryContext {
/// of \p Flags.
MCSymbol *registerNameAtAddress(StringRef Name, uint64_t Address,
uint64_t Size, uint16_t Alignment,
unsigned Flags = 0);
unsigned Flags = 0,
BinarySection *Section = NULL);

/// Return BinaryData registered at a given \p Address or nullptr if no
/// global symbol was registered at the location.
Expand Down
22 changes: 16 additions & 6 deletions bolt/lib/Core/BinaryContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1056,18 +1056,28 @@ void BinaryContext::adjustCodePadding() {
MCSymbol *BinaryContext::registerNameAtAddress(StringRef Name, uint64_t Address,
uint64_t Size,
uint16_t Alignment,
unsigned Flags) {
unsigned Flags,
BinarySection *Section) {
// Register the name with MCContext.
MCSymbol *Symbol = Ctx->getOrCreateSymbol(Name);
BinaryData *BD;

// Register out of section symbols only in GlobalSymbols map
if (Section && Section->getEndAddress() == Address) {
BD = new BinaryData(*Symbol, Address, Size, Alignment ? Alignment : 1,
*Section, Flags);
GlobalSymbols[Name] = BD;
return Symbol;
}

auto GAI = BinaryDataMap.find(Address);
BinaryData *BD;
if (GAI == BinaryDataMap.end()) {
ErrorOr<BinarySection &> SectionOrErr = getSectionForAddress(Address);
BinarySection &Section =
SectionOrErr ? SectionOrErr.get() : absoluteSection();
BinarySection &SectionRef = Section ? *Section
: SectionOrErr ? SectionOrErr.get()
: absoluteSection();
BD = new BinaryData(*Symbol, Address, Size, Alignment ? Alignment : 1,
Section, Flags);
SectionRef, Flags);
GAI = BinaryDataMap.emplace(Address, BD).first;
GlobalSymbols[Name] = BD;
updateObjectNesting(GAI);
Expand Down Expand Up @@ -1402,7 +1412,7 @@ void BinaryContext::postProcessSymbolTable() {
if ((BD->getName().starts_with("SYMBOLat") ||
BD->getName().starts_with("DATAat")) &&
!BD->getParent() && !BD->getSize() && !BD->isAbsolute() &&
BD->getSection()) {
BD->getSection().getSize()) {
this->errs() << "BOLT-WARNING: zero-sized top level symbol: " << *BD
<< "\n";
Valid = false;
Expand Down
5 changes: 4 additions & 1 deletion bolt/lib/Core/BinaryFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2502,7 +2502,10 @@ void BinaryFunction::annotateCFIState() {
}
}

assert(StateStack.empty() && "corrupt CFI stack");
if (!StateStack.empty()) {
BC.errs() << "BOLT-WARNING: non-empty CFI stack at the end of " << *this
<< '\n';
}
}

namespace {
Expand Down
4 changes: 2 additions & 2 deletions bolt/lib/Rewrite/BinaryPassManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,8 @@ Error BinaryFunctionPassManager::runAllPasses(BinaryContext &BC) {

Manager.registerPass(
std::make_unique<VeneerElimination>(PrintVeneerElimination));

Manager.registerPass(std::make_unique<ADRRelaxationPass>());
}

if (BC.isRISCV()) {
Expand Down Expand Up @@ -490,8 +492,6 @@ Error BinaryFunctionPassManager::runAllPasses(BinaryContext &BC) {
Manager.registerPass(std::make_unique<ReorderData>());

if (BC.isAArch64()) {
Manager.registerPass(std::make_unique<ADRRelaxationPass>());

// Tighten branches according to offset differences between branch and
// targets. No extra instructions after this pass, otherwise we may have
// relocations out of range and crash during linking.
Expand Down
72 changes: 63 additions & 9 deletions bolt/lib/Rewrite/RewriteInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -955,13 +955,13 @@ void RewriteInstance::discoverFileObjects() {
uint64_t SymbolSize = ELFSymbolRef(Symbol).getSize();
uint64_t SymbolAlignment = Symbol.getAlignment();

auto registerName = [&](uint64_t FinalSize) {
auto registerName = [&](uint64_t FinalSize, BinarySection *Section = NULL) {
// Register names even if it's not a function, e.g. for an entry point.
BC->registerNameAtAddress(UniqueName, SymbolAddress, FinalSize,
SymbolAlignment, SymbolFlags);
SymbolAlignment, SymbolFlags, Section);
if (!AlternativeName.empty())
BC->registerNameAtAddress(AlternativeName, SymbolAddress, FinalSize,
SymbolAlignment, SymbolFlags);
SymbolAlignment, SymbolFlags, Section);
};

section_iterator Section =
Expand All @@ -986,12 +986,25 @@ void RewriteInstance::discoverFileObjects() {
<< " for function\n");

if (SymbolAddress == Section->getAddress() + Section->getSize()) {
ErrorOr<BinarySection &> SectionOrError =
BC->getSectionForAddress(Section->getAddress());

// Skip symbols from invalid sections
if (!SectionOrError) {
BC->errs() << "BOLT-WARNING: " << UniqueName << " (0x"
<< Twine::utohexstr(SymbolAddress)
<< ") does not have any section\n";
continue;
}

assert(SymbolSize == 0 &&
"unexpect non-zero sized symbol at end of section");
LLVM_DEBUG(
dbgs()
<< "BOLT-DEBUG: rejecting as symbol points to end of its section\n");
registerName(SymbolSize);
LLVM_DEBUG({
dbgs() << "BOLT-DEBUG: rejecting as symbol " << UniqueName
<< " points to end of " << SectionOrError->getName()
<< " section\n";
});
registerName(SymbolSize, &SectionOrError.get());
continue;
}

Expand Down Expand Up @@ -2143,6 +2156,14 @@ bool RewriteInstance::analyzeRelocation(
if (!Relocation::isSupported(RType))
return false;

auto IsWeakReference = [](const SymbolRef &Symbol) {
Expected<uint32_t> SymFlagsOrErr = Symbol.getFlags();
if (!SymFlagsOrErr)
return false;
return (*SymFlagsOrErr & SymbolRef::SF_Undefined) &&
(*SymFlagsOrErr & SymbolRef::SF_Weak);
};

const bool IsAArch64 = BC->isAArch64();

const size_t RelSize = Relocation::getSizeForType(RType);
Expand Down Expand Up @@ -2174,7 +2195,8 @@ bool RewriteInstance::analyzeRelocation(
// Section symbols are marked as ST_Debug.
IsSectionRelocation = (cantFail(Symbol.getType()) == SymbolRef::ST_Debug);
// Check for PLT entry registered with symbol name
if (!SymbolAddress && (IsAArch64 || BC->isRISCV())) {
if (!SymbolAddress && !IsWeakReference(Symbol) &&
(IsAArch64 || BC->isRISCV())) {
const BinaryData *BD = BC->getPLTBinaryDataByName(SymbolName);
SymbolAddress = BD ? BD->getAddress() : 0;
}
Expand Down Expand Up @@ -2603,7 +2625,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 All @@ -2614,6 +2636,30 @@ void RewriteInstance::handleRelocation(const SectionRef &RelocatedSection,
}
}

if (Relocation::isGOT(RType) && !Relocation::isTLS(RType)) {
auto exitOnGotEndSymol = [&](StringRef Name) {
BC->errs() << "BOLT-ERROR: GOT table contains currently unsupported "
"section end symbol "
<< Name << "\n";
exit(1);
};

if (SymbolIter != InputFile->symbol_end() && ReferencedSection) {
if (cantFail(SymbolIter->getAddress()) ==
ReferencedSection->getEndAddress())
exitOnGotEndSymol(cantFail(SymbolIter->getName()));
} else {
// If no section and symbol are provided by relocation, try to find the
// symbol by its name, including the possibility that the symbol is local.
BinaryData *BD = BC->getBinaryDataByName(SymbolName);
if (!BD && NR.getUniquifiedNameCount(SymbolName) == 1)
BD = BC->getBinaryDataByName(NR.getUniqueName(SymbolName, 1));

if ((BD && BD->getAddress() == BD->getSection().getEndAddress()))
exitOnGotEndSymol(BD->getName());
}
}

if (!ReferencedSection)
ReferencedSection = BC->getSectionForAddress(SymbolAddress);

Expand Down Expand Up @@ -5509,6 +5555,14 @@ uint64_t RewriteInstance::getNewFunctionOrDataAddress(uint64_t OldAddress) {
if (const BinaryFunction *BF =
BC->getBinaryFunctionContainingAddress(OldAddress)) {
if (BF->isEmitted()) {
// If OldAddress is the another entry point of
// the function, then BOLT could get the new address.
if (BF->isMultiEntry()) {
for (const BinaryBasicBlock &BB : *BF)
if (BB.isEntryPoint() &&
(BF->getAddress() + BB.getOffset()) == OldAddress)
return BF->getOutputAddress() + BB.getOffset();
}
BC->errs() << "BOLT-ERROR: unable to get new address corresponding to "
"input address 0x"
<< Twine::utohexstr(OldAddress) << " in function " << *BF
Expand Down
Loading

0 comments on commit b12ab0f

Please sign in to comment.