Skip to content

Commit 919919f

Browse files
committed
Merge branch 'users/meinersbur/flang_runtime_FortranSupport' into users/meinersbur/flang_runtime_Testing
2 parents 40b2f71 + 080f30c commit 919919f

File tree

722 files changed

+32118
-8956
lines changed

Some content is hidden

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

722 files changed

+32118
-8956
lines changed

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/docs/ClangFormatStyleOptions.rst

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3421,6 +3421,35 @@ the configuration (without a prefix: ``Auto``).
34213421

34223422

34233423

3424+
.. _BreakBeforeTemplateCloser:
3425+
3426+
**BreakBeforeTemplateCloser** (``Boolean``) :versionbadge:`clang-format 21` :ref:`<BreakBeforeTemplateCloser>`
3427+
If ``true``, break before a template closing bracket (``>``) when there is
3428+
a line break after the matching opening bracket (``<``).
3429+
3430+
.. code-block:: c++
3431+
3432+
true:
3433+
template <typename Foo, typename Bar>
3434+
3435+
template <typename Foo,
3436+
typename Bar>
3437+
3438+
template <
3439+
typename Foo,
3440+
typename Bar
3441+
>
3442+
3443+
false:
3444+
template <typename Foo, typename Bar>
3445+
3446+
template <typename Foo,
3447+
typename Bar>
3448+
3449+
template <
3450+
typename Foo,
3451+
typename Bar>
3452+
34243453
.. _BreakBeforeTernaryOperators:
34253454

34263455
**BreakBeforeTernaryOperators** (``Boolean``) :versionbadge:`clang-format 3.7` :ref:`<BreakBeforeTernaryOperators>`

clang/docs/ControlFlowIntegrity.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,15 @@ cross-DSO function address equality. These properties make KCFI easier to
336336
adopt in low-level software. KCFI is limited to checking only function
337337
pointers, and isn't compatible with executable-only memory.
338338

339+
``-fsanitize-kcfi-arity``
340+
-----------------------------
341+
342+
For supported targets, this feature extends kCFI by telling the compiler to
343+
record information about each indirect-callable function's arity (i.e., the
344+
number of arguments passed in registers) into the binary. Some kernel CFI
345+
techniques, such as FineIBT, may be able to use this information to provide
346+
enhanced security.
347+
339348
Member Function Pointer Call Checking
340349
=====================================
341350

clang/docs/LanguageExtensions.rst

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1803,10 +1803,6 @@ The following type trait primitives are supported by Clang. Those traits marked
18031803
* ``__is_pointer_interconvertible_base_of`` (C++, GNU, Microsoft)
18041804
* ``__is_polymorphic`` (C++, GNU, Microsoft, Embarcadero)
18051805
* ``__is_reference`` (C++, Embarcadero)
1806-
* ``__is_referenceable`` (C++, GNU, Microsoft, Embarcadero):
1807-
Returns true if a type is referenceable, and false otherwise. A referenceable
1808-
type is a type that's either an object type, a reference type, or an unqualified
1809-
function type. This trait is deprecated and will be removed in Clang 21.
18101806
* ``__is_rvalue_reference`` (C++, Embarcadero)
18111807
* ``__is_same`` (C++, Embarcadero)
18121808
* ``__is_same_as`` (GCC): Synonym for ``__is_same``.

clang/docs/ReleaseNotes.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ C/C++ Language Potentially Breaking Changes
4242
C++ Specific Potentially Breaking Changes
4343
-----------------------------------------
4444

45+
- The type trait builtin ``__is_referenceable`` has been removed, since it has
46+
very few users and all the type traits that could benefit from it in the
47+
standard library already have their own bespoke builtins.
48+
4549
ABI Changes in This Version
4650
---------------------------
4751

@@ -112,6 +116,8 @@ Removed Compiler Flags
112116
Attribute Changes in Clang
113117
--------------------------
114118

119+
- The ``no_sanitize`` attribute now accepts both ``gnu`` and ``clang`` names.
120+
115121
Improvements to Clang's diagnostics
116122
-----------------------------------
117123

@@ -143,6 +149,8 @@ Bug Fixes to Attribute Support
143149
Bug Fixes to C++ Support
144150
^^^^^^^^^^^^^^^^^^^^^^^^
145151

152+
- Clang is now better at keeping track of friend function template instance contexts. (#GH55509)
153+
146154
Bug Fixes to AST Handling
147155
^^^^^^^^^^^^^^^^^^^^^^^^^
148156

@@ -227,6 +235,8 @@ AST Matchers
227235
clang-format
228236
------------
229237

238+
- Adds ``BreakBeforeTemplateCloser`` option.
239+
230240
libclang
231241
--------
232242

@@ -239,6 +249,11 @@ Static Analyzer
239249
New features
240250
^^^^^^^^^^^^
241251

252+
A new flag - `-static-libclosure` was introduced to support statically linking
253+
the runtime for the Blocks extension on Windows. This flag currently only
254+
changes the code generation, and even then, only on Windows. This does not
255+
impact the linker behaviour like the other `-static-*` flags.
256+
242257
Crash and bug fixes
243258
^^^^^^^^^^^^^^^^^^^
244259

clang/docs/UsersManual.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2223,6 +2223,12 @@ are listed below.
22232223

22242224
This option is currently experimental.
22252225

2226+
.. option:: -fsanitize-kcfi-arity
2227+
2228+
Extends kernel indirect call forward-edge control flow integrity with
2229+
additional function arity information (for supported targets). See
2230+
:doc:`ControlFlowIntegrity` for more details.
2231+
22262232
.. option:: -fstrict-vtable-pointers
22272233

22282234
Enable optimizations based on the strict rules for overwriting polymorphic

clang/docs/analyzer/developer-docs.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ Contents:
1111
developer-docs/InitializerLists
1212
developer-docs/nullability
1313
developer-docs/RegionStore
14+
developer-docs/PerformanceInvestigation

0 commit comments

Comments
 (0)