From owner-svn-src-all@FreeBSD.ORG Fri Jul 23 17:07:52 2010 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 5906B1065676; Fri, 23 Jul 2010 17:07:52 +0000 (UTC) (envelope-from avg@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 2EF318FC14; Fri, 23 Jul 2010 17:07:52 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o6NH7qoM059559; Fri, 23 Jul 2010 17:07:52 GMT (envelope-from avg@svn.freebsd.org) Received: (from avg@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o6NH7q8r059556; Fri, 23 Jul 2010 17:07:52 GMT (envelope-from avg@svn.freebsd.org) Message-Id: <201007231707.o6NH7q8r059556@svn.freebsd.org> From: Andriy Gapon Date: Fri, 23 Jul 2010 17:07:52 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r210423 - in head/sys: boot/common kern X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 23 Jul 2010 17:07:52 -0000 Author: avg Date: Fri Jul 23 17:07:51 2010 New Revision: 210423 URL: http://svn.freebsd.org/changeset/base/210423 Log: completely ignore zero-sized elf sections in modules of elf object type (amd64) Current code doesn't check size of elf sections and may perform needless actions of zero-sized memory allocation and similar. The bigger issue is that alignment requirement of a zero-sized section gets effectively applied to the next section if it has smaller alignment requirement. But other tools, like gdb and consequently kgdb, completely ignore zero-sized sections and thus may map symbols to addresses differently. Zero-sized sections are not typical in general. Their typical (only, even) cause in FreeBSD modules is inline assembly that creates custom sections which is found in pcpu.h and vnet.h. Mere inclusion of one of those header files produces a custom section in elf output. If there is no actual use for the section in a given module, then the section remains empty. Better solution is to avoid creating zero-sized sections altogether, which is in plans. Preloaded modules are handled in boot code (load_elf_obj.c), while dynamically loaded modules are handled by kernel (link_elf_obj.c). Based on code by: np MFC after: 3 weeks Modified: head/sys/boot/common/load_elf_obj.c head/sys/kern/link_elf_obj.c Modified: head/sys/boot/common/load_elf_obj.c ============================================================================== --- head/sys/boot/common/load_elf_obj.c Fri Jul 23 16:46:42 2010 (r210422) +++ head/sys/boot/common/load_elf_obj.c Fri Jul 23 17:07:51 2010 (r210423) @@ -221,6 +221,8 @@ __elfN(obj_loadimage)(struct preloaded_f for (i = 0; i < hdr->e_shnum; i++) shdr[i].sh_addr = 0; for (i = 0; i < hdr->e_shnum; i++) { + if (shdr[i].sh_size == 0) + continue; switch (shdr[i].sh_type) { case SHT_PROGBITS: case SHT_NOBITS: Modified: head/sys/kern/link_elf_obj.c ============================================================================== --- head/sys/kern/link_elf_obj.c Fri Jul 23 16:46:42 2010 (r210422) +++ head/sys/kern/link_elf_obj.c Fri Jul 23 17:07:51 2010 (r210423) @@ -555,6 +555,8 @@ link_elf_load_file(linker_class_t cls, c symtabindex = -1; symstrindex = -1; for (i = 0; i < hdr->e_shnum; i++) { + if (shdr[i].sh_size == 0) + continue; switch (shdr[i].sh_type) { case SHT_PROGBITS: case SHT_NOBITS: @@ -677,6 +679,8 @@ link_elf_load_file(linker_class_t cls, c /* Size up code/data(progbits) and bss(nobits). */ alignmask = 0; for (i = 0; i < hdr->e_shnum; i++) { + if (shdr[i].sh_size == 0) + continue; switch (shdr[i].sh_type) { case SHT_PROGBITS: case SHT_NOBITS: @@ -737,6 +741,8 @@ link_elf_load_file(linker_class_t cls, c ra = 0; alignmask = 0; for (i = 0; i < hdr->e_shnum; i++) { + if (shdr[i].sh_size == 0) + continue; switch (shdr[i].sh_type) { case SHT_PROGBITS: case SHT_NOBITS: