History

arm64: Fix -run

With -run the call instruction and a defined function can be far away, if the function is defined in the executable itself, not in the to be compiled code. So we always need PLT slots for -run, not just for undefined symbols.

Michael Matz committed 10 years ago

Commit 682ecc11 parent 7600b032 files · +12 −22Browse files

Unified · Split

2 files
  1. arm64-gen.c +2 −14
  2. tccelf.c +10 −8
arm64-gen.c+2−14
@@ -592,22 +592,10 @@ ST_FUNC void store(int r, SValue *sv) · 591 unmodified lines
592592
593593 static void arm64_gen_bl_or_b(int b)
594594 {
595− // Currently TCC's linker does not generate a PLT when TCC is invoked
596− // with "-run". This means functions can be out of range if we try to
597− // call them in the usual way. Until the linker is fixed, work around
598− // this by using R_AARCH64_MOVW_UABS_G* relocations; see arm64_sym.
599− int avoid_call26 = 1;
600−
601595 if ((vtop->r & (VT_VALMASK | VT_LVAL)) == VT_CONST) {
602596 assert(!b && (vtop->r & VT_SYM));
603− if (avoid_call26) {
604− arm64_sym(30, vtop->sym, 0);
605− o(0xd63f03c0); // blr x30
606− }
607− else {
608− greloc(cur_text_section, vtop->sym, ind, R_AARCH64_CALL26);
609− o(0x94000000); // bl .
610− }
597+ greloc(cur_text_section, vtop->sym, ind, R_AARCH64_CALL26);
598+ o(0x94000000); // bl .
611599 }
612600 else
613601 o(0xd61f0000 | (uint32_t)!b << 21 | intr(gv(RC_R30)) << 5); // br/blr
tccelf.c+10−8
@@ -826,7 +826,8 @@ ST_FUNC void relocate_section(TCCState *s1, Section *s) · 825 unmodified lines
826826 case R_AARCH64_CALL26:
827827 /* This check must match the one in build_got_entries, testing
828828 if we really need a PLT slot. */
829− if (sym->st_shndx == SHN_UNDEF)
829+ if (sym->st_shndx == SHN_UNDEF ||
830+ s1->output_type == TCC_OUTPUT_MEMORY)
830831 /* We've put the PLT slot offset into r_addend when generating
831832 it, and that's what we must use as relocation value (adjusted
832833 by section offset of course). */
@@ -1423,19 +1424,20 @@ ST_FUNC void build_got_entries(TCCState *s1) · 590 unmodified lines
14231424
14241425 case R_AARCH64_JUMP26:
14251426 case R_AARCH64_CALL26:
1426− if (!s1->got)
1427− build_got(s1);
1428− sym_index = ELFW(R_SYM)(rel->r_info);
1429− sym = &((ElfW(Sym) *)symtab_section->data)[sym_index];
1430− if (sym->st_shndx == SHN_UNDEF) {
1427+ if (!s1->got)
1428+ build_got(s1);
1429+ sym_index = ELFW(R_SYM)(rel->r_info);
1430+ sym = &((ElfW(Sym) *)symtab_section->data)[sym_index];
1431+ if (sym->st_shndx == SHN_UNDEF ||
1432+ s1->output_type == TCC_OUTPUT_MEMORY) {
14311433 unsigned long ofs;
14321434 reloc_type = R_AARCH64_JUMP_SLOT;
1433− ofs = put_got_entry(s1, reloc_type, sym->st_size,
1435+ ofs = put_got_entry(s1, reloc_type, sym->st_size,
14341436 sym->st_info, sym_index);
14351437 /* We store the place of the generated PLT slot
14361438 in our addend. */
14371439 rel->r_addend += ofs;
1438− }
1440+ }
14391441 break;
14401442 #elif defined(TCC_TARGET_C67)
14411443 case R_C60_GOT32:

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