]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
strip: Handle SHT_GROUP sections better.
authorMark Wielaard <mjw@redhat.com>
Tue, 17 May 2011 10:20:01 +0000 (12:20 +0200)
committerMark Wielaard <mjw@redhat.com>
Thu, 19 May 2011 08:38:43 +0000 (10:38 +0200)
src/ChangeLog
src/strip.c
tests/ChangeLog
tests/Makefile.am
tests/run-strip-groups.sh [new file with mode: 0755]
tests/testfile58.bz2 [new file with mode: 0644]

index 5f164e0d927368d9fda47481803ecfc3a0433e73..154b38e22e1c12e1b368e9bd8a0dc07ce150c8a8 100644 (file)
@@ -1,3 +1,10 @@
+2011-05-18  Mark Wielaard  <mjw@redhat.com>
+
+       * 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  <jakub@redhat.com>
 
        * readelf.c (print_ops): Handle DW_OP_GNU_const_type,
index 99374eb3c7c527f6a454b9f1933126987b805488..8c3c57de6e2e12c502b12cb35948f1ad726f7b17 100644 (file)
@@ -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)
index 674fe969b63b84bd3d0c9a0784f7b2d9bd1e12bb..2599b0ca85d888439b553c84fbf14a6d97382aff 100644 (file)
@@ -1,3 +1,11 @@
+2011-05-18  Mark Wielaard  <mjw@redhat.com>
+
+       * 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  <mpolacek@redhat.com>
 
        * alldts.c: New file.
index 35f55e3c139cca9c3ae02fb89ae306540ef76979..16a47e2e01ffec083e540eee9d0d95d2fc58903d 100644 (file)
@@ -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 (executable)
index 0000000..3434a61
--- /dev/null
@@ -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
+# <http://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 (file)
index 0000000..839efd9
Binary files /dev/null and b/tests/testfile58.bz2 differ