Skip to content

Commit 5e438fa

Browse files
committed
Merge branch 'users/meinersbur/flang_runtime' into users/meinersbur/flang_runtime_shared
2 parents 8a0a3e8 + 77d821c commit 5e438fa

File tree

1,296 files changed

+59355
-18625
lines changed

Some content is hidden

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

1,296 files changed

+59355
-18625
lines changed

.github/workflows/build-ci-container.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ jobs:
9696
run: |
9797
function push_container {
9898
image_name=$1
99-
latest_name=$(echo $image_name | sed 's/:[.0-9]\+$/:latest/g')
99+
latest_name=$(echo $image_name | sed 's/:[a-f0-9]\+$/:latest/g')
100100
podman tag $image_name $latest_name
101101
echo "Pushing $image_name ..."
102102
podman push $image_name

.github/workflows/release-binaries.yml

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ jobs:
5858
target-cmake-flags: ${{ steps.vars.outputs.target-cmake-flags }}
5959
ccache: ${{ steps.vars.outputs.ccache }}
6060
build-flang: ${{ steps.vars.outputs.build-flang }}
61-
enable-pgo: ${{ steps.vars.outputs.enable-pgo }}
6261
release-binary-basename: ${{ steps.vars.outputs.release-binary-basename }}
6362
release-binary-filename: ${{ steps.vars.outputs.release-binary-filename }}
6463
build-runs-on: ${{ steps.vars.outputs.build-runs-on }}
@@ -130,9 +129,6 @@ jobs:
130129
echo ccache=sccache >> $GITHUB_OUTPUT
131130
fi
132131
133-
# Detect necessary CMake flags
134-
echo "enable-pgo=false" >> $GITHUB_OUTPUT
135-
target_cmake_flags="-DLLVM_RELEASE_ENABLE_PGO=OFF"
136132
# The macOS builds try to cross compile some libraries so we need to
137133
# add extra CMake args to disable them.
138134
# See https://github.com/llvm/llvm-project/issues/99767
@@ -238,13 +234,14 @@ jobs:
238234
${{ needs.prepare.outputs.target-cmake-flags }} \
239235
-C clang/cmake/caches/Release.cmake \
240236
-DBOOTSTRAP_LLVM_PARALLEL_LINK_JOBS=1 \
241-
-DBOOTSTRAP_CPACK_PACKAGE_FILE_NAME="${{ needs.prepare.outputs.release-binary-basename }}"
237+
-DBOOTSTRAP_BOOTSTRAP_CPACK_PACKAGE_FILE_NAME="${{ needs.prepare.outputs.release-binary-basename }}"
242238
243239
- name: Build
244240
shell: bash
245241
run: |
246242
ninja -v -C ${{ steps.setup-stage.outputs.build-prefix }}/build stage2-package
247-
mv ${{ steps.setup-stage.outputs.build-prefix }}/build/tools/clang/stage2-bins/${{ needs.prepare.outputs.release-binary-filename }} .
243+
release_dir=`find ${{ steps.setup-stage.outputs.build-prefix }}/build -iname 'stage2-bins'`
244+
mv $release_dir/${{ needs.prepare.outputs.release-binary-filename }} .
248245
249246
- uses: actions/upload-artifact@26f96dfa697d77e81fd5907df203aa23a56210a8 #v4.3.0
250247
with:
@@ -259,7 +256,7 @@ jobs:
259256
shell: bash
260257
run: |
261258
find ${{ steps.setup-stage.outputs.build-prefix }}/build -iname ${{ needs.prepare.outputs.release-binary-filename }} -delete
262-
rm -Rf ${{ steps.setup-stage.outputs.build-prefix }}/build/tools/clang/stage2-bins/_CPack_Packages
259+
find ${{ steps.setup-stage.outputs.build-prefix }}/build -iname _CPack_Packages -prune -exec rm -r {} +
263260
264261
- name: Save Stage
265262
uses: ./workflows-main/.github/workflows/release-binaries-save-stage

bolt/include/bolt/Core/BinaryContext.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1435,6 +1435,17 @@ class BinaryContext {
14351435
bool PrintRelocations = false,
14361436
StringRef Endl = "\n") const;
14371437

1438+
/// Print data when embedded in the instruction stream keeping the format
1439+
/// similar to printInstruction().
1440+
void printData(raw_ostream &OS, ArrayRef<uint8_t> Data,
1441+
uint64_t Offset) const;
1442+
1443+
/// Extract data from the binary corresponding to [Address, Address + Size)
1444+
/// range. Return an empty ArrayRef if the address range does not belong to
1445+
/// any section in the binary, crosses a section boundary, or falls into a
1446+
/// virtual section.
1447+
ArrayRef<uint8_t> extractData(uint64_t Address, uint64_t Size) const;
1448+
14381449
/// Print a range of instructions.
14391450
template <typename Itr>
14401451
uint64_t

bolt/include/bolt/Core/BinaryFunction.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2060,6 +2060,11 @@ class BinaryFunction {
20602060
return Islands ? Islands->getAlignment() : 1;
20612061
}
20622062

2063+
/// If there is a constant island in the range [StartOffset, EndOffset),
2064+
/// return its address.
2065+
std::optional<uint64_t> getIslandInRange(uint64_t StartOffset,
2066+
uint64_t EndOffset) const;
2067+
20632068
uint64_t
20642069
estimateConstantIslandSize(const BinaryFunction *OnBehalfOf = nullptr) const {
20652070
if (!Islands)

bolt/lib/Core/BinaryContext.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1942,6 +1942,43 @@ static void printDebugInfo(raw_ostream &OS, const MCInst &Instruction,
19421942
OS << " discriminator:" << Row.Discriminator;
19431943
}
19441944

1945+
ArrayRef<uint8_t> BinaryContext::extractData(uint64_t Address,
1946+
uint64_t Size) const {
1947+
ArrayRef<uint8_t> Res;
1948+
1949+
const ErrorOr<const BinarySection &> Section = getSectionForAddress(Address);
1950+
if (!Section || Section->isVirtual())
1951+
return Res;
1952+
1953+
if (!Section->containsRange(Address, Size))
1954+
return Res;
1955+
1956+
auto *Bytes =
1957+
reinterpret_cast<const uint8_t *>(Section->getContents().data());
1958+
return ArrayRef<uint8_t>(Bytes + Address - Section->getAddress(), Size);
1959+
}
1960+
1961+
void BinaryContext::printData(raw_ostream &OS, ArrayRef<uint8_t> Data,
1962+
uint64_t Offset) const {
1963+
DataExtractor DE(Data, AsmInfo->isLittleEndian(),
1964+
AsmInfo->getCodePointerSize());
1965+
uint64_t DataOffset = 0;
1966+
while (DataOffset + 4 <= Data.size()) {
1967+
OS << format(" %08" PRIx64 ": \t.word\t0x", Offset + DataOffset);
1968+
const auto Word = DE.getUnsigned(&DataOffset, 4);
1969+
OS << Twine::utohexstr(Word) << '\n';
1970+
}
1971+
if (DataOffset + 2 <= Data.size()) {
1972+
OS << format(" %08" PRIx64 ": \t.short\t0x", Offset + DataOffset);
1973+
const auto Short = DE.getUnsigned(&DataOffset, 2);
1974+
OS << Twine::utohexstr(Short) << '\n';
1975+
}
1976+
if (DataOffset + 1 == Data.size()) {
1977+
OS << format(" %08" PRIx64 ": \t.byte\t0x%x\n", Offset + DataOffset,
1978+
Data[DataOffset]);
1979+
}
1980+
}
1981+
19451982
void BinaryContext::printInstruction(raw_ostream &OS, const MCInst &Instruction,
19461983
uint64_t Offset,
19471984
const BinaryFunction *Function,

bolt/lib/Core/BinaryFunction.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,11 +491,27 @@ void BinaryFunction::print(raw_ostream &OS, std::string Annotation) {
491491
// Offset of the instruction in function.
492492
uint64_t Offset = 0;
493493

494+
auto printConstantIslandInRange = [&](uint64_t Start, uint64_t End) {
495+
assert(Start <= End && "Invalid range");
496+
std::optional<uint64_t> IslandOffset = getIslandInRange(Start, End);
497+
498+
if (!IslandOffset)
499+
return;
500+
501+
const size_t IslandSize = getSizeOfDataInCodeAt(*IslandOffset);
502+
BC.printData(OS, BC.extractData(getAddress() + *IslandOffset, IslandSize),
503+
*IslandOffset);
504+
};
505+
494506
if (BasicBlocks.empty() && !Instructions.empty()) {
495507
// Print before CFG was built.
508+
uint64_t PrevOffset = 0;
496509
for (const std::pair<const uint32_t, MCInst> &II : Instructions) {
497510
Offset = II.first;
498511

512+
// Print any constant islands inbeetween the instructions.
513+
printConstantIslandInRange(PrevOffset, Offset);
514+
499515
// Print label if exists at this offset.
500516
auto LI = Labels.find(Offset);
501517
if (LI != Labels.end()) {
@@ -506,7 +522,12 @@ void BinaryFunction::print(raw_ostream &OS, std::string Annotation) {
506522
}
507523

508524
BC.printInstruction(OS, II.second, Offset, this);
525+
526+
PrevOffset = Offset;
509527
}
528+
529+
// Print any data at the end of the function.
530+
printConstantIslandInRange(PrevOffset, getMaxSize());
510531
}
511532

512533
StringRef SplitPointMsg = "";
@@ -1048,6 +1069,19 @@ size_t BinaryFunction::getSizeOfDataInCodeAt(uint64_t Offset) const {
10481069
return getSize() - Offset;
10491070
}
10501071

1072+
std::optional<uint64_t>
1073+
BinaryFunction::getIslandInRange(uint64_t StartOffset,
1074+
uint64_t EndOffset) const {
1075+
if (!Islands)
1076+
return std::nullopt;
1077+
1078+
auto Iter = llvm::lower_bound(Islands->DataOffsets, StartOffset);
1079+
if (Iter != Islands->DataOffsets.end() && *Iter < EndOffset)
1080+
return *Iter;
1081+
1082+
return std::nullopt;
1083+
}
1084+
10511085
bool BinaryFunction::isZeroPaddingAt(uint64_t Offset) const {
10521086
ArrayRef<uint8_t> FunctionData = *getData();
10531087
uint64_t EndOfCode = getSize();

bolt/test/AArch64/data-in-code.s

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
## Check that llvm-bolt prints data embedded in code.
2+
3+
# RUN: llvm-mc -filetype=obj -triple aarch64-unknown-unknown %s -o %t.o
4+
# RUN: %clang %cflags -fno-PIC -no-pie %t.o -o %t.exe -nostdlib \
5+
# RUN: -fuse-ld=lld -Wl,-q
6+
7+
## Check disassembly of BOLT input.
8+
# RUN: llvm-objdump %t.exe -d | FileCheck %s
9+
10+
# RUN: llvm-bolt %t.exe -o %t.bolt --print-disasm | FileCheck %s
11+
12+
.text
13+
.balign 4
14+
15+
.global _start
16+
.type _start, %function
17+
_start:
18+
mov x0, #0x0
19+
.word 0x4f82e010
20+
ret
21+
.byte 0x0, 0xff, 0x42
22+
# CHECK-LABEL: _start
23+
# CHECK: mov x0, #0x0
24+
# CHECK-NEXT: .word 0x4f82e010
25+
# CHECK-NEXT: ret
26+
# CHECK-NEXT: .short 0xff00
27+
# CHECK-NEXT: .byte 0x42
28+
.size _start, .-_start
29+
30+
## Force relocation mode.
31+
.reloc 0, R_AARCH64_NONE

bolt/test/AArch64/exceptions-plt.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
// REQUIRES: system-linux
44

5-
// RUN: %clangxx %cxxflags -O1 -Wl,-q,-znow %s -o %t.exe
5+
// RUN: %clang %cflags -fpic -shared -xc /dev/null -o %t.so
6+
// Link against a DSO to ensure PLT entries.
7+
// RUN: %clangxx %cxxflags -O1 -Wl,-q,-znow %s %t.so -o %t.exe
68
// RUN: llvm-bolt %t.exe -o %t.bolt.exe --plt=all --print-only=.*main.* \
79
// RUN: --print-finalized 2>&1 | FileCheck %s
810

bolt/test/AArch64/plt-call.test

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Verify that PLTCall optimization works.
22

3-
RUN: %clang %cflags %p/../Inputs/plt-tailcall.c \
3+
RUN: %clang %cflags -fpic -shared -xc /dev/null -o %t.so
4+
// Link against a DSO to ensure PLT entries.
5+
RUN: %clang %cflags %p/../Inputs/plt-tailcall.c %t.so \
46
RUN: -o %t -Wl,-q
57
RUN: llvm-bolt %t -o %t.bolt --plt=all --print-plt --print-only=foo | FileCheck %s
68

bolt/test/X86/callcont-fallthru.s

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
## Ensures that a call continuation fallthrough count is set when using
22
## pre-aggregated perf data.
33

4-
# RUN: %clangxx %cxxflags %s -o %t -Wl,-q -nostdlib
4+
# RUN: %clang %cflags -fpic -shared -xc /dev/null -o %t.so
5+
## Link against a DSO to ensure PLT entries.
6+
# RUN: %clangxx %cxxflags %s %t.so -o %t -Wl,-q -nostdlib
57
# RUN: link_fdata %s %t %t.pa1 PREAGG
68
# RUN: link_fdata %s %t %t.pa2 PREAGG2
79
# RUN: link_fdata %s %t %t.pa3 PREAGG3

0 commit comments

Comments
 (0)