History

Relocation updates

x86_64-link.c: Check relocations R_X86_64_32/R_X86_64_32S. These relocations can become to large if not configured with '--disable-static' or '--config-pie' and code is run with -run -ltcc. This only happens on x86_64. tccdbg.c: 1) Add some .debug (dummy) sections when dwarf is used. These sections are otherwise not relocated correctly for R_DATA_32DW. 2) Fix stab problem when reloc is applied twice.

herman ten brugge committed 10 months ago

Commit 5a370d81 parent 64cf0b83 files · +34 −9Browse files

Unified · Split

3 files
  1. Makefile +1 −1
  2. tccdbg.c +24 −8
  3. x86_64-link.c +9 −0
Makefile+1−1
@@ -476,7 +476,7 @@ tcc_c$(EXESUF): $($T_FILES) · 475 unmodified lines
476sani-tes% : tcc_s$(EXESUF)476sani-tes% : tcc_s$(EXESUF)
477 @$(MAKE) --no-print-directory TCC_LOCAL=$(CURDIR)/$< tes$*477 @$(MAKE) --no-print-directory TCC_LOCAL=$(CURDIR)/$< tes$*
478tcc_s$(EXESUF): $($T_FILES)478tcc_s$(EXESUF): $($T_FILES)
479 $S$(CC) tcc.c -o $@ -fsanitize=address,undefined $(DEFINES) $(CFLAGS) $(LIBS)479 $S$(CC) tcc.c -o $@ -fsanitize=address,undefined $(DEFINES) $(CFLAGS) $(LDFLAGS) $(LIBS)
480# test the installed tcc instead480# test the installed tcc instead
481test-install: $(TCCDEFS_H)481test-install: $(TCCDEFS_H)
482 @$(MAKE) -C tests TESTINSTALL=yes #_all482 @$(MAKE) -C tests TESTINSTALL=yes #_all
tccdbg.c+24−8
@@ -431,7 +431,7 @@ struct _tccdbg { · 430 unmodified lines
431#define FDE_ENCODING (DW_EH_PE_udata4 | DW_EH_PE_signed | DW_EH_PE_pcrel)431#define FDE_ENCODING (DW_EH_PE_udata4 | DW_EH_PE_signed | DW_EH_PE_pcrel)
432 432
433/* ------------------------------------------------------------------------- */433/* ------------------------------------------------------------------------- */
434static void put_stabs(TCCState *s1, const char *str, int type, int other,434static int put_stabs(TCCState *s1, const char *str, int type, int other,
435 int desc, unsigned long value);435 int desc, unsigned long value);
436 436
437ST_FUNC void tcc_debug_new(TCCState *s1)437ST_FUNC void tcc_debug_new(TCCState *s1)
@@ -449,6 +449,19 @@ ST_FUNC void tcc_debug_new(TCCState *s1) · 11 unmodified lines
449#endif449#endif
450 450
451 if (s1->dwarf) {451 if (s1->dwarf) {
452 int i;
453 /* The sections below are just to make reloctions with
454 R_DATA_32DW work correctly. See tccelf.c */
455 static const char *const debug[] = {
456 ".debug_macro",
457 ".debug_loc",
458 ".debug_ranges",
459 ".debug_loclists",
460 ".debug_rnglists",
461 ".debug_str_offsets",
462 ".debug_addr"
463 };
464
452 s1->dwlo = s1->nb_sections;465 s1->dwlo = s1->nb_sections;
453 dwarf_info_section =466 dwarf_info_section =
454 new_section(s1, ".debug_info", SHT_PROGBITS, shf);467 new_section(s1, ".debug_info", SHT_PROGBITS, shf);
@@ -458,6 +471,8 @@ ST_FUNC void tcc_debug_new(TCCState *s1) · 3 unmodified lines
458 new_section(s1, ".debug_line", SHT_PROGBITS, shf);471 new_section(s1, ".debug_line", SHT_PROGBITS, shf);
459 dwarf_aranges_section =472 dwarf_aranges_section =
460 new_section(s1, ".debug_aranges", SHT_PROGBITS, shf);473 new_section(s1, ".debug_aranges", SHT_PROGBITS, shf);
474 for (i = 0; i < sizeof(debug)/sizeof(debug[0]); i++)
475 new_section(s1, debug[i], SHT_PROGBITS, 0)->sh_addralign = 1;
461 shf |= SHF_MERGE | SHF_STRINGS;476 shf |= SHF_MERGE | SHF_STRINGS;
462 dwarf_str_section =477 dwarf_str_section =
463 new_section(s1, ".debug_str", SHT_PROGBITS, shf);478 new_section(s1, ".debug_str", SHT_PROGBITS, shf);
@@ -487,7 +502,7 @@ ST_FUNC void tcc_debug_new(TCCState *s1) · 23 unmodified lines
487}502}
488 503
489/* put stab debug information */504/* put stab debug information */
490static void put_stabs(TCCState *s1, const char *str, int type, int other, int desc,505static int put_stabs(TCCState *s1, const char *str, int type, int other, int desc,
491 unsigned long value)506 unsigned long value)
492{507{
493 Stab_Sym *sym;508 Stab_Sym *sym;
@@ -500,7 +515,7 @@ static void put_stabs(TCCState *s1, const char *str, int type, int other, int de · 6 unmodified lines
500 && sym->n_value == value) {515 && sym->n_value == value) {
501 /* just update line_number in previous entry */516 /* just update line_number in previous entry */
502 sym->n_desc = desc;517 sym->n_desc = desc;
503 return;518 return 0;
504 }519 }
505 520
506 sym = section_ptr_add(stab_section, sizeof(Stab_Sym));521 sym = section_ptr_add(stab_section, sizeof(Stab_Sym));
@@ -513,16 +528,17 @@ static void put_stabs(TCCState *s1, const char *str, int type, int other, int de · 6 unmodified lines
513 sym->n_other = other;528 sym->n_other = other;
514 sym->n_desc = desc;529 sym->n_desc = desc;
515 sym->n_value = value;530 sym->n_value = value;
531 return 1;
516}532}
517 533
518static void put_stabs_r(TCCState *s1, const char *str, int type, int other, int desc,534static void put_stabs_r(TCCState *s1, const char *str, int type, int other, int desc,
519 unsigned long value, Section *sec, int sym_index)535 unsigned long value, Section *sec, int sym_index)
520{536{
521 put_elf_reloc(symtab_section, stab_section,537 if (put_stabs(s1, str, type, other, desc, value))
522 stab_section->data_offset + 8,538 put_elf_reloc(symtab_section, stab_section,
523 sizeof ((Stab_Sym*)0)->n_value == PTR_SIZE ? R_DATA_PTR : R_DATA_32,539 stab_section->data_offset - 4,
524 sym_index);540 sizeof ((Stab_Sym*)0)->n_value == PTR_SIZE ? R_DATA_PTR : R_DATA_32,
525 put_stabs(s1, str, type, other, desc, value);541 sym_index);
526}542}
527 543
528static void put_stabn(TCCState *s1, int type, int other, int desc, int value)544static void put_stabn(TCCState *s1, int type, int other, int desc, int value)
x86_64-link.c+9−0
@@ -221,6 +221,15 @@ ST_FUNC void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, · 220 unmodified lines
221 qrel->r_addend = (int)read32le(ptr) + val;221 qrel->r_addend = (int)read32le(ptr) + val;
222 qrel++;222 qrel++;
223 }223 }
224 /* ignore relocation check for stab section */
225 if ((stab_section == NULL ||
226 addr < stab_section->sh_addr ||
227 addr >= (stab_section->sh_addr + stab_section->data_offset)) &&
228 ((type == R_X86_64_32 &&
229 (unsigned long long)val > 4294967295ULL) ||
230 (type == R_X86_64_32S &&
231 ((long long)val < -2147483648LL || (long long)val > 2147483647LL))))
232 tcc_error_noabort("internal error: relocation %d failed", type);
224 add32le(ptr, val);233 add32le(ptr, val);
225 break;234 break;
226 235

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