History

Reduce memory size macho executables

Do not align vmsize/filesize to SEG_PAGE_SIZE every time. Move rel_offset check down due to this change.

herman ten brugge committed 3 years ago

Commit b7356bb1 parent 6b398681 file · +6 −15Browse files

Unified · Split

tccmacho.c+6−15
@@ -1714,10 +1714,8 @@ static void collect_sections(TCCState *s1, struct macho *mo) · 1713 unmodified lines
1714 for (sk = sk_unknown; sk < sk_last; sk++) {1714 for (sk = sk_unknown; sk < sk_last; sk++) {
1715 struct section_64 *sec = NULL;1715 struct section_64 *sec = NULL;
1716 if (seg) {1716 if (seg) {
1717 seg->vmsize = (curaddr - seg->vmaddr + SEG_PAGE_SIZE - 1) & -SEG_PAGE_SIZE;1717 seg->vmsize = curaddr - seg->vmaddr;
1718 seg->filesize = (fileofs - seg->fileoff + SEG_PAGE_SIZE - 1) & -SEG_PAGE_SIZE;1718 seg->filesize = fileofs - seg->fileoff;
1719 curaddr = seg->vmaddr + seg->vmsize;
1720 fileofs = seg->fileoff + seg->filesize;
1721 }1719 }
1722#ifdef CONFIG_NEW_MACHO1720#ifdef CONFIG_NEW_MACHO
1723 if (sk == sk_linkedit) {1721 if (sk == sk_linkedit) {
@@ -1961,17 +1959,6 @@ ST_FUNC void bind_rebase_import(TCCState *s1, struct macho *mo) · 237 unmodified lines
1961 mo->bind_rebase[i + 1].bind ? "bind" : "rebase",1959 mo->bind_rebase[i + 1].bind ? "bind" : "rebase",
1962 s1->sections[mo->bind_rebase[i].section]->name, name);1960 s1->sections[mo->bind_rebase[i].section]->name, name);
1963 }1961 }
1964 for (i = 0; i < mo->n_bind_rebase; i++) {
1965 addr_t r_offset = mo->bind_rebase[i].rel.r_offset;
1966 if ((r_offset & 3) ||
1967 (r_offset & (SEG_PAGE_SIZE - 1)) >
1968 SEG_PAGE_SIZE - PTR_SIZE) {
1969 Section *s = s1->sections[mo->bind_rebase[i].section];
1970
1971 tcc_error("Illegal rel_offset %s %lld",
1972 s->name, (long long)r_offset);
1973 }
1974 }
1975 header = (struct dyld_chained_fixups_header *) data;1962 header = (struct dyld_chained_fixups_header *) data;
1976 data += (sizeof(struct dyld_chained_fixups_header) + 7) & -8;1963 data += (sizeof(struct dyld_chained_fixups_header) + 7) & -8;
1977 header->starts_offset = data - mo->chained_fixups->data;1964 header->starts_offset = data - mo->chained_fixups->data;
@@ -2024,6 +2011,10 @@ ST_FUNC void bind_rebase_import(TCCState *s1, struct macho *mo) · 46 unmodified lines
2024 addr_t r_offset = mo->bind_rebase[k].rel.r_offset;2011 addr_t r_offset = mo->bind_rebase[k].rel.r_offset;
2025 addr_t addr = s->sh_addr + r_offset;2012 addr_t addr = s->sh_addr + r_offset;
2026 2013
2014 if ((addr & 3) ||
2015 (addr & (SEG_PAGE_SIZE - 1)) > SEG_PAGE_SIZE - PTR_SIZE)
2016 tcc_error("Illegal rel_offset %s %lld",
2017 s->name, (long long)r_offset);
2027 if (addr >= end)2018 if (addr >= end)
2028 break;2019 break;
2029 if (addr >= start) {2020 if (addr >= start) {

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