Skip to content

Commit ee6d737

Browse files
SC llvm teamSC llvm team
SC llvm team
authored and
SC llvm team
committed
Merged main:ca28fcc6fce5 into amd-gfx:09c430c738aa
Local branch amd-gfx 09c430c Merged main:cbe583b0bd8d into amd-gfx:2cf84b60928b Remote branch main ca28fcc Revert "[nfc][Driver] Remove {{(.exe)?}} from sanitizer test (llvm#121160)"
2 parents 09c430c + ca28fcc commit ee6d737

File tree

37 files changed

+601
-194
lines changed

37 files changed

+601
-194
lines changed

bolt/docs/CommandLineArgumentReference.md

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -931,15 +931,6 @@
931931

932932
Remove redundant Address-Size override prefix
933933

934-
### BOLT options in relocation mode:
935-
936-
- `--align-macro-fusion=<value>`
937-
938-
Fix instruction alignment for macro-fusion (x86 relocation mode)
939-
- `none`: do not insert alignment no-ops for macro-fusion
940-
- `hot`: only insert alignment no-ops on hot execution paths (default)
941-
- `all`: always align instructions to allow macro-fusion
942-
943934
### BOLT instrumentation options:
944935

945936
`llvm-bolt <executable> -instrument [-o outputfile] <instrumented-executable>`

bolt/include/bolt/Core/BinaryData.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,11 @@ class BinaryData {
169169
return Parent && (Parent == BD || Parent->isAncestorOf(BD));
170170
}
171171

172+
void updateSize(uint64_t N) {
173+
if (N > Size)
174+
Size = N;
175+
}
176+
172177
void setIsMoveable(bool Flag) { IsMoveable = Flag; }
173178
void setSection(BinarySection &NewSection);
174179
void setOutputSection(BinarySection &NewSection) {

bolt/lib/Core/BinaryContext.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,6 +1076,7 @@ MCSymbol *BinaryContext::registerNameAtAddress(StringRef Name, uint64_t Address,
10761076
BD = GAI->second;
10771077
if (!BD->hasName(Name)) {
10781078
GlobalSymbols[Name] = BD;
1079+
BD->updateSize(Size);
10791080
BD->Symbols.push_back(Symbol);
10801081
}
10811082
}

bolt/lib/Rewrite/LinuxKernelRewriter.cpp

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#include "llvm/Support/CommandLine.h"
2222
#include "llvm/Support/Debug.h"
2323
#include "llvm/Support/Errc.h"
24+
#include "llvm/Support/ErrorOr.h"
25+
#include <regex>
2426

2527
#define DEBUG_TYPE "bolt-linux"
2628

@@ -89,6 +91,34 @@ static cl::opt<bool>
8991

9092
} // namespace opts
9193

94+
/// Linux kernel version
95+
struct LKVersion {
96+
LKVersion() {}
97+
LKVersion(unsigned Major, unsigned Minor, unsigned Rev)
98+
: Major(Major), Minor(Minor), Rev(Rev) {}
99+
100+
bool operator<(const LKVersion &Other) const {
101+
return std::make_tuple(Major, Minor, Rev) <
102+
std::make_tuple(Other.Major, Other.Minor, Other.Rev);
103+
}
104+
105+
bool operator>(const LKVersion &Other) const { return Other < *this; }
106+
107+
bool operator<=(const LKVersion &Other) const { return !(*this > Other); }
108+
109+
bool operator>=(const LKVersion &Other) const { return !(*this < Other); }
110+
111+
bool operator==(const LKVersion &Other) const {
112+
return Major == Other.Major && Minor == Other.Minor && Rev == Other.Rev;
113+
}
114+
115+
bool operator!=(const LKVersion &Other) const { return !(*this == Other); }
116+
117+
unsigned Major{0};
118+
unsigned Minor{0};
119+
unsigned Rev{0};
120+
};
121+
92122
/// Linux Kernel supports stack unwinding using ORC (oops rewind capability).
93123
/// ORC state at every IP can be described by the following data structure.
94124
struct ORCState {
@@ -148,6 +178,8 @@ class AddressExtractor : public DataExtractor {
148178
};
149179

150180
class LinuxKernelRewriter final : public MetadataRewriter {
181+
LKVersion LinuxKernelVersion;
182+
151183
/// Information required for updating metadata referencing an instruction.
152184
struct InstructionFixup {
153185
BinarySection &Section; // Section referencing the instruction.
@@ -249,6 +281,8 @@ class LinuxKernelRewriter final : public MetadataRewriter {
249281
ErrorOr<BinarySection &> PCIFixupSection = std::errc::bad_address;
250282
static constexpr size_t PCI_FIXUP_ENTRY_SIZE = 16;
251283

284+
Error detectLinuxKernelVersion();
285+
252286
/// Process linux kernel special sections and their relocations.
253287
void processLKSections();
254288

@@ -314,6 +348,9 @@ class LinuxKernelRewriter final : public MetadataRewriter {
314348
: MetadataRewriter("linux-kernel-rewriter", BC) {}
315349

316350
Error preCFGInitializer() override {
351+
if (Error E = detectLinuxKernelVersion())
352+
return E;
353+
317354
processLKSections();
318355

319356
if (Error E = processSMPLocks())
@@ -394,6 +431,28 @@ class LinuxKernelRewriter final : public MetadataRewriter {
394431
}
395432
};
396433

434+
Error LinuxKernelRewriter::detectLinuxKernelVersion() {
435+
if (BinaryData *BD = BC.getBinaryDataByName("linux_banner")) {
436+
const BinarySection &Section = BD->getSection();
437+
const std::string S =
438+
Section.getContents().substr(BD->getOffset(), BD->getSize()).str();
439+
440+
const std::regex Re(R"---(Linux version ((\d+)\.(\d+)(\.(\d+))?))---");
441+
std::smatch Match;
442+
if (std::regex_search(S, Match, Re)) {
443+
const unsigned Major = std::stoi(Match[2].str());
444+
const unsigned Minor = std::stoi(Match[3].str());
445+
const unsigned Rev = Match[5].matched ? std::stoi(Match[5].str()) : 0;
446+
LinuxKernelVersion = LKVersion(Major, Minor, Rev);
447+
BC.outs() << "BOLT-INFO: Linux kernel version is " << Match[1].str()
448+
<< "\n";
449+
return Error::success();
450+
}
451+
}
452+
return createStringError(errc::executable_format_error,
453+
"Linux kernel version is unknown");
454+
}
455+
397456
void LinuxKernelRewriter::processLKSections() {
398457
processLKKSymtab();
399458
processLKKSymtab(true);

bolt/test/X86/linux-alt-instruction.s

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,15 @@ _start:
142142
.section .orc_unwind_ip
143143
.long .L0 + 2 - .
144144

145+
## Linux kernel version
146+
.rodata
147+
.align 16
148+
.globl linux_banner
149+
.type linux_banner, @object
150+
linux_banner:
151+
.string "Linux version 6.6.61\n"
152+
.size linux_banner, . - linux_banner
153+
145154
## Fake Linux Kernel sections.
146155
.section __ksymtab,"a",@progbits
147156
.section __ksymtab_gpl,"a",@progbits

bolt/test/X86/linux-bug-table.s

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,15 @@ _start:
5656
.long .L1 - . # instruction
5757
.org 2b + 12
5858

59+
## Linux kernel version
60+
.rodata
61+
.align 16
62+
.globl linux_banner
63+
.type linux_banner, @object
64+
linux_banner:
65+
.string "Linux version 6.6.61\n"
66+
.size linux_banner, . - linux_banner
67+
5968
## Fake Linux Kernel sections.
6069
.section __ksymtab,"a",@progbits
6170
.section __ksymtab_gpl,"a",@progbits

bolt/test/X86/linux-exceptions.s

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,15 @@ foo:
5959
.long .LF0 - . # fixup
6060
.long 0 # data
6161

62+
## Linux kernel version
63+
.rodata
64+
.align 16
65+
.globl linux_banner
66+
.type linux_banner, @object
67+
linux_banner:
68+
.string "Linux version 6.6.61\n"
69+
.size linux_banner, . - linux_banner
70+
6271
## Fake Linux Kernel sections.
6372
.section __ksymtab,"a",@progbits
6473
.section __ksymtab_gpl,"a",@progbits

bolt/test/X86/linux-orc.s

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,15 @@ bar:
157157
.section .orc_unwind_ip
158158
.long .L4 - .
159159

160+
## Linux kernel version
161+
.rodata
162+
.align 16
163+
.globl linux_banner
164+
.type linux_banner, @object
165+
linux_banner:
166+
.string "Linux version 6.6.61\n"
167+
.size linux_banner, . - linux_banner
168+
160169
## Fake Linux Kernel sections.
161170
.section __ksymtab,"a",@progbits
162171
.section __ksymtab_gpl,"a",@progbits

bolt/test/X86/linux-parainstructions.s

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,15 @@ _start:
4949
.byte 1 # type
5050
.byte 7 # length
5151

52+
## Linux kernel version
53+
.rodata
54+
.align 16
55+
.globl linux_banner
56+
.type linux_banner, @object
57+
linux_banner:
58+
.string "Linux version 6.6.61\n"
59+
.size linux_banner, . - linux_banner
60+
5261
## Fake Linux Kernel sections.
5362
.section __ksymtab,"a",@progbits
5463
.section __ksymtab_gpl,"a",@progbits

bolt/test/X86/linux-pci-fixup.s

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ _start:
3636
.long 0x0 # class shift
3737
.long .L0 - . # fixup
3838

39+
## Linux kernel version
40+
.rodata
41+
.align 16
42+
.globl linux_banner
43+
.type linux_banner, @object
44+
linux_banner:
45+
.string "Linux version 6.6.61\n"
46+
.size linux_banner, . - linux_banner
47+
3948
## Fake Linux Kernel sections.
4049
.section __ksymtab,"a",@progbits
4150
.section __ksymtab_gpl,"a",@progbits

bolt/test/X86/linux-smp-locks.s

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ _start:
3535
.long .L0 - .
3636
.long .L1 - .
3737

38+
## Linux kernel version
39+
.rodata
40+
.align 16
41+
.globl linux_banner
42+
.type linux_banner, @object
43+
linux_banner:
44+
.string "Linux version 6.6.61\n"
45+
.size linux_banner, . - linux_banner
46+
3847
## Fake Linux Kernel sections.
3948
.section __ksymtab,"a",@progbits
4049
.section __ksymtab_gpl,"a",@progbits

bolt/test/X86/linux-static-calls.s

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,15 @@ __start_static_call_sites:
5454
.type __stop_static_call_sites, %object
5555
__stop_static_call_sites:
5656

57+
## Linux kernel version
58+
.rodata
59+
.align 16
60+
.globl linux_banner
61+
.type linux_banner, @object
62+
linux_banner:
63+
.string "Linux version 6.6.61\n"
64+
.size linux_banner, . - linux_banner
65+
5766
## Fake Linux Kernel sections.
5867
.section __ksymtab,"a",@progbits
5968
.section __ksymtab_gpl,"a",@progbits

bolt/test/X86/linux-static-keys.s

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,15 @@ __stop___jump_table:
8585
fake_static_key:
8686
.quad 0
8787

88+
## Linux kernel version
89+
.rodata
90+
.align 16
91+
.globl linux_banner
92+
.type linux_banner, @object
93+
linux_banner:
94+
.string "Linux version 6.6.61\n"
95+
.size linux_banner, . - linux_banner
96+
8897
## Fake Linux Kernel sections.
8998
.section __ksymtab,"a",@progbits
9099
.section __ksymtab_gpl,"a",@progbits

bolt/test/X86/linux-version.S

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# REQUIRES: system-linux
2+
3+
## Check that BOLT correctly detects the Linux kernel version
4+
5+
# RUN: %clang -DA -target x86_64-unknown-unknown \
6+
# RUN: %cflags -nostdlib %s -o %t.exe \
7+
# RUN: -Wl,--image-base=0xffffffff80000000,--no-dynamic-linker,--no-eh-frame-hdr
8+
# RUN: llvm-bolt %t.exe -o %t.out 2>&1 | FileCheck --check-prefix=CHECK-A %s
9+
10+
# RUN: %clang -DB -target x86_64-unknown-unknown \
11+
# RUN: %cflags -nostdlib %s -o %t.exe \
12+
# RUN: -Wl,--image-base=0xffffffff80000000,--no-dynamic-linker,--no-eh-frame-hdr
13+
# RUN: llvm-bolt %t.exe -o %t.out 2>&1 | FileCheck --check-prefix=CHECK-B %s
14+
15+
# RUN: %clang -DC -target x86_64-unknown-unknown \
16+
# RUN: %cflags -nostdlib %s -o %t.exe \
17+
# RUN: -Wl,--image-base=0xffffffff80000000,--no-dynamic-linker,--no-eh-frame-hdr
18+
# RUN: llvm-bolt %t.exe -o %t.out 2>&1 | FileCheck --check-prefix=CHECK-C %s
19+
20+
.text
21+
.globl foo
22+
.type foo, %function
23+
foo:
24+
ret
25+
.size foo, .-foo
26+
27+
## Linux kernel version
28+
.rodata
29+
.align 16
30+
.globl linux_banner
31+
.type linux_banner, @object
32+
linux_banner:
33+
34+
#ifdef A
35+
.string "Linux version 6.6.61\n"
36+
#endif
37+
# CHECK-A: BOLT-INFO: Linux kernel version is 6.6.61
38+
39+
#ifdef B
40+
.string "Linux version 6.6.50-rc4\n"
41+
#endif
42+
# CHECK-B: BOLT-INFO: Linux kernel version is 6.6.50
43+
44+
#ifdef C
45+
.string "Linux version 6.6\n"
46+
#endif
47+
# CHECK-C: BOLT-INFO: Linux kernel version is 6.6
48+
49+
.size linux_banner, . - linux_banner
50+
51+
## Fake Linux Kernel sections.
52+
.section __ksymtab,"a",@progbits
53+
.section __ksymtab_gpl,"a",@progbits

clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,12 @@ Configuration files:
6161
globs can be specified as a list instead of a
6262
string.
6363
ExcludeHeaderFilterRegex - Same as '--exclude-header-filter'.
64-
ExtraArgs - Same as '--extra-args'.
65-
ExtraArgsBefore - Same as '--extra-args-before'.
64+
ExtraArgs - Same as '--extra-arg'.
65+
ExtraArgsBefore - Same as '--extra-arg-before'.
6666
FormatStyle - Same as '--format-style'.
6767
HeaderFileExtensions - File extensions to consider to determine if a
6868
given diagnostic is located in a header file.
69-
HeaderFilterRegex - Same as '--header-filter-regex'.
69+
HeaderFilterRegex - Same as '--header-filter'.
7070
ImplementationFileExtensions - File extensions to consider to determine if a
7171
given diagnostic is located in an
7272
implementation file.

clang-tools-extra/docs/clang-tidy/index.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,8 @@ An overview of all the command-line options:
293293
globs can be specified as a list instead of a
294294
string.
295295
ExcludeHeaderFilterRegex - Same as '--exclude-header-filter'.
296-
ExtraArgs - Same as '--extra-args'.
297-
ExtraArgsBefore - Same as '--extra-args-before'.
296+
ExtraArgs - Same as '--extra-arg'.
297+
ExtraArgsBefore - Same as '--extra-arg-before'.
298298
FormatStyle - Same as '--format-style'.
299299
HeaderFileExtensions - File extensions to consider to determine if a
300300
given diagnostic is located in a header file.

0 commit comments

Comments
 (0)