From owner-svn-src-all@FreeBSD.ORG Wed Jul 21 09:47:15 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 335021065692; Wed, 21 Jul 2010 09:47:15 +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 090728FC16; Wed, 21 Jul 2010 09:47:15 +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 o6L9lEfi079238; Wed, 21 Jul 2010 09:47:14 GMT (envelope-from kaiw@svn.freebsd.org) Received: (from kaiw@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o6L9lELb079234; Wed, 21 Jul 2010 09:47:14 GMT (envelope-from kaiw@svn.freebsd.org) Message-Id: <201007210947.o6L9lELb079234@svn.freebsd.org> From: Kai Wang Date: Wed, 21 Jul 2010 09:47:14 +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: r210330 - head/lib/libelf 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: Wed, 21 Jul 2010 09:47:15 -0000 Author: kaiw Date: Wed Jul 21 09:47:14 2010 New Revision: 210330 URL: http://svn.freebsd.org/changeset/base/210330 Log: Allow an application that updates only the ELF Ehdr to work. Obtained from: elftoolchain MFC after: 1 month Modified: head/lib/libelf/_libelf.h head/lib/libelf/elf_scn.c head/lib/libelf/elf_update.c Modified: head/lib/libelf/_libelf.h ============================================================================== --- head/lib/libelf/_libelf.h Wed Jul 21 09:33:45 2010 (r210329) +++ head/lib/libelf/_libelf.h Wed Jul 21 09:47:14 2010 (r210330) @@ -176,6 +176,7 @@ void (*_libelf_get_translator(Elf_Type _ void *_libelf_getphdr(Elf *_e, int _elfclass); void *_libelf_getshdr(Elf_Scn *_scn, int _elfclass); void _libelf_init_elf(Elf *_e, Elf_Kind _kind); +int _libelf_load_scn(Elf *e, void *ehdr); int _libelf_malign(Elf_Type _t, int _elfclass); size_t _libelf_msize(Elf_Type _t, int _elfclass, unsigned int _version); void *_libelf_newphdr(Elf *_e, int _elfclass, size_t _count); Modified: head/lib/libelf/elf_scn.c ============================================================================== --- head/lib/libelf/elf_scn.c Wed Jul 21 09:33:45 2010 (r210329) +++ head/lib/libelf/elf_scn.c Wed Jul 21 09:47:14 2010 (r210330) @@ -38,7 +38,7 @@ __FBSDID("$FreeBSD$"); /* * Load an ELF section table and create a list of Elf_Scn structures. */ -static int +int _libelf_load_scn(Elf *e, void *ehdr) { int ec, swapbytes; Modified: head/lib/libelf/elf_update.c ============================================================================== --- head/lib/libelf/elf_update.c Wed Jul 21 09:33:45 2010 (r210329) +++ head/lib/libelf/elf_update.c Wed Jul 21 09:47:14 2010 (r210330) @@ -472,6 +472,11 @@ _libelf_resync_elf(Elf *e) * file. */ + if (e->e_cmd != ELF_C_WRITE && + (e->e_flags & LIBELF_F_SHDRS_LOADED) == 0 && + _libelf_load_scn(e, ehdr) == 0) + return ((off_t) -1); + if ((rc = _libelf_resync_sections(e, rc)) < 0) return ((off_t) -1); @@ -726,14 +731,9 @@ _libelf_write_elf(Elf *e, off_t newsize) assert(phoff % _libelf_falign(ELF_T_PHDR, ec) == 0); assert(fsz > 0); + src.d_buf = _libelf_getphdr(e, ec); src.d_version = dst.d_version = e->e_version; src.d_type = ELF_T_PHDR; - - if (ec == ELFCLASS32) - src.d_buf = e->e_u.e_elf.e_phdr.e_phdr32; - else - src.d_buf = e->e_u.e_elf.e_phdr.e_phdr64; - src.d_size = phnum * _libelf_msize(ELF_T_PHDR, ec, e->e_version);