To allow remapping the ro section the next section must start on a new page.
Unified · Split
| @@ -47,6 +47,10 @@ struct sym_version { · 46 unmodified lines | |||
| 47 | /* section is dynsymtab_section */ | 47 | /* section is dynsymtab_section */ |
| 48 | #define SHF_DYNSYM 0x40000000 | 48 | #define SHF_DYNSYM 0x40000000 |
| 49 | 49 | ||
| 50 | #ifndef PAGESIZE | ||
| 51 | # define PAGESIZE 4096 | ||
| 52 | #endif | ||
| 53 | |||
| 50 | /* ------------------------------------------------------------------------- */ | 54 | /* ------------------------------------------------------------------------- */ |
| 51 | 55 | ||
| 52 | ST_FUNC void tccelf_new(TCCState *s) | 56 | ST_FUNC void tccelf_new(TCCState *s) |
| @@ -1871,7 +1875,7 @@ static int layout_sections(TCCState *s1, ElfW(Phdr) *phdr, · 1818 unmodified lines | |||
| 1871 | long long tmp; | 1875 | long long tmp; |
| 1872 | addr_t addr; | 1876 | addr_t addr; |
| 1873 | ElfW(Phdr) *ph; | 1877 | ElfW(Phdr) *ph; |
| 1874 | int j, k, file_type = s1->output_type; | 1878 | int j, k, f, file_type = s1->output_type; |
| 1875 | 1879 | ||
| 1876 | s_align = ELF_PAGE_SIZE; | 1880 | s_align = ELF_PAGE_SIZE; |
| 1877 | if (s1->section_align) | 1881 | if (s1->section_align) |
| @@ -1924,6 +1928,7 @@ static int layout_sections(TCCState *s1, ElfW(Phdr) *phdr, · 46 unmodified lines | |||
| 1924 | info about the layout. We do the following ordering: interp, | 1928 | info about the layout. We do the following ordering: interp, |
| 1925 | symbol tables, relocations, progbits, nobits */ | 1929 | symbol tables, relocations, progbits, nobits */ |
| 1926 | /* XXX: do faster and simpler sorting */ | 1930 | /* XXX: do faster and simpler sorting */ |
| 1931 | f = -1; | ||
| 1927 | for(k = 0; k < 7; k++) { | 1932 | for(k = 0; k < 7; k++) { |
| 1928 | for(i = 1; i < s1->nb_sections; i++) { | 1933 | for(i = 1; i < s1->nb_sections; i++) { |
| 1929 | s = s1->sections[i]; | 1934 | s = s1->sections[i]; |
| @@ -1966,6 +1971,9 @@ static int layout_sections(TCCState *s1, ElfW(Phdr) *phdr, · 36 unmodified lines | |||
| 1966 | 0) { | 1971 | 0) { |
| 1967 | if (k != 4) | 1972 | if (k != 4) |
| 1968 | continue; | 1973 | continue; |
| 1974 | /* Align next section on page size. | ||
| 1975 | This is needed to remap roinf section ro. */ | ||
| 1976 | f = 1; | ||
| 1969 | } else { | 1977 | } else { |
| 1970 | if (k != 5) | 1978 | if (k != 5) |
| 1971 | continue; | 1979 | continue; |
| @@ -1974,6 +1982,8 @@ static int layout_sections(TCCState *s1, ElfW(Phdr) *phdr, · 2 unmodified lines | |||
| 1974 | 1982 | ||
| 1975 | /* section matches: we align it and add its size */ | 1983 | /* section matches: we align it and add its size */ |
| 1976 | tmp = addr; | 1984 | tmp = addr; |
| 1985 | if (f-- == 0) | ||
| 1986 | s->sh_addralign = PAGESIZE; | ||
| 1977 | addr = (addr + s->sh_addralign - 1) & | 1987 | addr = (addr + s->sh_addralign - 1) & |
| 1978 | ~(s->sh_addralign - 1); | 1988 | ~(s->sh_addralign - 1); |
| 1979 | file_offset += (int) ( addr - tmp ); | 1989 | file_offset += (int) ( addr - tmp ); |