Module Name: src Committed By: manu Date: Fri Oct 18 01:15:54 UTC 2019
Modified Files: src/sys/arch/i386/stand/lib: exec_multiboot2.c Log Message: Fix kernel symbols for multiboot2 Previous version just provided the ELF section table, which is correct as far as the multiboot 2 specification is concerned. But in order to retreive kernel symboles, the NetBSD kernelneeds symbol table and string table sections to be loaded in memory, and have an address set in the section table. Requires change: Add kernel symbols for multiboot1 src/sys/arch/i386/stand/lib/exec_multiboot1.c 1.2 - 1.3 src/sys/arch/i386/stand/lib/libi386.h 1.45 - 1.46 To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/sys/arch/i386/stand/lib/exec_multiboot2.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/arch/i386/stand/lib/exec_multiboot2.c diff -u src/sys/arch/i386/stand/lib/exec_multiboot2.c:1.2 src/sys/arch/i386/stand/lib/exec_multiboot2.c:1.3 --- src/sys/arch/i386/stand/lib/exec_multiboot2.c:1.2 Sun Sep 15 23:55:26 2019 +++ src/sys/arch/i386/stand/lib/exec_multiboot2.c Fri Oct 18 01:15:54 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: exec_multiboot2.c,v 1.2 2019/09/15 23:55:26 manu Exp $ */ +/* $NetBSD: exec_multiboot2.c,v 1.3 2019/10/18 01:15:54 manu Exp $ */ /* * Copyright (c) 2019 The NetBSD Foundation, Inc. @@ -976,9 +976,10 @@ mbi_elf_sections(struct multiboot_packag size_t len = 0; struct multiboot_tag_elf_sections *mbt = buf; Elf_Ehdr ehdr; + int class; Elf32_Ehdr *ehdr32 = NULL; Elf64_Ehdr *ehdr64 = NULL; - uint32_t shnum, shentsize, shstrndx, shoff; + uint64_t shnum, shentsize, shstrndx, shoff; size_t shdr_len; if (mbp->mbp_marks[MARK_SYM] == 0) @@ -992,7 +993,9 @@ mbi_elf_sections(struct multiboot_packag if (memcmp(&ehdr.e_ident, ELFMAG, SELFMAG) != 0) goto out; - switch (ehdr.e_ident[EI_CLASS]) { + class = ehdr.e_ident[EI_CLASS]; + + switch (class) { case ELFCLASS32: ehdr32 = (Elf32_Ehdr *)&ehdr; shnum = ehdr32->e_shnum; @@ -1017,8 +1020,7 @@ mbi_elf_sections(struct multiboot_packag len = sizeof(*mbt) + shdr_len; if (mbt) { - int fd = -1; - int ret = -1; + char *shdr = (char *)mbp->mbp_marks[MARK_SYM] + shoff; mbt->type = MULTIBOOT_TAG_TYPE_ELF_SECTIONS; mbt->size = len; @@ -1026,26 +1028,16 @@ mbi_elf_sections(struct multiboot_packag mbt->entsize = shentsize; mbt->shndx = shstrndx; - if ((fd = open(mbp->mbp_file, 0)) == -1) - goto out_read; - - if (lseek(fd, shoff, SEEK_SET) != shoff) - goto out_read; - - if (read(fd, mbt + 1, shdr_len) != shdr_len) - goto out_read; + pvbcopy((void *)shdr, mbt + 1, shdr_len); - ret = 0; -out_read: - if (fd != -1) - close(fd); - - if (ret != 0) { - printf("Error reading ELF sections from %s\n", - mbp->mbp_file); - len = 0; - } + /* + * Adjust sh_addr for symtab and strtab + * section that have been loaded. + */ + ksyms_addr_set(&ehdr, mbt + 1, + (void *)mbp->mbp_marks[MARK_SYM]); } + out: return roundup(len, MULTIBOOT_TAG_ALIGN); }