| @@ -1596,7 +1596,7 @@ ST_FUNC void fill_got_entry(TCCState *s1, ElfW_Rel *rel) · 1595 unmodified lines |
| 1596 | 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 */ |
| 1600 | 1600 | ST_FUNC void fill_got(TCCState *s1) |
| 1601 | 1601 | { |
| 1602 | 1602 | Section *s; |
| @@ -1848,6 +1848,7 @@ static int layout_sections(TCCState *s1, ElfW(Phdr) *phdr, int phnum, · 245 unmodified lines |
| 1848 | 1848 | int *sec_order) |
| 1849 | 1849 | { |
| 1850 | 1850 | int i, j, k, file_type, sh_order_index, file_offset; |
| 1851 | + unsigned long s_align; |
| 1851 | 1852 | long long tmp; |
| 1852 | 1853 | addr_t addr; |
| 1853 | 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 | 1857 | file_type = s1->output_type; |
| 1857 | 1858 | sh_order_index = 1; |
| 1859 | + file_offset = 0; |
| 1858 | 1860 | if (s1->output_format == TCC_OUTPUT_FORMAT_ELF) |
| 1859 | 1861 | 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; |
| 1862 | 1865 | |
| 1863 | 1866 | if (phnum > 0) { |
| 1864 | 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 | 1869 | addr = s1->text_addr; |
| 1867 | 1870 | /* we ensure that (addr % ELF_PAGE_SIZE) == file_offset % |
| 1868 | 1871 | 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); |
| 1871 | 1874 | if (a_offset < p_offset) |
| 1872 | | − a_offset += s1->section_align; |
| 1875 | + a_offset += s_align; |
| 1873 | 1876 | file_offset += (a_offset - p_offset); |
| 1874 | 1877 | } else { |
| 1875 | 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 | 1880 | else |
| 1878 | 1881 | addr = ELF_START_ADDR; |
| 1879 | 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 | 1886 | ph = &phdr[0]; |
| @@ -1899,7 +1902,7 @@ static int layout_sections(TCCState *s1, ElfW(Phdr) *phdr, int phnum, · 15 unmodified lines |
| 1899 | 1902 | ph->p_flags = PF_R | PF_X; |
| 1900 | 1903 | else |
| 1901 | 1904 | ph->p_flags = PF_R | PF_W; |
| 1902 | | − ph->p_align = s1->section_align; |
| 1905 | + ph->p_align = s_align; |
| 1903 | 1906 | |
| 1904 | 1907 | /* Decide the layout of sections loaded in memory. This must |
| 1905 | 1908 | 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 | 1994 | if (s1->output_format == TCC_OUTPUT_FORMAT_ELF) { |
| 1992 | 1995 | /* if in the middle of a page, we duplicate the page in |
| 1993 | 1996 | 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; |
| 1996 | 1999 | } 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); |
| 2000 | 2002 | } |
| 2001 | 2003 | } |
| 2002 | 2004 | } |
| @@ -2469,7 +2471,7 @@ static int elf_output_file(TCCState *s1, const char *filename) · 466 unmodified lines |
| 2469 | 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 | 2475 | if (file_type == TCC_OUTPUT_EXE && s1->static_link) |
| 2474 | 2476 | fill_got(s1); |
| 2475 | 2477 | |