History

Align next section after gnu_ro to pagesize

To allow remapping the ro section the next section must start on a new page.

herman ten brugge committed 5 years ago

Commit 3221cc41 parent b147a371 file · +11 −1Browse files

Unified · Split

tccelf.c+11−1
@@ -47,6 +47,10 @@ struct sym_version { · 46 unmodified lines
4747 /* section is dynsymtab_section */
4848 #define SHF_DYNSYM 0x40000000
4949
50+#ifndef PAGESIZE
51+# define PAGESIZE 4096
52+#endif
53+
5054 /* ------------------------------------------------------------------------- */
5155
5256 ST_FUNC void tccelf_new(TCCState *s)
@@ -1871,7 +1875,7 @@ static int layout_sections(TCCState *s1, ElfW(Phdr) *phdr, · 1818 unmodified lines
18711875 long long tmp;
18721876 addr_t addr;
18731877 ElfW(Phdr) *ph;
1874− int j, k, file_type = s1->output_type;
1878+ int j, k, f, file_type = s1->output_type;
18751879
18761880 s_align = ELF_PAGE_SIZE;
18771881 if (s1->section_align)
@@ -1924,6 +1928,7 @@ static int layout_sections(TCCState *s1, ElfW(Phdr) *phdr, · 46 unmodified lines
19241928 info about the layout. We do the following ordering: interp,
19251929 symbol tables, relocations, progbits, nobits */
19261930 /* XXX: do faster and simpler sorting */
1931+ f = -1;
19271932 for(k = 0; k < 7; k++) {
19281933 for(i = 1; i < s1->nb_sections; i++) {
19291934 s = s1->sections[i];
@@ -1966,6 +1971,9 @@ static int layout_sections(TCCState *s1, ElfW(Phdr) *phdr, · 36 unmodified lines
19661971 0) {
19671972 if (k != 4)
19681973 continue;
1974+ /* Align next section on page size.
1975+ This is needed to remap roinf section ro. */
1976+ f = 1;
19691977 } else {
19701978 if (k != 5)
19711979 continue;
@@ -1974,6 +1982,8 @@ static int layout_sections(TCCState *s1, ElfW(Phdr) *phdr, · 2 unmodified lines
19741982
19751983 /* section matches: we align it and add its size */
19761984 tmp = addr;
1985+ if (f-- == 0)
1986+ s->sh_addralign = PAGESIZE;
19771987 addr = (addr + s->sh_addralign - 1) &
19781988 ~(s->sh_addralign - 1);
19791989 file_offset += (int) ( addr - tmp );

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t