mirror of
https://github.com/mirror/tinycc.git
synced 2025-04-01 12:30:08 +08:00
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.
This commit is contained in:
parent
7600b03f35
commit
682ecc1745
12
arm64-gen.c
12
arm64-gen.c
@ -592,23 +592,11 @@ ST_FUNC void store(int r, SValue *sv)
|
|||||||
|
|
||||||
static void arm64_gen_bl_or_b(int b)
|
static void arm64_gen_bl_or_b(int b)
|
||||||
{
|
{
|
||||||
// Currently TCC's linker does not generate a PLT when TCC is invoked
|
|
||||||
// with "-run". This means functions can be out of range if we try to
|
|
||||||
// call them in the usual way. Until the linker is fixed, work around
|
|
||||||
// this by using R_AARCH64_MOVW_UABS_G* relocations; see arm64_sym.
|
|
||||||
int avoid_call26 = 1;
|
|
||||||
|
|
||||||
if ((vtop->r & (VT_VALMASK | VT_LVAL)) == VT_CONST) {
|
if ((vtop->r & (VT_VALMASK | VT_LVAL)) == VT_CONST) {
|
||||||
assert(!b && (vtop->r & VT_SYM));
|
assert(!b && (vtop->r & VT_SYM));
|
||||||
if (avoid_call26) {
|
|
||||||
arm64_sym(30, vtop->sym, 0);
|
|
||||||
o(0xd63f03c0); // blr x30
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
greloc(cur_text_section, vtop->sym, ind, R_AARCH64_CALL26);
|
greloc(cur_text_section, vtop->sym, ind, R_AARCH64_CALL26);
|
||||||
o(0x94000000); // bl .
|
o(0x94000000); // bl .
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
else
|
||||||
o(0xd61f0000 | (uint32_t)!b << 21 | intr(gv(RC_R30)) << 5); // br/blr
|
o(0xd61f0000 | (uint32_t)!b << 21 | intr(gv(RC_R30)) << 5); // br/blr
|
||||||
}
|
}
|
||||||
|
6
tccelf.c
6
tccelf.c
@ -826,7 +826,8 @@ ST_FUNC void relocate_section(TCCState *s1, Section *s)
|
|||||||
case R_AARCH64_CALL26:
|
case R_AARCH64_CALL26:
|
||||||
/* This check must match the one in build_got_entries, testing
|
/* This check must match the one in build_got_entries, testing
|
||||||
if we really need a PLT slot. */
|
if we really need a PLT slot. */
|
||||||
if (sym->st_shndx == SHN_UNDEF)
|
if (sym->st_shndx == SHN_UNDEF ||
|
||||||
|
s1->output_type == TCC_OUTPUT_MEMORY)
|
||||||
/* We've put the PLT slot offset into r_addend when generating
|
/* We've put the PLT slot offset into r_addend when generating
|
||||||
it, and that's what we must use as relocation value (adjusted
|
it, and that's what we must use as relocation value (adjusted
|
||||||
by section offset of course). */
|
by section offset of course). */
|
||||||
@ -1427,7 +1428,8 @@ ST_FUNC void build_got_entries(TCCState *s1)
|
|||||||
build_got(s1);
|
build_got(s1);
|
||||||
sym_index = ELFW(R_SYM)(rel->r_info);
|
sym_index = ELFW(R_SYM)(rel->r_info);
|
||||||
sym = &((ElfW(Sym) *)symtab_section->data)[sym_index];
|
sym = &((ElfW(Sym) *)symtab_section->data)[sym_index];
|
||||||
if (sym->st_shndx == SHN_UNDEF) {
|
if (sym->st_shndx == SHN_UNDEF ||
|
||||||
|
s1->output_type == TCC_OUTPUT_MEMORY) {
|
||||||
unsigned long ofs;
|
unsigned long ofs;
|
||||||
reloc_type = R_AARCH64_JUMP_SLOT;
|
reloc_type = R_AARCH64_JUMP_SLOT;
|
||||||
ofs = put_got_entry(s1, reloc_type, sym->st_size,
|
ofs = put_got_entry(s1, reloc_type, sym->st_size,
|
||||||
|
Loading…
Reference in New Issue
Block a user