History

win64: try to fix linkage

- revert to R_X86_64_PC32 for near calls on PE - revert to s1->section_align set to zero by default Untested. Compared to release_0_9_26 the pe-image looks back to normal. There are some differences in dissassembly (r10/r11 usage) but maybe that's ok.

grischka committed 12 years ago

Commit 0f51ccd1 parent ad787ab3 files · +23 −18Browse files

Unified · Split

3 files
  1. libtcc.c +0 −1
  2. tccelf.c +16 −14
  3. x86_64-gen.c +7 −3
libtcc.c+0−1
@@ -1033,7 +1033,6 @@ LIBTCCAPI TCCState *tcc_new(void) · 1032 unmodified lines
10331033 ".dynhashtab", SHF_PRIVATE);
10341034 s->alacarte_link = 1;
10351035 s->nocommon = 1;
1036− s->section_align = ELF_PAGE_SIZE;
10371036
10381037 #ifdef CHAR_IS_UNSIGNED
10391038 s->char_is_unsigned = 1;
tccelf.c+16−14
@@ -1596,7 +1596,7 @@ ST_FUNC void fill_got_entry(TCCState *s1, ElfW_Rel *rel) · 1595 unmodified lines
15961596 put32(s1->got->data + offset, sym->st_value & 0xffffffff);
15971597 }
15981598
1599−/* Perform relocation to GOT or PLT entries */
1599+/* Perform relocation to GOT or PLT entries */
16001600 ST_FUNC void fill_got(TCCState *s1)
16011601 {
16021602 Section *s;
@@ -1848,6 +1848,7 @@ static int layout_sections(TCCState *s1, ElfW(Phdr) *phdr, int phnum, · 245 unmodified lines
18481848 int *sec_order)
18491849 {
18501850 int i, j, k, file_type, sh_order_index, file_offset;
1851+ unsigned long s_align;
18511852 long long tmp;
18521853 addr_t addr;
18531854 ElfW(Phdr) *ph;
@@ -1855,10 +1856,12 @@ static int layout_sections(TCCState *s1, ElfW(Phdr) *phdr, int phnum, · 1 unmodified line
18551856
18561857 file_type = s1->output_type;
18571858 sh_order_index = 1;
1859+ file_offset = 0;
18581860 if (s1->output_format == TCC_OUTPUT_FORMAT_ELF)
18591861 file_offset = sizeof(ElfW(Ehdr)) + phnum * sizeof(ElfW(Phdr));
1860− else
1861− file_offset = 0;
1862+ s_align = ELF_PAGE_SIZE;
1863+ if (s1->section_align)
1864+ s_align = s1->section_align;
18621865
18631866 if (phnum > 0) {
18641867 if (s1->has_text_addr) {
@@ -1866,10 +1869,10 @@ static int layout_sections(TCCState *s1, ElfW(Phdr) *phdr, int phnum, · 1 unmodified line
18661869 addr = s1->text_addr;
18671870 /* we ensure that (addr % ELF_PAGE_SIZE) == file_offset %
18681871 ELF_PAGE_SIZE */
1869− a_offset = (int) (addr & (s1->section_align - 1));
1870− p_offset = file_offset & (s1->section_align - 1);
1872+ a_offset = (int) (addr & (s_align - 1));
1873+ p_offset = file_offset & (s_align - 1);
18711874 if (a_offset < p_offset)
1872− a_offset += s1->section_align;
1875+ a_offset += s_align;
18731876 file_offset += (a_offset - p_offset);
18741877 } else {
18751878 if (file_type == TCC_OUTPUT_DLL)
@@ -1877,7 +1880,7 @@ static int layout_sections(TCCState *s1, ElfW(Phdr) *phdr, int phnum, · 1 unmodified line
18771880 else
18781881 addr = ELF_START_ADDR;
18791882 /* compute address after headers */
1880− addr += (file_offset & (s1->section_align - 1));
1883+ addr += (file_offset & (s_align - 1));
18811884 }
18821885
18831886 ph = &phdr[0];
@@ -1899,7 +1902,7 @@ static int layout_sections(TCCState *s1, ElfW(Phdr) *phdr, int phnum, · 15 unmodified lines
18991902 ph->p_flags = PF_R | PF_X;
19001903 else
19011904 ph->p_flags = PF_R | PF_W;
1902− ph->p_align = s1->section_align;
1905+ ph->p_align = s_align;
19031906
19041907 /* Decide the layout of sections loaded in memory. This must
19051908 be done before program headers are filled since they contain
@@ -1991,12 +1994,11 @@ static int layout_sections(TCCState *s1, ElfW(Phdr) *phdr, int phnum, · 85 unmodified lines
19911994 if (s1->output_format == TCC_OUTPUT_FORMAT_ELF) {
19921995 /* if in the middle of a page, we duplicate the page in
19931996 memory so that one copy is RX and the other is RW */
1994− if ((addr & (s1->section_align - 1)) != 0)
1995− addr += s1->section_align;
1997+ if ((addr & (s_align - 1)) != 0)
1998+ addr += s_align;
19961999 } else {
1997− addr = (addr + s1->section_align - 1) & ~(s1->section_align - 1);
1998− file_offset = (file_offset + s1->section_align - 1) &
1999− ~(s1->section_align - 1);
2000+ addr = (addr + s_align - 1) & ~(s_align - 1);
2001+ file_offset = (file_offset + s_align - 1) & ~(s_align - 1);
20002002 }
20012003 }
20022004 }
@@ -2469,7 +2471,7 @@ static int elf_output_file(TCCState *s1, const char *filename) · 466 unmodified lines
24692471 goto the_end;
24702472 }
24712473
2472− /* Perform relocation to GOT or PLT entries */
2474+ /* Perform relocation to GOT or PLT entries */
24732475 if (file_type == TCC_OUTPUT_EXE && s1->static_link)
24742476 fill_got(s1);
24752477
x86_64-gen.c+7−3
@@ -288,7 +288,8 @@ static void gen_gotpcrel(int r, Sym *sym, int c) · 287 unmodified lines
288288 rel = (ElfW(Rela) *)(sr->data + sr->data_offset - sizeof(ElfW(Rela)));
289289 rel->r_addend = -4;
290290 #else
291− printf("picpic: %s %x %x | %02x %02x %02x\n", get_tok_str(sym->v, NULL), c, r,
291+ tcc_error("internal error: no GOT on PE: %s %x %x | %02x %02x %02x\n",
292+ get_tok_str(sym->v, NULL), c, r,
292293 cur_text_section->data[ind-3],
293294 cur_text_section->data[ind-2],
294295 cur_text_section->data[ind-1]
@@ -603,8 +604,11 @@ static void gcall_or_jmp(int is_jmp) · 308 unmodified lines
603604 /* constant case */
604605 if (vtop->r & VT_SYM) {
605606 /* relocation case */
606− greloc(cur_text_section, vtop->sym,
607− ind + 1, R_X86_64_PLT32);
607+#ifdef TCC_TARGET_PE
608+ greloc(cur_text_section, vtop->sym, ind + 1, R_X86_64_PC32);
609+#else
610+ greloc(cur_text_section, vtop->sym, ind + 1, R_X86_64_PLT32);
611+#endif
608612 } else {
609613 /* put an empty PC32 relocation */
610614 put_elf_reloc(symtab_section, cur_text_section,