From owner-freebsd-hackers@FreeBSD.ORG Fri Jun 25 08:46:12 2010 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 75D2F1065675; Fri, 25 Jun 2010 08:46:12 +0000 (UTC) (envelope-from avg@freebsd.org) Received: from citadel.icyb.net.ua (citadel.icyb.net.ua [212.40.38.140]) by mx1.freebsd.org (Postfix) with ESMTP id 16B998FC17; Fri, 25 Jun 2010 08:46:10 +0000 (UTC) Received: from porto.topspin.kiev.ua (porto-e.starpoint.kiev.ua [212.40.38.100]) by citadel.icyb.net.ua (8.8.8p3/ICyb-2.3exp) with ESMTP id LAA20190; Fri, 25 Jun 2010 11:46:09 +0300 (EEST) (envelope-from avg@freebsd.org) Received: from localhost.topspin.kiev.ua ([127.0.0.1]) by porto.topspin.kiev.ua with esmtp (Exim 4.34 (FreeBSD)) id 1OS4Y5-000C5E-6S; Fri, 25 Jun 2010 11:46:09 +0300 Message-ID: <4C246CD0.3020606@freebsd.org> Date: Fri, 25 Jun 2010 11:46:08 +0300 From: Andriy Gapon User-Agent: Thunderbird 2.0.0.24 (X11/20100603) MIME-Version: 1.0 To: freebsd-hackers@freebsd.org X-Enigmail-Version: 0.96.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Cc: "Bjoern A. Zeeb" , Navdeep Parhar , Peter Wemm Subject: elf obj load: skip zero-sized sections early X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 25 Jun 2010 08:46:12 -0000 Proposed patch skips zero sized sections without going into trouble of allocating section entry (progtab), doing zero-sized memory allocs and copies. I observe that sometimes zero-sized set_pcpu sections are produced in module objects, maybe when a module doesn't create any per cpu data of its one, but references external pcpu data. Not sure. Main goal of this patch is to play nice with external debugging tools (e.g. kgdb) which ignore zero-sized sections outright. Current code effectively ignores but may apply their alignment to the next non-zero section if its required alignment is smaller. So the patch should get rid of that side effect as well as do some very tiny resource conservation. This work is based on np@'s investigation and original patch: http://lists.freebsd.org/pipermail/freebsd-hackers/2009-November/030093.html diff --git a/sys/boot/common/load_elf_obj.c b/sys/boot/common/load_elf_obj.c index 4b3aaea..6f3b349 100644 --- a/sys/boot/common/load_elf_obj.c +++ b/sys/boot/common/load_elf_obj.c @@ -221,6 +221,8 @@ __elfN(obj_loadimage)(struct preloaded_file *fp, elf_file_t ef, u_int64_t off) 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: diff --git a/sys/kern/link_elf_obj.c b/sys/kern/link_elf_obj.c index a337fd0..b0df57d 100644 --- a/sys/kern/link_elf_obj.c +++ b/sys/kern/link_elf_obj.c @@ -555,6 +555,8 @@ link_elf_load_file(linker_class_t cls, const char *filename, 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, const char *filename, /* 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, const char *filename, 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: -- Andriy Gapon