Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/lib/libsa Explain how all that mess works, without actua...



details:   https://anonhg.NetBSD.org/src/rev/620f70e35b75
branches:  trunk
changeset: 350152:620f70e35b75
user:      maxv <maxv%NetBSD.org@localhost>
date:      Fri Jan 06 09:14:36 2017 +0000

description:
Explain how all that mess works, without actually fixing it yet.

diffstat:

 sys/lib/libsa/loadfile_elf32.c |  17 ++++++++++++++++-
 1 files changed, 16 insertions(+), 1 deletions(-)

diffs (31 lines):

diff -r 5ed4482d7a86 -r 620f70e35b75 sys/lib/libsa/loadfile_elf32.c
--- a/sys/lib/libsa/loadfile_elf32.c    Fri Jan 06 09:14:07 2017 +0000
+++ b/sys/lib/libsa/loadfile_elf32.c    Fri Jan 06 09:14:36 2017 +0000
@@ -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 @@
 #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)
 {



Home | Main Index | Thread Index | Old Index