Skip to content

Commit a446bad

Browse files
committed
Merge branch 'users/meinersbur/flang_runtime_FLANG_INCLUDE_RUNTIME' into users/meinersbur/flang_runtime_flang_rt
2 parents b2a6556 + d35bea0 commit a446bad

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

bolt/test/X86/cfi-instrs-reordered.s

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

44
# RUN: llvm-mc -filetype=obj -triple x86_64-unknown-unknown %s -o %t.o
55
# RUN: llvm-strip --strip-unneeded %t.o
6-
# RUN: %clangxx %cflags %t.o -o %t.exe
6+
# RUN: %clang %cflags -fpic -shared -xc /dev/null -o %t.so
7+
## Link against a DSO to ensure PLT entries.
8+
# RUN: %clangxx %cflags %t.o %t.so -o %t.exe
79
# RUN: llvm-bolt %t.exe -o %t --reorder-blocks=cache --print-after-lowering \
810
# RUN: --print-only=_Z10SolveCubicddddPiPd 2>&1 | FileCheck %s
911
#

bolt/test/X86/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/runtime/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
79
// RUN: %t.bolt.exe
810

bolt/test/runtime/plt-lld.test

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
// This test checks that the pointers to PLT are properly updated.
2-
// The test is using lld linker.
2+
// The test uses lld and links against a DSO to ensure PLT entries.
3+
RUN: %clang %cflags -fpic -shared -xc /dev/null -o %t.so
34

45
// Non-PIE:
5-
RUN: %clang %cflags -no-pie %p/../Inputs/plt.c -fuse-ld=lld \
6+
RUN: %clang %cflags -no-pie %p/../Inputs/plt.c %t.so -fuse-ld=lld \
67
RUN: -o %t.lld.exe -Wl,-q
78
RUN: llvm-bolt %t.lld.exe -o %t.lld.bolt.exe --use-old-text=0 --lite=0
89
RUN: %t.lld.bolt.exe | FileCheck %s
910

1011
// PIE:
11-
RUN: %clang %cflags -fPIC -pie %p/../Inputs/plt.c -fuse-ld=lld \
12+
RUN: %clang %cflags -fPIC -pie %p/../Inputs/plt.c %t.so -fuse-ld=lld \
1213
RUN: -o %t.lld.pie.exe -Wl,-q
1314
RUN: llvm-bolt %t.lld.pie.exe -o %t.lld.bolt.pie.exe --use-old-text=0 --lite=0
1415
RUN: %t.lld.bolt.pie.exe | FileCheck %s

clang-tools-extra/clang-doc/HTMLGenerator.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -964,7 +964,7 @@ HTMLGenerator::generateDocs(StringRef RootDir,
964964
for (const auto &Group : FileToInfos) {
965965
std::error_code FileErr;
966966
llvm::raw_fd_ostream InfoOS(Group.getKey(), FileErr,
967-
llvm::sys::fs::OF_None);
967+
llvm::sys::fs::OF_Text);
968968
if (FileErr) {
969969
return llvm::createStringError(FileErr, "Error opening file '%s'",
970970
Group.getKey().str().c_str());
@@ -1047,7 +1047,7 @@ static llvm::Error serializeIndex(ClangDocContext &CDCtx) {
10471047
llvm::SmallString<128> FilePath;
10481048
llvm::sys::path::native(CDCtx.OutDirectory, FilePath);
10491049
llvm::sys::path::append(FilePath, "index_json.js");
1050-
llvm::raw_fd_ostream OS(FilePath, FileErr, llvm::sys::fs::OF_None);
1050+
llvm::raw_fd_ostream OS(FilePath, FileErr, llvm::sys::fs::OF_Text);
10511051
if (FileErr != OK) {
10521052
return llvm::createStringError(llvm::inconvertibleErrorCode(),
10531053
"error creating index file: " +
@@ -1108,7 +1108,7 @@ static llvm::Error genIndex(const ClangDocContext &CDCtx) {
11081108
llvm::SmallString<128> IndexPath;
11091109
llvm::sys::path::native(CDCtx.OutDirectory, IndexPath);
11101110
llvm::sys::path::append(IndexPath, "index.html");
1111-
llvm::raw_fd_ostream IndexOS(IndexPath, FileErr, llvm::sys::fs::OF_None);
1111+
llvm::raw_fd_ostream IndexOS(IndexPath, FileErr, llvm::sys::fs::OF_Text);
11121112
if (FileErr != OK) {
11131113
return llvm::createStringError(llvm::inconvertibleErrorCode(),
11141114
"error creating main index: " +

clang-tools-extra/clang-doc/MDGenerator.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ static llvm::Error serializeIndex(ClangDocContext &CDCtx) {
300300
llvm::SmallString<128> FilePath;
301301
llvm::sys::path::native(CDCtx.OutDirectory, FilePath);
302302
llvm::sys::path::append(FilePath, "all_files.md");
303-
llvm::raw_fd_ostream OS(FilePath, FileErr, llvm::sys::fs::OF_None);
303+
llvm::raw_fd_ostream OS(FilePath, FileErr, llvm::sys::fs::OF_Text);
304304
if (FileErr)
305305
return llvm::createStringError(llvm::inconvertibleErrorCode(),
306306
"error creating index file: " +
@@ -323,7 +323,7 @@ static llvm::Error genIndex(ClangDocContext &CDCtx) {
323323
llvm::SmallString<128> FilePath;
324324
llvm::sys::path::native(CDCtx.OutDirectory, FilePath);
325325
llvm::sys::path::append(FilePath, "index.md");
326-
llvm::raw_fd_ostream OS(FilePath, FileErr, llvm::sys::fs::OF_None);
326+
llvm::raw_fd_ostream OS(FilePath, FileErr, llvm::sys::fs::OF_Text);
327327
if (FileErr)
328328
return llvm::createStringError(llvm::inconvertibleErrorCode(),
329329
"error creating index file: " +
@@ -407,7 +407,7 @@ MDGenerator::generateDocs(StringRef RootDir,
407407
for (const auto &Group : FileToInfos) {
408408
std::error_code FileErr;
409409
llvm::raw_fd_ostream InfoOS(Group.getKey(), FileErr,
410-
llvm::sys::fs::OF_None);
410+
llvm::sys::fs::OF_Text);
411411
if (FileErr) {
412412
return llvm::createStringError(FileErr, "Error opening file '%s'",
413413
Group.getKey().str().c_str());

clang-tools-extra/clang-doc/YAMLGenerator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ YAMLGenerator::generateDocs(StringRef RootDir,
347347
}
348348

349349
std::error_code FileErr;
350-
llvm::raw_fd_ostream InfoOS(Path, FileErr, llvm::sys::fs::OF_None);
350+
llvm::raw_fd_ostream InfoOS(Path, FileErr, llvm::sys::fs::OF_Text);
351351
if (FileErr) {
352352
return llvm::createStringError(FileErr, "Error opening file '%s'",
353353
Path.c_str());

clang-tools-extra/clang-include-fixer/FuzzySymbolIndex.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ FuzzySymbolIndex::queryRegexp(const std::vector<std::string> &Tokens) {
131131

132132
llvm::Expected<std::unique_ptr<FuzzySymbolIndex>>
133133
FuzzySymbolIndex::createFromYAML(StringRef FilePath) {
134-
auto Buffer = llvm::MemoryBuffer::getFile(FilePath);
134+
auto Buffer = llvm::MemoryBuffer::getFile(FilePath, /*IsText=*/true);
135135
if (!Buffer)
136136
return llvm::errorCodeToError(Buffer.getError());
137137
return std::make_unique<MemSymbolIndex>(

clang-tools-extra/clang-include-fixer/YamlSymbolIndex.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ namespace include_fixer {
2222

2323
llvm::ErrorOr<std::unique_ptr<YamlSymbolIndex>>
2424
YamlSymbolIndex::createFromFile(llvm::StringRef FilePath) {
25-
auto Buffer = llvm::MemoryBuffer::getFile(FilePath);
25+
auto Buffer = llvm::MemoryBuffer::getFile(FilePath, /*IsText=*/true);
2626
if (!Buffer)
2727
return Buffer.getError();
2828

0 commit comments

Comments
 (0)