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
1033 ".dynhashtab", SHF_PRIVATE);1033 ".dynhashtab", SHF_PRIVATE);
1034 s->alacarte_link = 1;1034 s->alacarte_link = 1;
1035 s->nocommon = 1;1035 s->nocommon = 1;
1036 s->section_align = ELF_PAGE_SIZE;
1037 1036
1038#ifdef CHAR_IS_UNSIGNED1037#ifdef CHAR_IS_UNSIGNED
1039 s->char_is_unsigned = 1;1038 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
1596 put32(s1->got->data + offset, sym->st_value & 0xffffffff);1596 put32(s1->got->data + offset, sym->st_value & 0xffffffff);
1597}1597}
1598 1598
1599/* Perform relocation to GOT or PLT entries */1599/* Perform relocation to GOT or PLT entries */
1600ST_FUNC void fill_got(TCCState *s1)1600ST_FUNC void fill_got(TCCState *s1)
1601{1601{
1602 Section *s;1602 Section *s;
@@ -1848,6 +1848,7 @@ static int layout_sections(TCCState *s1, ElfW(Phdr) *phdr, int phnum, · 245 unmodified lines
1848 int *sec_order)1848 int *sec_order)
1849{1849{
1850 int i, j, k, file_type, sh_order_index, file_offset;1850 int i, j, k, file_type, sh_order_index, file_offset;
1851 unsigned long s_align;
1851 long long tmp;1852 long long tmp;
1852 addr_t addr;1853 addr_t addr;
1853 ElfW(Phdr) *ph;1854 ElfW(Phdr) *ph;
@@ -1855,10 +1856,12 @@ static int layout_sections(TCCState *s1, ElfW(Phdr) *phdr, int phnum, · 1 unmodified line
1855 1856
1856 file_type = s1->output_type;1857 file_type = s1->output_type;
1857 sh_order_index = 1;1858 sh_order_index = 1;
1859 file_offset = 0;
1858 if (s1->output_format == TCC_OUTPUT_FORMAT_ELF)1860 if (s1->output_format == TCC_OUTPUT_FORMAT_ELF)
1859 file_offset = sizeof(ElfW(Ehdr)) + phnum * sizeof(ElfW(Phdr));1861 file_offset = sizeof(ElfW(Ehdr)) + phnum * sizeof(ElfW(Phdr));
1860 else1862 s_align = ELF_PAGE_SIZE;
1861 file_offset = 0;1863 if (s1->section_align)
1864 s_align = s1->section_align;
1862 1865
1863 if (phnum > 0) {1866 if (phnum > 0) {
1864 if (s1->has_text_addr) {1867 if (s1->has_text_addr) {
@@ -1866,10 +1869,10 @@ static int layout_sections(TCCState *s1, ElfW(Phdr) *phdr, int phnum, · 1 unmodified line
1866 addr = s1->text_addr;1869 addr = s1->text_addr;
1867 /* we ensure that (addr % ELF_PAGE_SIZE) == file_offset %1870 /* we ensure that (addr % ELF_PAGE_SIZE) == file_offset %
1868 ELF_PAGE_SIZE */1871 ELF_PAGE_SIZE */
1869 a_offset = (int) (addr & (s1->section_align - 1));1872 a_offset = (int) (addr & (s_align - 1));
1870 p_offset = file_offset & (s1->section_align - 1);1873 p_offset = file_offset & (s_align - 1);
1871 if (a_offset < p_offset)1874 if (a_offset < p_offset)
1872 a_offset += s1->section_align;1875 a_offset += s_align;
1873 file_offset += (a_offset - p_offset);1876 file_offset += (a_offset - p_offset);
1874 } else {1877 } else {
1875 if (file_type == TCC_OUTPUT_DLL)1878 if (file_type == TCC_OUTPUT_DLL)
@@ -1877,7 +1880,7 @@ static int layout_sections(TCCState *s1, ElfW(Phdr) *phdr, int phnum, · 1 unmodified line
1877 else1880 else
1878 addr = ELF_START_ADDR;1881 addr = ELF_START_ADDR;
1879 /* compute address after headers */1882 /* compute address after headers */
1880 addr += (file_offset & (s1->section_align - 1));1883 addr += (file_offset & (s_align - 1));
1881 }1884 }
1882 1885
1883 ph = &phdr[0];1886 ph = &phdr[0];
@@ -1899,7 +1902,7 @@ static int layout_sections(TCCState *s1, ElfW(Phdr) *phdr, int phnum, · 15 unmodified lines
1899 ph->p_flags = PF_R | PF_X;1902 ph->p_flags = PF_R | PF_X;
1900 else1903 else
1901 ph->p_flags = PF_R | PF_W;1904 ph->p_flags = PF_R | PF_W;
1902 ph->p_align = s1->section_align;1905 ph->p_align = s_align;
1903 1906
1904 /* Decide the layout of sections loaded in memory. This must1907 /* Decide the layout of sections loaded in memory. This must
1905 be done before program headers are filled since they contain1908 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
1991 if (s1->output_format == TCC_OUTPUT_FORMAT_ELF) {1994 if (s1->output_format == TCC_OUTPUT_FORMAT_ELF) {
1992 /* if in the middle of a page, we duplicate the page in1995 /* if in the middle of a page, we duplicate the page in
1993 memory so that one copy is RX and the other is RW */1996 memory so that one copy is RX and the other is RW */
1994 if ((addr & (s1->section_align - 1)) != 0)1997 if ((addr & (s_align - 1)) != 0)
1995 addr += s1->section_align;1998 addr += s_align;
1996 } else {1999 } else {
1997 addr = (addr + s1->section_align - 1) & ~(s1->section_align - 1);2000 addr = (addr + s_align - 1) & ~(s_align - 1);
1998 file_offset = (file_offset + s1->section_align - 1) &2001 file_offset = (file_offset + s_align - 1) & ~(s_align - 1);
1999 ~(s1->section_align - 1);
2000 }2002 }
2001 }2003 }
2002 }2004 }
@@ -2469,7 +2471,7 @@ static int elf_output_file(TCCState *s1, const char *filename) · 466 unmodified lines
2469 goto the_end;2471 goto the_end;
2470 }2472 }
2471 2473
2472 /* Perform relocation to GOT or PLT entries */2474 /* Perform relocation to GOT or PLT entries */
2473 if (file_type == TCC_OUTPUT_EXE && s1->static_link)2475 if (file_type == TCC_OUTPUT_EXE && s1->static_link)
2474 fill_got(s1);2476 fill_got(s1);
2475 2477
x86_64-gen.c+7−3
@@ -288,7 +288,8 @@ static void gen_gotpcrel(int r, Sym *sym, int c) · 287 unmodified lines
288 rel = (ElfW(Rela) *)(sr->data + sr->data_offset - sizeof(ElfW(Rela)));288 rel = (ElfW(Rela) *)(sr->data + sr->data_offset - sizeof(ElfW(Rela)));
289 rel->r_addend = -4;289 rel->r_addend = -4;
290#else290#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,
292 cur_text_section->data[ind-3],293 cur_text_section->data[ind-3],
293 cur_text_section->data[ind-2],294 cur_text_section->data[ind-2],
294 cur_text_section->data[ind-1]295 cur_text_section->data[ind-1]
@@ -603,8 +604,11 @@ static void gcall_or_jmp(int is_jmp) · 308 unmodified lines
603 /* constant case */604 /* constant case */
604 if (vtop->r & VT_SYM) {605 if (vtop->r & VT_SYM) {
605 /* relocation case */606 /* relocation case */
606 greloc(cur_text_section, vtop->sym,607#ifdef TCC_TARGET_PE
607 ind + 1, R_X86_64_PLT32);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
608 } else {612 } else {
609 /* put an empty PC32 relocation */613 /* put an empty PC32 relocation */
610 put_elf_reloc(symtab_section, cur_text_section,614 put_elf_reloc(symtab_section, cur_text_section,