From owner-svn-src-stable-7@FreeBSD.ORG Sat Sep 4 12:19:26 2010 Return-Path: Delivered-To: svn-src-stable-7@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 91A5110656F4; Sat, 4 Sep 2010 12:19:25 +0000 (UTC) (envelope-from kaiw@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 6F2EB8FC08; Sat, 4 Sep 2010 12:19:25 +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 o84CJPA0006198; Sat, 4 Sep 2010 12:19:25 GMT (envelope-from kaiw@svn.freebsd.org) Received: (from kaiw@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o84CJPpd006192; Sat, 4 Sep 2010 12:19:25 GMT (envelope-from kaiw@svn.freebsd.org) Message-Id: <201009041219.o84CJPpd006192@svn.freebsd.org> From: Kai Wang Date: Sat, 4 Sep 2010 12:19:25 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-7@freebsd.org X-SVN-Group: stable-7 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r212201 - stable/7/lib/libelf X-BeenThere: svn-src-stable-7@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for only the 7-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 04 Sep 2010 12:19:26 -0000 Author: kaiw Date: Sat Sep 4 12:19:25 2010 New Revision: 212201 URL: http://svn.freebsd.org/changeset/base/212201 Log: MFC r210325,r210326,r210328,r210349 r210325: Bug fix: when updating headers using the gelf_update_*() functions, the appropriate `dirty' bit needs to be set for both the Elf32 and Elf64 case. r210326: Improve compatibility with other implementations of the ELF(3) API: when an output file has no program headers, set the 'e_phentsize' field of the ELF executable header to zero. r210328: Bug fix: permit the creation of zero-sized sections. r210349: Remove a redundant word. Modified: stable/7/lib/libelf/elf.3 stable/7/lib/libelf/elf_update.c stable/7/lib/libelf/gelf_ehdr.c stable/7/lib/libelf/gelf_phdr.c stable/7/lib/libelf/gelf_shdr.c Directory Properties: stable/7/lib/libelf/ (props changed) Modified: stable/7/lib/libelf/elf.3 ============================================================================== --- stable/7/lib/libelf/elf.3 Sat Sep 4 12:19:19 2010 (r212200) +++ stable/7/lib/libelf/elf.3 Sat Sep 4 12:19:25 2010 (r212201) @@ -36,8 +36,8 @@ .Sh DESCRIPTION The .Lb libelf -library provides functions that allow an application to read and -manipulate ELF object files, and to read +provides functions that allow an application to read and manipulate +ELF object files, and to read .Xr ar 1 archives. The library allows the manipulation of ELF objects in a byte ordering Modified: stable/7/lib/libelf/elf_update.c ============================================================================== --- stable/7/lib/libelf/elf_update.c Sat Sep 4 12:19:19 2010 (r212200) +++ stable/7/lib/libelf/elf_update.c Sat Sep 4 12:19:25 2010 (r212201) @@ -422,8 +422,8 @@ _libelf_resync_elf(Elf *e) (E)->e_ident[EI_VERSION] = (V); \ (E)->e_ehsize = _libelf_fsize(ELF_T_EHDR, (EC), (V), \ (size_t) 1); \ - (E)->e_phentsize = _libelf_fsize(ELF_T_PHDR, (EC), (V), \ - (size_t) 1); \ + (E)->e_phentsize = (phnum == 0) ? 0 : _libelf_fsize( \ + ELF_T_PHDR, (EC), (V), (size_t) 1); \ (E)->e_shentsize = _libelf_fsize(ELF_T_SHDR, (EC), (V), \ (size_t) 1); \ } while (0) @@ -534,22 +534,24 @@ _libelf_write_scn(Elf *e, char *nf, Elf_ int ec; size_t fsz, msz, nobjects; uint32_t sh_type; - uint64_t sh_off; + uint64_t sh_off, sh_size; int elftype; Elf_Data *d, dst; - if ((ec = e->e_class) == ELFCLASS32) + if ((ec = e->e_class) == ELFCLASS32) { sh_type = s->s_shdr.s_shdr32.sh_type; - else + sh_size = (uint64_t) s->s_shdr.s_shdr32.sh_size; + } else { sh_type = s->s_shdr.s_shdr64.sh_type; + sh_size = s->s_shdr.s_shdr64.sh_size; + } /* * Ignore sections that do not allocate space in the file. */ - if (sh_type == SHT_NOBITS || sh_type == SHT_NULL) + if (sh_type == SHT_NOBITS || sh_type == SHT_NULL || sh_size == 0) return (rc); - elftype = _libelf_xlate_shtype(sh_type); assert(elftype >= ELF_T_FIRST && elftype <= ELF_T_LAST); Modified: stable/7/lib/libelf/gelf_ehdr.c ============================================================================== --- stable/7/lib/libelf/gelf_ehdr.c Sat Sep 4 12:19:19 2010 (r212200) +++ stable/7/lib/libelf/gelf_ehdr.c Sat Sep 4 12:19:25 2010 (r212201) @@ -137,6 +137,8 @@ gelf_update_ehdr(Elf *e, GElf_Ehdr *s) if ((ehdr = _libelf_ehdr(e, ec, 0)) == NULL) return (0); + (void) elf_flagehdr(e, ELF_C_SET, ELF_F_DIRTY); + if (ec == ELFCLASS64) { eh64 = (Elf64_Ehdr *) ehdr; *eh64 = *s; @@ -161,7 +163,5 @@ gelf_update_ehdr(Elf *e, GElf_Ehdr *s) eh32->e_shnum = s->e_shnum; eh32->e_shstrndx = s->e_shstrndx; - (void) elf_flagehdr(e, ELF_C_SET, ELF_F_DIRTY); - return (1); } Modified: stable/7/lib/libelf/gelf_phdr.c ============================================================================== --- stable/7/lib/libelf/gelf_phdr.c Sat Sep 4 12:19:19 2010 (r212200) +++ stable/7/lib/libelf/gelf_phdr.c Sat Sep 4 12:19:25 2010 (r212201) @@ -155,6 +155,8 @@ gelf_update_phdr(Elf *e, int ndx, GElf_P return (0); } + (void) elf_flagphdr(e, ELF_C_SET, ELF_F_DIRTY); + if (ec == ELFCLASS64) { ph64 = e->e_u.e_elf.e_phdr.e_phdr64 + ndx; *ph64 = *s; @@ -172,7 +174,5 @@ gelf_update_phdr(Elf *e, int ndx, GElf_P LIBELF_COPY_U32(ph32, s, p_memsz); LIBELF_COPY_U32(ph32, s, p_align); - (void) elf_flagphdr(e, ELF_C_SET, ELF_F_DIRTY); - return (1); } Modified: stable/7/lib/libelf/gelf_shdr.c ============================================================================== --- stable/7/lib/libelf/gelf_shdr.c Sat Sep 4 12:19:19 2010 (r212200) +++ stable/7/lib/libelf/gelf_shdr.c Sat Sep 4 12:19:25 2010 (r212201) @@ -107,6 +107,8 @@ gelf_update_shdr(Elf_Scn *scn, GElf_Shdr return (0); } + (void) elf_flagscn(scn, ELF_C_SET, ELF_F_DIRTY); + if (ec == ELFCLASS64) { scn->s_shdr.s_shdr64 = *s; return (1); @@ -125,7 +127,5 @@ gelf_update_shdr(Elf_Scn *scn, GElf_Shdr LIBELF_COPY_U32(sh32, s, sh_addralign); LIBELF_COPY_U32(sh32, s, sh_entsize); - (void) elf_flagscn(scn, ELF_C_SET, ELF_F_DIRTY); - return (1); }