llvm.org GIT mirror llvm / 06d0423
[RISCV] Support assembling %tls_{ie,gd}_pcrel_hi modifiers This patch adds support for parsing and assembling the %tls_ie_pcrel_hi and %tls_gd_pcrel_hi modifiers. Differential Revision: https://reviews.llvm.org/D55342 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358994 91177308-0d34-0410-b5e6-96231b3b80d8 Lewis Revill 1 year, 7 months ago
10 changed file(s) with 86 addition(s) and 10 deletion(s). Raw diff Collapse all Expand all
551551 if (!IsConstantImm) {
552552 IsValid = RISCVAsmParser::classifySymbolRef(getImm(), VK, Imm);
553553 return IsValid && (VK == RISCVMCExpr::VK_RISCV_PCREL_HI ||
554 VK == RISCVMCExpr::VK_RISCV_GOT_HI);
554 VK == RISCVMCExpr::VK_RISCV_GOT_HI ||
555 VK == RISCVMCExpr::VK_RISCV_TLS_GOT_HI ||
556 VK == RISCVMCExpr::VK_RISCV_TLS_GD_HI);
555557 } else {
556558 return isUInt<20>(Imm) && (VK == RISCVMCExpr::VK_RISCV_None ||
557559 VK == RISCVMCExpr::VK_RISCV_PCREL_HI ||
558 VK == RISCVMCExpr::VK_RISCV_GOT_HI);
560 VK == RISCVMCExpr::VK_RISCV_GOT_HI ||
561 VK == RISCVMCExpr::VK_RISCV_TLS_GOT_HI ||
562 VK == RISCVMCExpr::VK_RISCV_TLS_GD_HI);
559563 }
560564 }
561565
909913 case Match_InvalidUImm20AUIPC:
910914 return generateImmOutOfRangeError(
911915 Operands, ErrorInfo, 0, (1 << 20) - 1,
912 "operand must be a symbol with a %pcrel_hi/%got_pcrel_hi modifier "
913 "or an integer in the range");
916 "operand must be a symbol with a "
917 "%pcrel_hi/%got_pcrel_hi/%tls_ie_pcrel_hi/%tls_gd_pcrel_hi modifier or "
918 "an integer in the range");
914919 case Match_InvalidSImm21Lsb0JAL:
915920 return generateImmOutOfRangeError(
916921 Operands, ErrorInfo, -(1 << 20), (1 << 20) - 2,
3333 default:
3434 break;
3535 case RISCV::fixup_riscv_got_hi20:
36 case RISCV::fixup_riscv_tls_got_hi20:
37 case RISCV::fixup_riscv_tls_gd_hi20:
3638 return true;
3739 case RISCV::fixup_riscv_pcrel_lo12_i:
3840 case RISCV::fixup_riscv_pcrel_lo12_s:
5052 llvm_unreachable("Unexpected fixup kind for pcrel_lo12");
5153 break;
5254 case RISCV::fixup_riscv_got_hi20:
55 case RISCV::fixup_riscv_tls_got_hi20:
56 case RISCV::fixup_riscv_tls_gd_hi20:
5357 ShouldForce = true;
5458 break;
5559 case RISCV::fixup_riscv_pcrel_hi20:
178182 default:
179183 llvm_unreachable("Unknown fixup kind!");
180184 case RISCV::fixup_riscv_got_hi20:
185 case RISCV::fixup_riscv_tls_got_hi20:
186 case RISCV::fixup_riscv_tls_gd_hi20:
181187 llvm_unreachable("Relocation should be unconditionally forced\n");
182188 case FK_Data_1:
183189 case FK_Data_2:
108108 { "fixup_riscv_tprel_lo12_i", 20, 12, 0 },
109109 { "fixup_riscv_tprel_lo12_s", 0, 32, 0 },
110110 { "fixup_riscv_tprel_add", 0, 0, 0 },
111 { "fixup_riscv_tls_got_hi20", 12, 20, MCFixupKindInfo::FKF_IsPCRel },
112 { "fixup_riscv_tls_gd_hi20", 12, 20, MCFixupKindInfo::FKF_IsPCRel },
111113 { "fixup_riscv_jal", 12, 20, MCFixupKindInfo::FKF_IsPCRel },
112114 { "fixup_riscv_branch", 0, 32, MCFixupKindInfo::FKF_IsPCRel },
113115 { "fixup_riscv_rvc_jump", 2, 11, MCFixupKindInfo::FKF_IsPCRel },
9292 return ELF::R_RISCV_TPREL_LO12_S;
9393 case RISCV::fixup_riscv_tprel_add:
9494 return ELF::R_RISCV_TPREL_ADD;
95 case RISCV::fixup_riscv_tls_got_hi20:
96 return ELF::R_RISCV_TLS_GOT_HI20;
97 case RISCV::fixup_riscv_tls_gd_hi20:
98 return ELF::R_RISCV_TLS_GD_HI20;
9599 case RISCV::fixup_riscv_jal:
96100 return ELF::R_RISCV_JAL;
97101 case RISCV::fixup_riscv_branch:
4848 // fixup_riscv_tprel_add - A fixup corresponding to %tprel_add(foo) for the
4949 // add_tls instruction. Used to provide a hint to the linker.
5050 fixup_riscv_tprel_add,
51 // fixup_riscv_tls_got_hi20 - 20-bit fixup corresponding to
52 // tls_ie_pcrel_hi(foo) for instructions like auipc
53 fixup_riscv_tls_got_hi20,
54 // fixup_riscv_tls_gd_hi20 - 20-bit fixup corresponding to
55 // tls_gd_pcrel_hi(foo) for instructions like auipc
56 fixup_riscv_tls_gd_hi20,
5157 // fixup_riscv_jal - 20-bit fixup for symbol references in the jal
5258 // instruction
5359 fixup_riscv_jal,
306306 FixupKind = RISCV::fixup_riscv_tprel_hi20;
307307 RelaxCandidate = true;
308308 break;
309 case RISCVMCExpr::VK_RISCV_TLS_GOT_HI:
310 FixupKind = RISCV::fixup_riscv_tls_got_hi20;
311 break;
312 case RISCVMCExpr::VK_RISCV_TLS_GD_HI:
313 FixupKind = RISCV::fixup_riscv_tls_gd_hi20;
314 break;
309315 case RISCVMCExpr::VK_RISCV_CALL:
310316 FixupKind = RISCV::fixup_riscv_call;
311317 RelaxCandidate = true;
7777 default:
7878 continue;
7979 case RISCV::fixup_riscv_got_hi20:
80 case RISCV::fixup_riscv_tls_got_hi20:
81 case RISCV::fixup_riscv_tls_gd_hi20:
8082 case RISCV::fixup_riscv_pcrel_hi20:
8183 return &F;
8284 }
165167 case VK_RISCV_TPREL_LO:
166168 case VK_RISCV_TPREL_HI:
167169 case VK_RISCV_TPREL_ADD:
170 case VK_RISCV_TLS_GOT_HI:
171 case VK_RISCV_TLS_GD_HI:
168172 return false;
169173 }
170174 }
186190 .Case("tprel_lo", VK_RISCV_TPREL_LO)
187191 .Case("tprel_hi", VK_RISCV_TPREL_HI)
188192 .Case("tprel_add", VK_RISCV_TPREL_ADD)
193 .Case("tls_ie_pcrel_hi", VK_RISCV_TLS_GOT_HI)
194 .Case("tls_gd_pcrel_hi", VK_RISCV_TLS_GD_HI)
189195 .Default(VK_RISCV_Invalid);
190196 }
191197
209215 return "tprel_hi";
210216 case VK_RISCV_TPREL_ADD:
211217 return "tprel_add";
218 case VK_RISCV_TLS_GOT_HI:
219 return "tls_ie_pcrel_hi";
220 case VK_RISCV_TLS_GD_HI:
221 return "tls_gd_pcrel_hi";
212222 }
213223 }
214224
246256 default:
247257 return;
248258 case VK_RISCV_TPREL_HI:
259 case VK_RISCV_TLS_GOT_HI:
260 case VK_RISCV_TLS_GD_HI:
249261 break;
250262 }
251263
258270 if (Kind == VK_RISCV_PCREL_HI || Kind == VK_RISCV_PCREL_LO ||
259271 Kind == VK_RISCV_GOT_HI || Kind == VK_RISCV_TPREL_HI ||
260272 Kind == VK_RISCV_TPREL_LO || Kind == VK_RISCV_TPREL_ADD ||
273 Kind == VK_RISCV_TLS_GOT_HI || Kind == VK_RISCV_TLS_GD_HI ||
261274 Kind == VK_RISCV_CALL || Kind == VK_RISCV_CALL_PLT)
262275 return false;
263276
3131 VK_RISCV_TPREL_LO,
3232 VK_RISCV_TPREL_HI,
3333 VK_RISCV_TPREL_ADD,
34 VK_RISCV_TLS_GOT_HI,
35 VK_RISCV_TLS_GD_HI,
3436 VK_RISCV_CALL,
3537 VK_RISCV_CALL_PLT,
3638 VK_RISCV_Invalid
128128 # INSTR: sb t1, %pcrel_lo(.L2)(a2)
129129 # FIXUP: fixup A - offset: 0, value: %pcrel_lo(.L2), kind: fixup_riscv_pcrel_lo12_s
130130
131 .L3:
132 auipc t1, %tls_ie_pcrel_hi(foo)
133 # RELOC: R_RISCV_TLS_GOT_HI20 foo 0x0
134 # INSTR: auipc t1, %tls_ie_pcrel_hi(foo)
135 # FIXUP: fixup A - offset: 0, value: %tls_ie_pcrel_hi(foo), kind: fixup_riscv_tls_got_hi20
136
137 addi t1, t1, %pcrel_lo(.L3)
138 # RELOC: R_RISCV_PCREL_LO12_I .L3 0x0
139 # INSTR: addi t1, t1, %pcrel_lo(.L3)
140 # FIXUP: fixup A - offset: 0, value: %pcrel_lo(.L3), kind: fixup_riscv_pcrel_lo12_i
141
142 sb t1, %pcrel_lo(.L3)(a2)
143 # RELOC: R_RISCV_PCREL_LO12_S .L3 0x0
144 # INSTR: sb t1, %pcrel_lo(.L3)(a2)
145 # FIXUP: fixup A - offset: 0, value: %pcrel_lo(.L3), kind: fixup_riscv_pcrel_lo12_s
146
147 .L4:
148 auipc t1, %tls_gd_pcrel_hi(foo)
149 # RELOC: R_RISCV_TLS_GD_HI20 foo 0x0
150 # INSTR: auipc t1, %tls_gd_pcrel_hi(foo)
151 # FIXUP: fixup A - offset: 0, value: %tls_gd_pcrel_hi(foo), kind: fixup_riscv_tls_gd_hi20
152
153 addi t1, t1, %pcrel_lo(.L4)
154 # RELOC: R_RISCV_PCREL_LO12_I .L4 0x0
155 # INSTR: addi t1, t1, %pcrel_lo(.L4)
156 # FIXUP: fixup A - offset: 0, value: %pcrel_lo(.L4), kind: fixup_riscv_pcrel_lo12_i
157
158 sb t1, %pcrel_lo(.L4)(a2)
159 # RELOC: R_RISCV_PCREL_LO12_S .L4 0x0
160 # INSTR: sb t1, %pcrel_lo(.L4)(a2)
161 # FIXUP: fixup A - offset: 0, value: %pcrel_lo(.L4), kind: fixup_riscv_pcrel_lo12_s
162
131163 add t1, t1, tp, %tprel_add(foo)
132164 # RELOC: R_RISCV_TPREL_ADD foo 0x0
133165 # INSTR: add t1, t1, tp, %tprel_add(foo)
3939 ## uimm20
4040 lui a0, -1 # CHECK: :[[@LINE]]:9: error: operand must be a symbol with %hi/%tprel_hi modifier or an integer in the range [0, 1048575]
4141 lui s0, 1048576 # CHECK: :[[@LINE]]:9: error: operand must be a symbol with %hi/%tprel_hi modifier or an integer in the range [0, 1048575]
42 auipc zero, -0xf # CHECK: :[[@LINE]]:13: error: operand must be a symbol with a %pcrel_hi/%got_pcrel_hi modifier or an integer in the range [0, 1048575]
42 auipc zero, -0xf # CHECK: :[[@LINE]]:13: error: operand must be a symbol with a %pcrel_hi/%got_pcrel_hi/%tls_ie_pcrel_hi/%tls_gd_pcrel_hi modifier or an integer in the range [0, 1048575]
4343
4444 ## simm21_lsb0
4545 jal gp, -1048578 # CHECK: :[[@LINE]]:9: error: immediate must be a multiple of 2 bytes in the range [-1048576, 1048574]
104104
105105 ## uimm20
106106 lui a0, %lo(1) # CHECK: :[[@LINE]]:9: error: operand must be a symbol with %hi/%tprel_hi modifier or an integer in the range [0, 1048575]
107 auipc a1, %lo(foo) # CHECK: :[[@LINE]]:11: error: operand must be a symbol with a %pcrel_hi/%got_pcrel_hi modifier or an integer in the range [0, 1048575]
107 auipc a1, %lo(foo) # CHECK: :[[@LINE]]:11: error: operand must be a symbol with a %pcrel_hi/%got_pcrel_hi/%tls_ie_pcrel_hi/%tls_gd_pcrel_hi modifier or an integer in the range [0, 1048575]
108108
109109 ## simm21_lsb0
110110 jal gp, %lo(1) # CHECK: :[[@LINE]]:9: error: immediate must be a multiple of 2 bytes in the range [-1048576, 1048574]
124124 lui a0, %pcrel_lo(foo) # CHECK: :[[@LINE]]:9: error: operand must be a symbol with %hi/%tprel_hi modifier or an integer in the range [0, 1048575]
125125 lui a0, %pcrel_hi(foo) # CHECK: :[[@LINE]]:9: error: operand must be a symbol with %hi/%tprel_hi modifier or an integer in the range [0, 1048575]
126126
127 auipc a0, foo # CHECK: :[[@LINE]]:11: error: operand must be a symbol with a %pcrel_hi/%got_pcrel_hi modifier or an integer in the range [0, 1048575]
128 auipc a0, %lo(foo) # CHECK: :[[@LINE]]:11: error: operand must be a symbol with a %pcrel_hi/%got_pcrel_hi modifier or an integer in the range [0, 1048575]
129 auipc a0, %hi(foo) # CHECK: :[[@LINE]]:11: error: operand must be a symbol with a %pcrel_hi/%got_pcrel_hi modifier or an integer in the range [0, 1048575]
130 auipc a0, %pcrel_lo(foo) # CHECK: :[[@LINE]]:11: error: operand must be a symbol with a %pcrel_hi/%got_pcrel_hi modifier or an integer in the range [0, 1048575]
127 auipc a0, foo # CHECK: :[[@LINE]]:11: error: operand must be a symbol with a %pcrel_hi/%got_pcrel_hi/%tls_ie_pcrel_hi/%tls_gd_pcrel_hi modifier or an integer in the range [0, 1048575]
128 auipc a0, %lo(foo) # CHECK: :[[@LINE]]:11: error: operand must be a symbol with a %pcrel_hi/%got_pcrel_hi/%tls_ie_pcrel_hi/%tls_gd_pcrel_hi modifier or an integer in the range [0, 1048575]
129 auipc a0, %hi(foo) # CHECK: :[[@LINE]]:11: error: operand must be a symbol with a %pcrel_hi/%got_pcrel_hi/%tls_ie_pcrel_hi/%tls_gd_pcrel_hi modifier or an integer in the range [0, 1048575]
130 auipc a0, %pcrel_lo(foo) # CHECK: :[[@LINE]]:11: error: operand must be a symbol with a %pcrel_hi/%got_pcrel_hi/%tls_ie_pcrel_hi/%tls_gd_pcrel_hi modifier or an integer in the range [0, 1048575]
131131
132132 # TP-relative symbol names require a %tprel_add modifier.
133133 add a0, a0, tp, zero # CHECK: :[[@LINE]]:17: error: expected '%' for operand modifier