History

x86-64: Fix tcc -run. We need extra memory for PLT and GOT.

Size of the extra buffer is too large for now.

Shinichiro Hamaji committed 17 years ago

Commit 9a7173b1 parent e6ba81b2 files · +27 −12Browse files

Unified · Split

2 files
  1. tcc.c +22 −9
  2. tccelf.c +5 −3
tcc.c+22−9
@@ -545,6 +545,12 @@ struct TCCState { · 544 unmodified lines
545545
546546 /* for tcc_relocate */
547547 int runtime_added;
548+
549+#ifdef TCC_TARGET_X86_64
550+ /* write PLT and GOT here */
551+ char *runtime_plt_and_got;
552+ unsigned int runtime_plt_and_got_offset;
553+#endif
548554 };
549555
550556 /* The current value can be: */
@@ -1311,12 +1317,7 @@ Section *new_section(TCCState *s1, const char *name, int sh_type, int sh_flags) · 760 unmodified lines
13111317
13121318 static void free_section(Section *s)
13131319 {
1314−#ifdef TCC_TARGET_X86_64
1315− /* after tcc_relocate(), some sections share the data buffer.
1316− let's check if the data is allocated not to free the shared buffers */
1317− if (s->data_allocated)
1318−#endif
1319− tcc_free(s->data);
1320+ tcc_free(s->data);
13201321 }
13211322
13221323 /* realloc section and set its content to zero */
@@ -10327,14 +10328,22 @@ int tcc_relocate(TCCState *s1, void *ptr) · 9004 unmodified lines
1032710328 offset = (offset + length + 15) & ~15;
1032810329 }
1032910330
10331+#ifdef TCC_TARGET_X86_64
10332+ s1->runtime_plt_and_got_offset = 0;
10333+ s1->runtime_plt_and_got = (char *)(mem + offset);
10334+ /* double the size of the buffer for got and plt entries
10335+ XXX: calculate exact size for them? */
10336+ offset *= 2;
10337+#endif
10338+
10339+ if (0 == mem)
10340+ return offset + 15;
10341+
1033010342 /* relocate symbols */
1033110343 relocate_syms(s1, 1);
1033210344 if (s1->nb_errors)
1033310345 return -1;
1033410346
10335− if (0 == mem)
10336− return offset + 15;
10337−
1033810347 /* relocate each section */
1033910348 for(i = 1; i < s1->nb_sections; i++) {
1034010349 s = s1->sections[i];
@@ -10357,6 +10366,10 @@ int tcc_relocate(TCCState *s1, void *ptr) · 16 unmodified lines
1035710366 if (s->sh_flags & SHF_EXECINSTR)
1035810367 set_pages_executable(ptr, length);
1035910368 }
10369+#ifdef TCC_TARGET_X86_64
10370+ set_pages_executable(s1->runtime_plt_and_got,
10371+ s1->runtime_plt_and_got_offset);
10372+#endif
1036010373 return 0;
1036110374 }
1036210375
tccelf.c+5−3
@@ -480,7 +480,8 @@ static void relocate_syms(TCCState *s1, int do_resolve) · 479 unmodified lines
480480 #define JMP_TABLE_ENTRY_SIZE 14
481481 static unsigned long add_jmp_table(TCCState *s1, unsigned long val)
482482 {
483− char *p = (char *)section_ptr_add(text_section, JMP_TABLE_ENTRY_SIZE);
483+ char *p = s1->runtime_plt_and_got + s1->runtime_plt_and_got_offset;
484+ s1->runtime_plt_and_got_offset += JMP_TABLE_ENTRY_SIZE;
484485 /* jmp *0x0(%rip) */
485486 p[0] = 0xff;
486487 p[1] = 0x25;
@@ -491,8 +492,9 @@ static unsigned long add_jmp_table(TCCState *s1, unsigned long val) · 4 unmodified lines
491492
492493 static unsigned long add_got_table(TCCState *s1, unsigned long val)
493494 {
494− unsigned long *p =
495− (unsigned long *)section_ptr_add(text_section, sizeof(void *));
495+ unsigned long *p =(unsigned long *)(s1->runtime_plt_and_got +
496+ s1->runtime_plt_and_got_offset);
497+ s1->runtime_plt_and_got_offset += sizeof(void *);
496498 *p = val;
497499 return (unsigned long)p;
498500 }

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