Skip to content

Commit 7916cf7

Browse files
author
grischka
committed
tcc_error_noabort(): always use this unless compiling
This avoids 'exit(1)' with errors outside of compilation (nasty in particular with libtcc usage) As a sideeffect multiple errors can be seen for linker errors (such as undefined symbols, relocation errors, ...)
1 parent 19ef024 commit 7916cf7

17 files changed

+189
-180
lines changed

arm-link.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t
214214
h = x & 2;
215215
th_ko = (x & 3) && (!blx_avail || !is_call);
216216
if (th_ko || x >= 0x2000000 || x < -0x2000000)
217-
tcc_error("can't relocate value at %x,%d",addr, type);
217+
tcc_error_noabort("can't relocate value at %x,%d",addr, type);
218218
x >>= 2;
219219
x &= 0xffffff;
220220
/* Only reached if blx is avail and it is a call */
@@ -303,7 +303,7 @@ void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t
303303
- instruction must be a call (bl) or a jump to PLT */
304304
if (!to_thumb || x >= 0x1000000 || x < -0x1000000)
305305
if (to_thumb || (val & 2) || (!is_call && !to_plt))
306-
tcc_error("can't relocate value at %x,%d",addr, type);
306+
tcc_error_noabort("can't relocate value at %x,%d",addr, type);
307307

308308
/* Compute and store final offset */
309309
s = (x >> 24) & 1;
@@ -374,7 +374,7 @@ void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t
374374
x = (x * 2) / 2;
375375
x += val - addr;
376376
if((x^(x>>1))&0x40000000)
377-
tcc_error("can't relocate value at %x,%d",addr, type);
377+
tcc_error_noabort("can't relocate value at %x,%d",addr, type);
378378
(*(int *)ptr) |= x & 0x7fffffff;
379379
}
380380
return;

arm64-link.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ ST_FUNC void relocate_plt(TCCState *s1)
126126
uint64_t got = s1->got->sh_addr + 16;
127127
uint64_t off = (got >> 12) - (plt >> 12);
128128
if ((off + ((uint32_t)1 << 20)) >> 21)
129-
tcc_error("Failed relocating PLT (off=0x%lx, got=0x%lx, plt=0x%lx)", (long)off, (long)got, (long)plt);
129+
tcc_error_noabort("Failed relocating PLT (off=0x%lx, got=0x%lx, plt=0x%lx)", (long)off, (long)got, (long)plt);
130130
write32le(p, 0xa9bf7bf0); // stp x16,x30,[sp,#-16]!
131131
write32le(p + 4, (0x90000010 | // adrp x16,...
132132
(off & 0x1ffffc) << 3 | (off & 3) << 29));
@@ -145,7 +145,7 @@ ST_FUNC void relocate_plt(TCCState *s1)
145145
uint64_t addr = got + read64le(p);
146146
uint64_t off = (addr >> 12) - (pc >> 12);
147147
if ((off + ((uint32_t)1 << 20)) >> 21)
148-
tcc_error("Failed relocating PLT (off=0x%lx, addr=0x%lx, pc=0x%lx)", (long)off, (long)addr, (long)pc);
148+
tcc_error_noabort("Failed relocating PLT (off=0x%lx, addr=0x%lx, pc=0x%lx)", (long)off, (long)addr, (long)pc);
149149
write32le(p, (0x90000010 | // adrp x16,...
150150
(off & 0x1ffffc) << 3 | (off & 3) << 29));
151151
write32le(p + 4, (0xf9400211 | // ldr x17,[x16,#...]
@@ -239,7 +239,7 @@ void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t
239239
case R_AARCH64_ADR_PREL_PG_HI21: {
240240
uint64_t off = (val >> 12) - (addr >> 12);
241241
if ((off + ((uint64_t)1 << 20)) >> 21)
242-
tcc_error("R_AARCH64_ADR_PREL_PG_HI21 relocation failed");
242+
tcc_error_noabort("R_AARCH64_ADR_PREL_PG_HI21 relocation failed");
243243
write32le(ptr, ((read32le(ptr) & 0x9f00001f) |
244244
(off & 0x1ffffc) << 3 | (off & 3) << 29));
245245
return;
@@ -272,7 +272,7 @@ void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t
272272
(char *) symtab_section->link->data + sym->st_name);
273273
#endif
274274
if (((val - addr) + ((uint64_t)1 << 27)) & ~(uint64_t)0xffffffc)
275-
tcc_error("R_AARCH64_(JUMP|CALL)26 relocation failed"
275+
tcc_error_noabort("R_AARCH64_(JUMP|CALL)26 relocation failed"
276276
" (val=%lx, addr=%lx)", (long)val, (long)addr);
277277
write32le(ptr, (0x14000000 |
278278
(uint32_t)(type == R_AARCH64_CALL26) << 31 |
@@ -283,7 +283,7 @@ void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t
283283
(((s1->got->sh_addr +
284284
get_sym_attr(s1, sym_index, 0)->got_offset) >> 12) - (addr >> 12));
285285
if ((off + ((uint64_t)1 << 20)) >> 21)
286-
tcc_error("R_AARCH64_ADR_GOT_PAGE relocation failed");
286+
tcc_error_noabort("R_AARCH64_ADR_GOT_PAGE relocation failed");
287287
write32le(ptr, ((read32le(ptr) & 0x9f00001f) |
288288
(off & 0x1ffffc) << 3 | (off & 3) << 29));
289289
return;

c67-link.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ int gotplt_entry_type (int reloc_type)
6767

6868
ST_FUNC unsigned create_plt_entry(TCCState *s1, unsigned got_offset, struct sym_attr *attr)
6969
{
70-
tcc_error("C67 got not implemented");
70+
tcc_error_noabort("C67 got not implemented");
7171
return 0;
7272
}
7373

i386-link.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t
227227
case R_386_16:
228228
if (s1->output_format != TCC_OUTPUT_FORMAT_BINARY) {
229229
output_file:
230-
tcc_error("can only produce 16-bit binary files");
230+
tcc_error_noabort("can only produce 16-bit binary files");
231231
}
232232
write16le(ptr, read16le(ptr) + val);
233233
return;
@@ -274,7 +274,7 @@ void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t
274274
add32le(ptr + 5, -x);
275275
}
276276
else
277-
tcc_error("unexpected R_386_TLS_GD pattern");
277+
tcc_error_noabort("unexpected R_386_TLS_GD pattern");
278278
}
279279
return;
280280
case R_386_TLS_LDM:
@@ -297,7 +297,7 @@ void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t
297297
rel[1].r_info = ELFW(R_INFO)(0, R_386_NONE);
298298
}
299299
else
300-
tcc_error("unexpected R_386_TLS_LDM pattern");
300+
tcc_error_noabort("unexpected R_386_TLS_LDM pattern");
301301
}
302302
return;
303303
case R_386_TLS_LDO_32:

0 commit comments

Comments
 (0)