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
17141714 for (sk = sk_unknown; sk < sk_last; sk++) {
17151715 struct section_64 *sec = NULL;
17161716 if (seg) {
1717− seg->vmsize = (curaddr - seg->vmaddr + SEG_PAGE_SIZE - 1) & -SEG_PAGE_SIZE;
1718− seg->filesize = (fileofs - seg->fileoff + SEG_PAGE_SIZE - 1) & -SEG_PAGE_SIZE;
1719− curaddr = seg->vmaddr + seg->vmsize;
1720− fileofs = seg->fileoff + seg->filesize;
1717+ seg->vmsize = curaddr - seg->vmaddr;
1718+ seg->filesize = fileofs - seg->fileoff;
17211719 }
17221720 #ifdef CONFIG_NEW_MACHO
17231721 if (sk == sk_linkedit) {
@@ -1961,17 +1959,6 @@ ST_FUNC void bind_rebase_import(TCCState *s1, struct macho *mo) · 237 unmodified lines
19611959 mo->bind_rebase[i + 1].bind ? "bind" : "rebase",
19621960 s1->sections[mo->bind_rebase[i].section]->name, name);
19631961 }
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− }
19751962 header = (struct dyld_chained_fixups_header *) data;
19761963 data += (sizeof(struct dyld_chained_fixups_header) + 7) & -8;
19771964 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
20242011 addr_t r_offset = mo->bind_rebase[k].rel.r_offset;
20252012 addr_t addr = s->sh_addr + r_offset;
20262013
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);
20272018 if (addr >= end)
20282019 break;
20292020 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