From 7a125b9306c4743eaee062bdab301f890e3c6309 Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Tue, 17 May 2011 12:20:01 +0200 Subject: [PATCH] strip: Handle SHT_GROUP sections better. --- src/ChangeLog | 7 +++++ src/strip.c | 32 ++++++++++++++++--- tests/ChangeLog | 8 +++++ tests/Makefile.am | 6 ++-- tests/run-strip-groups.sh | 63 ++++++++++++++++++++++++++++++++++++++ tests/testfile58.bz2 | Bin 0 -> 1680 bytes 6 files changed, 109 insertions(+), 7 deletions(-) create mode 100755 tests/run-strip-groups.sh create mode 100644 tests/testfile58.bz2 diff --git a/src/ChangeLog b/src/ChangeLog index 5f164e0d9..154b38e22 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,10 @@ +2011-05-18 Mark Wielaard + + * strip.c (handle_elf): Make sure all sections of a removed group + section are removed too. Don't discard SHT_GROUP sections, copy + section table before it gets modified. Section group signature + symbols don't have to be retained. + 2011-05-16 Jakub Jelinek * readelf.c (print_ops): Handle DW_OP_GNU_const_type, diff --git a/src/strip.c b/src/strip.c index 99374eb3c..8c3c57de6 100644 --- a/src/strip.c +++ b/src/strip.c @@ -726,6 +726,22 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname, || shdr_info[cnt].shdr.sh_type == SHT_RELA) && shdr_info[shdr_info[cnt].shdr.sh_info].idx != 0) shdr_info[cnt].idx = 1; + + /* If a group section is marked as being removed make + sure all the sections it contains are being removed, too. */ + if (shdr_info[cnt].shdr.sh_type == SHT_GROUP) + { + Elf32_Word *grpref; + grpref = (Elf32_Word *) shdr_info[cnt].data->d_buf; + for (size_t in = 1; + in < shdr_info[cnt].data->d_size / sizeof (Elf32_Word); + ++in) + if (shdr_info[grpref[in]].idx != 0) + { + shdr_info[cnt].idx = 1; + break; + } + } } if (shdr_info[cnt].idx == 1) @@ -883,6 +899,7 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname, bool discard_section = (shdr_info[cnt].idx > 0 && shdr_info[cnt].debug_data == NULL && shdr_info[cnt].shdr.sh_type != SHT_NOTE + && shdr_info[cnt].shdr.sh_type != SHT_GROUP && cnt != ehdr->e_shstrndx); /* Set the section header in the new file. */ @@ -912,7 +929,8 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname, *debugdata = *shdr_info[cnt].data; if (discard_section) debugdata->d_buf = NULL; - else if (shdr_info[cnt].debug_data != NULL) + else if (shdr_info[cnt].debug_data != NULL + || shdr_info[cnt].shdr.sh_type == SHT_GROUP) { /* Copy the original data before it gets modified. */ shdr_info[cnt].debug_data = debugdata; @@ -1261,9 +1279,15 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname, } else if (debug_fname == NULL || shdr_info[cnt].debug_data == NULL) - /* This is a section symbol for a section which has - been removed. */ - assert (GELF_ST_TYPE (sym->st_info) == STT_SECTION); + /* This is a section or group signature symbol + for a section which has been removed. */ + { + size_t sidx = (sym->st_shndx != SHN_XINDEX + ? sym->st_shndx : xshndx); + assert (GELF_ST_TYPE (sym->st_info) == STT_SECTION + || (shdr_info[sidx].shdr.sh_type == SHT_GROUP + && shdr_info[sidx].shdr.sh_info == inner)); + } } if (destidx != inner) diff --git a/tests/ChangeLog b/tests/ChangeLog index 674fe969b..2599b0ca8 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,11 @@ +2011-05-18 Mark Wielaard + + * run-strip-groups.sh: New test. + * testfile58.bz2: New test file. + * Makefile.am (EXTRA_DIST): Add testfile58.bz2. + (TESTS): Add run-strip-groups.sh. + (EXTRA_DIST): Likewise. + 2011-03-28 Marek Polacek * alldts.c: New file. diff --git a/tests/Makefile.am b/tests/Makefile.am index 35f55e3c1..16a47e2e0 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -70,7 +70,7 @@ TESTS = run-arextract.sh run-arsymtest.sh newfile test-nlist \ newscn run-strip-test.sh run-strip-test2.sh \ run-strip-test3.sh run-strip-test4.sh run-strip-test5.sh \ run-strip-test6.sh run-strip-test7.sh run-strip-test8.sh \ - run-unstrip-test.sh run-unstrip-test2.sh \ + run-strip-groups.sh run-unstrip-test.sh run-unstrip-test2.sh \ run-ecp-test.sh run-ecp-test2.sh run-alldts.sh \ run-elflint-test.sh run-elflint-self.sh run-ranlib-test.sh \ run-ranlib-test2.sh run-ranlib-test3.sh run-ranlib-test4.sh \ @@ -110,7 +110,7 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh \ testfile13.bz2 run-strip-test3.sh run-allfcts.sh \ run-line2addr.sh run-elflint-test.sh testfile14.bz2 \ run-strip-test4.sh run-strip-test5.sh run-strip-test6.sh \ - run-strip-test7.sh run-strip-test8.sh \ + run-strip-test7.sh run-strip-test8.sh run-strip-groups.sh \ run-unstrip-test.sh run-unstrip-test2.sh \ run-elflint-self.sh run-ranlib-test.sh run-ranlib-test2.sh \ run-ranlib-test3.sh run-ranlib-test4.sh \ @@ -158,7 +158,7 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh \ testfile55-32.bz2 testfile55-32.debug.bz2 \ testfile55-32.prelink.bz2 testfile55-64.bz2 \ testfile55-64.debug.bz2 testfile55-64.prelink.bz2 \ - testfile56.bz2 testfile57.bz2 + testfile56.bz2 testfile57.bz2 testfile58.bz2 installed_TESTS_ENVIRONMENT = libdir=$(DESTDIR)$(libdir) \ bindir=$(DESTDIR)$(bindir) \ diff --git a/tests/run-strip-groups.sh b/tests/run-strip-groups.sh new file mode 100755 index 000000000..3434a61eb --- /dev/null +++ b/tests/run-strip-groups.sh @@ -0,0 +1,63 @@ +#! /bin/sh +# Copyright (C) 2011 Red Hat, Inc. +# This file is part of Red Hat elfutils. +# +# Red Hat elfutils is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by the +# Free Software Foundation; version 2 of the License. +# +# Red Hat elfutils is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Red Hat elfutils; if not, write to the Free Software Foundation, +# Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA. +# +# Red Hat elfutils is an included package of the Open Invention Network. +# An included package of the Open Invention Network is a package for which +# Open Invention Network licensees cross-license their patents. No patent +# license is granted, either expressly or impliedly, by designation as an +# included package. Should you wish to participate in the Open Invention +# Network licensing program, please visit www.openinventionnetwork.com +# . +# +# g++ -gdwarf-4 -c testfile58.cxx +# class ct +# { +# private: +# int i; +# +# public: +# void foo () +# { +# i = 1; +# } +# +# int bar () +# { +# return i; +# } +# }; +# +# int baz () +# { +# class ct c; +# c.foo (); +# return c.bar (); +# } + +. $srcdir/test-subr.sh + +infile=testfile58 +outfile=$infile.stripped +dbgfile=$infile.debug + +testfiles $infile +tempfiles $outfile $dbgfile + +testrun ../src/strip -o $outfile -f $dbgfile $infile +testrun ../src/elflint -q $infile +testrun ../src/elflint -q $outfile +testrun ../src/elflint -q -d $dbgfile diff --git a/tests/testfile58.bz2 b/tests/testfile58.bz2 new file mode 100644 index 0000000000000000000000000000000000000000..839efd92cea86cab17b39d5755867cdb0057a4c4 GIT binary patch literal 1680 zc-jGw25ftDositO9C2q}O6iD@Q|xAE0#IbJ zqd!8;QN_C8OK#Z)!Xd<$Q_YGg=Z2>k`P)Pg&2;=;q~d zdY^57I|>7WFsW)vYGe!rXJ4tq%*?x)k5Xoax^K{747AG$LqM}wl$mBe9DbDPv=mYV zxt7SGqz{V_&E@jU%(rE^VoHLY3UuVK2|!aD7{?EFgQop>bOlW&B#=pqmX+CW=iNrff?hLBCB)y9xXf>mlL1WBniCM4Ph(l)FD7%j6~CXOQx zn=ux;7bloNxJL^nLFqJ%1|$uM1y5oD8@2!$jRg&7F$6T5NJDBEp{rv-4JF0CKqcYM z3QUue6KF`~H4O-c5WsD*Hpbd8xKX=lY%W#io)EmlKDp(_jEWU_J<^?;d%?q!j=xr3yziz1tvtZT4{&>-P|6fj$ zS=g|HJuoe>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