This is needed to reach tinycc's PLT from the compiled program.
Unified · Split
| @@ -547,7 +547,7 @@ struct TCCState { · 546 unmodified lines | ||
| 547 | 547 | #endif |
| 548 | 548 | |
| 549 | 549 | #ifndef TCC_TARGET_PE |
| 550 | −#ifdef TCC_TARGET_X86_64 | |
| 550 | +#if defined TCC_TARGET_X86_64 || defined TCC_TARGET_ARM | |
| 551 | 551 | /* write PLT and GOT here */ |
| 552 | 552 | char *runtime_plt_and_got; |
| 553 | 553 | unsigned int runtime_plt_and_got_offset; |
| @@ -504,6 +504,17 @@ static uplong add_got_table(TCCState *s1, uplong val) · 503 unmodified lines | ||
| 504 | 504 | *p = val; |
| 505 | 505 | return (uplong)p; |
| 506 | 506 | } |
| 507 | +#elif defined TCC_TARGET_ARM | |
| 508 | +#define JMP_TABLE_ENTRY_SIZE 8 | |
| 509 | +static int add_jmp_table(TCCState *s1, int val) | |
| 510 | +{ | |
| 511 | + uint32_t *p = (uint32_t *)(s1->runtime_plt_and_got + s1->runtime_plt_and_got_offset); | |
| 512 | + s1->runtime_plt_and_got_offset += JMP_TABLE_ENTRY_SIZE; | |
| 513 | + /* ldr pc, [pc, #-4] */ | |
| 514 | + p[0] = 0xE51FF004; | |
| 515 | + p[1] = val; | |
| 516 | + return (int)p; | |
| 517 | +} | |
| 507 | 518 | #endif |
| 508 | 519 | #endif |
| 509 | 520 | |
| @@ -611,6 +622,11 @@ ST_FUNC void relocate_section(TCCState *s1, Section *s) · 101 unmodified lines | ||
| 611 | 622 | x -= 0x1000000; |
| 612 | 623 | x *= 4; |
| 613 | 624 | x += val - addr; |
| 625 | +#ifndef TCC_TARGET_PE | |
| 626 | + if((x & 3) != 0 || x >= 0x4000000 || x < -0x4000000) | |
| 627 | + if (s1->output_type == TCC_OUTPUT_MEMORY) | |
| 628 | + x += add_jmp_table(s1, val) - val; /* add veneer */ | |
| 629 | +#endif | |
| 614 | 630 | if((x & 3) != 0 || x >= 0x4000000 || x < -0x4000000) |
| 615 | 631 | error("can't relocate value at %x",addr); |
| 616 | 632 | x >>= 2; |
| @@ -150,7 +150,7 @@ static int tcc_relocate_ex(TCCState *s1, void *ptr) · 149 unmodified lines | ||
| 150 | 150 | if (s1->nb_errors) |
| 151 | 151 | return -1; |
| 152 | 152 | |
| 153 | −#if defined TCC_TARGET_X86_64 && !defined TCC_TARGET_PE | |
| 153 | +#if (defined TCC_TARGET_X86_64 || defined TCC_TARGET_ARM) && !defined TCC_TARGET_PE | |
| 154 | 154 | s1->runtime_plt_and_got_offset = 0; |
| 155 | 155 | s1->runtime_plt_and_got = (char *)(mem + offset); |
| 156 | 156 | /* double the size of the buffer for got and plt entries |
| @@ -184,7 +184,7 @@ static int tcc_relocate_ex(TCCState *s1, void *ptr) · 27 unmodified lines | ||
| 184 | 184 | set_pages_executable(ptr, length); |
| 185 | 185 | } |
| 186 | 186 | |
| 187 | −#if defined TCC_TARGET_X86_64 && !defined TCC_TARGET_PE | |
| 187 | +#if (defined TCC_TARGET_X86_64 || defined TCC_TARGET_ARM) && !defined TCC_TARGET_PE | |
| 188 | 188 | set_pages_executable(s1->runtime_plt_and_got, |
| 189 | 189 | s1->runtime_plt_and_got_offset); |
| 190 | 190 | #endif |