Skip to content

Commit 5c22358

Browse files
SC llvm teamSC llvm team
SC llvm team
authored and
SC llvm team
committed
Merged main:918829959f96 into amd-gfx:7ce30e5343ec
Local branch amd-gfx 7ce30e5 Merged main:941c75a53036 into amd-gfx:ff5630892f5f563d Remote branch main 9188299 [clang] Subscribe to DR changes
2 parents 7ce30e5 + 9188299 commit 5c22358

File tree

253 files changed

+12284
-4458
lines changed

Some content is hidden

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

253 files changed

+12284
-4458
lines changed

.github/CODEOWNERS

+4
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,7 @@
2626
/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp @nikic
2727
/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp @nikic
2828
/llvm/lib/Transforms/InstCombine/ @nikic
29+
30+
/clang/test/CXX/drs/ @Endilll
31+
/clang/www/cxx_dr_status.html @Endilll
32+
/clang/www/make_cxx_dr_status @Endilll

bolt/lib/Core/BinaryFunction.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -1761,7 +1761,8 @@ bool BinaryFunction::postProcessIndirectBranches(
17611761
uint64_t LastJT = 0;
17621762
uint16_t LastJTIndexReg = BC.MIB->getNoRegister();
17631763
for (BinaryBasicBlock &BB : blocks()) {
1764-
for (MCInst &Instr : BB) {
1764+
for (BinaryBasicBlock::iterator II = BB.begin(); II != BB.end(); ++II) {
1765+
MCInst &Instr = *II;
17651766
if (!BC.MIB->isIndirectBranch(Instr))
17661767
continue;
17671768

@@ -1789,7 +1790,7 @@ bool BinaryFunction::postProcessIndirectBranches(
17891790
const MCExpr *DispExpr;
17901791
MCInst *PCRelBaseInstr;
17911792
IndirectBranchType Type = BC.MIB->analyzeIndirectBranch(
1792-
Instr, BB.begin(), BB.end(), PtrSize, MemLocInstr, BaseRegNum,
1793+
Instr, BB.begin(), II, PtrSize, MemLocInstr, BaseRegNum,
17931794
IndexRegNum, DispValue, DispExpr, PCRelBaseInstr);
17941795
if (Type != IndirectBranchType::UNKNOWN || MemLocInstr != nullptr)
17951796
continue;

bolt/lib/Core/Relocation.cpp

+26
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@
2020
using namespace llvm;
2121
using namespace bolt;
2222

23+
namespace ELFReserved {
24+
enum {
25+
R_RISCV_TPREL_I = 49,
26+
R_RISCV_TPREL_S = 50,
27+
};
28+
} // namespace ELFReserved
29+
2330
Triple::ArchType Relocation::Arch;
2431

2532
static bool isSupportedX86(uint64_t Type) {
@@ -111,6 +118,13 @@ static bool isSupportedRISCV(uint64_t Type) {
111118
case ELF::R_RISCV_LO12_I:
112119
case ELF::R_RISCV_LO12_S:
113120
case ELF::R_RISCV_64:
121+
case ELF::R_RISCV_TLS_GOT_HI20:
122+
case ELF::R_RISCV_TPREL_HI20:
123+
case ELF::R_RISCV_TPREL_ADD:
124+
case ELF::R_RISCV_TPREL_LO12_I:
125+
case ELF::R_RISCV_TPREL_LO12_S:
126+
case ELFReserved::R_RISCV_TPREL_I:
127+
case ELFReserved::R_RISCV_TPREL_S:
114128
return true;
115129
}
116130
}
@@ -214,6 +228,7 @@ static size_t getSizeForTypeRISCV(uint64_t Type) {
214228
return 4;
215229
case ELF::R_RISCV_64:
216230
case ELF::R_RISCV_GOT_HI20:
231+
case ELF::R_RISCV_TLS_GOT_HI20:
217232
// See extractValueRISCV for why this is necessary.
218233
return 8;
219234
}
@@ -532,6 +547,7 @@ static uint64_t extractValueRISCV(uint64_t Type, uint64_t Contents,
532547
case ELF::R_RISCV_BRANCH:
533548
return extractBImmRISCV(Contents);
534549
case ELF::R_RISCV_GOT_HI20:
550+
case ELF::R_RISCV_TLS_GOT_HI20:
535551
// We need to know the exact address of the GOT entry so we extract the
536552
// value from both the AUIPC and L[D|W]. We cannot rely on the symbol in the
537553
// relocation for this since it simply refers to the object that is stored
@@ -600,6 +616,7 @@ static bool isGOTRISCV(uint64_t Type) {
600616
default:
601617
return false;
602618
case ELF::R_RISCV_GOT_HI20:
619+
case ELF::R_RISCV_TLS_GOT_HI20:
603620
return true;
604621
}
605622
}
@@ -636,6 +653,14 @@ static bool isTLSRISCV(uint64_t Type) {
636653
switch (Type) {
637654
default:
638655
return false;
656+
case ELF::R_RISCV_TLS_GOT_HI20:
657+
case ELF::R_RISCV_TPREL_HI20:
658+
case ELF::R_RISCV_TPREL_ADD:
659+
case ELF::R_RISCV_TPREL_LO12_I:
660+
case ELF::R_RISCV_TPREL_LO12_S:
661+
case ELFReserved::R_RISCV_TPREL_I:
662+
case ELFReserved::R_RISCV_TPREL_S:
663+
return true;
639664
}
640665
}
641666

@@ -733,6 +758,7 @@ static bool isPCRelativeRISCV(uint64_t Type) {
733758
case ELF::R_RISCV_RVC_JUMP:
734759
case ELF::R_RISCV_RVC_BRANCH:
735760
case ELF::R_RISCV_32_PCREL:
761+
case ELF::R_RISCV_TLS_GOT_HI20:
736762
return true;
737763
}
738764
}

bolt/lib/Passes/FixRISCVCallsPass.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,12 @@ void FixRISCVCallsPass::runOnFunction(BinaryFunction &BF) {
4343

4444
MCInst OldCall = *NextII;
4545
auto L = BC.scopeLock();
46-
MIB->createCall(*II, Target, Ctx);
46+
47+
if (MIB->isTailCall(*NextII))
48+
MIB->createTailCall(*II, Target, Ctx);
49+
else
50+
MIB->createCall(*II, Target, Ctx);
51+
4752
MIB->moveAnnotations(std::move(OldCall), *II);
4853

4954
// The original offset was set on the jalr of the auipc+jalr pair. Since

bolt/lib/Rewrite/RewriteInstance.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -2334,7 +2334,8 @@ void RewriteInstance::handleRelocation(const SectionRef &RelocatedSection,
23342334
if (BC->isX86())
23352335
return;
23362336

2337-
// The non-got related TLS relocations on AArch64 also could be skipped.
2337+
// The non-got related TLS relocations on AArch64 and RISC-V also could be
2338+
// skipped.
23382339
if (!Relocation::isGOT(RType))
23392340
return;
23402341
}

bolt/lib/Target/RISCV/RISCVMCPlusBuilder.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class RISCVMCPlusBuilder : public MCPlusBuilder {
4646
case ELF::R_RISCV_HI20:
4747
case ELF::R_RISCV_LO12_I:
4848
case ELF::R_RISCV_LO12_S:
49+
case ELF::R_RISCV_TLS_GOT_HI20:
4950
return true;
5051
default:
5152
llvm_unreachable("Unexpected RISCV relocation type in code");
@@ -86,6 +87,7 @@ class RISCVMCPlusBuilder : public MCPlusBuilder {
8687
return false;
8788
case RISCV::JALR:
8889
case RISCV::C_JALR:
90+
case RISCV::C_JR:
8991
return true;
9092
}
9193
}
@@ -157,6 +159,17 @@ class RISCVMCPlusBuilder : public MCPlusBuilder {
157159
DispValue = 0;
158160
DispExpr = nullptr;
159161
PCRelBaseOut = nullptr;
162+
163+
// Check for the following long tail call sequence:
164+
// 1: auipc xi, %pcrel_hi(sym)
165+
// jalr zero, %pcrel_lo(1b)(xi)
166+
if (Instruction.getOpcode() == RISCV::JALR && Begin != End) {
167+
MCInst &PrevInst = *std::prev(End);
168+
if (isRISCVCall(PrevInst, Instruction) &&
169+
Instruction.getOperand(0).getReg() == RISCV::X0)
170+
return IndirectBranchType::POSSIBLE_TAIL_CALL;
171+
}
172+
160173
return IndirectBranchType::UNKNOWN;
161174
}
162175

@@ -396,6 +409,7 @@ class RISCVMCPlusBuilder : public MCPlusBuilder {
396409
default:
397410
return Expr;
398411
case ELF::R_RISCV_GOT_HI20:
412+
case ELF::R_RISCV_TLS_GOT_HI20:
399413
// The GOT is reused so no need to create GOT relocations
400414
case ELF::R_RISCV_PCREL_HI20:
401415
return RISCVMCExpr::create(Expr, RISCVMCExpr::VK_RISCV_PCREL_HI, Ctx);
+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
--- !ELF
2+
FileHeader:
3+
Class: ELFCLASS64
4+
Data: ELFDATA2LSB
5+
Type: ET_EXEC
6+
Machine: EM_RISCV
7+
Entry: 0x100B0
8+
ProgramHeaders:
9+
- Type: PT_LOAD
10+
Flags: [ PF_X, PF_R ]
11+
FirstSec: .text
12+
LastSec: .text
13+
VAddr: 0x10000
14+
Align: 0x1000
15+
Offset: 0x0
16+
- Type: PT_TLS
17+
Flags: [ PF_R ]
18+
FirstSec: .tbss
19+
LastSec: .tbss
20+
VAddr: 0x110C0
21+
Align: 0x8
22+
Offset: 0xc0
23+
Sections:
24+
- Name: .text
25+
Type: SHT_PROGBITS
26+
Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
27+
Address: 0x100B0
28+
AddressAlign: 0x4
29+
Content: '13000000832202002320520067800000'
30+
- Name: .tbss
31+
Type: SHT_NOBITS
32+
Flags: [ SHF_WRITE, SHF_ALLOC, SHF_TLS ]
33+
Address: 0x110C0
34+
AddressAlign: 0x8
35+
Size: 0x8
36+
- Name: .rela.text
37+
Type: SHT_RELA
38+
Flags: [ SHF_INFO_LINK ]
39+
Link: .symtab
40+
AddressAlign: 0x8
41+
Info: .text
42+
Relocations:
43+
- Offset: 0x100B4
44+
Type: R_RISCV_NONE
45+
- Offset: 0x100B4
46+
Type: R_RISCV_RELAX
47+
- Offset: 0x100B4
48+
Type: R_RISCV_NONE
49+
- Offset: 0x100B4
50+
Type: R_RISCV_RELAX
51+
- Offset: 0x100B4
52+
Symbol: i
53+
Type: 0x31
54+
- Offset: 0x100B4
55+
Type: R_RISCV_RELAX
56+
- Offset: 0x100B8
57+
Symbol: i
58+
Type: 0x32
59+
- Offset: 0x100B8
60+
Type: R_RISCV_RELAX
61+
- Type: SectionHeaderTable
62+
Sections:
63+
- Name: .text
64+
- Name: .rela.text
65+
- Name: .tbss
66+
- Name: .symtab
67+
- Name: .strtab
68+
- Name: .shstrtab
69+
Symbols:
70+
- Name: .text
71+
Type: STT_SECTION
72+
Section: .text
73+
Value: 0x100B0
74+
- Name: .tbss
75+
Type: STT_SECTION
76+
Section: .tbss
77+
Value: 0x110C0
78+
- Name: '__global_pointer$'
79+
Index: SHN_ABS
80+
Binding: STB_GLOBAL
81+
Value: 0x118C0
82+
- Name: i
83+
Type: STT_TLS
84+
Section: .tbss
85+
Binding: STB_GLOBAL
86+
Size: 0x8
87+
- Name: _start
88+
Section: .text
89+
Binding: STB_GLOBAL
90+
Value: 0x100B0
91+
Size: 0x10
92+
...

bolt/test/RISCV/call-annotations.s

+32-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// RUN: llvm-mc -triple riscv64 -filetype obj -o %t.o %s
55
// RUN: ld.lld --emit-relocs -o %t %t.o
66
// RUN: llvm-bolt --enable-bat --print-cfg --print-fix-riscv-calls \
7-
// RUN: --print-only=_start -o /dev/null %t | FileCheck %s
7+
// RUN: -o /dev/null %t | FileCheck %s
88

99
.text
1010
.global f
@@ -19,15 +19,46 @@ f:
1919
// CHECK-NEXT: jal ra, f # Offset: 8
2020
// CHECK-NEXT: jal zero, f # TAILCALL # Offset: 12
2121

22+
// CHECK-LABEL: Binary Function "long_tail" after building cfg {
23+
// CHECK: auipc t1, f
24+
// CHECK-NEXT: jalr zero, -24(t1) # TAILCALL # Offset: 8
25+
26+
// CHECK-LABEL: Binary Function "compressed_tail" after building cfg {
27+
// CHECK: jr a0 # TAILCALL # Offset: 0
28+
2229
// CHECK-LABEL: Binary Function "_start" after fix-riscv-calls {
2330
// CHECK: call f # Offset: 0
2431
// CHECK-NEXT: call f # Offset: 8
2532
// CHECK-NEXT: tail f # TAILCALL # Offset: 12
2633

34+
// CHECK-LABEL: Binary Function "long_tail" after fix-riscv-calls {
35+
// CHECK: tail f # TAILCALL # Offset: 4
36+
37+
// CHECK-LABEL: Binary Function "compressed_tail" after fix-riscv-calls {
38+
// CHECK: jr a0 # TAILCALL # Offset: 0
39+
2740
.globl _start
2841
.p2align 1
2942
_start:
3043
call f
3144
jal f
3245
jal zero, f
3346
.size _start, .-_start
47+
48+
.globl long_tail
49+
.p2align 1
50+
long_tail:
51+
// NOTE: BOLT assumes indirect calls in single-BB functions are tail calls
52+
// so artificially introduce a second BB to force RISC-V-specific analysis
53+
// to get triggered.
54+
beq a0, a1, 1f
55+
1:
56+
tail f
57+
.size long_tail, .-long_tail
58+
59+
.globl compressed_tail
60+
.p2align 1
61+
.option rvc
62+
compressed_tail:
63+
c.jr a0
64+
.size compressed_tail, .-compressed_tail

bolt/test/RISCV/reloc-tls.s

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// RUN: llvm-mc -triple riscv64 -filetype obj -o %t.o %s
2+
// RUN: ld.lld --emit-relocs -o %t %t.o
3+
// RUN: llvm-bolt --print-cfg --print-only=tls_le,tls_ie -o /dev/null %t \
4+
// RUN: | FileCheck %s
5+
6+
// CHECK-LABEL: Binary Function "tls_le{{.*}}" after building cfg {
7+
// CHECK: lui a5, 0
8+
// CHECK-NEXT: add a5, a5, tp
9+
// CHECK-NEXT: lw t0, 0(a5)
10+
// CHECK-NEXT: sw t0, 0(a5)
11+
12+
// CHECK-LABEL: Binary Function "tls_ie" after building cfg {
13+
// CHECK-LABEL: .Ltmp0
14+
// CHECK: auipc a0, %pcrel_hi(__BOLT_got_zero+{{[0-9]+}})
15+
// CHECK-NEXT: ld a0, %pcrel_lo(.Ltmp0)(a0)
16+
.text
17+
.globl tls_le, _start
18+
.p2align 2
19+
tls_le:
20+
_start:
21+
nop
22+
lui a5, %tprel_hi(i)
23+
add a5, a5, tp, %tprel_add(i)
24+
lw t0, %tprel_lo(i)(a5)
25+
sw t0, %tprel_lo(i)(a5)
26+
ret
27+
.size _start, .-_start
28+
29+
.globl tls_ie
30+
.p2align 2
31+
tls_ie:
32+
nop
33+
la.tls.ie a0, i
34+
ret
35+
.size tls_ie, .-tls_ie
36+
37+
.section .tbss,"awT",@nobits
38+
.type i,@object
39+
.globl i
40+
.p2align 3
41+
i:
42+
.quad 0
43+
.size i, .-i
44+

bolt/test/RISCV/tls-le-gnu-ld.test

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// This test checks that the binaries produces with GNU ld TLS le relaxation are
2+
// properly processed by BOLT. GNU ld currently emits two non-standard
3+
// relocations (R_RISCV_TPREL_I and R_RISCV_TPREL_S) in this case.
4+
5+
// RUN: yaml2obj %p/Inputs/tls-le-gnu-ld.yaml &> %t.exe
6+
// RUN: llvm-bolt %t.exe -o %t.bolt.exe --print-cfg --print-only=_start \
7+
// RUN: | FileCheck %s
8+
9+
// CHECK: Binary Function "_start" after building cfg {
10+
// CHECK: lw t0, 0(tp)
11+
// CHECK-NEXT: sw t0, 0(tp)

clang/docs/ClangFormatStyleOptions.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -5730,7 +5730,7 @@ Examples
57305730
========
57315731

57325732
A style similar to the `Linux Kernel style
5733-
<https://www.kernel.org/doc/Documentation/CodingStyle>`_:
5733+
<https://www.kernel.org/doc/html/latest/process/coding-style.html>`_:
57345734

57355735
.. code-block:: yaml
57365736

0 commit comments

Comments
 (0)