Skip to content

Commit 5dc2f44

Browse files
authored
[RISCV] Mark QC Relocations as Relaxable (#142794)
Some of the QC relocations are relaxable, in particular there are relaxations defined for: - `R_RISCV_QC_E_JUMP_PLT` - `R_RISCV_QC_E_32` - `R_RISCV_QC_ABS20_U` This change ensures that llvm-mc correctly emits R_RISCV_RELAX relocations for the relevant fixups.
1 parent ba8077c commit 5dc2f44

File tree

4 files changed

+61
-0
lines changed

4 files changed

+61
-0
lines changed

llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCCodeEmitter.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,7 @@ uint64_t RISCVMCCodeEmitter::getImmOpValue(const MCInst &MI, unsigned OpNo,
624624
break;
625625
case RISCVMCExpr::VK_QC_ABS20:
626626
FixupKind = RISCV::fixup_riscv_qc_abs20_u;
627+
RelaxCandidate = true;
627628
break;
628629
}
629630
} else if (Kind == MCExpr::SymbolRef || Kind == MCExpr::Binary) {
@@ -642,8 +643,10 @@ uint64_t RISCVMCCodeEmitter::getImmOpValue(const MCInst &MI, unsigned OpNo,
642643
FixupKind = RISCV::fixup_riscv_qc_e_branch;
643644
} else if (MIFrm == RISCVII::InstFormatQC_EAI) {
644645
FixupKind = RISCV::fixup_riscv_qc_e_32;
646+
RelaxCandidate = true;
645647
} else if (MIFrm == RISCVII::InstFormatQC_EJ) {
646648
FixupKind = RISCV::fixup_riscv_qc_e_jump_plt;
649+
RelaxCandidate = true;
647650
}
648651
}
649652

llvm/test/MC/RISCV/xqcibi-relocations.s

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,17 @@ same_section:
7474
same_section_extern:
7575
nop
7676

77+
.option relax
78+
79+
# ASM: qc.bnei t3, 14, same_section
80+
# OBJ: qc.bnei t3, 0xe, 0x28 <same_section>
81+
qc.bnei t3, 14, same_section
82+
83+
# ASM: qc.e.bgeui s2, 24, same_section
84+
# OBJ-NEXT: qc.e.bgeui s2, 0x18, 0x28 <same_section>
85+
qc.e.bgeui s2, 24, same_section
86+
87+
.option norelax
7788

7889
.section .text.second, "ax", @progbits
7990

llvm/test/MC/RISCV/xqcilb-relocations.s

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,24 @@ same_section:
7676
same_section_extern:
7777
nop
7878

79+
.option relax
80+
81+
# ASM: qc.e.j same_section
82+
# OBJ: qc.e.j 0x38 <same_section_extern+0x4>
83+
# OBJ-NEXT: R_RISCV_VENDOR QUALCOMM{{$}}
84+
# OBJ-NEXT: R_RISCV_CUSTOM195 same_section{{$}}
85+
# OBJ-NEXT: R_RISCV_RELAX
86+
qc.e.j same_section
87+
88+
# ASM: qc.e.jal same_section
89+
# OBJ-NEXT: qc.e.jal 0x3e <same_section_extern+0xa>
90+
# OBJ-NEXT: R_RISCV_VENDOR QUALCOMM{{$}}
91+
# OBJ-NEXT: R_RISCV_CUSTOM195 same_section{{$}}
92+
# OBJ-NEXT: R_RISCV_RELAX
93+
qc.e.jal same_section
94+
95+
.option norelax
96+
7997
.section .text.other, "ax", @progbits
8098

8199
# ASM-LABEL: other_section:

llvm/test/MC/RISCV/xqcili-relocations.s

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,35 @@ qc.e.li s3, other_section
7070
same_section:
7171
nop
7272

73+
.option relax
74+
75+
# ASM: qc.li a1, %qc.abs20(0)
76+
# OBJ: qc.li a1, 0x0
77+
# OBJ-NEXT: R_RISCV_VENDOR QUALCOMM{{$}}
78+
# OBJ-NEXT: R_RISCV_CUSTOM192 *ABS*{{$}}
79+
# OBJ-NEXT: R_RISCV_RELAX
80+
qc.li a1, %qc.abs20(abs_symbol)
81+
82+
# ASM: qc.e.li s1, 0
83+
# OBJ-NEXT: qc.e.li s1, 0x0
84+
qc.e.li s1, abs_symbol
85+
86+
# ASM: qc.li a1, %qc.abs20(undef)
87+
# OBJ-NEXT: qc.li a1, 0x0
88+
# OBJ-NEXT: R_RISCV_VENDOR QUALCOMM{{$}}
89+
# OBJ-NEXT: R_RISCV_CUSTOM192 undef{{$}}
90+
# OBJ-NEXT: R_RISCV_RELAX
91+
qc.li a1, %qc.abs20(undef)
92+
93+
# ASM: qc.e.li s1, undef
94+
# OBJ-NEXT: qc.e.li s1, 0x0
95+
# OBJ-NEXT: R_RISCV_VENDOR QUALCOMM{{$}}
96+
# OBJ-NEXT: R_RISCV_CUSTOM194 undef{{$}}
97+
# OBJ-NEXT: R_RISCV_RELAX
98+
qc.e.li s1, undef
99+
100+
.option norelax
101+
73102
.section .text.other, "ax", @progbits
74103

75104
# ASM-LABEL: other_section:

0 commit comments

Comments
 (0)