From owner-svn-src-head@freebsd.org Fri Mar 20 15:50:38 2020 Return-Path: Delivered-To: svn-src-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 7FECA26AB11; Fri, 20 Mar 2020 15:50:38 +0000 (UTC) (envelope-from emaste@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 48kSsp2w9bz4G0J; Fri, 20 Mar 2020 15:50:38 +0000 (UTC) (envelope-from emaste@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 5F55E25E18; Fri, 20 Mar 2020 15:50:38 +0000 (UTC) (envelope-from emaste@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 02KFocuD053705; Fri, 20 Mar 2020 15:50:38 GMT (envelope-from emaste@FreeBSD.org) Received: (from emaste@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 02KFocgG053704; Fri, 20 Mar 2020 15:50:38 GMT (envelope-from emaste@FreeBSD.org) Message-Id: <202003201550.02KFocgG053704@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: emaste set sender to emaste@FreeBSD.org using -f From: Ed Maste Date: Fri, 20 Mar 2020 15:50:38 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r359166 - head/contrib/elftoolchain/elfcopy X-SVN-Group: head X-SVN-Commit-Author: emaste X-SVN-Commit-Paths: head/contrib/elftoolchain/elfcopy X-SVN-Commit-Revision: 359166 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 20 Mar 2020 15:50:38 -0000 Author: emaste Date: Fri Mar 20 15:50:37 2020 New Revision: 359166 URL: https://svnweb.freebsd.org/changeset/base/359166 Log: objcopy: add new sections also when there is no .shstrtab Previously objcopy (elfcopy) --add-sections inserted new sections before .shstrtab, but omitted them if there was no .shstrtab. Now, after processing existing sections add new sections if they were not yet added. PR: 241437 Reported by: arrowd Submitted by: Tiger Gao Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D23571 Modified: head/contrib/elftoolchain/elfcopy/sections.c Modified: head/contrib/elftoolchain/elfcopy/sections.c ============================================================================== --- head/contrib/elftoolchain/elfcopy/sections.c Fri Mar 20 15:07:25 2020 (r359165) +++ head/contrib/elftoolchain/elfcopy/sections.c Fri Mar 20 15:50:37 2020 (r359166) @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -341,6 +342,7 @@ create_scn(struct elfcopy *ecp) size_t indx; uint64_t oldndx, newndx; int elferr, sec_flags, reorder; + bool sections_added; /* * Insert a pseudo section that contains the ELF header @@ -364,6 +366,7 @@ create_scn(struct elfcopy *ecp) errx(EXIT_FAILURE, "elf_getshstrndx failed: %s", elf_errmsg(-1)); + sections_added = false; reorder = 0; is = NULL; while ((is = elf_nextscn(ecp->ein, is)) != NULL) { @@ -438,12 +441,14 @@ create_scn(struct elfcopy *ecp) oldndx = newndx = SHN_UNDEF; if (strcmp(name, ".symtab") != 0 && strcmp(name, ".strtab") != 0) { + /* Add new sections before .shstrtab if we have one. */ if (!strcmp(name, ".shstrtab")) { /* * Add sections specified by --add-section and * gnu debuglink. we want these sections have * smaller index than .shstrtab section. */ + sections_added = true; if (ecp->debuglink != NULL) add_gnu_debuglink(ecp); if (ecp->flags & SEC_ADD) @@ -504,6 +509,12 @@ create_scn(struct elfcopy *ecp) ecp->strtab = s; insert_to_sec_list(ecp, s, 0); + } + if (!sections_added) { + if (ecp->debuglink != NULL) + add_gnu_debuglink(ecp); + if (ecp->flags & SEC_ADD) + insert_sections(ecp); } elferr = elf_errno(); if (elferr != 0)