Module Name: src Committed By: maxv Date: Fri Jan 6 09:14:36 UTC 2017
Modified Files: src/sys/lib/libsa: loadfile_elf32.c Log Message: Explain how all that mess works, without actually fixing it yet. To generate a diff of this commit: cvs rdiff -u -r1.33 -r1.34 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.33 src/sys/lib/libsa/loadfile_elf32.c:1.34 --- src/sys/lib/libsa/loadfile_elf32.c:1.33 Sat Dec 3 09:20:55 2016 +++ src/sys/lib/libsa/loadfile_elf32.c Fri Jan 6 09:14:36 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: loadfile_elf32.c,v 1.33 2016/12/03 09:20:55 maxv Exp $ */ +/* $NetBSD: loadfile_elf32.c,v 1.34 2017/01/06 09:14:36 maxv Exp $ */ /* * Copyright (c) 1997, 2008 The NetBSD Foundation, Inc. @@ -259,6 +259,21 @@ externalize_shdr(Elf_Byte bo, Elf_Shdr * #define IS_DATA(p) (p.p_flags & PF_W) #define IS_BSS(p) (p.p_filesz < p.p_memsz) +/* + * Load the ELF binary into memory. Layout of the memory: + * +-----------------+------------+-----------------+-----------------+ + * | KERNEL SEGMENTS | ELF HEADER | SECTION HEADERS | SYMBOL SECTIONS | + * +-----------------+------------+-----------------+-----------------+ + * The KERNEL SEGMENTS start address is fixed by the segments themselves. We + * then map the rest by increasing maxp. + * + * The offsets of the SYMBOL SECTIONS are relative to the start address of the + * ELF HEADER. The shdr offset of ELF HEADER points to SECTION HEADERS. + * + * We just give the kernel a pointer to the ELF HEADER, which is enough for it + * to find the location and number of symbols by itself later. + */ + int ELFNAMEEND(loadfile)(int fd, Elf_Ehdr *elf, u_long *marks, int flags) {