History

Update for clang -fsanitize

I tried to fix all remaining warnings/errors reported by -fsanitize. The riscv64-gen.c is a bit large because it contained a lot of warnings. I forgot some arm-link.c changes in last commit. The other changes are all small fixes to avoid warnings/errors.

herman ten brugge committed 1 year ago

Commit 666e88e1 parent 8025a828 files · +68 −74Browse files

Unified · Split

8 files
  1. arm-gen.c +2 −2
  2. arm-link.c +10 −10
  3. include/stddef.h +1 −1
  4. riscv64-gen.c +44 −56
  5. riscv64-link.c +1 −1
  6. tccelf.c +6 −3
  7. tccgen.c +1 −1
  8. x86_64-gen.c +3 −0
arm-gen.c+2−2
@@ -310,7 +310,7 @@ static uint32_t stuff_const(uint32_t op, uint32_t c) · 309 unmodified lines
310 if(c<256) /* catch undefined <<32 */310 if(c<256) /* catch undefined <<32 */
311 return op|c;311 return op|c;
312 for(i=2;i<32;i+=2) {312 for(i=2;i<32;i+=2) {
313 m=(0xff>>i)|(0xff<<(32-i));313 m=(0xffu>>i)|(0xffu<<(32-i));
314 if(!(c&~m))314 if(!(c&~m))
315 return op|(i<<7)|(c<<i)|(c>>(32-i));315 return op|(i<<7)|(c<<i)|(c>>(32-i));
316 }316 }
@@ -593,7 +593,7 @@ void load(int r, SValue *sv) · 276 unmodified lines
593 sign=0;593 sign=0;
594 else {594 else {
595 sign=1;595 sign=1;
596 fc=-fc;596 fc=-(unsigned)fc;
597 }597 }
598 598
599 v = fr & VT_VALMASK;599 v = fr & VT_VALMASK;
arm-link.c+10−10
@@ -201,10 +201,10 @@ ST_FUNC void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, · 200 unmodified lines
201 write32le(ptr, read32le(ptr) & 0xff000000);201 write32le(ptr, read32le(ptr) & 0xff000000);
202 if (x & 0x800000)202 if (x & 0x800000)
203 x -= 0x1000000;203 x -= 0x1000000;
204 x <<= 2;204 x = (unsigned) x << 2;
205 blx_avail = (CONFIG_TCC_CPUVER >= 5);205 blx_avail = (CONFIG_TCC_CPUVER >= 5);
206 is_thumb = val & 1;206 is_thumb = val & 1;
207 is_bl = (*(unsigned *) ptr) >> 24 == 0xeb;207 is_bl = ((unsigned) read32le(ptr)) >> 24 == 0xeb;
208 is_call = (type == R_ARM_CALL || (type == R_ARM_PC24 && is_bl));208 is_call = (type == R_ARM_CALL || (type == R_ARM_PC24 && is_bl));
209 x += val - addr;209 x += val - addr;
210#ifdef DEBUG_RELOC210#ifdef DEBUG_RELOC
@@ -241,8 +241,8 @@ ST_FUNC void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, · 30 unmodified lines
241 return;241 return;
242 242
243 /* Get initial offset */243 /* Get initial offset */
244 hi = (*(uint16_t *)ptr);244 hi = (uint16_t) read16le(ptr);
245 lo = (*(uint16_t *)(ptr+2));245 lo = (uint16_t) read16le(ptr+2);
246 s = (hi >> 10) & 1;246 s = (hi >> 10) & 1;
247 j1 = (lo >> 13) & 1;247 j1 = (lo >> 13) & 1;
248 j2 = (lo >> 11) & 1;248 j2 = (lo >> 11) & 1;
@@ -313,11 +313,11 @@ ST_FUNC void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, · 64 unmodified lines
313 j2 = s ^ (i2 ^ 1);313 j2 = s ^ (i2 ^ 1);
314 imm10 = (x >> 12) & 0x3ff;314 imm10 = (x >> 12) & 0x3ff;
315 imm11 = (x >> 1) & 0x7ff;315 imm11 = (x >> 1) & 0x7ff;
316 (*(uint16_t *)ptr) = (uint16_t) ((hi & 0xf800) |316 write16le(ptr, (uint16_t) ((hi & 0xf800) |
317 (s << 10) | imm10);317 (s << 10) | imm10));
318 (*(uint16_t *)(ptr+2)) = (uint16_t) ((lo & 0xc000) |318 write16le(ptr+2, (uint16_t) ((lo & 0xc000) |
319 (j1 << 13) | blx_bit | (j2 << 11) |319 (j1 << 13) | blx_bit | (j2 << 11) |
320 imm11);320 imm11));
321 }321 }
322 return;322 return;
323 case R_ARM_MOVT_ABS:323 case R_ARM_MOVT_ABS:
@@ -422,7 +422,7 @@ ST_FUNC void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, · 98 unmodified lines
422 return;422 return;
423 case R_ARM_GLOB_DAT:423 case R_ARM_GLOB_DAT:
424 case R_ARM_JUMP_SLOT:424 case R_ARM_JUMP_SLOT:
425 *(addr_t *)ptr = val;425 write32le(ptr, val);
426 return;426 return;
427 case R_ARM_NONE:427 case R_ARM_NONE:
428 /* Nothing to do. Normally used to indicate a dependency428 /* Nothing to do. Normally used to indicate a dependency
include/stddef.h+1−1
@@ -17,7 +17,7 @@ typedef union { long long __ll; long double __ld; } max_align_t; · 16 unmodified lines
17#endif17#endif
18 18
19#undef offsetof19#undef offsetof
20#define offsetof(type, field) ((size_t)&((type *)0)->field)20#define offsetof(type, field) __builtin_offsetof(type, field)
21 21
22#if defined __i386__ || defined __x86_64__22#if defined __i386__ || defined __x86_64__
23void *alloca(size_t size);23void *alloca(size_t size);
riscv64-gen.c+44−56
@@ -35,6 +35,10 @@ · 34 unmodified lines
35#include "tcc.h"35#include "tcc.h"
36#include <assert.h>36#include <assert.h>
37 37
38#define UPPER(x) (((unsigned)(x) + 0x800u) & 0xfffff000)
39#define SIGN7(x) ((((x) & 0xff) ^ 0x80) - 0x80)
40#define SIGN11(x) ((((x) & 0xfff) ^ 0x800) - 0x800)
41
38ST_DATA const char * const target_machine_defs =42ST_DATA const char * const target_machine_defs =
39 "__riscv\0"43 "__riscv\0"
40 "__riscv_xlen 64\0"44 "__riscv_xlen 64\0"
@@ -163,7 +167,7 @@ ST_FUNC void gsym_addr(int t_, int a_) · 122 unmodified lines
163 }167 }
164}168}
165 169
166static int load_symofs(int r, SValue *sv, int forstore)170static int load_symofs(int r, SValue *sv, int forstore, int *new_fc)
167{171{
168 int rr, doload = 0, large_addend = 0;172 int rr, doload = 0, large_addend = 0;
169 int fc = sv->c.i, v = sv->r & VT_VALMASK;173 int fc = sv->c.i, v = sv->r & VT_VALMASK;
@@ -173,7 +177,7 @@ static int load_symofs(int r, SValue *sv, int forstore) · 3 unmodified lines
173 if (sv->sym->type.t & VT_STATIC) { // XXX do this per linker relax177 if (sv->sym->type.t & VT_STATIC) { // XXX do this per linker relax
174 greloca(cur_text_section, sv->sym, ind,178 greloca(cur_text_section, sv->sym, ind,
175 R_RISCV_PCREL_HI20, sv->c.i);179 R_RISCV_PCREL_HI20, sv->c.i);
176 sv->c.i = 0;180 *new_fc = 0;
177 } else {181 } else {
178 if (((unsigned)fc + (1 << 11)) >> 12){182 if (((unsigned)fc + (1 << 11)) >> 12){
179 large_addend = 1;183 large_addend = 1;
@@ -193,9 +197,9 @@ static int load_symofs(int r, SValue *sv, int forstore) · 13 unmodified lines
193 if (doload) {197 if (doload) {
194 EI(0x03, 3, rr, rr, 0); // ld RR, 0(RR)198 EI(0x03, 3, rr, rr, 0); // ld RR, 0(RR)
195 if (large_addend) {199 if (large_addend) {
196 o(0x37 | (6 << 7) | ((0x800 + fc) & 0xfffff000)); //lui t1, high(fc)200 o(0x37 | (6 << 7) | UPPER(fc)); //lui t1, high(fc)
197 ER(0x33, 0, rr, rr, 6, 0); // add RR, RR, t1201 ER(0x33, 0, rr, rr, 6, 0); // add RR, RR, t1
198 sv->c.i = fc << 20 >> 20;202 *new_fc = SIGN11(fc);
199 }203 }
200 }204 }
201 } else if (v == VT_LOCAL || v == VT_LLOCAL) {205 } else if (v == VT_LOCAL || v == VT_LLOCAL) {
@@ -204,9 +208,9 @@ static int load_symofs(int r, SValue *sv, int forstore) · 2 unmodified lines
204 tcc_error("unimp: store(giant local off) (0x%lx)", (long)sv->c.i);208 tcc_error("unimp: store(giant local off) (0x%lx)", (long)sv->c.i);
205 if (((unsigned)fc + (1 << 11)) >> 12) {209 if (((unsigned)fc + (1 << 11)) >> 12) {
206 rr = is_ireg(r) ? ireg(r) : 5; // t0210 rr = is_ireg(r) ? ireg(r) : 5; // t0
207 o(0x37 | (rr << 7) | ((0x800 + fc) & 0xfffff000)); //lui RR, upper(fc)211 o(0x37 | (rr << 7) | UPPER(fc)); //lui RR, upper(fc)
208 ER(0x33, 0, rr, rr, 8, 0); // add RR, RR, s0212 ER(0x33, 0, rr, rr, 8, 0); // add RR, RR, s0
209 sv->c.i = fc << 20 >> 20;213 *new_fc = SIGN11(fc);
210 }214 }
211 } else215 } else
212 tcc_error("uhh");216 tcc_error("uhh");
@@ -217,13 +221,12 @@ static void load_large_constant(int rr, int fc, uint32_t pi) · 4 unmodified lines
217{221{
218 if (fc < 0)222 if (fc < 0)
219 pi++;223 pi++;
220 o(0x37 | (rr << 7) | (((pi + 0x800) & 0xfffff000))); // lui RR, up(up(fc))224 o(0x37 | (rr << 7) | UPPER(pi)); // lui RR, up(up(fc))
221 EI(0x13, 0, rr, rr, (int)pi << 20 >> 20); // addi RR, RR, lo(up(fc))225 EI(0x13, 0, rr, rr, SIGN11(pi)); // addi RR, RR, lo(up(fc))
222 EI(0x13, 1, rr, rr, 12); // slli RR, RR, 12226 EI(0x13, 1, rr, rr, 12); // slli RR, RR, 12
223 EI(0x13, 0, rr, rr, (fc + (1 << 19)) >> 20); // addi RR, RR, up(lo(fc))227 EI(0x13, 0, rr, rr, SIGN11(((unsigned)fc + (1 << 19)) >> 20)); // addi RR, RR, up(lo(fc))
224 EI(0x13, 1, rr, rr, 12); // slli RR, RR, 12228 EI(0x13, 1, rr, rr, 12); // slli RR, RR, 12
225 fc = (fc + (1 << 7)) << 12 >> 12;229 EI(0x13, 0, rr, rr, SIGN11(((unsigned)fc + (1 << 7)) >> 8)); // addi RR, RR, lo1(lo(fc))
226 EI(0x13, 0, rr, rr, fc >> 8); // addi RR, RR, lo1(lo(fc))
227 EI(0x13, 1, rr, rr, 8); // slli RR, RR, 8230 EI(0x13, 1, rr, rr, 8); // slli RR, RR, 8
228}231}
229 232
@@ -233,7 +236,6 @@ ST_FUNC void load(int r, SValue *sv) · 3 unmodified lines
233 int v = fr & VT_VALMASK;236 int v = fr & VT_VALMASK;
234 int rr = is_ireg(r) ? ireg(r) : freg(r);237 int rr = is_ireg(r) ? ireg(r) : freg(r);
235 int fc = sv->c.i;238 int fc = sv->c.i;
236 uint64_t save_fc = sv->c.i;
237 int bt = sv->type.t & VT_BTYPE;239 int bt = sv->type.t & VT_BTYPE;
238 int align, size;240 int align, size;
239 if (fr & VT_LVAL) {241 if (fr & VT_LVAL) {
@@ -246,16 +248,14 @@ ST_FUNC void load(int r, SValue *sv) · 6 unmodified lines
246 if (size < 4 && !is_float(sv->type.t) && (sv->type.t & VT_UNSIGNED))248 if (size < 4 && !is_float(sv->type.t) && (sv->type.t & VT_UNSIGNED))
247 func3 |= 4;249 func3 |= 4;
248 if (v == VT_LOCAL || (fr & VT_SYM)) {250 if (v == VT_LOCAL || (fr & VT_SYM)) {
249 br = load_symofs(r, sv, 0);251 br = load_symofs(r, sv, 0, &fc);
250 fc = sv->c.i;
251 } else if (v < VT_CONST) {252 } else if (v < VT_CONST) {
252 br = ireg(v);253 br = ireg(v);
253 /*if (((unsigned)fc + (1 << 11)) >> 12)254 /*if (((unsigned)fc + (1 << 11)) >> 12)
254 tcc_error("unimp: load(large addend) (0x%x)", fc);*/255 tcc_error("unimp: load(large addend) (0x%x)", fc);*/
255 fc = 0; // XXX store ofs in LVAL(reg)256 fc = 0; // XXX store ofs in LVAL(reg)
256 } else if (v == VT_LLOCAL) {257 } else if (v == VT_LLOCAL) {
257 br = load_symofs(r, sv, 0);258 br = load_symofs(r, sv, 0, &fc);
258 fc = sv->c.i;
259 EI(0x03, 3, rr, br, fc); // ld RR, fc(BR)259 EI(0x03, 3, rr, br, fc); // ld RR, fc(BR)
260 br = rr;260 br = rr;
261 fc = 0;261 fc = 0;
@@ -264,10 +264,10 @@ ST_FUNC void load(int r, SValue *sv) · 2 unmodified lines
264 si >>= 32;264 si >>= 32;
265 if (si != 0) {265 if (si != 0) {
266 load_large_constant(rr, fc, si);266 load_large_constant(rr, fc, si);
267 fc = fc << 24 >> 24;267 fc = SIGN7(fc);
268 } else {268 } else {
269 o(0x37 | (rr << 7) | ((0x800 + fc) & 0xfffff000)); //lui RR, upper(fc)269 o(0x37 | (rr << 7) | UPPER(fc)); //lui RR, upper(fc)
270 fc = fc << 20 >> 20;270 fc = SIGN11(fc);
271 }271 }
272 br = rr;272 br = rr;
273 } else {273 } else {
@@ -278,18 +278,17 @@ ST_FUNC void load(int r, SValue *sv) · 4 unmodified lines
278 int rb = 0, do32bit = 8, zext = 0;278 int rb = 0, do32bit = 8, zext = 0;
279 assert((!is_float(sv->type.t) && is_ireg(r)) || bt == VT_LDOUBLE);279 assert((!is_float(sv->type.t) && is_ireg(r)) || bt == VT_LDOUBLE);
280 if (fr & VT_SYM) {280 if (fr & VT_SYM) {
281 rb = load_symofs(r, sv, 0);281 rb = load_symofs(r, sv, 0, &fc);
282 fc = sv->c.i;
283 do32bit = 0;282 do32bit = 0;
284 }283 }
285 if (is_float(sv->type.t) && bt != VT_LDOUBLE)284 if (is_float(sv->type.t) && bt != VT_LDOUBLE)
286 tcc_error("unimp: load(float)");285 tcc_error("unimp: load(float)");
287 if (fc != sv->c.i) {286 if (do32bit && fc != sv->c.i) {
288 int64_t si = sv->c.i;287 int64_t si = sv->c.i;
289 si >>= 32;288 si >>= 32;
290 if (si != 0) {289 if (si != 0) {
291 load_large_constant(rr, fc, si);290 load_large_constant(rr, fc, si);
292 fc = fc << 24 >> 24;291 fc = SIGN7(fc);
293 rb = rr;292 rb = rr;
294 do32bit = 0;293 do32bit = 0;
295 } else if (bt == VT_LLONG) {294 } else if (bt == VT_LLONG) {
@@ -299,17 +298,16 @@ ST_FUNC void load(int r, SValue *sv) · 3 unmodified lines
299 }298 }
300 }299 }
301 if (((unsigned)fc + (1 << 11)) >> 12)300 if (((unsigned)fc + (1 << 11)) >> 12)
302 o(0x37 | (rr << 7) | ((0x800 + fc) & 0xfffff000)), rb = rr; //lui RR, upper(fc)301 o(0x37 | (rr << 7) | UPPER(fc)), rb = rr; //lui RR, upper(fc)
303 if (fc || (rr != rb) || do32bit || (fr & VT_SYM))302 if (fc || (rr != rb) || do32bit || (fr & VT_SYM))
304 EI(0x13 | do32bit, 0, rr, rb, fc << 20 >> 20); // addi[w] R, x0|R, FC303 EI(0x13 | do32bit, 0, rr, rb, SIGN11(fc)); // addi[w] R, x0|R, FC
305 if (zext) {304 if (zext) {
306 EI(0x13, 1, rr, rr, 32); // slli RR, RR, 32305 EI(0x13, 1, rr, rr, 32); // slli RR, RR, 32
307 EI(0x13, 5, rr, rr, 32); // srli RR, RR, 32306 EI(0x13, 5, rr, rr, 32); // srli RR, RR, 32
308 }307 }
309 } else if (v == VT_LOCAL) {308 } else if (v == VT_LOCAL) {
310 int br = load_symofs(r, sv, 0);309 int br = load_symofs(r, sv, 0, &fc);
311 assert(is_ireg(r));310 assert(is_ireg(r));
312 fc = sv->c.i;
313 EI(0x13, 0, rr, br, fc); // addi R, s0, FC311 EI(0x13, 0, rr, br, fc); // addi R, s0, FC
314 } else if (v < VT_CONST) { /* reg-reg */312 } else if (v < VT_CONST) { /* reg-reg */
315 //assert(!fc); XXX support offseted regs313 //assert(!fc); XXX support offseted regs
@@ -324,7 +322,7 @@ ST_FUNC void load(int r, SValue *sv) · 8 unmodified lines
324 func7 |= 1;322 func7 |= 1;
325 assert(size == 4 || size == 8);323 assert(size == 4 || size == 8);
326 o(0x53 | (rr << 7) | ((is_freg(v) ? freg(v) : ireg(v)) << 15)324 o(0x53 | (rr << 7) | ((is_freg(v) ? freg(v) : ireg(v)) << 15)
327 | (func7 << 25)); // fmv.{w.x, x.w, d.x, x.d} RR, VR325 | ((unsigned)func7 << 25)); // fmv.{w.x, x.w, d.x, x.d} RR, VR
328 }326 }
329 } else if (v == VT_CMP) {327 } else if (v == VT_CMP) {
330 int op = vtop->cmp_op;328 int op = vtop->cmp_op;
@@ -371,7 +369,6 @@ ST_FUNC void load(int r, SValue *sv) · 40 unmodified lines
371 EI(0x13, 0, rr, 0, t ^ 1); // addi RR, x0, !t369 EI(0x13, 0, rr, 0, t ^ 1); // addi RR, x0, !t
372 } else370 } else
373 tcc_error("unimp: load(non-const)");371 tcc_error("unimp: load(non-const)");
374 sv->c.i = save_fc;
375}372}
376 373
377ST_FUNC void store(int r, SValue *sv)374ST_FUNC void store(int r, SValue *sv)
@@ -379,7 +376,6 @@ ST_FUNC void store(int r, SValue *sv) · 1 unmodified line
379 int fr = sv->r & VT_VALMASK;376 int fr = sv->r & VT_VALMASK;
380 int rr = is_ireg(r) ? ireg(r) : freg(r), ptrreg;377 int rr = is_ireg(r) ? ireg(r) : freg(r), ptrreg;
381 int fc = sv->c.i;378 int fc = sv->c.i;
382 uint64_t save_fc = sv->c.i;
383 int bt = sv->type.t & VT_BTYPE;379 int bt = sv->type.t & VT_BTYPE;
384 int align, size = type_size(&sv->type, &align);380 int align, size = type_size(&sv->type, &align);
385 assert(!is_float(bt) || is_freg(r) || bt == VT_LDOUBLE);381 assert(!is_float(bt) || is_freg(r) || bt == VT_LDOUBLE);
@@ -393,8 +389,7 @@ ST_FUNC void store(int r, SValue *sv) · 7 unmodified lines
393 tcc_error("unimp: large sized store");389 tcc_error("unimp: large sized store");
394 assert(sv->r & VT_LVAL);390 assert(sv->r & VT_LVAL);
395 if (fr == VT_LOCAL || (sv->r & VT_SYM)) {391 if (fr == VT_LOCAL || (sv->r & VT_SYM)) {
396 ptrreg = load_symofs(-1, sv, 1);392 ptrreg = load_symofs(-1, sv, 1, &fc);
397 fc = sv->c.i;
398 } else if (fr < VT_CONST) {393 } else if (fr < VT_CONST) {
399 ptrreg = ireg(fr);394 ptrreg = ireg(fr);
400 /*if (((unsigned)fc + (1 << 11)) >> 12)395 /*if (((unsigned)fc + (1 << 11)) >> 12)
@@ -406,17 +401,16 @@ ST_FUNC void store(int r, SValue *sv) · 5 unmodified lines
406 si >>= 32;401 si >>= 32;
407 if (si != 0) {402 if (si != 0) {
408 load_large_constant(ptrreg, fc, si);403 load_large_constant(ptrreg, fc, si);
409 fc = fc << 24 >> 24;404 fc = SIGN7(fc);
410 } else {405 } else {
411 o(0x37 | (ptrreg << 7) | ((0x800 + fc) & 0xfffff000)); //lui RR, upper(fc)406 o(0x37 | (ptrreg << 7) | UPPER(fc)); //lui RR, upper(fc)
412 fc = fc << 20 >> 20;407 fc = SIGN11(fc);
413 }408 }
414 } else409 } else
415 tcc_error("implement me: %s(!local)", __FUNCTION__);410 tcc_error("implement me: %s(!local)", __FUNCTION__);
416 ES(is_freg(r) ? 0x27 : 0x23, // fs... | s...411 ES(is_freg(r) ? 0x27 : 0x23, // fs... | s...
417 size == 1 ? 0 : size == 2 ? 1 : size == 4 ? 2 : 3, // ... [wd] | [bhwd]412 size == 1 ? 0 : size == 2 ? 1 : size == 4 ? 2 : 3, // ... [wd] | [bhwd]
418 ptrreg, rr, fc); // RR, fc(base)413 ptrreg, rr, fc); // RR, fc(base)
419 sv->c.i = save_fc;
420}414}
421 415
422static void gcall_or_jmp(int docall)416static void gcall_or_jmp(int docall)
@@ -634,11 +628,8 @@ ST_FUNC void gfunc_call(int nb_args) · 211 unmodified lines
634 628
635 if (stack_add) {629 if (stack_add) {
636 if (stack_add >= 0x800) {630 if (stack_add >= 0x800) {
637 unsigned int bit11 = (((unsigned int)-stack_add) >> 11) & 1;631 o(0x37 | (5 << 7) | UPPER(-stack_add)); //lui t0, upper(v)
638 o(0x37 | (5 << 7) |632 EI(0x13, 0, 5, 5, SIGN11(-stack_add)); // addi t0, t0, lo(v)
639 ((-stack_add + (bit11 << 12)) & 0xfffff000)); //lui t0, upper(v)
640 EI(0x13, 0, 5, 5, ((-stack_add & 0xfff) - bit11 * (1 << 12)));
641 // addi t0, t0, lo(v)
642 ER(0x33, 0, 2, 2, 5, 0); // add sp, sp, t0633 ER(0x33, 0, 2, 2, 5, 0); // add sp, sp, t0
643 }634 }
644 else635 else
@@ -766,11 +757,8 @@ done: · 121 unmodified lines
766 vtop -= nb_args + 1;757 vtop -= nb_args + 1;
767 if (stack_add) {758 if (stack_add) {
768 if (stack_add >= 0x800) {759 if (stack_add >= 0x800) {
769 unsigned int bit11 = ((unsigned int)stack_add >> 11) & 1;760 o(0x37 | (5 << 7) | UPPER(stack_add)); //lui t0, upper(v)
770 o(0x37 | (5 << 7) |761 EI(0x13, 0, 5, 5, SIGN11(stack_add)); // addi t0, t0, lo(v)
771 ((stack_add + (bit11 << 12)) & 0xfffff000)); //lui t0, upper(v)
772 EI(0x13, 0, 5, 5, (stack_add & 0xfff) - bit11 * (1 << 12));
773 // addi t0, t0, lo(v)
774 ER(0x33, 0, 2, 2, 5, 0); // add sp, sp, t0762 ER(0x33, 0, 2, 2, 5, 0); // add sp, sp, t0
775 }763 }
776 else764 else
@@ -911,8 +899,8 @@ ST_FUNC void gfunc_epilog(void) · 134 unmodified lines
911 899
912 if (v >= (1 << 11)) {900 if (v >= (1 << 11)) {
913 d = 16;901 d = 16;
914 o(0x37 | (5 << 7) | ((0x800 + (v-16)) & 0xfffff000)); //lui t0, upper(v)902 o(0x37 | (5 << 7) | UPPER(v-16)); //lui t0, upper(v)
915 EI(0x13, 0, 5, 5, (v-16) << 20 >> 20); // addi t0, t0, lo(v)903 EI(0x13, 0, 5, 5, SIGN11(v-16)); // addi t0, t0, lo(v)
916 ER(0x33, 0, 2, 2, 5, 0); // add sp, sp, t0904 ER(0x33, 0, 2, 2, 5, 0); // add sp, sp, t0
917 }905 }
918 EI(0x03, 3, 1, 2, d - 8 - num_va_regs * 8); // ld ra, v-8(sp)906 EI(0x03, 3, 1, 2, d - 8 - num_va_regs * 8); // ld ra, v-8(sp)
@@ -922,8 +910,8 @@ ST_FUNC void gfunc_epilog(void) · 3 unmodified lines
922 large_ofs_ind = ind;910 large_ofs_ind = ind;
923 if (v >= (1 << 11)) {911 if (v >= (1 << 11)) {
924 EI(0x13, 0, 8, 2, d - num_va_regs * 8); // addi s0, sp, d912 EI(0x13, 0, 8, 2, d - num_va_regs * 8); // addi s0, sp, d
925 o(0x37 | (5 << 7) | ((0x800 + (v-16)) & 0xfffff000)); //lui t0, upper(v)913 o(0x37 | (5 << 7) | UPPER(v-16)); //lui t0, upper(v)
926 EI(0x13, 0, 5, 5, (v-16) << 20 >> 20); // addi t0, t0, lo(v)914 EI(0x13, 0, 5, 5, SIGN11(v-16)); // addi t0, t0, lo(v)
927 ER(0x33, 0, 2, 2, 5, 0x20); // sub sp, sp, t0915 ER(0x33, 0, 2, 2, 5, 0x20); // sub sp, sp, t0
928 gjmp_addr(func_sub_sp_offset + 5*4);916 gjmp_addr(func_sub_sp_offset + 5*4);
929 }917 }
@@ -972,8 +960,8 @@ ST_FUNC void gjmp_addr(int a) · 42 unmodified lines
972{960{
973 uint32_t r = a - ind, imm;961 uint32_t r = a - ind, imm;
974 if ((r + (1 << 21)) & ~((1U << 22) - 2)) {962 if ((r + (1 << 21)) & ~((1U << 22) - 2)) {
975 o(0x17 | (5 << 7) | (((r + 0x800) & 0xfffff000))); // lui RR, up(r)963 o(0x17 | (5 << 7) | UPPER(r)); // lui RR, up(r)
976 r = (int)r << 20 >> 20;964 r = SIGN11(r);
977 EI(0x67, 0, 0, 5, r); // jalr x0, r(t0)965 EI(0x67, 0, 0, 5, r); // jalr x0, r(t0)
978 } else {966 } else {
979 imm = (((r >> 12) & 0xff) << 12)967 imm = (((r >> 12) & 0xff) << 12)
@@ -1394,9 +1382,9 @@ ST_FUNC void ggoto(void) · 414 unmodified lines
1394ST_FUNC void gen_vla_sp_save(int addr)1382ST_FUNC void gen_vla_sp_save(int addr)
1395{1383{
1396 if (((unsigned)addr + (1 << 11)) >> 12) {1384 if (((unsigned)addr + (1 << 11)) >> 12) {
1397 o(0x37 | (5 << 7) | ((0x800 + addr) & 0xfffff000)); //lui t0,upper(addr)1385 o(0x37 | (5 << 7) | UPPER(addr)); //lui t0,upper(addr)
1398 ER(0x33, 0, 5, 5, 8, 0); // add t0, t0, s01386 ER(0x33, 0, 5, 5, 8, 0); // add t0, t0, s0
1399 ES(0x23, 3, 5, 2, (int)addr << 20 >> 20); // sd sp, fc(t0)1387 ES(0x23, 3, 5, 2, SIGN11(addr)); // sd sp, fc(t0)
1400 }1388 }
1401 else1389 else
1402 ES(0x23, 3, 8, 2, addr); // sd sp, fc(s0)1390 ES(0x23, 3, 8, 2, addr); // sd sp, fc(s0)
@@ -1405,9 +1393,9 @@ ST_FUNC void gen_vla_sp_save(int addr) · 2 unmodified lines
1405ST_FUNC void gen_vla_sp_restore(int addr)1393ST_FUNC void gen_vla_sp_restore(int addr)
1406{1394{
1407 if (((unsigned)addr + (1 << 11)) >> 12) {1395 if (((unsigned)addr + (1 << 11)) >> 12) {
1408 o(0x37 | (5 << 7) | ((0x800 + addr) & 0xfffff000)); //lui t0,upper(addr)1396 o(0x37 | (5 << 7) | UPPER(addr)); //lui t0,upper(addr)
1409 ER(0x33, 0, 5, 5, 8, 0); // add t0, t0, s01397 ER(0x33, 0, 5, 5, 8, 0); // add t0, t0, s0
1410 EI(0x03, 3, 2, 5, (int)addr << 20 >> 20); // ld sp, fc(t0)1398 EI(0x03, 3, 2, 5, SIGN11(addr)); // ld sp, fc(t0)
1411 }1399 }
1412 else1400 else
1413 EI(0x03, 3, 2, 8, addr); // ld sp, fc(s0)1401 EI(0x03, 3, 2, 8, addr); // ld sp, fc(s0)
riscv64-link.c+1−1
@@ -347,7 +347,7 @@ ST_FUNC void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, · 346 unmodified lines
347 *ptr = (*ptr & ~0xff) | (val & 0xff);347 *ptr = (*ptr & ~0xff) | (val & 0xff);
348 return;348 return;
349 case R_RISCV_SET16:349 case R_RISCV_SET16:
350 write16le(ptr, (read16le(ptr) & ~0xffff) | (val & 0xffff));350 write16le(ptr, val);
351 return;351 return;
352 case R_RISCV_SUB6:352 case R_RISCV_SUB6:
353 *ptr = (*ptr & ~0x3f) | ((*ptr - val) & 0x3f);353 *ptr = (*ptr & ~0x3f) | ((*ptr - val) & 0x3f);
tccelf.c+6−3
@@ -1129,6 +1129,7 @@ static void relocate_section(TCCState *s1, Section *s, Section *sr) · 1128 unmodified lines
1129 1129
1130 qrel = (ElfW_Rel *)sr->data;1130 qrel = (ElfW_Rel *)sr->data;
1131 for_each_elem(sr, 0, rel, ElfW_Rel) {1131 for_each_elem(sr, 0, rel, ElfW_Rel) {
1132 if (s->data == NULL) continue; /* bss */
1132 ptr = s->data + rel->r_offset;1133 ptr = s->data + rel->r_offset;
1133 sym_index = ELFW(R_SYM)(rel->r_info);1134 sym_index = ELFW(R_SYM)(rel->r_info);
1134 sym = &((ElfW(Sym) *)symtab_section->data)[sym_index];1135 sym = &((ElfW(Sym) *)symtab_section->data)[sym_index];
@@ -1595,7 +1596,8 @@ ST_FUNC void tcc_add_btstub(TCCState *s1) · 460 unmodified lines
1595 1596
1596 s = data_section;1597 s = data_section;
1597 /* Align to PTR_SIZE */1598 /* Align to PTR_SIZE */
1598 section_ptr_add(s, -s->data_offset & (PTR_SIZE - 1));1599 if (s->data_offset)
1600 section_ptr_add(s, -s->data_offset & (PTR_SIZE - 1));
1599 o = s->data_offset;1601 o = s->data_offset;
1600 /* create a struct rt_context (see tccrun.c) */1602 /* create a struct rt_context (see tccrun.c) */
1601 if (s1->dwarf) {1603 if (s1->dwarf) {
@@ -3257,7 +3259,7 @@ invalid: · 1655 unmodified lines
3257 sm_table[i].s = s;3259 sm_table[i].s = s;
3258 /* concatenate sections */3260 /* concatenate sections */
3259 size = sh->sh_size;3261 size = sh->sh_size;
3260 if (sh->sh_type != SHT_NOBITS) {3262 if (sh->sh_type != SHT_NOBITS && size) {
3261 unsigned char *ptr;3263 unsigned char *ptr;
3262 lseek(fd, file_offset + sh->sh_offset, SEEK_SET);3264 lseek(fd, file_offset + sh->sh_offset, SEEK_SET);
3263 ptr = section_ptr_add(s, size);3265 ptr = section_ptr_add(s, size);
@@ -3308,6 +3310,7 @@ invalid: · 44 unmodified lines
3308 /* resolve symbols */3310 /* resolve symbols */
3309 old_to_new_syms = tcc_mallocz(nb_syms * sizeof(int));3311 old_to_new_syms = tcc_mallocz(nb_syms * sizeof(int));
3310 3312
3313 if (nb_syms == 0) goto skip;
3311 sym = symtab + 1;3314 sym = symtab + 1;
3312 for(i = 1; i < nb_syms; i++, sym++) {3315 for(i = 1; i < nb_syms; i++, sym++) {
3313 if (sym->st_shndx != SHN_UNDEF &&3316 if (sym->st_shndx != SHN_UNDEF &&
@@ -3340,7 +3343,7 @@ invalid: · 26 unmodified lines
3340 sym->st_shndx, name);3343 sym->st_shndx, name);
3341 old_to_new_syms[i] = sym_index;3344 old_to_new_syms[i] = sym_index;
3342 }3345 }
3343 3346skip:
3344 /* third pass to patch relocation entries */3347 /* third pass to patch relocation entries */
3345 for(i = 1; i < ehdr.e_shnum; i++) {3348 for(i = 1; i < ehdr.e_shnum; i++) {
3346 s = sm_table[i].s;3349 s = sm_table[i].s;
tccgen.c+1−1
@@ -4562,7 +4562,7 @@ do_decl: · 4561 unmodified lines
4562 } else {4562 } else {
4563 type1.t = (type1.t & ~VT_STRUCT_MASK)4563 type1.t = (type1.t & ~VT_STRUCT_MASK)
4564 | VT_BITFIELD4564 | VT_BITFIELD
4565 | (bit_size << (VT_STRUCT_SHIFT + 6));4565 | ((unsigned)bit_size << (VT_STRUCT_SHIFT + 6));
4566 }4566 }
4567 }4567 }
4568 if (v != 0 || (type1.t & VT_BTYPE) == VT_STRUCT) {4568 if (v != 0 || (type1.t & VT_BTYPE) == VT_STRUCT) {
x86_64-gen.c+3−0
@@ -409,6 +409,7 @@ void load(int r, SValue *sv) · 408 unmodified lines
409 v1.type.t = VT_LLONG;409 v1.type.t = VT_LLONG;
410 v1.r = VT_CONST;410 v1.r = VT_CONST;
411 v1.c.i = sv->c.i;411 v1.c.i = sv->c.i;
412 v1.sym = NULL;
412 fr = r;413 fr = r;
413 if (!(reg_classes[fr] & (RC_INT|RC_R11)))414 if (!(reg_classes[fr] & (RC_INT|RC_R11)))
414 fr = get_reg(RC_INT);415 fr = get_reg(RC_INT);
@@ -1938,6 +1939,7 @@ void gen_opf(int op) · 1523 unmodified lines
1938 v1.type.t = VT_PTR;1939 v1.type.t = VT_PTR;
1939 v1.r = VT_LOCAL | VT_LVAL;1940 v1.r = VT_LOCAL | VT_LVAL;
1940 v1.c.i = fc;1941 v1.c.i = fc;
1942 v1.sym = NULL;
1941 load(r, &v1);1943 load(r, &v1);
1942 fc = 0;1944 fc = 0;
1943 vtop->r = r = r | VT_LVAL;1945 vtop->r = r = r | VT_LVAL;
@@ -2006,6 +2008,7 @@ void gen_opf(int op) · 62 unmodified lines
2006 v1.type.t = VT_PTR;2008 v1.type.t = VT_PTR;
2007 v1.r = VT_LOCAL | VT_LVAL;2009 v1.r = VT_LOCAL | VT_LVAL;
2008 v1.c.i = fc;2010 v1.c.i = fc;
2011 v1.sym = NULL;
2009 load(r, &v1);2012 load(r, &v1);
2010 fc = 0;2013 fc = 0;
2011 vtop->r = r = r | VT_LVAL;2014 vtop->r = r = r | VT_LVAL;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t