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