]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
Handle SHF_GNU_RETAIN in eu-readelf and eu-elflint.
authorMark Wielaard <mark@klomp.org>
Sat, 12 Dec 2020 22:36:15 +0000 (23:36 +0100)
committerMark Wielaard <mark@klomp.org>
Wed, 16 Dec 2020 18:44:47 +0000 (19:44 +0100)
readelf -S now shows 'R' when SHF_GNU_RETAIN is set.
elflint accepts SHF_GNU_RETAIN when set on section in --gnu mode.

Signed-off-by: Mark Wielaard <mark@klomp.org>
src/ChangeLog
src/elflint.c
src/readelf.c
tests/ChangeLog
tests/Makefile.am
tests/run-retain.sh [new file with mode: 0755]
tests/testfile-retain.o.bz2 [new file with mode: 0644]

index a7b227db5710581a656572c3e9739fefad61022d..2e428e0bc681ccdbf075ff70b1a050c8b51e8662 100644 (file)
@@ -1,3 +1,8 @@
+2020-12-12  Mark Wielaard  <mark@klomp.org>
+
+       * elflint.c (check_sections): Handle SHF_GNU_RETAIN.
+       * readelf.c (print_shdr): Likewise.
+
 2020-12-16  Dmitry V. Levin  <ldv@altlinux.org>
 
        * *.c: Replace gettext(...) with _(...).
index cb1079de90a501e418e65ef06fd95a9d68e98d9e..b3cbaade9e307b3b6da43ec050539fad87054b6b 100644 (file)
@@ -3935,6 +3935,9 @@ section [%2zu] '%s': size not multiple of entry size\n"),
                       cnt, section_name (ebl, cnt), sh_flags & SHF_MASKPROC);
              sh_flags &= ~(GElf_Xword) SHF_MASKPROC;
            }
+         if (sh_flags & SHF_MASKOS)
+           if (gnuld)
+             sh_flags &= ~(GElf_Xword) SHF_GNU_RETAIN;
          if (sh_flags != 0)
            ERROR (_("section [%2zu] '%s' contains unknown flag(s)"
                            " %#" PRIx64 "\n"),
index 824ab31b08de10d8c0cc4a644b6dfe66dfe27156..829a418d204830ad36a10cdceb1eb224886f70ca 100644 (file)
@@ -1298,6 +1298,8 @@ There are %zd section headers, starting at offset %#" PRIx64 ":\n\
        *cp++ = 'O';
       if (shdr->sh_flags & SHF_EXCLUDE)
        *cp++ = 'E';
+      if (shdr->sh_flags & SHF_GNU_RETAIN)
+       *cp++ = 'R';
       *cp = '\0';
 
       const char *sname;
index 119cf8e771b8a1a255a5d85149b4a2729eb23896..b9edd24902c49881ed9caf2b681771502f2b1e92 100644 (file)
@@ -1,3 +1,10 @@
+2020-12-12  Mark Wielaard  <mark@klomp.org>
+
+       * testfile-retain.o.bz2: New test file.
+       * run-retain.sh: New test.
+       * Makefile.am (TESTS): Add run-retain.sh.
+       (EXTRA_DIST): Add run-retain.sh and testfile-retain.o.bz2
+
 2020-12-16  Dmitry V. Levin  <ldv@altlinux.org>
 
        * dwflmodtest.c (N_): Remove.
index 3cca2251dd8e76e2ba164d8549f09e6fece03706..502becffb2a5c28726a35530a77d1842345da872 100644 (file)
@@ -125,6 +125,7 @@ TESTS = run-arextract.sh run-arsymtest.sh run-ar.sh newfile test-nlist \
        run-readelf-aranges.sh run-readelf-line.sh run-readelf-z.sh \
        run-readelf-frames.sh \
        run-readelf-n.sh \
+       run-retain.sh \
        run-native-test.sh run-bug1-test.sh \
        run-debuglink.sh run-debugaltlink.sh run-buildid.sh \
        dwfl-bug-addr-overflow run-addrname-test.sh \
@@ -318,6 +319,7 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh run-ar.sh \
             testfile_gnu_props.32be.o.bz2 \
             testfile_gnu_props.64be.o.bz2 \
             testfile-gnu-property-note-aarch64.bz2 \
+            run-retain.sh testfile-retain.o.bz2 \
             run-allfcts-multi.sh \
             test-offset-loop.bz2 test-offset-loop.alt.bz2 \
             run-prelink-addr-test.sh \
diff --git a/tests/run-retain.sh b/tests/run-retain.sh
new file mode 100755 (executable)
index 0000000..c5376de
--- /dev/null
@@ -0,0 +1,44 @@
+# Copyright (C) 2020 Red Hat, Inc.
+# This file is part of elfutils.
+#
+# This file 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; either version 3 of the License, or
+# (at your option) any later version.
+#
+# 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 this program.  If not, see <http://www.gnu.org/licenses/>.
+
+. $srcdir/test-subr.sh
+
+# - retian.s
+#   .section        .data.retain,"R" 
+#   .word   1
+#
+# as -o testfile-retain.o retain.s
+
+testfiles testfile-retain.o
+
+testrun_compare ${abs_top_builddir}/src/readelf -S testfile-retain.o << EOF
+There are 9 section headers, starting at offset 0x158:
+
+Section Headers:
+[Nr] Name                 Type         Addr             Off      Size     ES Flags Lk Inf Al
+[ 0]                      NULL         0000000000000000 00000000 00000000  0        0   0  0
+[ 1] .text                PROGBITS     0000000000000000 00000040 00000000  0 AX     0   0  1
+[ 2] .data                PROGBITS     0000000000000000 00000040 00000000  0 WA     0   0  1
+[ 3] .bss                 NOBITS       0000000000000000 00000040 00000000  0 WA     0   0  1
+[ 4] .data.retain         PROGBITS     0000000000000000 00000040 00000002  0 WAR    0   0  1
+[ 5] .note.gnu.property   NOTE         0000000000000000 00000048 00000030  0 A      0   0  8
+[ 6] .symtab              SYMTAB       0000000000000000 00000078 00000090 24        7   6  8
+[ 7] .strtab              STRTAB       0000000000000000 00000108 00000001  0        0   0  1
+[ 8] .shstrtab            STRTAB       0000000000000000 00000109 0000004c  0        0   0  1
+
+EOF
+
+testrun ${abs_top_builddir}/src/elflint --gnu testfile-retain.o
diff --git a/tests/testfile-retain.o.bz2 b/tests/testfile-retain.o.bz2
new file mode 100644 (file)
index 0000000..7571c0e
Binary files /dev/null and b/tests/testfile-retain.o.bz2 differ