| @@ -542,15 +542,6 @@ struct TCCState { · 541 unmodified lines |
| 542 | 542 | |
| 543 | 543 | /* output file for preprocessing */ |
| 544 | 544 | FILE *outfile; |
| 545 | | − |
| 546 | | −#ifdef TCC_TARGET_X86_64 |
| 547 | | − /* buffer to store jump tables used when the output is memory */ |
| 548 | | − char *jmp_table; |
| 549 | | − int jmp_table_num; |
| 550 | | − /* buffer to store got tables used when the output is memory */ |
| 551 | | − void **got_table; |
| 552 | | − int got_table_num; |
| 553 | | −#endif |
| 554 | 545 | }; |
| 555 | 546 | |
| 556 | 547 | /* The current value can be: */ |
| @@ -1315,7 +1306,12 @@ Section *new_section(TCCState *s1, const char *name, int sh_type, int sh_flags) · 758 unmodified lines |
| 1315 | 1306 | |
| 1316 | 1307 | static void free_section(Section *s) |
| 1317 | 1308 | { |
| 1318 | | − tcc_free(s->data); |
| 1309 | +#ifdef TCC_TARGET_X86_64 |
| 1310 | + /* after tcc_relocate(), some sections share the data buffer. |
| 1311 | + let's check if the data is allocated not to free the shared buffers */ |
| 1312 | + if (s->data_allocated) |
| 1313 | +#endif |
| 1314 | + tcc_free(s->data); |
| 1319 | 1315 | } |
| 1320 | 1316 | |
| 1321 | 1317 | /* realloc section and set its content to zero */ |
| @@ -10276,6 +10272,51 @@ int tcc_relocate(TCCState *s1) · 8954 unmodified lines |
| 10276 | 10272 | #ifndef TCC_TARGET_PE |
| 10277 | 10273 | build_got_entries(s1); |
| 10278 | 10274 | #endif |
| 10275 | + |
| 10276 | +#ifdef TCC_TARGET_X86_64 |
| 10277 | + { |
| 10278 | + /* If the distance of two sections are longer than 32bit, our |
| 10279 | + program will crash. Let's combine all sections which are |
| 10280 | + necessary to run the program into a single buffer in the |
| 10281 | + text section */ |
| 10282 | + unsigned char *p; |
| 10283 | + int size; |
| 10284 | + /* calculate the size of buffers we need */ |
| 10285 | + size = 0; |
| 10286 | + for(i = 1; i < s1->nb_sections; i++) { |
| 10287 | + s = s1->sections[i]; |
| 10288 | + if (s->sh_flags & SHF_ALLOC) { |
| 10289 | + size += s->data_offset; |
| 10290 | + } |
| 10291 | + } |
| 10292 | + /* double the size of the buffer for got and plt entries |
| 10293 | + XXX: calculate exact size for them? */ |
| 10294 | + section_realloc(text_section, size * 2); |
| 10295 | + p = text_section->data + text_section->data_offset; |
| 10296 | + /* we will put got and plt after this offset */ |
| 10297 | + text_section->data_offset = size; |
| 10298 | + |
| 10299 | + for(i = 1; i < s1->nb_sections; i++) { |
| 10300 | + s = s1->sections[i]; |
| 10301 | + if (s->sh_flags & SHF_ALLOC) { |
| 10302 | + if (s != text_section && s->data_offset) { |
| 10303 | + if (s->sh_type == SHT_NOBITS) { |
| 10304 | + /* for bss section */ |
| 10305 | + memset(p, 0, s->data_offset); |
| 10306 | + } else { |
| 10307 | + memcpy(p, s->data, s->data_offset); |
| 10308 | + tcc_free(s->data); |
| 10309 | + } |
| 10310 | + s->data = p; |
| 10311 | + /* we won't free s->data for this section */ |
| 10312 | + s->data_allocated = 0; |
| 10313 | + p += s->data_offset; |
| 10314 | + } |
| 10315 | + s->sh_addr = (unsigned long)s->data; |
| 10316 | + } |
| 10317 | + } |
| 10318 | + } |
| 10319 | +#else |
| 10279 | 10320 | /* compute relocation address : section are relocated in place. We |
| 10280 | 10321 | also alloc the bss space */ |
| 10281 | 10322 | for(i = 1; i < s1->nb_sections; i++) { |
| @@ -10286,6 +10327,7 @@ int tcc_relocate(TCCState *s1) · 4 unmodified lines |
| 10286 | 10327 | s->sh_addr = (unsigned long)s->data; |
| 10287 | 10328 | } |
| 10288 | 10329 | } |
| 10330 | +#endif |
| 10289 | 10331 | |
| 10290 | 10332 | relocate_syms(s1, 1); |
| 10291 | 10333 | |
| @@ -10505,11 +10547,6 @@ TCCState *tcc_new(void) · 213 unmodified lines |
| 10505 | 10547 | /* XXX: currently the PE linker is not ready to support that */ |
| 10506 | 10548 | s->leading_underscore = 1; |
| 10507 | 10549 | #endif |
| 10508 | | − |
| 10509 | | −#ifdef TCC_TARGET_X86_64 |
| 10510 | | − s->jmp_table = NULL; |
| 10511 | | − s->got_table = NULL; |
| 10512 | | −#endif |
| 10513 | 10550 | return s; |
| 10514 | 10551 | } |
| 10515 | 10552 | |
| @@ -10546,10 +10583,6 @@ void tcc_delete(TCCState *s1) · 30 unmodified lines |
| 10546 | 10583 | dynarray_reset(&s1->include_paths, &s1->nb_include_paths); |
| 10547 | 10584 | dynarray_reset(&s1->sysinclude_paths, &s1->nb_sysinclude_paths); |
| 10548 | 10585 | |
| 10549 | | −#ifdef TCC_TARGET_X86_64 |
| 10550 | | − tcc_free(s1->jmp_table); |
| 10551 | | − tcc_free(s1->got_table); |
| 10552 | | −#endif |
| 10553 | 10586 | tcc_free(s1); |
| 10554 | 10587 | } |
| 10555 | 10588 | |