Module Name: src Committed By: maxv Date: Mon Nov 13 20:21:10 UTC 2017
Modified Files: src/sys/lib/libsa: loadfile_elf32.c Log Message: Revert my last revision, that is to say, don't group sections into segments anymore. Initially I did this because I wanted to compress the sections by reducing the padding between them; but we'll handle that differently. To generate a diff of this commit: cvs rdiff -u -r1.48 -r1.49 src/sys/lib/libsa/loadfile_elf32.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/lib/libsa/loadfile_elf32.c diff -u src/sys/lib/libsa/loadfile_elf32.c:1.48 src/sys/lib/libsa/loadfile_elf32.c:1.49 --- src/sys/lib/libsa/loadfile_elf32.c:1.48 Wed Oct 18 16:29:56 2017 +++ src/sys/lib/libsa/loadfile_elf32.c Mon Nov 13 20:21:10 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: loadfile_elf32.c,v 1.48 2017/10/18 16:29:56 maxv Exp $ */ +/* $NetBSD: loadfile_elf32.c,v 1.49 2017/11/13 20:21:10 maxv Exp $ */ /* * Copyright (c) 1997, 2008, 2017 The NetBSD Foundation, Inc. @@ -341,7 +341,7 @@ ELFNAMEEND(loadfile_dynamic)(int fd, Elf { const u_long offset = 0; Elf_Shdr *shdr; - Elf_Addr shpp, addr, align; + Elf_Addr shpp, addr; int i, j, loaded; size_t size, shdrsz; Elf_Addr maxp, elfp = 0; @@ -383,101 +383,11 @@ ELFNAMEEND(loadfile_dynamic)(int fd, Elf maxp += roundup(shdrsz, ELFROUND); /* - * Load the KERNEL SECTIONS, and group them into segments. First text, - * then rodata, then data. Between sections, we align to the requested - * section alignment. Between segments, we align to KERNALIGN. + * Load the KERNEL SECTIONS. */ - - /* text */ - maxp = roundup(maxp, KERNALIGN); - for (i = 0; i < elf->e_shnum; i++) { - if (!(shdr[i].sh_flags & SHF_EXECINSTR)) { - continue; - } - align = shdr[i].sh_addralign; - if (align == 0) { - align = ELFROUND; - } - addr = roundup(maxp, align); - size = (size_t)shdr[i].sh_size; - - loaded = 0; - switch (shdr[i].sh_type) { - case SHT_NOBITS: - /* Zero out bss. */ - BZERO(addr, size); - loaded = 1; - break; - case SHT_PROGBITS: - ret = ELFNAMEEND(readfile_global)(fd, offset, - shdr[i].sh_offset, addr, size); - if (ret == -1) { - goto out; - } - loaded = 1; - break; - default: - loaded = 0; - break; - } - - if (loaded) { - shdr[i].sh_offset = addr - elfp; - maxp = addr + size; - } - } - - /* rodata */ - maxp = roundup(maxp, KERNALIGN); - for (i = 0; i < elf->e_shnum; i++) { - if ((shdr[i].sh_flags & (SHF_EXECINSTR|SHF_WRITE))) { - continue; - } - align = shdr[i].sh_addralign; - if (align == 0) { - align = ELFROUND; - } - addr = roundup(maxp, align); - size = (size_t)shdr[i].sh_size; - - loaded = 0; - switch (shdr[i].sh_type) { - case SHT_NOBITS: - /* Zero out bss. */ - BZERO(addr, size); - loaded = 1; - break; - case SHT_PROGBITS: - ret = ELFNAMEEND(readfile_global)(fd, offset, - shdr[i].sh_offset, addr, size); - if (ret == -1) { - goto out; - } - loaded = 1; - break; - default: - loaded = 0; - break; - } - - if (loaded) { - shdr[i].sh_offset = addr - elfp; - maxp = addr + size; - } - } - - /* data */ maxp = roundup(maxp, KERNALIGN); for (i = 0; i < elf->e_shnum; i++) { - if (!(shdr[i].sh_flags & SHF_WRITE) || - (shdr[i].sh_flags & SHF_EXECINSTR)) { - continue; - } - align = shdr[i].sh_addralign; - if (align == 0) { - align = ELFROUND; - } - addr = roundup(maxp, align); + addr = maxp; size = (size_t)shdr[i].sh_size; loaded = 0; @@ -501,15 +411,15 @@ ELFNAMEEND(loadfile_dynamic)(int fd, Elf } if (loaded) { - shdr[i].sh_offset = addr - elfp; - maxp = addr + size; + shdr[i].sh_offset = maxp - elfp; + maxp = roundup(maxp + size, KERNALIGN); } } /* * Load the SYM+REL SECTIONS. */ - maxp = roundup(maxp, KERNALIGN); + maxp = roundup(maxp, ELFROUND); for (i = 0; i < elf->e_shnum; i++) { addr = maxp; size = (size_t)shdr[i].sh_size;