History

ARM: allow jumps > 32MB on -run

This is needed to reach tinycc's PLT from the compiled program.

Daniel Glöckner committed 16 years ago

Commit 741841d1 parent a64727b3 files · +19 −3Browse files

Unified · Split

3 files
  1. tcc.h +1 −1
  2. tccelf.c +16 −0
  3. tccrun.c +2 −2
tcc.h+1−1
@@ -547,7 +547,7 @@ struct TCCState { · 546 unmodified lines
547547 #endif
548548
549549 #ifndef TCC_TARGET_PE
550−#ifdef TCC_TARGET_X86_64
550+#if defined TCC_TARGET_X86_64 || defined TCC_TARGET_ARM
551551 /* write PLT and GOT here */
552552 char *runtime_plt_and_got;
553553 unsigned int runtime_plt_and_got_offset;
tccelf.c+16−0
@@ -504,6 +504,17 @@ static uplong add_got_table(TCCState *s1, uplong val) · 503 unmodified lines
504504 *p = val;
505505 return (uplong)p;
506506 }
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+}
507518 #endif
508519 #endif
509520
@@ -611,6 +622,11 @@ ST_FUNC void relocate_section(TCCState *s1, Section *s) · 101 unmodified lines
611622 x -= 0x1000000;
612623 x *= 4;
613624 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
614630 if((x & 3) != 0 || x >= 0x4000000 || x < -0x4000000)
615631 error("can't relocate value at %x",addr);
616632 x >>= 2;
tccrun.c+2−2
@@ -150,7 +150,7 @@ static int tcc_relocate_ex(TCCState *s1, void *ptr) · 149 unmodified lines
150150 if (s1->nb_errors)
151151 return -1;
152152
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
154154 s1->runtime_plt_and_got_offset = 0;
155155 s1->runtime_plt_and_got = (char *)(mem + offset);
156156 /* 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
184184 set_pages_executable(ptr, length);
185185 }
186186
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
188188 set_pages_executable(s1->runtime_plt_and_got,
189189 s1->runtime_plt_and_got_offset);
190190 #endif

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