public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] strip: keep .ctf section in stripped file
@ 2022-05-31  2:26 Guillermo E. Martinez
  2022-05-31  7:06 ` Mark Wielaard
  0 siblings, 1 reply; 29+ messages in thread
From: Guillermo E. Martinez @ 2022-05-31  2:26 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Guillermo E. Martinez

Hello elfutils team,

This patch is meant to avoid remove the CTF section in
stripped files.  Please let me know your thoughts.

Kind regard,
Guillermo


CTF debug format was designed to be present in stripped files, so
this section should not be removed, so a new --remove-ctf option
is added to indicate explicitly that .ctf section will be stripped
out from binary file.

Signed-off-by: Guillermo E. Martinez <guillermo.e.martinez@oracle.com>
---
 ChangeLog                          |  23 ++++
 libebl/eblsectionstripp.c          |   4 +-
 libebl/libebl.h                    |   2 +-
 libelf/elf-knowledge.h             |   7 +-
 libelf/elf32_checksum.c            |   2 +-
 src/elfcmp.c                       |   4 +-
 src/strip.c                        |  71 ++++++++--
 tests/Makefile.am                  |   6 +-
 tests/run-strip-remove-keep-ctf.sh | 207 +++++++++++++++++++++++++++++
 tests/testfile-ctf.bz2             | Bin 0 -> 3317 bytes
 10 files changed, 304 insertions(+), 22 deletions(-)
 create mode 100755 tests/run-strip-remove-keep-ctf.sh
 create mode 100755 tests/testfile-ctf.bz2

diff --git a/ChangeLog b/ChangeLog
index f1a14b5c..2b608866 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,26 @@
+2022-05-21  Guillermo E. Martinez  <guillermo.e.martinez@oracle.com>
+
+	* libebl/eblsectionstripp.c (ebl_section_strip_p): Use
+	remove_ctf argument.
+	(SECTION_STRIP_P): Likewise.
+	* libebl/libebl.h (ebl_section_strip_p): Likewise.
+	* libelf/elf-knowledge.h (SECTION_STRIP_P): Update macro
+	definition to use remove_ctf to determine whether .ctf
+	section is stripped out.
+	* libelf/elf32_checksum.c (elfw2): Use false value for
+	remove_ctf parameter.
+	* src/elfcmp.c (main): Likewise.
+	* src/strip.c (options): Add --remove-ctf option set by
+	remove_ctf variable.
+	(set_remove_special_section_opt): Add new function.
+	(erratic_special_section_opt): Likewise.
+	(parse_opt): Parse new --remove-ctf option.
+	(handle_elf): Adjust .comment and use remove_ctf argument.
+	* tests/Makefile.am (TEST): Add run-strip-remove-keep-ctf.sh
+	and testfile-ctf.bz2.
+	* tests/run-strip-remove-keep-ctf.sh: Add new testcase.
+	* tests/testfile-ctf.bz2: Add new test harness.
+
 2022-05-02  Mark Wielaard  <mark@klomp.org>
 
 	* Makefile.am (AM_DISTCHECK_CONFIGURE_FLAGS): Remove
diff --git a/libebl/eblsectionstripp.c b/libebl/eblsectionstripp.c
index a5624ffe..f26cc170 100644
--- a/libebl/eblsectionstripp.c
+++ b/libebl/eblsectionstripp.c
@@ -37,7 +37,7 @@
 bool
 ebl_section_strip_p (Ebl *ebl, const GElf_Shdr *shdr,
 		     const char *name, bool remove_comment,
-		     bool only_remove_debug)
+		     bool only_remove_debug, bool remove_ctf)
 {
   /* If only debug information should be removed check the name.  There
      is unfortunately no other way.  */
@@ -66,5 +66,5 @@ ebl_section_strip_p (Ebl *ebl, const GElf_Shdr *shdr,
       return false;
     }
 
-  return SECTION_STRIP_P (shdr, name, remove_comment);
+  return SECTION_STRIP_P (shdr, name, remove_comment, remove_ctf);
 }
diff --git a/libebl/libebl.h b/libebl/libebl.h
index 731001d3..067b769e 100644
--- a/libebl/libebl.h
+++ b/libebl/libebl.h
@@ -205,7 +205,7 @@ extern bool ebl_relative_reloc_p (Ebl *ebl, int reloc);
 /* Check whether section should be stripped.  */
 extern bool ebl_section_strip_p (Ebl *ebl,
 				 const GElf_Shdr *shdr, const char *name,
-				 bool remove_comment, bool only_remove_debug);
+				 bool remove_comment, bool only_remove_debug, bool remove_ctf);
 
 /* Check if backend uses a bss PLT in this file.  */
 extern bool ebl_bss_plt_p (Ebl *ebl);
diff --git a/libelf/elf-knowledge.h b/libelf/elf-knowledge.h
index 6e005fa5..903a0f4f 100644
--- a/libelf/elf-knowledge.h
+++ b/libelf/elf-knowledge.h
@@ -34,7 +34,7 @@
 
 
 /* Test whether a section can be stripped or not.  */
-#define SECTION_STRIP_P(shdr, name, remove_comment) \
+#define SECTION_STRIP_P(shdr, name, remove_comment, remove_ctf) \
   /* Sections which are allocated are not removed.  */			      \
   (((shdr)->sh_flags & SHF_ALLOC) == 0					      \
    /* We never remove .note sections.  */				      \
@@ -45,7 +45,10 @@
 	   && strncmp (name, ".gnu.warning.", sizeof ".gnu.warning." - 1) != 0\
 	   /* We remove .comment sections only if explicitly told to do so. */\
 	   && (remove_comment						      \
-	       || strcmp (name, ".comment") != 0))))
+	       || strcmp (name, ".comment") != 0)  \
+	   /* We remove .ctf sections only if explicitly told to do so. */\
+	   && (remove_ctf						      \
+	       || strcmp (name, ".ctf") != 0))))
 
 
 /* Test whether `sh_info' field in section header contains a section
diff --git a/libelf/elf32_checksum.c b/libelf/elf32_checksum.c
index c5f27bbe..190bad7d 100644
--- a/libelf/elf32_checksum.c
+++ b/libelf/elf32_checksum.c
@@ -105,7 +105,7 @@ elfw2(LIBELFBITS,checksum) (Elf *elf)
 
       if (SECTION_STRIP_P (shdr,
 			   INTUSE(elf_strptr) (elf, shstrndx, shdr->sh_name),
-			   true))
+			   true, false))
 	/* The section can be stripped.  Don't use it.  */
 	continue;
 
diff --git a/src/elfcmp.c b/src/elfcmp.c
index 21d8d9dc..76f15735 100644
--- a/src/elfcmp.c
+++ b/src/elfcmp.c
@@ -270,7 +270,7 @@ main (int argc, char *argv[])
 	    sname1 = elf_strptr (elf1, shstrndx1, shdr1->sh_name);
 	}
       while (scn1 != NULL && shdr1 != NULL
-	     && ebl_section_strip_p (ebl1, shdr1, sname1, true, false));
+	     && ebl_section_strip_p (ebl1, shdr1, sname1, true, false, false));
 
       GElf_Shdr shdr2_mem;
       GElf_Shdr *shdr2;
@@ -283,7 +283,7 @@ main (int argc, char *argv[])
 	    sname2 = elf_strptr (elf2, shstrndx2, shdr2->sh_name);
 	}
       while (scn2 != NULL && shdr2 != NULL
-	     && ebl_section_strip_p (ebl2, shdr2, sname2, true, false));
+	     && ebl_section_strip_p (ebl2, shdr2, sname2, true, false, false));
 
       if (scn1 == NULL || scn2 == NULL || shdr1 == NULL || shdr2 == NULL)
 	break;
diff --git a/src/strip.c b/src/strip.c
index 452b1279..6f79a1d0 100644
--- a/src/strip.c
+++ b/src/strip.c
@@ -62,6 +62,7 @@ ARGP_PROGRAM_BUG_ADDRESS_DEF = PACKAGE_BUGREPORT;
 #define OPT_RELOC_DEBUG 	0x103
 #define OPT_KEEP_SECTION 	0x104
 #define OPT_RELOC_DEBUG_ONLY    0x105
+#define OPT_REMOVE_CTF	        0x106
 
 
 /* Definitions of arguments for argp functions.  */
@@ -87,6 +88,8 @@ static const struct argp_option options[] =
     N_("Similar to --reloc-debug-sections, but resolve all trivial relocations between debug sections in place.  No other stripping is performed (operation is not reversible, incompatible with -f, -g, --remove-comment and --remove-section)"), 0 },
   { "remove-comment", OPT_REMOVE_COMMENT, NULL, 0,
     N_("Remove .comment section"), 0 },
+  { "remove-ctf", OPT_REMOVE_CTF, NULL, 0,
+    N_("Remove .ctf section"), 0 },
   { "remove-section", 'R', "SECTION", 0, N_("Remove the named section.  SECTION is an extended wildcard pattern.  May be given more than once.  Only non-allocated sections can be removed."), 0 },
   { "keep-section", OPT_KEEP_SECTION, "SECTION", 0, N_("Keep the named section.  SECTION is an extended wildcard pattern.  May be given more than once."), 0 },
   { "permissive", OPT_PERMISSIVE, NULL, 0,
@@ -150,6 +153,9 @@ static bool preserve_dates;
 /* If true .comment sections will be removed.  */
 static bool remove_comment;
 
+/* If true .ctf sections will be removed.  */
+static bool remove_ctf;
+
 /* If true remove all debug sections.  */
 static bool remove_debug;
 
@@ -217,6 +223,48 @@ section_name_matches (struct section_pattern *patterns, const char *name)
   return false;
 }
 
+static void
+set_remove_special_section_opt (const char *arg)
+{
+  if (fnmatch (arg, ".comment", FNM_EXTMATCH) == 0)
+    remove_comment = true;
+  else if (fnmatch (arg, ".ctf", FNM_EXTMATCH) == 0)
+    remove_ctf = true;
+}
+
+static error_t
+erratic_special_section_opt (struct argp_state *state)
+{
+  int s;
+  struct {
+    const char *name;
+    bool remove;
+  } special_secs[] = {
+      {
+        .name = ".comment",
+        .remove = remove_comment
+      },
+      {
+        .name = ".ctf",
+        .remove = remove_ctf
+      },
+      {
+        .name = NULL,
+      }
+  };
+
+  for (s = 0; special_secs[s].name; ++s)
+    if (special_secs[s].remove == true
+        && section_name_matches (keep_secs, special_secs[s].name))
+      {
+        argp_error (state,
+                    _("cannot both keep and remove %s section"),
+                    special_secs[s].name);
+        return EINVAL;
+      }
+
+  return 0;
+}
 
 int
 main (int argc, char *argv[])
@@ -325,9 +373,12 @@ parse_opt (int key, char *arg, struct argp_state *state)
       remove_comment = true;
       break;
 
+    case OPT_REMOVE_CTF:
+      remove_ctf = true;
+      break;
+
     case 'R':
-      if (fnmatch (arg, ".comment", FNM_EXTMATCH) == 0)
-	remove_comment = true;
+      set_remove_special_section_opt (arg);
       add_pattern (&remove_secs, arg);
       break;
 
@@ -353,13 +404,8 @@ parse_opt (int key, char *arg, struct argp_state *state)
       break;
 
     case ARGP_KEY_SUCCESS:
-      if (remove_comment == true
-	  && section_name_matches (keep_secs, ".comment"))
-	{
-	  argp_error (state,
-		      _("cannot both keep and remove .comment section"));
-	  return EINVAL;
-	}
+      if (erratic_special_section_opt (state))
+        return EINVAL;
       break;
 
     default:
@@ -1358,7 +1404,7 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname,
      all sections which are not used at runtime are stripped out.  But
      there are a few exceptions:
 
-     - special sections named ".comment" and ".note" are kept
+     - special sections named ".comment", ".note" and ".ctf" are kept
      - OS or architecture specific sections are kept since we might not
        know how to handle them
      - if a section is referred to from a section which is not removed
@@ -1371,7 +1417,7 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname,
     if (remove_shdrs ? !(shdr_info[cnt].shdr.sh_flags & SHF_ALLOC)
 	: (ebl_section_strip_p (ebl, &shdr_info[cnt].shdr,
 				shdr_info[cnt].name, remove_comment,
-				remove_debug)
+				remove_debug, remove_ctf)
 	   || cnt == shstrndx
 	   || section_name_matches (remove_secs, shdr_info[cnt].name)))
       {
@@ -1534,7 +1580,8 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname,
 						    &shdr_info[scnidx].shdr,
 						    shdr_info[scnidx].name,
 						    remove_comment,
-						    remove_debug)
+						    remove_debug,
+						    remove_ctf)
 			       && ebl_data_marker_symbol (ebl, sym,
 					elf_strptr (elf,
 						    shdr_info[cnt].shdr.sh_link,
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 84c3950a..f30d958e 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -197,7 +197,8 @@ TESTS = run-arextract.sh run-arsymtest.sh run-ar.sh newfile test-nlist \
 	msg_tst system-elf-libelf-test \
 	$(asm_TESTS) run-disasm-bpf.sh run-low_high_pc-dw-form-indirect.sh \
 	run-nvidia-extended-linemap-libdw.sh run-nvidia-extended-linemap-readelf.sh \
-	run-readelf-dw-form-indirect.sh run-strip-largealign.sh
+	run-readelf-dw-form-indirect.sh run-strip-largealign.sh \
+	run-strip-remove-keep-ctf.sh
 
 if !BIARCH
 export ELFUTILS_DISABLE_BIARCH = 1
@@ -580,7 +581,8 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh run-ar.sh \
 	     run-readelf-dw-form-indirect.sh testfile-dw-form-indirect.bz2 \
 	     run-nvidia-extended-linemap-libdw.sh run-nvidia-extended-linemap-readelf.sh \
 	     testfile_nvidia_linemap.bz2 \
-	     testfile-largealign.o.bz2 run-strip-largealign.sh
+	     testfile-largealign.o.bz2 run-strip-largealign.sh \
+	     testfile-ctf.bz2 run-strip-remove-keep-ctf.sh
 
 
 if USE_VALGRIND
diff --git a/tests/run-strip-remove-keep-ctf.sh b/tests/run-strip-remove-keep-ctf.sh
new file mode 100755
index 00000000..1a9bd93b
--- /dev/null
+++ b/tests/run-strip-remove-keep-ctf.sh
@@ -0,0 +1,207 @@
+#! /bin/sh
+# Copyright (C) 2022 Oracle, 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
+
+# strip -o output and -f debug files
+tempfiles testfile.elf testfile.debug
+
+# A random 32bit testfile
+testfiles testfile-ctf
+
+# strip should keep .ctf section
+echo strip testfile-ctf
+testrun ${abs_top_builddir}/src/strip -o testfile.elf -f testfile.debug testfile-ctf
+echo elflint testfile.elf
+testrun ${abs_top_builddir}/src/elflint --gnu testfile.elf
+echo elflint testfile.debug
+testrun ${abs_top_builddir}/src/elflint --gnu -d testfile.debug
+echo readelf testfile.elf
+testrun_compare ${abs_top_builddir}/src/readelf -S testfile.elf <<\EOF
+There are 30 section headers, starting at offset 0x3330:
+
+Section Headers:
+[Nr] Name                 Type         Addr             Off      Size     ES Flags Lk Inf Al
+[ 0]                      NULL         0000000000000000 00000000 00000000  0        0   0  0
+[ 1] .interp              PROGBITS     0000000000400318 00000318 0000001c  0 A      0   0  1
+[ 2] .note.gnu.property   NOTE         0000000000400338 00000338 00000020  0 A      0   0  8
+[ 3] .note.ABI-tag        NOTE         0000000000400358 00000358 00000020  0 A      0   0  4
+[ 4] .hash                HASH         0000000000400378 00000378 00000028  4 A      6   0  8
+[ 5] .gnu.hash            GNU_HASH     00000000004003a0 000003a0 0000001c  0 A      6   0  8
+[ 6] .dynsym              DYNSYM       00000000004003c0 000003c0 00000078 24 A      7   1  8
+[ 7] .dynstr              STRTAB       0000000000400438 00000438 00000057  0 A      0   0  1
+[ 8] .gnu.version         GNU_versym   0000000000400490 00000490 0000000a  2 A      6   0  2
+[ 9] .gnu.version_r       GNU_verneed  00000000004004a0 000004a0 00000030  0 A      7   1  8
+[10] .rela.dyn            RELA         00000000004004d0 000004d0 00000030 24 A      6   0  8
+[11] .rela.plt            RELA         0000000000400500 00000500 00000030 24 AI     6  23  8
+[12] .init                PROGBITS     0000000000401000 00001000 00000017  0 AX     0   0  4
+[13] .plt                 PROGBITS     0000000000401020 00001020 00000030 16 AX     0   0 16
+[14] .text                PROGBITS     0000000000401050 00001050 000001d1  0 AX     0   0 16
+[15] .fini                PROGBITS     0000000000401224 00001224 00000009  0 AX     0   0  4
+[16] .rodata              PROGBITS     0000000000402000 00002000 00000010  0 A      0   0  4
+[17] .eh_frame_hdr        PROGBITS     0000000000402010 00002010 0000003c  0 A      0   0  4
+[18] .eh_frame            PROGBITS     0000000000402050 00002050 00000100  0 A      0   0  8
+[19] .init_array          INIT_ARRAY   0000000000403e00 00002e00 00000008  8 WA     0   0  8
+[20] .fini_array          FINI_ARRAY   0000000000403e08 00002e08 00000008  8 WA     0   0  8
+[21] .dynamic             DYNAMIC      0000000000403e10 00002e10 000001e0 16 WA     7   0  8
+[22] .got                 PROGBITS     0000000000403ff0 00002ff0 00000010  8 WA     0   0  8
+[23] .got.plt             PROGBITS     0000000000404000 00003000 00000028  8 WA     0   0  8
+[24] .data                PROGBITS     0000000000404028 00003028 00000010  0 WA     0   0  8
+[25] .bss                 NOBITS       0000000000404038 00003038 00000008  0 WA     0   0  4
+[26] .comment             PROGBITS     0000000000000000 00003038 0000002a  1 MS     0   0  1
+[27] .ctf                 PROGBITS     0000000000000000 00003062 000001af  0        0   0  1
+[28] .gnu_debuglink       PROGBITS     0000000000000000 00003214 00000014  0        0   0  4
+[29] .shstrtab            STRTAB       0000000000000000 00003228 00000107  0        0   0  1
+
+EOF
+echo readelf testfile.debug
+testrun_compare ${abs_top_builddir}/src/readelf -S testfile.debug <<\EOF
+There are 37 section headers, starting at offset 0xdf0:
+
+Section Headers:
+[Nr] Name                 Type         Addr             Off      Size     ES Flags Lk Inf Al
+[ 0]                      NULL         0000000000000000 00000000 00000000  0        0   0  0
+[ 1] .interp              NOBITS       0000000000400318 00000318 0000001c  0 A      0   0  1
+[ 2] .note.gnu.property   NOTE         0000000000400338 00000318 00000020  0 A      0   0  8
+[ 3] .note.ABI-tag        NOTE         0000000000400358 00000338 00000020  0 A      0   0  4
+[ 4] .hash                NOBITS       0000000000400378 00000358 00000028  4 A      6   0  8
+[ 5] .gnu.hash            NOBITS       00000000004003a0 00000358 0000001c  0 A      6   0  8
+[ 6] .dynsym              NOBITS       00000000004003c0 00000358 00000078 24 A      7   1  8
+[ 7] .dynstr              NOBITS       0000000000400438 00000358 00000057  0 A      0   0  1
+[ 8] .gnu.version         NOBITS       0000000000400490 00000358 0000000a  2 A      6   0  2
+[ 9] .gnu.version_r       NOBITS       00000000004004a0 00000358 00000030  0 A      7   1  8
+[10] .rela.dyn            NOBITS       00000000004004d0 00000358 00000030 24 A      6   0  8
+[11] .rela.plt            NOBITS       0000000000400500 00000358 00000030 24 AI     6  23  8
+[12] .init                NOBITS       0000000000401000 00000358 00000017  0 AX     0   0  4
+[13] .plt                 NOBITS       0000000000401020 00000360 00000030 16 AX     0   0 16
+[14] .text                NOBITS       0000000000401050 00000360 000001d1  0 AX     0   0 16
+[15] .fini                NOBITS       0000000000401224 00000360 00000009  0 AX     0   0  4
+[16] .rodata              NOBITS       0000000000402000 00000360 00000010  0 A      0   0  4
+[17] .eh_frame_hdr        NOBITS       0000000000402010 00000360 0000003c  0 A      0   0  4
+[18] .eh_frame            NOBITS       0000000000402050 00000360 00000100  0 A      0   0  8
+[19] .init_array          NOBITS       0000000000403e00 00000360 00000008  8 WA     0   0  8
+[20] .fini_array          NOBITS       0000000000403e08 00000360 00000008  8 WA     0   0  8
+[21] .dynamic             NOBITS       0000000000403e10 00000360 000001e0 16 WA     7   0  8
+[22] .got                 NOBITS       0000000000403ff0 00000360 00000010  8 WA     0   0  8
+[23] .got.plt             NOBITS       0000000000404000 00000360 00000028  8 WA     0   0  8
+[24] .data                NOBITS       0000000000404028 00000360 00000010  0 WA     0   0  8
+[25] .bss                 NOBITS       0000000000404038 00000360 00000008  0 WA     0   0  4
+[26] .comment             NOBITS       0000000000000000 00000360 0000002a  1 MS     0   0  1
+[27] .ctf                 NOBITS       0000000000000000 00000360 000001af  0        0   0  1
+[28] .debug_aranges       PROGBITS     0000000000000000 00000360 00000030  0        0   0  1
+[29] .debug_info          PROGBITS     0000000000000000 00000390 00000121  0        0   0  1
+[30] .debug_abbrev        PROGBITS     0000000000000000 000004b1 000000b6  0        0   0  1
+[31] .debug_line          PROGBITS     0000000000000000 00000567 00000063  0        0   0  1
+[32] .debug_str           PROGBITS     0000000000000000 000005ca 000000ba  1 MS     0   0  1
+[33] .debug_line_str      PROGBITS     0000000000000000 00000684 0000005c  1 MS     0   0  1
+[34] .symtab              SYMTAB       0000000000000000 000006e0 000003c0 24       35  21  8
+[35] .strtab              STRTAB       0000000000000000 00000aa0 000001f1  0        0   0  1
+[36] .shstrtab            STRTAB       0000000000000000 00000c91 00000158  0        0   0  1
+
+EOF
+
+# Explicitly removes .ctf section
+echo strip --remove-ctf testfile
+testrun ${abs_top_builddir}/src/strip --remove-ctf -o testfile.elf -f testfile.debug testfile-ctf
+echo elflint testfile.elf
+testrun ${abs_top_builddir}/src/elflint --gnu testfile.elf
+echo elflint testfile.debug
+testrun ${abs_top_builddir}/src/elflint --gnu -d testfile.debug
+echo readelf testfile.elf
+testrun_compare ${abs_top_builddir}/src/readelf -S testfile.elf <<\EOF
+There are 29 section headers, starting at offset 0x3180:
+
+Section Headers:
+[Nr] Name                 Type         Addr             Off      Size     ES Flags Lk Inf Al
+[ 0]                      NULL         0000000000000000 00000000 00000000  0        0   0  0
+[ 1] .interp              PROGBITS     0000000000400318 00000318 0000001c  0 A      0   0  1
+[ 2] .note.gnu.property   NOTE         0000000000400338 00000338 00000020  0 A      0   0  8
+[ 3] .note.ABI-tag        NOTE         0000000000400358 00000358 00000020  0 A      0   0  4
+[ 4] .hash                HASH         0000000000400378 00000378 00000028  4 A      6   0  8
+[ 5] .gnu.hash            GNU_HASH     00000000004003a0 000003a0 0000001c  0 A      6   0  8
+[ 6] .dynsym              DYNSYM       00000000004003c0 000003c0 00000078 24 A      7   1  8
+[ 7] .dynstr              STRTAB       0000000000400438 00000438 00000057  0 A      0   0  1
+[ 8] .gnu.version         GNU_versym   0000000000400490 00000490 0000000a  2 A      6   0  2
+[ 9] .gnu.version_r       GNU_verneed  00000000004004a0 000004a0 00000030  0 A      7   1  8
+[10] .rela.dyn            RELA         00000000004004d0 000004d0 00000030 24 A      6   0  8
+[11] .rela.plt            RELA         0000000000400500 00000500 00000030 24 AI     6  23  8
+[12] .init                PROGBITS     0000000000401000 00001000 00000017  0 AX     0   0  4
+[13] .plt                 PROGBITS     0000000000401020 00001020 00000030 16 AX     0   0 16
+[14] .text                PROGBITS     0000000000401050 00001050 000001d1  0 AX     0   0 16
+[15] .fini                PROGBITS     0000000000401224 00001224 00000009  0 AX     0   0  4
+[16] .rodata              PROGBITS     0000000000402000 00002000 00000010  0 A      0   0  4
+[17] .eh_frame_hdr        PROGBITS     0000000000402010 00002010 0000003c  0 A      0   0  4
+[18] .eh_frame            PROGBITS     0000000000402050 00002050 00000100  0 A      0   0  8
+[19] .init_array          INIT_ARRAY   0000000000403e00 00002e00 00000008  8 WA     0   0  8
+[20] .fini_array          FINI_ARRAY   0000000000403e08 00002e08 00000008  8 WA     0   0  8
+[21] .dynamic             DYNAMIC      0000000000403e10 00002e10 000001e0 16 WA     7   0  8
+[22] .got                 PROGBITS     0000000000403ff0 00002ff0 00000010  8 WA     0   0  8
+[23] .got.plt             PROGBITS     0000000000404000 00003000 00000028  8 WA     0   0  8
+[24] .data                PROGBITS     0000000000404028 00003028 00000010  0 WA     0   0  8
+[25] .bss                 NOBITS       0000000000404038 00003038 00000008  0 WA     0   0  4
+[26] .comment             PROGBITS     0000000000000000 00003038 0000002a  1 MS     0   0  1
+[27] .gnu_debuglink       PROGBITS     0000000000000000 00003064 00000014  0        0   0  4
+[28] .shstrtab            STRTAB       0000000000000000 00003078 00000102  0        0   0  1
+
+EOF
+echo readelf testfile.debug
+testrun_compare ${abs_top_builddir}/src/readelf -S testfile.debug <<\EOF
+There are 37 section headers, starting at offset 0xfa0:
+
+Section Headers:
+[Nr] Name                 Type         Addr             Off      Size     ES Flags Lk Inf Al
+[ 0]                      NULL         0000000000000000 00000000 00000000  0        0   0  0
+[ 1] .interp              NOBITS       0000000000400318 00000318 0000001c  0 A      0   0  1
+[ 2] .note.gnu.property   NOTE         0000000000400338 00000318 00000020  0 A      0   0  8
+[ 3] .note.ABI-tag        NOTE         0000000000400358 00000338 00000020  0 A      0   0  4
+[ 4] .hash                NOBITS       0000000000400378 00000358 00000028  4 A      6   0  8
+[ 5] .gnu.hash            NOBITS       00000000004003a0 00000358 0000001c  0 A      6   0  8
+[ 6] .dynsym              NOBITS       00000000004003c0 00000358 00000078 24 A      7   1  8
+[ 7] .dynstr              NOBITS       0000000000400438 00000358 00000057  0 A      0   0  1
+[ 8] .gnu.version         NOBITS       0000000000400490 00000358 0000000a  2 A      6   0  2
+[ 9] .gnu.version_r       NOBITS       00000000004004a0 00000358 00000030  0 A      7   1  8
+[10] .rela.dyn            NOBITS       00000000004004d0 00000358 00000030 24 A      6   0  8
+[11] .rela.plt            NOBITS       0000000000400500 00000358 00000030 24 AI     6  23  8
+[12] .init                NOBITS       0000000000401000 00000358 00000017  0 AX     0   0  4
+[13] .plt                 NOBITS       0000000000401020 00000360 00000030 16 AX     0   0 16
+[14] .text                NOBITS       0000000000401050 00000360 000001d1  0 AX     0   0 16
+[15] .fini                NOBITS       0000000000401224 00000360 00000009  0 AX     0   0  4
+[16] .rodata              NOBITS       0000000000402000 00000360 00000010  0 A      0   0  4
+[17] .eh_frame_hdr        NOBITS       0000000000402010 00000360 0000003c  0 A      0   0  4
+[18] .eh_frame            NOBITS       0000000000402050 00000360 00000100  0 A      0   0  8
+[19] .init_array          NOBITS       0000000000403e00 00000360 00000008  8 WA     0   0  8
+[20] .fini_array          NOBITS       0000000000403e08 00000360 00000008  8 WA     0   0  8
+[21] .dynamic             NOBITS       0000000000403e10 00000360 000001e0 16 WA     7   0  8
+[22] .got                 NOBITS       0000000000403ff0 00000360 00000010  8 WA     0   0  8
+[23] .got.plt             NOBITS       0000000000404000 00000360 00000028  8 WA     0   0  8
+[24] .data                NOBITS       0000000000404028 00000360 00000010  0 WA     0   0  8
+[25] .bss                 NOBITS       0000000000404038 00000360 00000008  0 WA     0   0  4
+[26] .comment             NOBITS       0000000000000000 00000360 0000002a  1 MS     0   0  1
+[27] .ctf                 PROGBITS     0000000000000000 00000360 000001af  0        0   0  1
+[28] .debug_aranges       PROGBITS     0000000000000000 0000050f 00000030  0        0   0  1
+[29] .debug_info          PROGBITS     0000000000000000 0000053f 00000121  0        0   0  1
+[30] .debug_abbrev        PROGBITS     0000000000000000 00000660 000000b6  0        0   0  1
+[31] .debug_line          PROGBITS     0000000000000000 00000716 00000063  0        0   0  1
+[32] .debug_str           PROGBITS     0000000000000000 00000779 000000ba  1 MS     0   0  1
+[33] .debug_line_str      PROGBITS     0000000000000000 00000833 0000005c  1 MS     0   0  1
+[34] .symtab              SYMTAB       0000000000000000 00000890 000003c0 24       35  21  8
+[35] .strtab              STRTAB       0000000000000000 00000c50 000001f1  0        0   0  1
+[36] .shstrtab            STRTAB       0000000000000000 00000e41 00000158  0        0   0  1
+
+EOF
+
+exit 0
diff --git a/tests/testfile-ctf.bz2 b/tests/testfile-ctf.bz2
new file mode 100755
index 0000000000000000000000000000000000000000..af909af0fe7b7d88f11426e349e867e39fddfafd
GIT binary patch
literal 3317
zcmV<R3<~o?T4*^jL0KkKSuG_=7yt}J|NsC0|NsC0|NsB@|NsC0|Nj5)^>ool$yNRQ
z{a*L~|6kw>L^-~iz!v3`m9t8Amleo4T#|O$(vEkAge1Wxr<C$FJxm$^rfp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EhR}9WKhMn

literal 0
HcmV?d00001


base-commit: 27414ecffd6cc71c9af7bacc75ce448121ac005f
-- 
2.35.1


^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH] strip: keep .ctf section in stripped file
  2022-05-31  2:26 [PATCH] strip: keep .ctf section in stripped file Guillermo E. Martinez
@ 2022-05-31  7:06 ` Mark Wielaard
  2022-05-31 10:26   ` Jose E. Marchesi
                     ` (2 more replies)
  0 siblings, 3 replies; 29+ messages in thread
From: Mark Wielaard @ 2022-05-31  7:06 UTC (permalink / raw)
  To: Guillermo E. Martinez; +Cc: elfutils-devel, nickc

Hi Guillermo,

On Mon, May 30, 2022 at 09:26:19PM -0500, Guillermo E. Martinez via Elfutils-devel wrote:
> Hello elfutils team,
> 
> This patch is meant to avoid remove the CTF section in
> stripped files.  Please let me know your thoughts.
>
> CTF debug format was designed to be present in stripped files, so
> this section should not be removed, so a new --remove-ctf option
> is added to indicate explicitly that .ctf section will be stripped
> out from binary file.

First, very nice patch. My only real concern with it is that it should
describe how the testfile-ctf.bz2 is generated. We don't want really
random test binaries in the testsuite. There should be at least some
method to regenerate them, even if we don't automate that. See
e.g. tests/run-readelf-n.sh which also uses binary test files, but has
a little description on how each of them was generated.

I am CCing Nick Clifton who works on binutils and annobin to check how
binutils strip handles this. And because we were recently discussing
putting some annobin data in a special section and how to indicate
that this section should be explicitly kept or removed. It would be
great if we could come to some kind of standard way of marking such
sections so we don't need special arguments for each such section or
at least have a more generic SECTION_STRIP_P macro.

Note, that this might not be possible, these sections might be to
different/specific that generalizing over them is impossible. But it
would be good to at least try and discuss it. If only so that elfutils
eu-strip and binutils strip agree on how to handle/coordinate on such
special sections.

Cheers,

Mark

> Signed-off-by: Guillermo E. Martinez <guillermo.e.martinez@oracle.com>
> ---
>  ChangeLog                          |  23 ++++
>  libebl/eblsectionstripp.c          |   4 +-
>  libebl/libebl.h                    |   2 +-
>  libelf/elf-knowledge.h             |   7 +-
>  libelf/elf32_checksum.c            |   2 +-
>  src/elfcmp.c                       |   4 +-
>  src/strip.c                        |  71 ++++++++--
>  tests/Makefile.am                  |   6 +-
>  tests/run-strip-remove-keep-ctf.sh | 207 +++++++++++++++++++++++++++++
>  tests/testfile-ctf.bz2             | Bin 0 -> 3317 bytes
>  10 files changed, 304 insertions(+), 22 deletions(-)
>  create mode 100755 tests/run-strip-remove-keep-ctf.sh
>  create mode 100755 tests/testfile-ctf.bz2
> 
> diff --git a/ChangeLog b/ChangeLog
> index f1a14b5c..2b608866 100644
> --- a/ChangeLog
> +++ b/ChangeLog
> @@ -1,3 +1,26 @@
> +2022-05-21  Guillermo E. Martinez  <guillermo.e.martinez@oracle.com>
> +
> +	* libebl/eblsectionstripp.c (ebl_section_strip_p): Use
> +	remove_ctf argument.
> +	(SECTION_STRIP_P): Likewise.
> +	* libebl/libebl.h (ebl_section_strip_p): Likewise.
> +	* libelf/elf-knowledge.h (SECTION_STRIP_P): Update macro
> +	definition to use remove_ctf to determine whether .ctf
> +	section is stripped out.
> +	* libelf/elf32_checksum.c (elfw2): Use false value for
> +	remove_ctf parameter.
> +	* src/elfcmp.c (main): Likewise.
> +	* src/strip.c (options): Add --remove-ctf option set by
> +	remove_ctf variable.
> +	(set_remove_special_section_opt): Add new function.
> +	(erratic_special_section_opt): Likewise.
> +	(parse_opt): Parse new --remove-ctf option.
> +	(handle_elf): Adjust .comment and use remove_ctf argument.
> +	* tests/Makefile.am (TEST): Add run-strip-remove-keep-ctf.sh
> +	and testfile-ctf.bz2.
> +	* tests/run-strip-remove-keep-ctf.sh: Add new testcase.
> +	* tests/testfile-ctf.bz2: Add new test harness.
> +
>  2022-05-02  Mark Wielaard  <mark@klomp.org>
>  
>  	* Makefile.am (AM_DISTCHECK_CONFIGURE_FLAGS): Remove
> diff --git a/libebl/eblsectionstripp.c b/libebl/eblsectionstripp.c
> index a5624ffe..f26cc170 100644
> --- a/libebl/eblsectionstripp.c
> +++ b/libebl/eblsectionstripp.c
> @@ -37,7 +37,7 @@
>  bool
>  ebl_section_strip_p (Ebl *ebl, const GElf_Shdr *shdr,
>  		     const char *name, bool remove_comment,
> -		     bool only_remove_debug)
> +		     bool only_remove_debug, bool remove_ctf)
>  {
>    /* If only debug information should be removed check the name.  There
>       is unfortunately no other way.  */
> @@ -66,5 +66,5 @@ ebl_section_strip_p (Ebl *ebl, const GElf_Shdr *shdr,
>        return false;
>      }
>  
> -  return SECTION_STRIP_P (shdr, name, remove_comment);
> +  return SECTION_STRIP_P (shdr, name, remove_comment, remove_ctf);
>  }
> diff --git a/libebl/libebl.h b/libebl/libebl.h
> index 731001d3..067b769e 100644
> --- a/libebl/libebl.h
> +++ b/libebl/libebl.h
> @@ -205,7 +205,7 @@ extern bool ebl_relative_reloc_p (Ebl *ebl, int reloc);
>  /* Check whether section should be stripped.  */
>  extern bool ebl_section_strip_p (Ebl *ebl,
>  				 const GElf_Shdr *shdr, const char *name,
> -				 bool remove_comment, bool only_remove_debug);
> +				 bool remove_comment, bool only_remove_debug, bool remove_ctf);
>  
>  /* Check if backend uses a bss PLT in this file.  */
>  extern bool ebl_bss_plt_p (Ebl *ebl);
> diff --git a/libelf/elf-knowledge.h b/libelf/elf-knowledge.h
> index 6e005fa5..903a0f4f 100644
> --- a/libelf/elf-knowledge.h
> +++ b/libelf/elf-knowledge.h
> @@ -34,7 +34,7 @@
>  
>  
>  /* Test whether a section can be stripped or not.  */
> -#define SECTION_STRIP_P(shdr, name, remove_comment) \
> +#define SECTION_STRIP_P(shdr, name, remove_comment, remove_ctf) \
>    /* Sections which are allocated are not removed.  */			      \
>    (((shdr)->sh_flags & SHF_ALLOC) == 0					      \
>     /* We never remove .note sections.  */				      \
> @@ -45,7 +45,10 @@
>  	   && strncmp (name, ".gnu.warning.", sizeof ".gnu.warning." - 1) != 0\
>  	   /* We remove .comment sections only if explicitly told to do so. */\
>  	   && (remove_comment						      \
> -	       || strcmp (name, ".comment") != 0))))
> +	       || strcmp (name, ".comment") != 0)  \
> +	   /* We remove .ctf sections only if explicitly told to do so. */\
> +	   && (remove_ctf						      \
> +	       || strcmp (name, ".ctf") != 0))))
>  
>  
>  /* Test whether `sh_info' field in section header contains a section
> diff --git a/libelf/elf32_checksum.c b/libelf/elf32_checksum.c
> index c5f27bbe..190bad7d 100644
> --- a/libelf/elf32_checksum.c
> +++ b/libelf/elf32_checksum.c
> @@ -105,7 +105,7 @@ elfw2(LIBELFBITS,checksum) (Elf *elf)
>  
>        if (SECTION_STRIP_P (shdr,
>  			   INTUSE(elf_strptr) (elf, shstrndx, shdr->sh_name),
> -			   true))
> +			   true, false))
>  	/* The section can be stripped.  Don't use it.  */
>  	continue;
>  
> diff --git a/src/elfcmp.c b/src/elfcmp.c
> index 21d8d9dc..76f15735 100644
> --- a/src/elfcmp.c
> +++ b/src/elfcmp.c
> @@ -270,7 +270,7 @@ main (int argc, char *argv[])
>  	    sname1 = elf_strptr (elf1, shstrndx1, shdr1->sh_name);
>  	}
>        while (scn1 != NULL && shdr1 != NULL
> -	     && ebl_section_strip_p (ebl1, shdr1, sname1, true, false));
> +	     && ebl_section_strip_p (ebl1, shdr1, sname1, true, false, false));
>  
>        GElf_Shdr shdr2_mem;
>        GElf_Shdr *shdr2;
> @@ -283,7 +283,7 @@ main (int argc, char *argv[])
>  	    sname2 = elf_strptr (elf2, shstrndx2, shdr2->sh_name);
>  	}
>        while (scn2 != NULL && shdr2 != NULL
> -	     && ebl_section_strip_p (ebl2, shdr2, sname2, true, false));
> +	     && ebl_section_strip_p (ebl2, shdr2, sname2, true, false, false));
>  
>        if (scn1 == NULL || scn2 == NULL || shdr1 == NULL || shdr2 == NULL)
>  	break;
> diff --git a/src/strip.c b/src/strip.c
> index 452b1279..6f79a1d0 100644
> --- a/src/strip.c
> +++ b/src/strip.c
> @@ -62,6 +62,7 @@ ARGP_PROGRAM_BUG_ADDRESS_DEF = PACKAGE_BUGREPORT;
>  #define OPT_RELOC_DEBUG 	0x103
>  #define OPT_KEEP_SECTION 	0x104
>  #define OPT_RELOC_DEBUG_ONLY    0x105
> +#define OPT_REMOVE_CTF	        0x106
>  
>  
>  /* Definitions of arguments for argp functions.  */
> @@ -87,6 +88,8 @@ static const struct argp_option options[] =
>      N_("Similar to --reloc-debug-sections, but resolve all trivial relocations between debug sections in place.  No other stripping is performed (operation is not reversible, incompatible with -f, -g, --remove-comment and --remove-section)"), 0 },
>    { "remove-comment", OPT_REMOVE_COMMENT, NULL, 0,
>      N_("Remove .comment section"), 0 },
> +  { "remove-ctf", OPT_REMOVE_CTF, NULL, 0,
> +    N_("Remove .ctf section"), 0 },
>    { "remove-section", 'R', "SECTION", 0, N_("Remove the named section.  SECTION is an extended wildcard pattern.  May be given more than once.  Only non-allocated sections can be removed."), 0 },
>    { "keep-section", OPT_KEEP_SECTION, "SECTION", 0, N_("Keep the named section.  SECTION is an extended wildcard pattern.  May be given more than once."), 0 },
>    { "permissive", OPT_PERMISSIVE, NULL, 0,
> @@ -150,6 +153,9 @@ static bool preserve_dates;
>  /* If true .comment sections will be removed.  */
>  static bool remove_comment;
>  
> +/* If true .ctf sections will be removed.  */
> +static bool remove_ctf;
> +
>  /* If true remove all debug sections.  */
>  static bool remove_debug;
>  
> @@ -217,6 +223,48 @@ section_name_matches (struct section_pattern *patterns, const char *name)
>    return false;
>  }
>  
> +static void
> +set_remove_special_section_opt (const char *arg)
> +{
> +  if (fnmatch (arg, ".comment", FNM_EXTMATCH) == 0)
> +    remove_comment = true;
> +  else if (fnmatch (arg, ".ctf", FNM_EXTMATCH) == 0)
> +    remove_ctf = true;
> +}
> +
> +static error_t
> +erratic_special_section_opt (struct argp_state *state)
> +{
> +  int s;
> +  struct {
> +    const char *name;
> +    bool remove;
> +  } special_secs[] = {
> +      {
> +        .name = ".comment",
> +        .remove = remove_comment
> +      },
> +      {
> +        .name = ".ctf",
> +        .remove = remove_ctf
> +      },
> +      {
> +        .name = NULL,
> +      }
> +  };
> +
> +  for (s = 0; special_secs[s].name; ++s)
> +    if (special_secs[s].remove == true
> +        && section_name_matches (keep_secs, special_secs[s].name))
> +      {
> +        argp_error (state,
> +                    _("cannot both keep and remove %s section"),
> +                    special_secs[s].name);
> +        return EINVAL;
> +      }
> +
> +  return 0;
> +}
>  
>  int
>  main (int argc, char *argv[])
> @@ -325,9 +373,12 @@ parse_opt (int key, char *arg, struct argp_state *state)
>        remove_comment = true;
>        break;
>  
> +    case OPT_REMOVE_CTF:
> +      remove_ctf = true;
> +      break;
> +
>      case 'R':
> -      if (fnmatch (arg, ".comment", FNM_EXTMATCH) == 0)
> -	remove_comment = true;
> +      set_remove_special_section_opt (arg);
>        add_pattern (&remove_secs, arg);
>        break;
>  
> @@ -353,13 +404,8 @@ parse_opt (int key, char *arg, struct argp_state *state)
>        break;
>  
>      case ARGP_KEY_SUCCESS:
> -      if (remove_comment == true
> -	  && section_name_matches (keep_secs, ".comment"))
> -	{
> -	  argp_error (state,
> -		      _("cannot both keep and remove .comment section"));
> -	  return EINVAL;
> -	}
> +      if (erratic_special_section_opt (state))
> +        return EINVAL;
>        break;
>  
>      default:
> @@ -1358,7 +1404,7 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname,
>       all sections which are not used at runtime are stripped out.  But
>       there are a few exceptions:
>  
> -     - special sections named ".comment" and ".note" are kept
> +     - special sections named ".comment", ".note" and ".ctf" are kept
>       - OS or architecture specific sections are kept since we might not
>         know how to handle them
>       - if a section is referred to from a section which is not removed
> @@ -1371,7 +1417,7 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname,
>      if (remove_shdrs ? !(shdr_info[cnt].shdr.sh_flags & SHF_ALLOC)
>  	: (ebl_section_strip_p (ebl, &shdr_info[cnt].shdr,
>  				shdr_info[cnt].name, remove_comment,
> -				remove_debug)
> +				remove_debug, remove_ctf)
>  	   || cnt == shstrndx
>  	   || section_name_matches (remove_secs, shdr_info[cnt].name)))
>        {
> @@ -1534,7 +1580,8 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname,
>  						    &shdr_info[scnidx].shdr,
>  						    shdr_info[scnidx].name,
>  						    remove_comment,
> -						    remove_debug)
> +						    remove_debug,
> +						    remove_ctf)
>  			       && ebl_data_marker_symbol (ebl, sym,
>  					elf_strptr (elf,
>  						    shdr_info[cnt].shdr.sh_link,
> diff --git a/tests/Makefile.am b/tests/Makefile.am
> index 84c3950a..f30d958e 100644
> --- a/tests/Makefile.am
> +++ b/tests/Makefile.am
> @@ -197,7 +197,8 @@ TESTS = run-arextract.sh run-arsymtest.sh run-ar.sh newfile test-nlist \
>  	msg_tst system-elf-libelf-test \
>  	$(asm_TESTS) run-disasm-bpf.sh run-low_high_pc-dw-form-indirect.sh \
>  	run-nvidia-extended-linemap-libdw.sh run-nvidia-extended-linemap-readelf.sh \
> -	run-readelf-dw-form-indirect.sh run-strip-largealign.sh
> +	run-readelf-dw-form-indirect.sh run-strip-largealign.sh \
> +	run-strip-remove-keep-ctf.sh
>  
>  if !BIARCH
>  export ELFUTILS_DISABLE_BIARCH = 1
> @@ -580,7 +581,8 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh run-ar.sh \
>  	     run-readelf-dw-form-indirect.sh testfile-dw-form-indirect.bz2 \
>  	     run-nvidia-extended-linemap-libdw.sh run-nvidia-extended-linemap-readelf.sh \
>  	     testfile_nvidia_linemap.bz2 \
> -	     testfile-largealign.o.bz2 run-strip-largealign.sh
> +	     testfile-largealign.o.bz2 run-strip-largealign.sh \
> +	     testfile-ctf.bz2 run-strip-remove-keep-ctf.sh
>  
>  
>  if USE_VALGRIND
> diff --git a/tests/run-strip-remove-keep-ctf.sh b/tests/run-strip-remove-keep-ctf.sh
> new file mode 100755
> index 00000000..1a9bd93b
> --- /dev/null
> +++ b/tests/run-strip-remove-keep-ctf.sh
> @@ -0,0 +1,207 @@
> +#! /bin/sh
> +# Copyright (C) 2022 Oracle, 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
> +
> +# strip -o output and -f debug files
> +tempfiles testfile.elf testfile.debug
> +
> +# A random 32bit testfile
> +testfiles testfile-ctf
> +
> +# strip should keep .ctf section
> +echo strip testfile-ctf
> +testrun ${abs_top_builddir}/src/strip -o testfile.elf -f testfile.debug testfile-ctf
> +echo elflint testfile.elf
> +testrun ${abs_top_builddir}/src/elflint --gnu testfile.elf
> +echo elflint testfile.debug
> +testrun ${abs_top_builddir}/src/elflint --gnu -d testfile.debug
> +echo readelf testfile.elf
> +testrun_compare ${abs_top_builddir}/src/readelf -S testfile.elf <<\EOF
> +There are 30 section headers, starting at offset 0x3330:
> +
> +Section Headers:
> +[Nr] Name                 Type         Addr             Off      Size     ES Flags Lk Inf Al
> +[ 0]                      NULL         0000000000000000 00000000 00000000  0        0   0  0
> +[ 1] .interp              PROGBITS     0000000000400318 00000318 0000001c  0 A      0   0  1
> +[ 2] .note.gnu.property   NOTE         0000000000400338 00000338 00000020  0 A      0   0  8
> +[ 3] .note.ABI-tag        NOTE         0000000000400358 00000358 00000020  0 A      0   0  4
> +[ 4] .hash                HASH         0000000000400378 00000378 00000028  4 A      6   0  8
> +[ 5] .gnu.hash            GNU_HASH     00000000004003a0 000003a0 0000001c  0 A      6   0  8
> +[ 6] .dynsym              DYNSYM       00000000004003c0 000003c0 00000078 24 A      7   1  8
> +[ 7] .dynstr              STRTAB       0000000000400438 00000438 00000057  0 A      0   0  1
> +[ 8] .gnu.version         GNU_versym   0000000000400490 00000490 0000000a  2 A      6   0  2
> +[ 9] .gnu.version_r       GNU_verneed  00000000004004a0 000004a0 00000030  0 A      7   1  8
> +[10] .rela.dyn            RELA         00000000004004d0 000004d0 00000030 24 A      6   0  8
> +[11] .rela.plt            RELA         0000000000400500 00000500 00000030 24 AI     6  23  8
> +[12] .init                PROGBITS     0000000000401000 00001000 00000017  0 AX     0   0  4
> +[13] .plt                 PROGBITS     0000000000401020 00001020 00000030 16 AX     0   0 16
> +[14] .text                PROGBITS     0000000000401050 00001050 000001d1  0 AX     0   0 16
> +[15] .fini                PROGBITS     0000000000401224 00001224 00000009  0 AX     0   0  4
> +[16] .rodata              PROGBITS     0000000000402000 00002000 00000010  0 A      0   0  4
> +[17] .eh_frame_hdr        PROGBITS     0000000000402010 00002010 0000003c  0 A      0   0  4
> +[18] .eh_frame            PROGBITS     0000000000402050 00002050 00000100  0 A      0   0  8
> +[19] .init_array          INIT_ARRAY   0000000000403e00 00002e00 00000008  8 WA     0   0  8
> +[20] .fini_array          FINI_ARRAY   0000000000403e08 00002e08 00000008  8 WA     0   0  8
> +[21] .dynamic             DYNAMIC      0000000000403e10 00002e10 000001e0 16 WA     7   0  8
> +[22] .got                 PROGBITS     0000000000403ff0 00002ff0 00000010  8 WA     0   0  8
> +[23] .got.plt             PROGBITS     0000000000404000 00003000 00000028  8 WA     0   0  8
> +[24] .data                PROGBITS     0000000000404028 00003028 00000010  0 WA     0   0  8
> +[25] .bss                 NOBITS       0000000000404038 00003038 00000008  0 WA     0   0  4
> +[26] .comment             PROGBITS     0000000000000000 00003038 0000002a  1 MS     0   0  1
> +[27] .ctf                 PROGBITS     0000000000000000 00003062 000001af  0        0   0  1
> +[28] .gnu_debuglink       PROGBITS     0000000000000000 00003214 00000014  0        0   0  4
> +[29] .shstrtab            STRTAB       0000000000000000 00003228 00000107  0        0   0  1
> +
> +EOF
> +echo readelf testfile.debug
> +testrun_compare ${abs_top_builddir}/src/readelf -S testfile.debug <<\EOF
> +There are 37 section headers, starting at offset 0xdf0:
> +
> +Section Headers:
> +[Nr] Name                 Type         Addr             Off      Size     ES Flags Lk Inf Al
> +[ 0]                      NULL         0000000000000000 00000000 00000000  0        0   0  0
> +[ 1] .interp              NOBITS       0000000000400318 00000318 0000001c  0 A      0   0  1
> +[ 2] .note.gnu.property   NOTE         0000000000400338 00000318 00000020  0 A      0   0  8
> +[ 3] .note.ABI-tag        NOTE         0000000000400358 00000338 00000020  0 A      0   0  4
> +[ 4] .hash                NOBITS       0000000000400378 00000358 00000028  4 A      6   0  8
> +[ 5] .gnu.hash            NOBITS       00000000004003a0 00000358 0000001c  0 A      6   0  8
> +[ 6] .dynsym              NOBITS       00000000004003c0 00000358 00000078 24 A      7   1  8
> +[ 7] .dynstr              NOBITS       0000000000400438 00000358 00000057  0 A      0   0  1
> +[ 8] .gnu.version         NOBITS       0000000000400490 00000358 0000000a  2 A      6   0  2
> +[ 9] .gnu.version_r       NOBITS       00000000004004a0 00000358 00000030  0 A      7   1  8
> +[10] .rela.dyn            NOBITS       00000000004004d0 00000358 00000030 24 A      6   0  8
> +[11] .rela.plt            NOBITS       0000000000400500 00000358 00000030 24 AI     6  23  8
> +[12] .init                NOBITS       0000000000401000 00000358 00000017  0 AX     0   0  4
> +[13] .plt                 NOBITS       0000000000401020 00000360 00000030 16 AX     0   0 16
> +[14] .text                NOBITS       0000000000401050 00000360 000001d1  0 AX     0   0 16
> +[15] .fini                NOBITS       0000000000401224 00000360 00000009  0 AX     0   0  4
> +[16] .rodata              NOBITS       0000000000402000 00000360 00000010  0 A      0   0  4
> +[17] .eh_frame_hdr        NOBITS       0000000000402010 00000360 0000003c  0 A      0   0  4
> +[18] .eh_frame            NOBITS       0000000000402050 00000360 00000100  0 A      0   0  8
> +[19] .init_array          NOBITS       0000000000403e00 00000360 00000008  8 WA     0   0  8
> +[20] .fini_array          NOBITS       0000000000403e08 00000360 00000008  8 WA     0   0  8
> +[21] .dynamic             NOBITS       0000000000403e10 00000360 000001e0 16 WA     7   0  8
> +[22] .got                 NOBITS       0000000000403ff0 00000360 00000010  8 WA     0   0  8
> +[23] .got.plt             NOBITS       0000000000404000 00000360 00000028  8 WA     0   0  8
> +[24] .data                NOBITS       0000000000404028 00000360 00000010  0 WA     0   0  8
> +[25] .bss                 NOBITS       0000000000404038 00000360 00000008  0 WA     0   0  4
> +[26] .comment             NOBITS       0000000000000000 00000360 0000002a  1 MS     0   0  1
> +[27] .ctf                 NOBITS       0000000000000000 00000360 000001af  0        0   0  1
> +[28] .debug_aranges       PROGBITS     0000000000000000 00000360 00000030  0        0   0  1
> +[29] .debug_info          PROGBITS     0000000000000000 00000390 00000121  0        0   0  1
> +[30] .debug_abbrev        PROGBITS     0000000000000000 000004b1 000000b6  0        0   0  1
> +[31] .debug_line          PROGBITS     0000000000000000 00000567 00000063  0        0   0  1
> +[32] .debug_str           PROGBITS     0000000000000000 000005ca 000000ba  1 MS     0   0  1
> +[33] .debug_line_str      PROGBITS     0000000000000000 00000684 0000005c  1 MS     0   0  1
> +[34] .symtab              SYMTAB       0000000000000000 000006e0 000003c0 24       35  21  8
> +[35] .strtab              STRTAB       0000000000000000 00000aa0 000001f1  0        0   0  1
> +[36] .shstrtab            STRTAB       0000000000000000 00000c91 00000158  0        0   0  1
> +
> +EOF
> +
> +# Explicitly removes .ctf section
> +echo strip --remove-ctf testfile
> +testrun ${abs_top_builddir}/src/strip --remove-ctf -o testfile.elf -f testfile.debug testfile-ctf
> +echo elflint testfile.elf
> +testrun ${abs_top_builddir}/src/elflint --gnu testfile.elf
> +echo elflint testfile.debug
> +testrun ${abs_top_builddir}/src/elflint --gnu -d testfile.debug
> +echo readelf testfile.elf
> +testrun_compare ${abs_top_builddir}/src/readelf -S testfile.elf <<\EOF
> +There are 29 section headers, starting at offset 0x3180:
> +
> +Section Headers:
> +[Nr] Name                 Type         Addr             Off      Size     ES Flags Lk Inf Al
> +[ 0]                      NULL         0000000000000000 00000000 00000000  0        0   0  0
> +[ 1] .interp              PROGBITS     0000000000400318 00000318 0000001c  0 A      0   0  1
> +[ 2] .note.gnu.property   NOTE         0000000000400338 00000338 00000020  0 A      0   0  8
> +[ 3] .note.ABI-tag        NOTE         0000000000400358 00000358 00000020  0 A      0   0  4
> +[ 4] .hash                HASH         0000000000400378 00000378 00000028  4 A      6   0  8
> +[ 5] .gnu.hash            GNU_HASH     00000000004003a0 000003a0 0000001c  0 A      6   0  8
> +[ 6] .dynsym              DYNSYM       00000000004003c0 000003c0 00000078 24 A      7   1  8
> +[ 7] .dynstr              STRTAB       0000000000400438 00000438 00000057  0 A      0   0  1
> +[ 8] .gnu.version         GNU_versym   0000000000400490 00000490 0000000a  2 A      6   0  2
> +[ 9] .gnu.version_r       GNU_verneed  00000000004004a0 000004a0 00000030  0 A      7   1  8
> +[10] .rela.dyn            RELA         00000000004004d0 000004d0 00000030 24 A      6   0  8
> +[11] .rela.plt            RELA         0000000000400500 00000500 00000030 24 AI     6  23  8
> +[12] .init                PROGBITS     0000000000401000 00001000 00000017  0 AX     0   0  4
> +[13] .plt                 PROGBITS     0000000000401020 00001020 00000030 16 AX     0   0 16
> +[14] .text                PROGBITS     0000000000401050 00001050 000001d1  0 AX     0   0 16
> +[15] .fini                PROGBITS     0000000000401224 00001224 00000009  0 AX     0   0  4
> +[16] .rodata              PROGBITS     0000000000402000 00002000 00000010  0 A      0   0  4
> +[17] .eh_frame_hdr        PROGBITS     0000000000402010 00002010 0000003c  0 A      0   0  4
> +[18] .eh_frame            PROGBITS     0000000000402050 00002050 00000100  0 A      0   0  8
> +[19] .init_array          INIT_ARRAY   0000000000403e00 00002e00 00000008  8 WA     0   0  8
> +[20] .fini_array          FINI_ARRAY   0000000000403e08 00002e08 00000008  8 WA     0   0  8
> +[21] .dynamic             DYNAMIC      0000000000403e10 00002e10 000001e0 16 WA     7   0  8
> +[22] .got                 PROGBITS     0000000000403ff0 00002ff0 00000010  8 WA     0   0  8
> +[23] .got.plt             PROGBITS     0000000000404000 00003000 00000028  8 WA     0   0  8
> +[24] .data                PROGBITS     0000000000404028 00003028 00000010  0 WA     0   0  8
> +[25] .bss                 NOBITS       0000000000404038 00003038 00000008  0 WA     0   0  4
> +[26] .comment             PROGBITS     0000000000000000 00003038 0000002a  1 MS     0   0  1
> +[27] .gnu_debuglink       PROGBITS     0000000000000000 00003064 00000014  0        0   0  4
> +[28] .shstrtab            STRTAB       0000000000000000 00003078 00000102  0        0   0  1
> +
> +EOF
> +echo readelf testfile.debug
> +testrun_compare ${abs_top_builddir}/src/readelf -S testfile.debug <<\EOF
> +There are 37 section headers, starting at offset 0xfa0:
> +
> +Section Headers:
> +[Nr] Name                 Type         Addr             Off      Size     ES Flags Lk Inf Al
> +[ 0]                      NULL         0000000000000000 00000000 00000000  0        0   0  0
> +[ 1] .interp              NOBITS       0000000000400318 00000318 0000001c  0 A      0   0  1
> +[ 2] .note.gnu.property   NOTE         0000000000400338 00000318 00000020  0 A      0   0  8
> +[ 3] .note.ABI-tag        NOTE         0000000000400358 00000338 00000020  0 A      0   0  4
> +[ 4] .hash                NOBITS       0000000000400378 00000358 00000028  4 A      6   0  8
> +[ 5] .gnu.hash            NOBITS       00000000004003a0 00000358 0000001c  0 A      6   0  8
> +[ 6] .dynsym              NOBITS       00000000004003c0 00000358 00000078 24 A      7   1  8
> +[ 7] .dynstr              NOBITS       0000000000400438 00000358 00000057  0 A      0   0  1
> +[ 8] .gnu.version         NOBITS       0000000000400490 00000358 0000000a  2 A      6   0  2
> +[ 9] .gnu.version_r       NOBITS       00000000004004a0 00000358 00000030  0 A      7   1  8
> +[10] .rela.dyn            NOBITS       00000000004004d0 00000358 00000030 24 A      6   0  8
> +[11] .rela.plt            NOBITS       0000000000400500 00000358 00000030 24 AI     6  23  8
> +[12] .init                NOBITS       0000000000401000 00000358 00000017  0 AX     0   0  4
> +[13] .plt                 NOBITS       0000000000401020 00000360 00000030 16 AX     0   0 16
> +[14] .text                NOBITS       0000000000401050 00000360 000001d1  0 AX     0   0 16
> +[15] .fini                NOBITS       0000000000401224 00000360 00000009  0 AX     0   0  4
> +[16] .rodata              NOBITS       0000000000402000 00000360 00000010  0 A      0   0  4
> +[17] .eh_frame_hdr        NOBITS       0000000000402010 00000360 0000003c  0 A      0   0  4
> +[18] .eh_frame            NOBITS       0000000000402050 00000360 00000100  0 A      0   0  8
> +[19] .init_array          NOBITS       0000000000403e00 00000360 00000008  8 WA     0   0  8
> +[20] .fini_array          NOBITS       0000000000403e08 00000360 00000008  8 WA     0   0  8
> +[21] .dynamic             NOBITS       0000000000403e10 00000360 000001e0 16 WA     7   0  8
> +[22] .got                 NOBITS       0000000000403ff0 00000360 00000010  8 WA     0   0  8
> +[23] .got.plt             NOBITS       0000000000404000 00000360 00000028  8 WA     0   0  8
> +[24] .data                NOBITS       0000000000404028 00000360 00000010  0 WA     0   0  8
> +[25] .bss                 NOBITS       0000000000404038 00000360 00000008  0 WA     0   0  4
> +[26] .comment             NOBITS       0000000000000000 00000360 0000002a  1 MS     0   0  1
> +[27] .ctf                 PROGBITS     0000000000000000 00000360 000001af  0        0   0  1
> +[28] .debug_aranges       PROGBITS     0000000000000000 0000050f 00000030  0        0   0  1
> +[29] .debug_info          PROGBITS     0000000000000000 0000053f 00000121  0        0   0  1
> +[30] .debug_abbrev        PROGBITS     0000000000000000 00000660 000000b6  0        0   0  1
> +[31] .debug_line          PROGBITS     0000000000000000 00000716 00000063  0        0   0  1
> +[32] .debug_str           PROGBITS     0000000000000000 00000779 000000ba  1 MS     0   0  1
> +[33] .debug_line_str      PROGBITS     0000000000000000 00000833 0000005c  1 MS     0   0  1
> +[34] .symtab              SYMTAB       0000000000000000 00000890 000003c0 24       35  21  8
> +[35] .strtab              STRTAB       0000000000000000 00000c50 000001f1  0        0   0  1
> +[36] .shstrtab            STRTAB       0000000000000000 00000e41 00000158  0        0   0  1
> +
> +EOF
> +
> +exit 0
> diff --git a/tests/testfile-ctf.bz2 b/tests/testfile-ctf.bz2
> new file mode 100755
> index 0000000000000000000000000000000000000000..af909af0fe7b7d88f11426e349e867e39fddfafd
> GIT binary patch
> literal 3317
> zcmV<R3<~o?T4*^jL0KkKSuG_=7yt}J|NsC0|NsC0|NsB@|NsC0|Nj5)^>ool$yNRQ
> z{a*L~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mM%Q1y%4y2!F^FOR5R}XT5m}}~R$>^-_y{lzo9GAxKnC1%lRLf2hlw{|
> z=K9FQJM@bKW<U?s0y0tze|y&A#86~fZ)D;VuK)lwttW|^Y5x~;ML1B9EhR}9WKhMn
> 
> literal 0
> HcmV?d00001
> 
> 
> base-commit: 27414ecffd6cc71c9af7bacc75ce448121ac005f
> -- 
> 2.35.1
> 

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH] strip: keep .ctf section in stripped file
  2022-05-31  7:06 ` Mark Wielaard
@ 2022-05-31 10:26   ` Jose E. Marchesi
  2022-05-31 12:50     ` Jose E. Marchesi
  2022-06-01  4:34   ` Guillermo E. Martinez
  2022-06-01 15:55   ` [PATCHv2] " Guillermo E. Martinez
  2 siblings, 1 reply; 29+ messages in thread
From: Jose E. Marchesi @ 2022-05-31 10:26 UTC (permalink / raw)
  To: Mark Wielaard; +Cc: Guillermo E. Martinez, elfutils-devel, Nick Clifton


[Added Nick in CC.]

> Hi Guillermo,
>
> On Mon, May 30, 2022 at 09:26:19PM -0500, Guillermo E. Martinez via Elfutils-devel wrote:
>> Hello elfutils team,
>> 
>> This patch is meant to avoid remove the CTF section in
>> stripped files.  Please let me know your thoughts.
>>
>> CTF debug format was designed to be present in stripped files, so
>> this section should not be removed, so a new --remove-ctf option
>> is added to indicate explicitly that .ctf section will be stripped
>> out from binary file.
>
> First, very nice patch. My only real concern with it is that it should
> describe how the testfile-ctf.bz2 is generated. We don't want really
> random test binaries in the testsuite. There should be at least some
> method to regenerate them, even if we don't automate that. See
> e.g. tests/run-readelf-n.sh which also uses binary test files, but has
> a little description on how each of them was generated.
>
> I am CCing Nick Clifton who works on binutils and annobin to check how
> binutils strip handles this. And because we were recently discussing
> putting some annobin data in a special section and how to indicate
> that this section should be explicitly kept or removed. It would be
> great if we could come to some kind of standard way of marking such
> sections so we don't need special arguments for each such section or
> at least have a more generic SECTION_STRIP_P macro.

AFAIK the binutils `strip' does not strip .ctf sections.

> Note, that this might not be possible, these sections might be to
> different/specific that generalizing over them is impossible. But it
> would be good to at least try and discuss it. If only so that elfutils
> eu-strip and binutils strip agree on how to handle/coordinate on such
> special sections.

What about using an OS-specific section flag in elf.h, something like:

#define SHF_GNU_PERSISTENT 0x0ff00001 /* Section must not be stripped.  */

>
> Cheers,
>
> Mark
>
>> Signed-off-by: Guillermo E. Martinez <guillermo.e.martinez@oracle.com>
>> ---
>>  ChangeLog                          |  23 ++++
>>  libebl/eblsectionstripp.c          |   4 +-
>>  libebl/libebl.h                    |   2 +-
>>  libelf/elf-knowledge.h             |   7 +-
>>  libelf/elf32_checksum.c            |   2 +-
>>  src/elfcmp.c                       |   4 +-
>>  src/strip.c                        |  71 ++++++++--
>>  tests/Makefile.am                  |   6 +-
>>  tests/run-strip-remove-keep-ctf.sh | 207 +++++++++++++++++++++++++++++
>>  tests/testfile-ctf.bz2             | Bin 0 -> 3317 bytes
>>  10 files changed, 304 insertions(+), 22 deletions(-)
>>  create mode 100755 tests/run-strip-remove-keep-ctf.sh
>>  create mode 100755 tests/testfile-ctf.bz2
>> 
>> diff --git a/ChangeLog b/ChangeLog
>> index f1a14b5c..2b608866 100644
>> --- a/ChangeLog
>> +++ b/ChangeLog
>> @@ -1,3 +1,26 @@
>> +2022-05-21  Guillermo E. Martinez  <guillermo.e.martinez@oracle.com>
>> +
>> +	* libebl/eblsectionstripp.c (ebl_section_strip_p): Use
>> +	remove_ctf argument.
>> +	(SECTION_STRIP_P): Likewise.
>> +	* libebl/libebl.h (ebl_section_strip_p): Likewise.
>> +	* libelf/elf-knowledge.h (SECTION_STRIP_P): Update macro
>> +	definition to use remove_ctf to determine whether .ctf
>> +	section is stripped out.
>> +	* libelf/elf32_checksum.c (elfw2): Use false value for
>> +	remove_ctf parameter.
>> +	* src/elfcmp.c (main): Likewise.
>> +	* src/strip.c (options): Add --remove-ctf option set by
>> +	remove_ctf variable.
>> +	(set_remove_special_section_opt): Add new function.
>> +	(erratic_special_section_opt): Likewise.
>> +	(parse_opt): Parse new --remove-ctf option.
>> +	(handle_elf): Adjust .comment and use remove_ctf argument.
>> +	* tests/Makefile.am (TEST): Add run-strip-remove-keep-ctf.sh
>> +	and testfile-ctf.bz2.
>> +	* tests/run-strip-remove-keep-ctf.sh: Add new testcase.
>> +	* tests/testfile-ctf.bz2: Add new test harness.
>> +
>>  2022-05-02  Mark Wielaard  <mark@klomp.org>
>>  
>>  	* Makefile.am (AM_DISTCHECK_CONFIGURE_FLAGS): Remove
>> diff --git a/libebl/eblsectionstripp.c b/libebl/eblsectionstripp.c
>> index a5624ffe..f26cc170 100644
>> --- a/libebl/eblsectionstripp.c
>> +++ b/libebl/eblsectionstripp.c
>> @@ -37,7 +37,7 @@
>>  bool
>>  ebl_section_strip_p (Ebl *ebl, const GElf_Shdr *shdr,
>>  		     const char *name, bool remove_comment,
>> -		     bool only_remove_debug)
>> +		     bool only_remove_debug, bool remove_ctf)
>>  {
>>    /* If only debug information should be removed check the name.  There
>>       is unfortunately no other way.  */
>> @@ -66,5 +66,5 @@ ebl_section_strip_p (Ebl *ebl, const GElf_Shdr *shdr,
>>        return false;
>>      }
>>  
>> -  return SECTION_STRIP_P (shdr, name, remove_comment);
>> +  return SECTION_STRIP_P (shdr, name, remove_comment, remove_ctf);
>>  }
>> diff --git a/libebl/libebl.h b/libebl/libebl.h
>> index 731001d3..067b769e 100644
>> --- a/libebl/libebl.h
>> +++ b/libebl/libebl.h
>> @@ -205,7 +205,7 @@ extern bool ebl_relative_reloc_p (Ebl *ebl, int reloc);
>>  /* Check whether section should be stripped.  */
>>  extern bool ebl_section_strip_p (Ebl *ebl,
>>  				 const GElf_Shdr *shdr, const char *name,
>> -				 bool remove_comment, bool only_remove_debug);
>> +				 bool remove_comment, bool only_remove_debug, bool remove_ctf);
>>  
>>  /* Check if backend uses a bss PLT in this file.  */
>>  extern bool ebl_bss_plt_p (Ebl *ebl);
>> diff --git a/libelf/elf-knowledge.h b/libelf/elf-knowledge.h
>> index 6e005fa5..903a0f4f 100644
>> --- a/libelf/elf-knowledge.h
>> +++ b/libelf/elf-knowledge.h
>> @@ -34,7 +34,7 @@
>>  
>>  
>>  /* Test whether a section can be stripped or not.  */
>> -#define SECTION_STRIP_P(shdr, name, remove_comment) \
>> +#define SECTION_STRIP_P(shdr, name, remove_comment, remove_ctf) \
>>    /* Sections which are allocated are not removed.  */			      \
>>    (((shdr)->sh_flags & SHF_ALLOC) == 0					      \
>>     /* We never remove .note sections.  */				      \
>> @@ -45,7 +45,10 @@
>>  	   && strncmp (name, ".gnu.warning.", sizeof ".gnu.warning." - 1) != 0\
>>  	   /* We remove .comment sections only if explicitly told to do so. */\
>>  	   && (remove_comment						      \
>> -	       || strcmp (name, ".comment") != 0))))
>> +	       || strcmp (name, ".comment") != 0)  \
>> +	   /* We remove .ctf sections only if explicitly told to do so. */\
>> +	   && (remove_ctf						      \
>> +	       || strcmp (name, ".ctf") != 0))))
>>  
>>  
>>  /* Test whether `sh_info' field in section header contains a section
>> diff --git a/libelf/elf32_checksum.c b/libelf/elf32_checksum.c
>> index c5f27bbe..190bad7d 100644
>> --- a/libelf/elf32_checksum.c
>> +++ b/libelf/elf32_checksum.c
>> @@ -105,7 +105,7 @@ elfw2(LIBELFBITS,checksum) (Elf *elf)
>>  
>>        if (SECTION_STRIP_P (shdr,
>>  			   INTUSE(elf_strptr) (elf, shstrndx, shdr->sh_name),
>> -			   true))
>> +			   true, false))
>>  	/* The section can be stripped.  Don't use it.  */
>>  	continue;
>>  
>> diff --git a/src/elfcmp.c b/src/elfcmp.c
>> index 21d8d9dc..76f15735 100644
>> --- a/src/elfcmp.c
>> +++ b/src/elfcmp.c
>> @@ -270,7 +270,7 @@ main (int argc, char *argv[])
>>  	    sname1 = elf_strptr (elf1, shstrndx1, shdr1->sh_name);
>>  	}
>>        while (scn1 != NULL && shdr1 != NULL
>> -	     && ebl_section_strip_p (ebl1, shdr1, sname1, true, false));
>> +	     && ebl_section_strip_p (ebl1, shdr1, sname1, true, false, false));
>>  
>>        GElf_Shdr shdr2_mem;
>>        GElf_Shdr *shdr2;
>> @@ -283,7 +283,7 @@ main (int argc, char *argv[])
>>  	    sname2 = elf_strptr (elf2, shstrndx2, shdr2->sh_name);
>>  	}
>>        while (scn2 != NULL && shdr2 != NULL
>> -	     && ebl_section_strip_p (ebl2, shdr2, sname2, true, false));
>> +	     && ebl_section_strip_p (ebl2, shdr2, sname2, true, false, false));
>>  
>>        if (scn1 == NULL || scn2 == NULL || shdr1 == NULL || shdr2 == NULL)
>>  	break;
>> diff --git a/src/strip.c b/src/strip.c
>> index 452b1279..6f79a1d0 100644
>> --- a/src/strip.c
>> +++ b/src/strip.c
>> @@ -62,6 +62,7 @@ ARGP_PROGRAM_BUG_ADDRESS_DEF = PACKAGE_BUGREPORT;
>>  #define OPT_RELOC_DEBUG 	0x103
>>  #define OPT_KEEP_SECTION 	0x104
>>  #define OPT_RELOC_DEBUG_ONLY    0x105
>> +#define OPT_REMOVE_CTF	        0x106
>>  
>>  
>>  /* Definitions of arguments for argp functions.  */
>> @@ -87,6 +88,8 @@ static const struct argp_option options[] =
>> N_("Similar to --reloc-debug-sections, but resolve all trivial
> relocations between debug sections in place.  No other stripping is
> performed (operation is not reversible, incompatible with -f, -g,
> --remove-comment and --remove-section)"), 0 },
>>    { "remove-comment", OPT_REMOVE_COMMENT, NULL, 0,
>>      N_("Remove .comment section"), 0 },
>> +  { "remove-ctf", OPT_REMOVE_CTF, NULL, 0,
>> +    N_("Remove .ctf section"), 0 },
>> { "remove-section", 'R', "SECTION", 0, N_("Remove the named section.
> SECTION is an extended wildcard pattern.  May be given more than once.
> Only non-allocated sections can be removed."), 0 },
>> { "keep-section", OPT_KEEP_SECTION, "SECTION", 0, N_("Keep the named
> section.  SECTION is an extended wildcard pattern.  May be given more
> than once."), 0 },
>>    { "permissive", OPT_PERMISSIVE, NULL, 0,
>> @@ -150,6 +153,9 @@ static bool preserve_dates;
>>  /* If true .comment sections will be removed.  */
>>  static bool remove_comment;
>>  
>> +/* If true .ctf sections will be removed.  */
>> +static bool remove_ctf;
>> +
>>  /* If true remove all debug sections.  */
>>  static bool remove_debug;
>>  
>> @@ -217,6 +223,48 @@ section_name_matches (struct section_pattern *patterns, const char *name)
>>    return false;
>>  }
>>  
>> +static void
>> +set_remove_special_section_opt (const char *arg)
>> +{
>> +  if (fnmatch (arg, ".comment", FNM_EXTMATCH) == 0)
>> +    remove_comment = true;
>> +  else if (fnmatch (arg, ".ctf", FNM_EXTMATCH) == 0)
>> +    remove_ctf = true;
>> +}
>> +
>> +static error_t
>> +erratic_special_section_opt (struct argp_state *state)
>> +{
>> +  int s;
>> +  struct {
>> +    const char *name;
>> +    bool remove;
>> +  } special_secs[] = {
>> +      {
>> +        .name = ".comment",
>> +        .remove = remove_comment
>> +      },
>> +      {
>> +        .name = ".ctf",
>> +        .remove = remove_ctf
>> +      },
>> +      {
>> +        .name = NULL,
>> +      }
>> +  };
>> +
>> +  for (s = 0; special_secs[s].name; ++s)
>> +    if (special_secs[s].remove == true
>> +        && section_name_matches (keep_secs, special_secs[s].name))
>> +      {
>> +        argp_error (state,
>> +                    _("cannot both keep and remove %s section"),
>> +                    special_secs[s].name);
>> +        return EINVAL;
>> +      }
>> +
>> +  return 0;
>> +}
>>  
>>  int
>>  main (int argc, char *argv[])
>> @@ -325,9 +373,12 @@ parse_opt (int key, char *arg, struct argp_state *state)
>>        remove_comment = true;
>>        break;
>>  
>> +    case OPT_REMOVE_CTF:
>> +      remove_ctf = true;
>> +      break;
>> +
>>      case 'R':
>> -      if (fnmatch (arg, ".comment", FNM_EXTMATCH) == 0)
>> -	remove_comment = true;
>> +      set_remove_special_section_opt (arg);
>>        add_pattern (&remove_secs, arg);
>>        break;
>>  
>> @@ -353,13 +404,8 @@ parse_opt (int key, char *arg, struct argp_state *state)
>>        break;
>>  
>>      case ARGP_KEY_SUCCESS:
>> -      if (remove_comment == true
>> -	  && section_name_matches (keep_secs, ".comment"))
>> -	{
>> -	  argp_error (state,
>> -		      _("cannot both keep and remove .comment section"));
>> -	  return EINVAL;
>> -	}
>> +      if (erratic_special_section_opt (state))
>> +        return EINVAL;
>>        break;
>>  
>>      default:
>> @@ -1358,7 +1404,7 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname,
>>       all sections which are not used at runtime are stripped out.  But
>>       there are a few exceptions:
>>  
>> -     - special sections named ".comment" and ".note" are kept
>> +     - special sections named ".comment", ".note" and ".ctf" are kept
>>       - OS or architecture specific sections are kept since we might not
>>         know how to handle them
>>       - if a section is referred to from a section which is not removed
>> @@ -1371,7 +1417,7 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname,
>>      if (remove_shdrs ? !(shdr_info[cnt].shdr.sh_flags & SHF_ALLOC)
>>  	: (ebl_section_strip_p (ebl, &shdr_info[cnt].shdr,
>>  				shdr_info[cnt].name, remove_comment,
>> -				remove_debug)
>> +				remove_debug, remove_ctf)
>>  	   || cnt == shstrndx
>>  	   || section_name_matches (remove_secs, shdr_info[cnt].name)))
>>        {
>> @@ -1534,7 +1580,8 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname,
>>  						    &shdr_info[scnidx].shdr,
>>  						    shdr_info[scnidx].name,
>>  						    remove_comment,
>> -						    remove_debug)
>> +						    remove_debug,
>> +						    remove_ctf)
>>  			       && ebl_data_marker_symbol (ebl, sym,
>>  					elf_strptr (elf,
>>  						    shdr_info[cnt].shdr.sh_link,
>> diff --git a/tests/Makefile.am b/tests/Makefile.am
>> index 84c3950a..f30d958e 100644
>> --- a/tests/Makefile.am
>> +++ b/tests/Makefile.am
>> @@ -197,7 +197,8 @@ TESTS = run-arextract.sh run-arsymtest.sh run-ar.sh newfile test-nlist \
>>  	msg_tst system-elf-libelf-test \
>>  	$(asm_TESTS) run-disasm-bpf.sh run-low_high_pc-dw-form-indirect.sh \
>>  	run-nvidia-extended-linemap-libdw.sh run-nvidia-extended-linemap-readelf.sh \
>> -	run-readelf-dw-form-indirect.sh run-strip-largealign.sh
>> +	run-readelf-dw-form-indirect.sh run-strip-largealign.sh \
>> +	run-strip-remove-keep-ctf.sh
>>  
>>  if !BIARCH
>>  export ELFUTILS_DISABLE_BIARCH = 1
>> @@ -580,7 +581,8 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh run-ar.sh \
>>  	     run-readelf-dw-form-indirect.sh testfile-dw-form-indirect.bz2 \
>>  	     run-nvidia-extended-linemap-libdw.sh run-nvidia-extended-linemap-readelf.sh \
>>  	     testfile_nvidia_linemap.bz2 \
>> -	     testfile-largealign.o.bz2 run-strip-largealign.sh
>> +	     testfile-largealign.o.bz2 run-strip-largealign.sh \
>> +	     testfile-ctf.bz2 run-strip-remove-keep-ctf.sh
>>  
>>  
>>  if USE_VALGRIND
>> diff --git a/tests/run-strip-remove-keep-ctf.sh b/tests/run-strip-remove-keep-ctf.sh
>> new file mode 100755
>> index 00000000..1a9bd93b
>> --- /dev/null
>> +++ b/tests/run-strip-remove-keep-ctf.sh
>> @@ -0,0 +1,207 @@
>> +#! /bin/sh
>> +# Copyright (C) 2022 Oracle, 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
>> +
>> +# strip -o output and -f debug files
>> +tempfiles testfile.elf testfile.debug
>> +
>> +# A random 32bit testfile
>> +testfiles testfile-ctf
>> +
>> +# strip should keep .ctf section
>> +echo strip testfile-ctf
>> +testrun ${abs_top_builddir}/src/strip -o testfile.elf -f testfile.debug testfile-ctf
>> +echo elflint testfile.elf
>> +testrun ${abs_top_builddir}/src/elflint --gnu testfile.elf
>> +echo elflint testfile.debug
>> +testrun ${abs_top_builddir}/src/elflint --gnu -d testfile.debug
>> +echo readelf testfile.elf
>> +testrun_compare ${abs_top_builddir}/src/readelf -S testfile.elf <<\EOF
>> +There are 30 section headers, starting at offset 0x3330:
>> +
>> +Section Headers:
>> +[Nr] Name                 Type         Addr             Off      Size     ES Flags Lk Inf Al
>> +[ 0]                      NULL         0000000000000000 00000000 00000000  0        0   0  0
>> +[ 1] .interp              PROGBITS     0000000000400318 00000318 0000001c  0 A      0   0  1
>> +[ 2] .note.gnu.property   NOTE         0000000000400338 00000338 00000020  0 A      0   0  8
>> +[ 3] .note.ABI-tag        NOTE         0000000000400358 00000358 00000020  0 A      0   0  4
>> +[ 4] .hash                HASH         0000000000400378 00000378 00000028  4 A      6   0  8
>> +[ 5] .gnu.hash            GNU_HASH     00000000004003a0 000003a0 0000001c  0 A      6   0  8
>> +[ 6] .dynsym              DYNSYM       00000000004003c0 000003c0 00000078 24 A      7   1  8
>> +[ 7] .dynstr              STRTAB       0000000000400438 00000438 00000057  0 A      0   0  1
>> +[ 8] .gnu.version         GNU_versym   0000000000400490 00000490 0000000a  2 A      6   0  2
>> +[ 9] .gnu.version_r       GNU_verneed  00000000004004a0 000004a0 00000030  0 A      7   1  8
>> +[10] .rela.dyn            RELA         00000000004004d0 000004d0 00000030 24 A      6   0  8
>> +[11] .rela.plt            RELA         0000000000400500 00000500 00000030 24 AI     6  23  8
>> +[12] .init                PROGBITS     0000000000401000 00001000 00000017  0 AX     0   0  4
>> +[13] .plt                 PROGBITS     0000000000401020 00001020 00000030 16 AX     0   0 16
>> +[14] .text                PROGBITS     0000000000401050 00001050 000001d1  0 AX     0   0 16
>> +[15] .fini                PROGBITS     0000000000401224 00001224 00000009  0 AX     0   0  4
>> +[16] .rodata              PROGBITS     0000000000402000 00002000 00000010  0 A      0   0  4
>> +[17] .eh_frame_hdr        PROGBITS     0000000000402010 00002010 0000003c  0 A      0   0  4
>> +[18] .eh_frame            PROGBITS     0000000000402050 00002050 00000100  0 A      0   0  8
>> +[19] .init_array          INIT_ARRAY   0000000000403e00 00002e00 00000008  8 WA     0   0  8
>> +[20] .fini_array          FINI_ARRAY   0000000000403e08 00002e08 00000008  8 WA     0   0  8
>> +[21] .dynamic             DYNAMIC      0000000000403e10 00002e10 000001e0 16 WA     7   0  8
>> +[22] .got                 PROGBITS     0000000000403ff0 00002ff0 00000010  8 WA     0   0  8
>> +[23] .got.plt             PROGBITS     0000000000404000 00003000 00000028  8 WA     0   0  8
>> +[24] .data                PROGBITS     0000000000404028 00003028 00000010  0 WA     0   0  8
>> +[25] .bss                 NOBITS       0000000000404038 00003038 00000008  0 WA     0   0  4
>> +[26] .comment             PROGBITS     0000000000000000 00003038 0000002a  1 MS     0   0  1
>> +[27] .ctf                 PROGBITS     0000000000000000 00003062 000001af  0        0   0  1
>> +[28] .gnu_debuglink       PROGBITS     0000000000000000 00003214 00000014  0        0   0  4
>> +[29] .shstrtab            STRTAB       0000000000000000 00003228 00000107  0        0   0  1
>> +
>> +EOF
>> +echo readelf testfile.debug
>> +testrun_compare ${abs_top_builddir}/src/readelf -S testfile.debug <<\EOF
>> +There are 37 section headers, starting at offset 0xdf0:
>> +
>> +Section Headers:
>> +[Nr] Name                 Type         Addr             Off      Size     ES Flags Lk Inf Al
>> +[ 0]                      NULL         0000000000000000 00000000 00000000  0        0   0  0
>> +[ 1] .interp              NOBITS       0000000000400318 00000318 0000001c  0 A      0   0  1
>> +[ 2] .note.gnu.property   NOTE         0000000000400338 00000318 00000020  0 A      0   0  8
>> +[ 3] .note.ABI-tag        NOTE         0000000000400358 00000338 00000020  0 A      0   0  4
>> +[ 4] .hash                NOBITS       0000000000400378 00000358 00000028  4 A      6   0  8
>> +[ 5] .gnu.hash            NOBITS       00000000004003a0 00000358 0000001c  0 A      6   0  8
>> +[ 6] .dynsym              NOBITS       00000000004003c0 00000358 00000078 24 A      7   1  8
>> +[ 7] .dynstr              NOBITS       0000000000400438 00000358 00000057  0 A      0   0  1
>> +[ 8] .gnu.version         NOBITS       0000000000400490 00000358 0000000a  2 A      6   0  2
>> +[ 9] .gnu.version_r       NOBITS       00000000004004a0 00000358 00000030  0 A      7   1  8
>> +[10] .rela.dyn            NOBITS       00000000004004d0 00000358 00000030 24 A      6   0  8
>> +[11] .rela.plt            NOBITS       0000000000400500 00000358 00000030 24 AI     6  23  8
>> +[12] .init                NOBITS       0000000000401000 00000358 00000017  0 AX     0   0  4
>> +[13] .plt                 NOBITS       0000000000401020 00000360 00000030 16 AX     0   0 16
>> +[14] .text                NOBITS       0000000000401050 00000360 000001d1  0 AX     0   0 16
>> +[15] .fini                NOBITS       0000000000401224 00000360 00000009  0 AX     0   0  4
>> +[16] .rodata              NOBITS       0000000000402000 00000360 00000010  0 A      0   0  4
>> +[17] .eh_frame_hdr        NOBITS       0000000000402010 00000360 0000003c  0 A      0   0  4
>> +[18] .eh_frame            NOBITS       0000000000402050 00000360 00000100  0 A      0   0  8
>> +[19] .init_array          NOBITS       0000000000403e00 00000360 00000008  8 WA     0   0  8
>> +[20] .fini_array          NOBITS       0000000000403e08 00000360 00000008  8 WA     0   0  8
>> +[21] .dynamic             NOBITS       0000000000403e10 00000360 000001e0 16 WA     7   0  8
>> +[22] .got                 NOBITS       0000000000403ff0 00000360 00000010  8 WA     0   0  8
>> +[23] .got.plt             NOBITS       0000000000404000 00000360 00000028  8 WA     0   0  8
>> +[24] .data                NOBITS       0000000000404028 00000360 00000010  0 WA     0   0  8
>> +[25] .bss                 NOBITS       0000000000404038 00000360 00000008  0 WA     0   0  4
>> +[26] .comment             NOBITS       0000000000000000 00000360 0000002a  1 MS     0   0  1
>> +[27] .ctf                 NOBITS       0000000000000000 00000360 000001af  0        0   0  1
>> +[28] .debug_aranges       PROGBITS     0000000000000000 00000360 00000030  0        0   0  1
>> +[29] .debug_info          PROGBITS     0000000000000000 00000390 00000121  0        0   0  1
>> +[30] .debug_abbrev        PROGBITS     0000000000000000 000004b1 000000b6  0        0   0  1
>> +[31] .debug_line          PROGBITS     0000000000000000 00000567 00000063  0        0   0  1
>> +[32] .debug_str           PROGBITS     0000000000000000 000005ca 000000ba  1 MS     0   0  1
>> +[33] .debug_line_str      PROGBITS     0000000000000000 00000684 0000005c  1 MS     0   0  1
>> +[34] .symtab              SYMTAB       0000000000000000 000006e0 000003c0 24       35  21  8
>> +[35] .strtab              STRTAB       0000000000000000 00000aa0 000001f1  0        0   0  1
>> +[36] .shstrtab            STRTAB       0000000000000000 00000c91 00000158  0        0   0  1
>> +
>> +EOF
>> +
>> +# Explicitly removes .ctf section
>> +echo strip --remove-ctf testfile
>> +testrun ${abs_top_builddir}/src/strip --remove-ctf -o testfile.elf
> -f testfile.debug testfile-ctf
>> +echo elflint testfile.elf
>> +testrun ${abs_top_builddir}/src/elflint --gnu testfile.elf
>> +echo elflint testfile.debug
>> +testrun ${abs_top_builddir}/src/elflint --gnu -d testfile.debug
>> +echo readelf testfile.elf
>> +testrun_compare ${abs_top_builddir}/src/readelf -S testfile.elf <<\EOF
>> +There are 29 section headers, starting at offset 0x3180:
>> +
>> +Section Headers:
>> +[Nr] Name                 Type         Addr             Off      Size     ES Flags Lk Inf Al
>> +[ 0]                      NULL         0000000000000000 00000000 00000000  0        0   0  0
>> +[ 1] .interp              PROGBITS     0000000000400318 00000318 0000001c  0 A      0   0  1
>> +[ 2] .note.gnu.property   NOTE         0000000000400338 00000338 00000020  0 A      0   0  8
>> +[ 3] .note.ABI-tag        NOTE         0000000000400358 00000358 00000020  0 A      0   0  4
>> +[ 4] .hash                HASH         0000000000400378 00000378 00000028  4 A      6   0  8
>> +[ 5] .gnu.hash            GNU_HASH     00000000004003a0 000003a0 0000001c  0 A      6   0  8
>> +[ 6] .dynsym              DYNSYM       00000000004003c0 000003c0 00000078 24 A      7   1  8
>> +[ 7] .dynstr              STRTAB       0000000000400438 00000438 00000057  0 A      0   0  1
>> +[ 8] .gnu.version         GNU_versym   0000000000400490 00000490 0000000a  2 A      6   0  2
>> +[ 9] .gnu.version_r       GNU_verneed  00000000004004a0 000004a0 00000030  0 A      7   1  8
>> +[10] .rela.dyn            RELA         00000000004004d0 000004d0 00000030 24 A      6   0  8
>> +[11] .rela.plt            RELA         0000000000400500 00000500 00000030 24 AI     6  23  8
>> +[12] .init                PROGBITS     0000000000401000 00001000 00000017  0 AX     0   0  4
>> +[13] .plt                 PROGBITS     0000000000401020 00001020 00000030 16 AX     0   0 16
>> +[14] .text                PROGBITS     0000000000401050 00001050 000001d1  0 AX     0   0 16
>> +[15] .fini                PROGBITS     0000000000401224 00001224 00000009  0 AX     0   0  4
>> +[16] .rodata              PROGBITS     0000000000402000 00002000 00000010  0 A      0   0  4
>> +[17] .eh_frame_hdr        PROGBITS     0000000000402010 00002010 0000003c  0 A      0   0  4
>> +[18] .eh_frame            PROGBITS     0000000000402050 00002050 00000100  0 A      0   0  8
>> +[19] .init_array          INIT_ARRAY   0000000000403e00 00002e00 00000008  8 WA     0   0  8
>> +[20] .fini_array          FINI_ARRAY   0000000000403e08 00002e08 00000008  8 WA     0   0  8
>> +[21] .dynamic             DYNAMIC      0000000000403e10 00002e10 000001e0 16 WA     7   0  8
>> +[22] .got                 PROGBITS     0000000000403ff0 00002ff0 00000010  8 WA     0   0  8
>> +[23] .got.plt             PROGBITS     0000000000404000 00003000 00000028  8 WA     0   0  8
>> +[24] .data                PROGBITS     0000000000404028 00003028 00000010  0 WA     0   0  8
>> +[25] .bss                 NOBITS       0000000000404038 00003038 00000008  0 WA     0   0  4
>> +[26] .comment             PROGBITS     0000000000000000 00003038 0000002a  1 MS     0   0  1
>> +[27] .gnu_debuglink       PROGBITS     0000000000000000 00003064 00000014  0        0   0  4
>> +[28] .shstrtab            STRTAB       0000000000000000 00003078 00000102  0        0   0  1
>> +
>> +EOF
>> +echo readelf testfile.debug
>> +testrun_compare ${abs_top_builddir}/src/readelf -S testfile.debug <<\EOF
>> +There are 37 section headers, starting at offset 0xfa0:
>> +
>> +Section Headers:
>> +[Nr] Name                 Type         Addr             Off      Size     ES Flags Lk Inf Al
>> +[ 0]                      NULL         0000000000000000 00000000 00000000  0        0   0  0
>> +[ 1] .interp              NOBITS       0000000000400318 00000318 0000001c  0 A      0   0  1
>> +[ 2] .note.gnu.property   NOTE         0000000000400338 00000318 00000020  0 A      0   0  8
>> +[ 3] .note.ABI-tag        NOTE         0000000000400358 00000338 00000020  0 A      0   0  4
>> +[ 4] .hash                NOBITS       0000000000400378 00000358 00000028  4 A      6   0  8
>> +[ 5] .gnu.hash            NOBITS       00000000004003a0 00000358 0000001c  0 A      6   0  8
>> +[ 6] .dynsym              NOBITS       00000000004003c0 00000358 00000078 24 A      7   1  8
>> +[ 7] .dynstr              NOBITS       0000000000400438 00000358 00000057  0 A      0   0  1
>> +[ 8] .gnu.version         NOBITS       0000000000400490 00000358 0000000a  2 A      6   0  2
>> +[ 9] .gnu.version_r       NOBITS       00000000004004a0 00000358 00000030  0 A      7   1  8
>> +[10] .rela.dyn            NOBITS       00000000004004d0 00000358 00000030 24 A      6   0  8
>> +[11] .rela.plt            NOBITS       0000000000400500 00000358 00000030 24 AI     6  23  8
>> +[12] .init                NOBITS       0000000000401000 00000358 00000017  0 AX     0   0  4
>> +[13] .plt                 NOBITS       0000000000401020 00000360 00000030 16 AX     0   0 16
>> +[14] .text                NOBITS       0000000000401050 00000360 000001d1  0 AX     0   0 16
>> +[15] .fini                NOBITS       0000000000401224 00000360 00000009  0 AX     0   0  4
>> +[16] .rodata              NOBITS       0000000000402000 00000360 00000010  0 A      0   0  4
>> +[17] .eh_frame_hdr        NOBITS       0000000000402010 00000360 0000003c  0 A      0   0  4
>> +[18] .eh_frame            NOBITS       0000000000402050 00000360 00000100  0 A      0   0  8
>> +[19] .init_array          NOBITS       0000000000403e00 00000360 00000008  8 WA     0   0  8
>> +[20] .fini_array          NOBITS       0000000000403e08 00000360 00000008  8 WA     0   0  8
>> +[21] .dynamic             NOBITS       0000000000403e10 00000360 000001e0 16 WA     7   0  8
>> +[22] .got                 NOBITS       0000000000403ff0 00000360 00000010  8 WA     0   0  8
>> +[23] .got.plt             NOBITS       0000000000404000 00000360 00000028  8 WA     0   0  8
>> +[24] .data                NOBITS       0000000000404028 00000360 00000010  0 WA     0   0  8
>> +[25] .bss                 NOBITS       0000000000404038 00000360 00000008  0 WA     0   0  4
>> +[26] .comment             NOBITS       0000000000000000 00000360 0000002a  1 MS     0   0  1
>> +[27] .ctf                 PROGBITS     0000000000000000 00000360 000001af  0        0   0  1
>> +[28] .debug_aranges       PROGBITS     0000000000000000 0000050f 00000030  0        0   0  1
>> +[29] .debug_info          PROGBITS     0000000000000000 0000053f 00000121  0        0   0  1
>> +[30] .debug_abbrev        PROGBITS     0000000000000000 00000660 000000b6  0        0   0  1
>> +[31] .debug_line          PROGBITS     0000000000000000 00000716 00000063  0        0   0  1
>> +[32] .debug_str           PROGBITS     0000000000000000 00000779 000000ba  1 MS     0   0  1
>> +[33] .debug_line_str      PROGBITS     0000000000000000 00000833 0000005c  1 MS     0   0  1
>> +[34] .symtab              SYMTAB       0000000000000000 00000890 000003c0 24       35  21  8
>> +[35] .strtab              STRTAB       0000000000000000 00000c50 000001f1  0        0   0  1
>> +[36] .shstrtab            STRTAB       0000000000000000 00000e41 00000158  0        0   0  1
>> +
>> +EOF
>> +
>> +exit 0
>> diff --git a/tests/testfile-ctf.bz2 b/tests/testfile-ctf.bz2
>> new file mode 100755
>> index 0000000000000000000000000000000000000000..af909af0fe7b7d88f11426e349e867e39fddfafd
>> GIT binary patch
>> literal 3317
>> zcmV<R3<~o?T4*^jL0KkKSuG_=7yt}J|NsC0|NsC0|NsB@|NsC0|Nj5)^>ool$yNRQ
>> z{a*L~|6kw>L^-~iz!v3`m9t8Amleo4T#|O$(vEkAge1Wxr<C$FJxm$^rfpNy{VC~_
>> zCZ;kcq&-ck>NZ63n@P1crqp@}KT>I<Wf+*610eK|K$t<JCYm%FdYS_v>KYBHv}y*X
>> zKqEq8YMum7N$DPx^o=q!(WaROk5FloMuv?8Mu5;70009u4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ML1B9EhR}9WKhMn
>> 
>> literal 0
>> HcmV?d00001
>> 
>> 
>> base-commit: 27414ecffd6cc71c9af7bacc75ce448121ac005f
>> -- 
>> 2.35.1
>> 

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH] strip: keep .ctf section in stripped file
  2022-05-31 10:26   ` Jose E. Marchesi
@ 2022-05-31 12:50     ` Jose E. Marchesi
  0 siblings, 0 replies; 29+ messages in thread
From: Jose E. Marchesi @ 2022-05-31 12:50 UTC (permalink / raw)
  To: Mark Wielaard; +Cc: Guillermo E. Martinez, elfutils-devel, Nick Clifton


> [Added Nick in CC.]
>
>> Hi Guillermo,
>>
>> On Mon, May 30, 2022 at 09:26:19PM -0500, Guillermo E. Martinez via Elfutils-devel wrote:
>>> Hello elfutils team,
>>> 
>>> This patch is meant to avoid remove the CTF section in
>>> stripped files.  Please let me know your thoughts.
>>>
>>> CTF debug format was designed to be present in stripped files, so
>>> this section should not be removed, so a new --remove-ctf option
>>> is added to indicate explicitly that .ctf section will be stripped
>>> out from binary file.
>>
>> First, very nice patch. My only real concern with it is that it should
>> describe how the testfile-ctf.bz2 is generated. We don't want really
>> random test binaries in the testsuite. There should be at least some
>> method to regenerate them, even if we don't automate that. See
>> e.g. tests/run-readelf-n.sh which also uses binary test files, but has
>> a little description on how each of them was generated.
>>
>> I am CCing Nick Clifton who works on binutils and annobin to check how
>> binutils strip handles this. And because we were recently discussing
>> putting some annobin data in a special section and how to indicate
>> that this section should be explicitly kept or removed. It would be
>> great if we could come to some kind of standard way of marking such
>> sections so we don't need special arguments for each such section or
>> at least have a more generic SECTION_STRIP_P macro.
>>
>> Note, that this might not be possible, these sections might be to
>> different/specific that generalizing over them is impossible. But it
>> would be good to at least try and discuss it. If only so that elfutils
>> eu-strip and binutils strip agree on how to handle/coordinate on such
>> special sections.
>
> What about using an OS-specific section flag in elf.h, something like:
>
> #define SHF_GNU_PERSISTENT 0x0ff00001 /* Section must not be stripped.  */

It now occurs to me that it would be probably better to use a less
abstract name for the flag, like SHF_GNU_NOSTRIP (I'm not that good on
naming stuff.) :)

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH] strip: keep .ctf section in stripped file
  2022-05-31  7:06 ` Mark Wielaard
  2022-05-31 10:26   ` Jose E. Marchesi
@ 2022-06-01  4:34   ` Guillermo E. Martinez
  2022-06-01 15:55   ` [PATCHv2] " Guillermo E. Martinez
  2 siblings, 0 replies; 29+ messages in thread
From: Guillermo E. Martinez @ 2022-06-01  4:34 UTC (permalink / raw)
  To: Mark Wielaard; +Cc: elfutils-devel, nickc

On Tuesday, May 31, 2022 2:06:26 AM CDT Mark Wielaard wrote:
Hi, Mark
> 
> On Mon, May 30, 2022 at 09:26:19PM -0500, Guillermo E. Martinez via Elfutils-devel wrote:
> > Hello elfutils team,
> > 
> > This patch is meant to avoid remove the CTF section in
> > stripped files.  Please let me know your thoughts.
> >
> > CTF debug format was designed to be present in stripped files, so
> > this section should not be removed, so a new --remove-ctf option
> > is added to indicate explicitly that .ctf section will be stripped
> > out from binary file.
> 
> First, very nice patch. My only real concern with it is that it should
> describe how the testfile-ctf.bz2 is generated. We don't want really
> random test binaries in the testsuite. There should be at least some
> method to regenerate them, even if we don't automate that. See
> e.g. tests/run-readelf-n.sh which also uses binary test files, but has
> a little description on how each of them was generated.
sure, I will take a look in tests/run-readelf-n.sh to see how it can be
regenerated and update it in patch v2.

> I am CCing Nick Clifton who works on binutils and annobin to check how
> binutils strip handles this. And because we were recently discussing
> putting some annobin data in a special section and how to indicate
> that this section should be explicitly kept or removed. It would be
> great if we could come to some kind of standard way of marking such
> sections so we don't need special arguments for each such section or
> at least have a more generic SECTION_STRIP_P macro.
ok, let me check how strip from binutils keeps by default .ctf section.

> Note, that this might not be possible, these sections might be to
> different/specific that generalizing over them is impossible. But it
> would be good to at least try and discuss it. If only so that elfutils
> eu-strip and binutils strip agree on how to handle/coordinate on such
> special sections.
ok.
[...]

Thanks for your comments!
guillermo



^ permalink raw reply	[flat|nested] 29+ messages in thread

* [PATCHv2] strip: keep .ctf section in stripped file
  2022-05-31  7:06 ` Mark Wielaard
  2022-05-31 10:26   ` Jose E. Marchesi
  2022-06-01  4:34   ` Guillermo E. Martinez
@ 2022-06-01 15:55   ` Guillermo E. Martinez
  2022-12-20 21:35     ` Mark Wielaard
  2023-02-23 18:42     ` [PATCH v3] " Guillermo E. Martinez
  2 siblings, 2 replies; 29+ messages in thread
From: Guillermo E. Martinez @ 2022-06-01 15:55 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Guillermo E. Martinez

Hello,

This is the second version patch to avoid remove the CTF section in
stripped files. Changes from v1:

  - Add description in tests/run-strip-remove-keep-ctf.sh
    mentioning how to regenerate test input file (testfile-ctf)

Please let me know your thoughts.

Kind regard,
guillermo

CTF debug format was designed to be present in stripped files, so
this section should not be removed, so a new --remove-ctf option
is added to indicate explicitly that .ctf section will be stripped
out from binary file.

Signed-off-by: Guillermo E. Martinez <guillermo.e.martinez@oracle.com>
---
 ChangeLog                          |  23 ++++
 libebl/eblsectionstripp.c          |   4 +-
 libebl/libebl.h                    |   2 +-
 libelf/elf-knowledge.h             |   7 +-
 libelf/elf32_checksum.c            |   2 +-
 src/elfcmp.c                       |   4 +-
 src/strip.c                        |  71 ++++++++--
 tests/Makefile.am                  |   6 +-
 tests/run-strip-remove-keep-ctf.sh | 212 +++++++++++++++++++++++++++++
 tests/testfile-ctf.bz2             | Bin 0 -> 2620 bytes
 10 files changed, 309 insertions(+), 22 deletions(-)
 create mode 100755 tests/run-strip-remove-keep-ctf.sh
 create mode 100755 tests/testfile-ctf.bz2

diff --git a/ChangeLog b/ChangeLog
index f1a14b5c..2b608866 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,26 @@
+2022-05-21  Guillermo E. Martinez  <guillermo.e.martinez@oracle.com>
+
+	* libebl/eblsectionstripp.c (ebl_section_strip_p): Use
+	remove_ctf argument.
+	(SECTION_STRIP_P): Likewise.
+	* libebl/libebl.h (ebl_section_strip_p): Likewise.
+	* libelf/elf-knowledge.h (SECTION_STRIP_P): Update macro
+	definition to use remove_ctf to determine whether .ctf
+	section is stripped out.
+	* libelf/elf32_checksum.c (elfw2): Use false value for
+	remove_ctf parameter.
+	* src/elfcmp.c (main): Likewise.
+	* src/strip.c (options): Add --remove-ctf option set by
+	remove_ctf variable.
+	(set_remove_special_section_opt): Add new function.
+	(erratic_special_section_opt): Likewise.
+	(parse_opt): Parse new --remove-ctf option.
+	(handle_elf): Adjust .comment and use remove_ctf argument.
+	* tests/Makefile.am (TEST): Add run-strip-remove-keep-ctf.sh
+	and testfile-ctf.bz2.
+	* tests/run-strip-remove-keep-ctf.sh: Add new testcase.
+	* tests/testfile-ctf.bz2: Add new test harness.
+
 2022-05-02  Mark Wielaard  <mark@klomp.org>
 
 	* Makefile.am (AM_DISTCHECK_CONFIGURE_FLAGS): Remove
diff --git a/libebl/eblsectionstripp.c b/libebl/eblsectionstripp.c
index a5624ffe..f26cc170 100644
--- a/libebl/eblsectionstripp.c
+++ b/libebl/eblsectionstripp.c
@@ -37,7 +37,7 @@
 bool
 ebl_section_strip_p (Ebl *ebl, const GElf_Shdr *shdr,
 		     const char *name, bool remove_comment,
-		     bool only_remove_debug)
+		     bool only_remove_debug, bool remove_ctf)
 {
   /* If only debug information should be removed check the name.  There
      is unfortunately no other way.  */
@@ -66,5 +66,5 @@ ebl_section_strip_p (Ebl *ebl, const GElf_Shdr *shdr,
       return false;
     }
 
-  return SECTION_STRIP_P (shdr, name, remove_comment);
+  return SECTION_STRIP_P (shdr, name, remove_comment, remove_ctf);
 }
diff --git a/libebl/libebl.h b/libebl/libebl.h
index 731001d3..067b769e 100644
--- a/libebl/libebl.h
+++ b/libebl/libebl.h
@@ -205,7 +205,7 @@ extern bool ebl_relative_reloc_p (Ebl *ebl, int reloc);
 /* Check whether section should be stripped.  */
 extern bool ebl_section_strip_p (Ebl *ebl,
 				 const GElf_Shdr *shdr, const char *name,
-				 bool remove_comment, bool only_remove_debug);
+				 bool remove_comment, bool only_remove_debug, bool remove_ctf);
 
 /* Check if backend uses a bss PLT in this file.  */
 extern bool ebl_bss_plt_p (Ebl *ebl);
diff --git a/libelf/elf-knowledge.h b/libelf/elf-knowledge.h
index 6e005fa5..903a0f4f 100644
--- a/libelf/elf-knowledge.h
+++ b/libelf/elf-knowledge.h
@@ -34,7 +34,7 @@
 
 
 /* Test whether a section can be stripped or not.  */
-#define SECTION_STRIP_P(shdr, name, remove_comment) \
+#define SECTION_STRIP_P(shdr, name, remove_comment, remove_ctf) \
   /* Sections which are allocated are not removed.  */			      \
   (((shdr)->sh_flags & SHF_ALLOC) == 0					      \
    /* We never remove .note sections.  */				      \
@@ -45,7 +45,10 @@
 	   && strncmp (name, ".gnu.warning.", sizeof ".gnu.warning." - 1) != 0\
 	   /* We remove .comment sections only if explicitly told to do so. */\
 	   && (remove_comment						      \
-	       || strcmp (name, ".comment") != 0))))
+	       || strcmp (name, ".comment") != 0)  \
+	   /* We remove .ctf sections only if explicitly told to do so. */\
+	   && (remove_ctf						      \
+	       || strcmp (name, ".ctf") != 0))))
 
 
 /* Test whether `sh_info' field in section header contains a section
diff --git a/libelf/elf32_checksum.c b/libelf/elf32_checksum.c
index c5f27bbe..190bad7d 100644
--- a/libelf/elf32_checksum.c
+++ b/libelf/elf32_checksum.c
@@ -105,7 +105,7 @@ elfw2(LIBELFBITS,checksum) (Elf *elf)
 
       if (SECTION_STRIP_P (shdr,
 			   INTUSE(elf_strptr) (elf, shstrndx, shdr->sh_name),
-			   true))
+			   true, false))
 	/* The section can be stripped.  Don't use it.  */
 	continue;
 
diff --git a/src/elfcmp.c b/src/elfcmp.c
index 21d8d9dc..76f15735 100644
--- a/src/elfcmp.c
+++ b/src/elfcmp.c
@@ -270,7 +270,7 @@ main (int argc, char *argv[])
 	    sname1 = elf_strptr (elf1, shstrndx1, shdr1->sh_name);
 	}
       while (scn1 != NULL && shdr1 != NULL
-	     && ebl_section_strip_p (ebl1, shdr1, sname1, true, false));
+	     && ebl_section_strip_p (ebl1, shdr1, sname1, true, false, false));
 
       GElf_Shdr shdr2_mem;
       GElf_Shdr *shdr2;
@@ -283,7 +283,7 @@ main (int argc, char *argv[])
 	    sname2 = elf_strptr (elf2, shstrndx2, shdr2->sh_name);
 	}
       while (scn2 != NULL && shdr2 != NULL
-	     && ebl_section_strip_p (ebl2, shdr2, sname2, true, false));
+	     && ebl_section_strip_p (ebl2, shdr2, sname2, true, false, false));
 
       if (scn1 == NULL || scn2 == NULL || shdr1 == NULL || shdr2 == NULL)
 	break;
diff --git a/src/strip.c b/src/strip.c
index 452b1279..6f79a1d0 100644
--- a/src/strip.c
+++ b/src/strip.c
@@ -62,6 +62,7 @@ ARGP_PROGRAM_BUG_ADDRESS_DEF = PACKAGE_BUGREPORT;
 #define OPT_RELOC_DEBUG 	0x103
 #define OPT_KEEP_SECTION 	0x104
 #define OPT_RELOC_DEBUG_ONLY    0x105
+#define OPT_REMOVE_CTF	        0x106
 
 
 /* Definitions of arguments for argp functions.  */
@@ -87,6 +88,8 @@ static const struct argp_option options[] =
     N_("Similar to --reloc-debug-sections, but resolve all trivial relocations between debug sections in place.  No other stripping is performed (operation is not reversible, incompatible with -f, -g, --remove-comment and --remove-section)"), 0 },
   { "remove-comment", OPT_REMOVE_COMMENT, NULL, 0,
     N_("Remove .comment section"), 0 },
+  { "remove-ctf", OPT_REMOVE_CTF, NULL, 0,
+    N_("Remove .ctf section"), 0 },
   { "remove-section", 'R', "SECTION", 0, N_("Remove the named section.  SECTION is an extended wildcard pattern.  May be given more than once.  Only non-allocated sections can be removed."), 0 },
   { "keep-section", OPT_KEEP_SECTION, "SECTION", 0, N_("Keep the named section.  SECTION is an extended wildcard pattern.  May be given more than once."), 0 },
   { "permissive", OPT_PERMISSIVE, NULL, 0,
@@ -150,6 +153,9 @@ static bool preserve_dates;
 /* If true .comment sections will be removed.  */
 static bool remove_comment;
 
+/* If true .ctf sections will be removed.  */
+static bool remove_ctf;
+
 /* If true remove all debug sections.  */
 static bool remove_debug;
 
@@ -217,6 +223,48 @@ section_name_matches (struct section_pattern *patterns, const char *name)
   return false;
 }
 
+static void
+set_remove_special_section_opt (const char *arg)
+{
+  if (fnmatch (arg, ".comment", FNM_EXTMATCH) == 0)
+    remove_comment = true;
+  else if (fnmatch (arg, ".ctf", FNM_EXTMATCH) == 0)
+    remove_ctf = true;
+}
+
+static error_t
+erratic_special_section_opt (struct argp_state *state)
+{
+  int s;
+  struct {
+    const char *name;
+    bool remove;
+  } special_secs[] = {
+      {
+        .name = ".comment",
+        .remove = remove_comment
+      },
+      {
+        .name = ".ctf",
+        .remove = remove_ctf
+      },
+      {
+        .name = NULL,
+      }
+  };
+
+  for (s = 0; special_secs[s].name; ++s)
+    if (special_secs[s].remove == true
+        && section_name_matches (keep_secs, special_secs[s].name))
+      {
+        argp_error (state,
+                    _("cannot both keep and remove %s section"),
+                    special_secs[s].name);
+        return EINVAL;
+      }
+
+  return 0;
+}
 
 int
 main (int argc, char *argv[])
@@ -325,9 +373,12 @@ parse_opt (int key, char *arg, struct argp_state *state)
       remove_comment = true;
       break;
 
+    case OPT_REMOVE_CTF:
+      remove_ctf = true;
+      break;
+
     case 'R':
-      if (fnmatch (arg, ".comment", FNM_EXTMATCH) == 0)
-	remove_comment = true;
+      set_remove_special_section_opt (arg);
       add_pattern (&remove_secs, arg);
       break;
 
@@ -353,13 +404,8 @@ parse_opt (int key, char *arg, struct argp_state *state)
       break;
 
     case ARGP_KEY_SUCCESS:
-      if (remove_comment == true
-	  && section_name_matches (keep_secs, ".comment"))
-	{
-	  argp_error (state,
-		      _("cannot both keep and remove .comment section"));
-	  return EINVAL;
-	}
+      if (erratic_special_section_opt (state))
+        return EINVAL;
       break;
 
     default:
@@ -1358,7 +1404,7 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname,
      all sections which are not used at runtime are stripped out.  But
      there are a few exceptions:
 
-     - special sections named ".comment" and ".note" are kept
+     - special sections named ".comment", ".note" and ".ctf" are kept
      - OS or architecture specific sections are kept since we might not
        know how to handle them
      - if a section is referred to from a section which is not removed
@@ -1371,7 +1417,7 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname,
     if (remove_shdrs ? !(shdr_info[cnt].shdr.sh_flags & SHF_ALLOC)
 	: (ebl_section_strip_p (ebl, &shdr_info[cnt].shdr,
 				shdr_info[cnt].name, remove_comment,
-				remove_debug)
+				remove_debug, remove_ctf)
 	   || cnt == shstrndx
 	   || section_name_matches (remove_secs, shdr_info[cnt].name)))
       {
@@ -1534,7 +1580,8 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname,
 						    &shdr_info[scnidx].shdr,
 						    shdr_info[scnidx].name,
 						    remove_comment,
-						    remove_debug)
+						    remove_debug,
+						    remove_ctf)
 			       && ebl_data_marker_symbol (ebl, sym,
 					elf_strptr (elf,
 						    shdr_info[cnt].shdr.sh_link,
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 84c3950a..f30d958e 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -197,7 +197,8 @@ TESTS = run-arextract.sh run-arsymtest.sh run-ar.sh newfile test-nlist \
 	msg_tst system-elf-libelf-test \
 	$(asm_TESTS) run-disasm-bpf.sh run-low_high_pc-dw-form-indirect.sh \
 	run-nvidia-extended-linemap-libdw.sh run-nvidia-extended-linemap-readelf.sh \
-	run-readelf-dw-form-indirect.sh run-strip-largealign.sh
+	run-readelf-dw-form-indirect.sh run-strip-largealign.sh \
+	run-strip-remove-keep-ctf.sh
 
 if !BIARCH
 export ELFUTILS_DISABLE_BIARCH = 1
@@ -580,7 +581,8 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh run-ar.sh \
 	     run-readelf-dw-form-indirect.sh testfile-dw-form-indirect.bz2 \
 	     run-nvidia-extended-linemap-libdw.sh run-nvidia-extended-linemap-readelf.sh \
 	     testfile_nvidia_linemap.bz2 \
-	     testfile-largealign.o.bz2 run-strip-largealign.sh
+	     testfile-largealign.o.bz2 run-strip-largealign.sh \
+	     testfile-ctf.bz2 run-strip-remove-keep-ctf.sh
 
 
 if USE_VALGRIND
diff --git a/tests/run-strip-remove-keep-ctf.sh b/tests/run-strip-remove-keep-ctf.sh
new file mode 100755
index 00000000..9a4fde72
--- /dev/null
+++ b/tests/run-strip-remove-keep-ctf.sh
@@ -0,0 +1,212 @@
+#! /bin/sh
+# Copyright (C) 2022 Oracle, 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
+
+# - testfile-ctf.c
+# int
+# main ()
+# {
+#   return 0;
+# }
+#
+# gcc -gctf -g -o testfile-ctf testfile-ctf.c
+# eu-strip testfile-ctf
+
+# strip -o output and -f debug files
+tempfiles testfile.elf testfile.debug
+
+# A random 32bit testfile
+testfiles testfile-ctf
+
+# strip should keep .ctf section
+echo strip testfile-ctf
+testrun ${abs_top_builddir}/src/strip -o testfile.elf -f testfile.debug testfile-ctf
+echo elflint testfile.elf
+testrun ${abs_top_builddir}/src/elflint --gnu testfile.elf
+echo elflint testfile.debug
+testrun ${abs_top_builddir}/src/elflint --gnu -d testfile.debug
+echo readelf testfile.elf
+testrun_compare ${abs_top_builddir}/src/readelf -S testfile.elf <<\EOF
+There are 28 section headers, starting at offset 0x31d8:
+
+Section Headers:
+[Nr] Name                 Type         Addr             Off      Size     ES Flags Lk Inf Al
+[ 0]                      NULL         0000000000000000 00000000 00000000  0        0   0  0
+[ 1] .interp              PROGBITS     0000000000400318 00000318 0000001c  0 A      0   0  1
+[ 2] .note.gnu.property   NOTE         0000000000400338 00000338 00000020  0 A      0   0  8
+[ 3] .note.ABI-tag        NOTE         0000000000400358 00000358 00000020  0 A      0   0  4
+[ 4] .hash                HASH         0000000000400378 00000378 00000018  4 A      6   0  8
+[ 5] .gnu.hash            GNU_HASH     0000000000400390 00000390 0000001c  0 A      6   0  8
+[ 6] .dynsym              DYNSYM       00000000004003b0 000003b0 00000048 24 A      7   1  8
+[ 7] .dynstr              STRTAB       00000000004003f8 000003f8 00000038  0 A      0   0  1
+[ 8] .gnu.version         GNU_versym   0000000000400430 00000430 00000006  2 A      6   0  2
+[ 9] .gnu.version_r       GNU_verneed  0000000000400438 00000438 00000020  0 A      7   1  8
+[10] .rela.dyn            RELA         0000000000400458 00000458 00000030 24 A      6   0  8
+[11] .init                PROGBITS     0000000000401000 00001000 00000017  0 AX     0   0  4
+[12] .text                PROGBITS     0000000000401020 00001020 00000191  0 AX     0   0 16
+[13] .fini                PROGBITS     00000000004011b4 000011b4 00000009  0 AX     0   0  4
+[14] .rodata              PROGBITS     0000000000402000 00002000 00000004  4 AM     0   0  4
+[15] .eh_frame_hdr        PROGBITS     0000000000402004 00002004 00000034  0 A      0   0  4
+[16] .eh_frame            PROGBITS     0000000000402038 00002038 000000d8  0 A      0   0  8
+[17] .init_array          INIT_ARRAY   0000000000403e40 00002e40 00000008  8 WA     0   0  8
+[18] .fini_array          FINI_ARRAY   0000000000403e48 00002e48 00000008  8 WA     0   0  8
+[19] .dynamic             DYNAMIC      0000000000403e50 00002e50 000001a0 16 WA     7   0  8
+[20] .got                 PROGBITS     0000000000403ff0 00002ff0 00000010  8 WA     0   0  8
+[21] .got.plt             PROGBITS     0000000000404000 00003000 00000018  8 WA     0   0  8
+[22] .data                PROGBITS     0000000000404018 00003018 00000010  0 WA     0   0  8
+[23] .bss                 NOBITS       0000000000404028 00003028 00000008  0 WA     0   0  1
+[24] .comment             PROGBITS     0000000000000000 00003028 0000002a  1 MS     0   0  1
+[25] .ctf                 PROGBITS     0000000000000000 00003052 00000071  0        0   0  1
+[26] .gnu_debuglink       PROGBITS     0000000000000000 000030c4 00000014  0        0   0  4
+[27] .shstrtab            STRTAB       0000000000000000 000030d8 000000fd  0        0   0  1
+
+EOF
+echo readelf testfile.debug
+testrun_compare ${abs_top_builddir}/src/readelf -S testfile.debug <<\EOF
+There are 35 section headers, starting at offset 0xb80:
+
+Section Headers:
+[Nr] Name                 Type         Addr             Off      Size     ES Flags Lk Inf Al
+[ 0]                      NULL         0000000000000000 00000000 00000000  0        0   0  0
+[ 1] .interp              NOBITS       0000000000400318 00000318 0000001c  0 A      0   0  1
+[ 2] .note.gnu.property   NOTE         0000000000400338 00000318 00000020  0 A      0   0  8
+[ 3] .note.ABI-tag        NOTE         0000000000400358 00000338 00000020  0 A      0   0  4
+[ 4] .hash                NOBITS       0000000000400378 00000358 00000018  4 A      6   0  8
+[ 5] .gnu.hash            NOBITS       0000000000400390 00000358 0000001c  0 A      6   0  8
+[ 6] .dynsym              NOBITS       00000000004003b0 00000358 00000048 24 A      7   1  8
+[ 7] .dynstr              NOBITS       00000000004003f8 00000358 00000038  0 A      0   0  1
+[ 8] .gnu.version         NOBITS       0000000000400430 00000358 00000006  2 A      6   0  2
+[ 9] .gnu.version_r       NOBITS       0000000000400438 00000358 00000020  0 A      7   1  8
+[10] .rela.dyn            NOBITS       0000000000400458 00000358 00000030 24 A      6   0  8
+[11] .init                NOBITS       0000000000401000 00000358 00000017  0 AX     0   0  4
+[12] .text                NOBITS       0000000000401020 00000360 00000191  0 AX     0   0 16
+[13] .fini                NOBITS       00000000004011b4 00000360 00000009  0 AX     0   0  4
+[14] .rodata              NOBITS       0000000000402000 00000360 00000004  4 AM     0   0  4
+[15] .eh_frame_hdr        NOBITS       0000000000402004 00000360 00000034  0 A      0   0  4
+[16] .eh_frame            NOBITS       0000000000402038 00000360 000000d8  0 A      0   0  8
+[17] .init_array          NOBITS       0000000000403e40 00000360 00000008  8 WA     0   0  8
+[18] .fini_array          NOBITS       0000000000403e48 00000360 00000008  8 WA     0   0  8
+[19] .dynamic             NOBITS       0000000000403e50 00000360 000001a0 16 WA     7   0  8
+[20] .got                 NOBITS       0000000000403ff0 00000360 00000010  8 WA     0   0  8
+[21] .got.plt             NOBITS       0000000000404000 00000360 00000018  8 WA     0   0  8
+[22] .data                NOBITS       0000000000404018 00000360 00000010  0 WA     0   0  8
+[23] .bss                 NOBITS       0000000000404028 00000360 00000008  0 WA     0   0  1
+[24] .comment             NOBITS       0000000000000000 00000360 0000002a  1 MS     0   0  1
+[25] .ctf                 NOBITS       0000000000000000 00000360 00000071  0        0   0  1
+[26] .debug_aranges       PROGBITS     0000000000000000 00000360 00000030  0        0   0  1
+[27] .debug_info          PROGBITS     0000000000000000 00000390 00000054  0        0   0  1
+[28] .debug_abbrev        PROGBITS     0000000000000000 000003e4 00000038  0        0   0  1
+[29] .debug_line          PROGBITS     0000000000000000 0000041c 0000004f  0        0   0  1
+[30] .debug_str           PROGBITS     0000000000000000 0000046b 0000005f  1 MS     0   0  1
+[31] .debug_line_str      PROGBITS     0000000000000000 000004ca 0000001c  1 MS     0   0  1
+[32] .symtab              SYMTAB       0000000000000000 000004e8 00000378 24       33  20  8
+[33] .strtab              STRTAB       0000000000000000 00000860 000001cb  0        0   0  1
+[34] .shstrtab            STRTAB       0000000000000000 00000a2b 0000014e  0        0   0  1
+
+EOF
+
+# gcc -gctf -g -o testfile-ctf testfile-ctf.c
+# eu-strip --remove-ctf testfile-ctf
+
+# Explicitly removes .ctf section
+echo strip --remove-ctf testfile-ctf
+testrun ${abs_top_builddir}/src/strip --remove-ctf -o testfile.elf -f testfile.debug testfile-ctf
+echo elflint testfile.elf
+testrun ${abs_top_builddir}/src/elflint --gnu testfile.elf
+echo elflint testfile.debug
+testrun ${abs_top_builddir}/src/elflint --gnu -d testfile.debug
+echo readelf testfile.elf
+testrun_compare ${abs_top_builddir}/src/readelf -S testfile.elf <<\EOF
+There are 27 section headers, starting at offset 0x3160:
+
+Section Headers:
+[Nr] Name                 Type         Addr             Off      Size     ES Flags Lk Inf Al
+[ 0]                      NULL         0000000000000000 00000000 00000000  0        0   0  0
+[ 1] .interp              PROGBITS     0000000000400318 00000318 0000001c  0 A      0   0  1
+[ 2] .note.gnu.property   NOTE         0000000000400338 00000338 00000020  0 A      0   0  8
+[ 3] .note.ABI-tag        NOTE         0000000000400358 00000358 00000020  0 A      0   0  4
+[ 4] .hash                HASH         0000000000400378 00000378 00000018  4 A      6   0  8
+[ 5] .gnu.hash            GNU_HASH     0000000000400390 00000390 0000001c  0 A      6   0  8
+[ 6] .dynsym              DYNSYM       00000000004003b0 000003b0 00000048 24 A      7   1  8
+[ 7] .dynstr              STRTAB       00000000004003f8 000003f8 00000038  0 A      0   0  1
+[ 8] .gnu.version         GNU_versym   0000000000400430 00000430 00000006  2 A      6   0  2
+[ 9] .gnu.version_r       GNU_verneed  0000000000400438 00000438 00000020  0 A      7   1  8
+[10] .rela.dyn            RELA         0000000000400458 00000458 00000030 24 A      6   0  8
+[11] .init                PROGBITS     0000000000401000 00001000 00000017  0 AX     0   0  4
+[12] .text                PROGBITS     0000000000401020 00001020 00000191  0 AX     0   0 16
+[13] .fini                PROGBITS     00000000004011b4 000011b4 00000009  0 AX     0   0  4
+[14] .rodata              PROGBITS     0000000000402000 00002000 00000004  4 AM     0   0  4
+[15] .eh_frame_hdr        PROGBITS     0000000000402004 00002004 00000034  0 A      0   0  4
+[16] .eh_frame            PROGBITS     0000000000402038 00002038 000000d8  0 A      0   0  8
+[17] .init_array          INIT_ARRAY   0000000000403e40 00002e40 00000008  8 WA     0   0  8
+[18] .fini_array          FINI_ARRAY   0000000000403e48 00002e48 00000008  8 WA     0   0  8
+[19] .dynamic             DYNAMIC      0000000000403e50 00002e50 000001a0 16 WA     7   0  8
+[20] .got                 PROGBITS     0000000000403ff0 00002ff0 00000010  8 WA     0   0  8
+[21] .got.plt             PROGBITS     0000000000404000 00003000 00000018  8 WA     0   0  8
+[22] .data                PROGBITS     0000000000404018 00003018 00000010  0 WA     0   0  8
+[23] .bss                 NOBITS       0000000000404028 00003028 00000008  0 WA     0   0  1
+[24] .comment             PROGBITS     0000000000000000 00003028 0000002a  1 MS     0   0  1
+[25] .gnu_debuglink       PROGBITS     0000000000000000 00003054 00000014  0        0   0  4
+[26] .shstrtab            STRTAB       0000000000000000 00003068 000000f8  0        0   0  1
+
+EOF
+echo readelf testfile.debug
+testrun_compare ${abs_top_builddir}/src/readelf -S testfile.debug <<\EOF
+There are 35 section headers, starting at offset 0xbf0:
+
+Section Headers:
+[Nr] Name                 Type         Addr             Off      Size     ES Flags Lk Inf Al
+[ 0]                      NULL         0000000000000000 00000000 00000000  0        0   0  0
+[ 1] .interp              NOBITS       0000000000400318 00000318 0000001c  0 A      0   0  1
+[ 2] .note.gnu.property   NOTE         0000000000400338 00000318 00000020  0 A      0   0  8
+[ 3] .note.ABI-tag        NOTE         0000000000400358 00000338 00000020  0 A      0   0  4
+[ 4] .hash                NOBITS       0000000000400378 00000358 00000018  4 A      6   0  8
+[ 5] .gnu.hash            NOBITS       0000000000400390 00000358 0000001c  0 A      6   0  8
+[ 6] .dynsym              NOBITS       00000000004003b0 00000358 00000048 24 A      7   1  8
+[ 7] .dynstr              NOBITS       00000000004003f8 00000358 00000038  0 A      0   0  1
+[ 8] .gnu.version         NOBITS       0000000000400430 00000358 00000006  2 A      6   0  2
+[ 9] .gnu.version_r       NOBITS       0000000000400438 00000358 00000020  0 A      7   1  8
+[10] .rela.dyn            NOBITS       0000000000400458 00000358 00000030 24 A      6   0  8
+[11] .init                NOBITS       0000000000401000 00000358 00000017  0 AX     0   0  4
+[12] .text                NOBITS       0000000000401020 00000360 00000191  0 AX     0   0 16
+[13] .fini                NOBITS       00000000004011b4 00000360 00000009  0 AX     0   0  4
+[14] .rodata              NOBITS       0000000000402000 00000360 00000004  4 AM     0   0  4
+[15] .eh_frame_hdr        NOBITS       0000000000402004 00000360 00000034  0 A      0   0  4
+[16] .eh_frame            NOBITS       0000000000402038 00000360 000000d8  0 A      0   0  8
+[17] .init_array          NOBITS       0000000000403e40 00000360 00000008  8 WA     0   0  8
+[18] .fini_array          NOBITS       0000000000403e48 00000360 00000008  8 WA     0   0  8
+[19] .dynamic             NOBITS       0000000000403e50 00000360 000001a0 16 WA     7   0  8
+[20] .got                 NOBITS       0000000000403ff0 00000360 00000010  8 WA     0   0  8
+[21] .got.plt             NOBITS       0000000000404000 00000360 00000018  8 WA     0   0  8
+[22] .data                NOBITS       0000000000404018 00000360 00000010  0 WA     0   0  8
+[23] .bss                 NOBITS       0000000000404028 00000360 00000008  0 WA     0   0  1
+[24] .comment             NOBITS       0000000000000000 00000360 0000002a  1 MS     0   0  1
+[25] .ctf                 PROGBITS     0000000000000000 00000360 00000071  0        0   0  1
+[26] .debug_aranges       PROGBITS     0000000000000000 000003d1 00000030  0        0   0  1
+[27] .debug_info          PROGBITS     0000000000000000 00000401 00000054  0        0   0  1
+[28] .debug_abbrev        PROGBITS     0000000000000000 00000455 00000038  0        0   0  1
+[29] .debug_line          PROGBITS     0000000000000000 0000048d 0000004f  0        0   0  1
+[30] .debug_str           PROGBITS     0000000000000000 000004dc 0000005f  1 MS     0   0  1
+[31] .debug_line_str      PROGBITS     0000000000000000 0000053b 0000001c  1 MS     0   0  1
+[32] .symtab              SYMTAB       0000000000000000 00000558 00000378 24       33  20  8
+[33] .strtab              STRTAB       0000000000000000 000008d0 000001cb  0        0   0  1
+[34] .shstrtab            STRTAB       0000000000000000 00000a9b 0000014e  0        0   0  1
+
+EOF
+
+exit 0
diff --git a/tests/testfile-ctf.bz2 b/tests/testfile-ctf.bz2
new file mode 100755
index 0000000000000000000000000000000000000000..f48bb9304f1e2194500f5091dbb3aa1a7b8806cc
GIT binary patch
literal 2620
zcmV-C3d8k6T4*^jL0KkKSvsAgApi-}fB*mg|Ns8~|NH;%|Np=L|N8&`;Z;EeM^^pq
z_0HDc|9{{JtX!7+2XAK`<!#%WuUv(84tmI*aL|NkDT(DN>U&iEGE>xgo=NORrc=hL
znN6sAhp5oWnwbMb5uh|_h-rjrlhgs}sQo1M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rOD6FlQIZ|>ZxJC
zG!Gxy{IguUv>}k0(J#OqDk?%7M9BiLdV^wQ%>d9u173S3x73>Rb_m2=M8+!@_`ttH
eHW{(i1h|K>n&{ifS>W^k_`8xR!i0g;?HLHGprbti

literal 0
HcmV?d00001


base-commit: b8713b3fd0617415c76df8c9da70f8e2f26d3134
-- 
2.35.1


^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCHv2] strip: keep .ctf section in stripped file
  2022-06-01 15:55   ` [PATCHv2] " Guillermo E. Martinez
@ 2022-12-20 21:35     ` Mark Wielaard
  2023-02-22 16:42       ` Mark Wielaard
  2023-02-23 18:42     ` [PATCH v3] " Guillermo E. Martinez
  1 sibling, 1 reply; 29+ messages in thread
From: Mark Wielaard @ 2022-12-20 21:35 UTC (permalink / raw)
  To: Guillermo E. Martinez; +Cc: elfutils-devel, Jose E. Marchesi, nickc

Hi Guillermo,

On Wed, Jun 01, 2022 at 10:55:27AM -0500, Guillermo E. Martinez via Elfutils-devel wrote:
> This is the second version patch to avoid remove the CTF section in
> stripped files. Changes from v1:
> 
>   - Add description in tests/run-strip-remove-keep-ctf.sh
>     mentioning how to regenerate test input file (testfile-ctf)
> 
> Please let me know your thoughts.
>
> [...]
> 
> CTF debug format was designed to be present in stripped files, so
> this section should not be removed, so a new --remove-ctf option
> is added to indicate explicitly that .ctf section will be stripped
> out from binary file.

Sorry, I see I never reviewed this v2 variant.  I know we tried to
coordinate with binutils so eu-strip and binutils strip would do the
same thing. And that Jose had an idea for a new section flag to
automatically detect what section should/shouldn't be stripped (into a
separate .debug file). What was the conclusion of that?

Thanks,

Mark

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCHv2] strip: keep .ctf section in stripped file
  2022-12-20 21:35     ` Mark Wielaard
@ 2023-02-22 16:42       ` Mark Wielaard
  2023-02-22 16:59         ` Jose E. Marchesi
  2023-02-22 17:12         ` Guillermo E. Martinez
  0 siblings, 2 replies; 29+ messages in thread
From: Mark Wielaard @ 2023-02-22 16:42 UTC (permalink / raw)
  To: Guillermo E. Martinez; +Cc: elfutils-devel, Jose E. Marchesi, nickc

Hi,

On Tue, 2022-12-20 at 22:35 +0100, Mark Wielaard wrote:
> On Wed, Jun 01, 2022 at 10:55:27AM -0500, Guillermo E. Martinez via Elfutils-devel wrote:
> > This is the second version patch to avoid remove the CTF section in
> > stripped files. Changes from v1:
> > 
> >   - Add description in tests/run-strip-remove-keep-ctf.sh
> >     mentioning how to regenerate test input file (testfile-ctf)
> > 
> > Please let me know your thoughts.
> > 
> > [...]
> > 
> > CTF debug format was designed to be present in stripped files, so
> > this section should not be removed, so a new --remove-ctf option
> > is added to indicate explicitly that .ctf section will be stripped
> > out from binary file.
> 
> Sorry, I see I never reviewed this v2 variant.  I know we tried to
> coordinate with binutils so eu-strip and binutils strip would do the
> same thing. And that Jose had an idea for a new section flag to
> automatically detect what section should/shouldn't be stripped (into a
> separate .debug file). What was the conclusion of that?

Any update on this?
How should .ctf sections be dealt with by strip like tools?

Thanks,

Mark

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCHv2] strip: keep .ctf section in stripped file
  2023-02-22 16:42       ` Mark Wielaard
@ 2023-02-22 16:59         ` Jose E. Marchesi
  2023-02-22 17:12         ` Guillermo E. Martinez
  1 sibling, 0 replies; 29+ messages in thread
From: Jose E. Marchesi @ 2023-02-22 16:59 UTC (permalink / raw)
  To: Mark Wielaard; +Cc: Guillermo E. Martinez, elfutils-devel, nickc


> Hi,
>
> On Tue, 2022-12-20 at 22:35 +0100, Mark Wielaard wrote:
>> On Wed, Jun 01, 2022 at 10:55:27AM -0500, Guillermo E. Martinez via Elfutils-devel wrote:
>> > This is the second version patch to avoid remove the CTF section in
>> > stripped files. Changes from v1:
>> > 
>> >   - Add description in tests/run-strip-remove-keep-ctf.sh
>> >     mentioning how to regenerate test input file (testfile-ctf)
>> > 
>> > Please let me know your thoughts.
>> > 
>> > [...]
>> > 
>> > CTF debug format was designed to be present in stripped files, so
>> > this section should not be removed, so a new --remove-ctf option
>> > is added to indicate explicitly that .ctf section will be stripped
>> > out from binary file.
>> 
>> Sorry, I see I never reviewed this v2 variant.  I know we tried to
>> coordinate with binutils so eu-strip and binutils strip would do the
>> same thing. And that Jose had an idea for a new section flag to
>> automatically detect what section should/shouldn't be stripped (into a
>> separate .debug file). What was the conclusion of that?
>
> Any update on this?
> How should .ctf sections be dealt with by strip like tools?

I think the conclusion was that having a NOSTRIP flag in the object file
is far from trivial, because what "strip" means for several people and
tools is not clear.

So I guess we are stuck with the old keep-a-list method.

Or we may add NOSTRIP meaning "_never ever_ strip this section, period,
no matter what."

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCHv2] strip: keep .ctf section in stripped file
  2023-02-22 16:42       ` Mark Wielaard
  2023-02-22 16:59         ` Jose E. Marchesi
@ 2023-02-22 17:12         ` Guillermo E. Martinez
  2023-02-22 23:04           ` Mark Wielaard
  1 sibling, 1 reply; 29+ messages in thread
From: Guillermo E. Martinez @ 2023-02-22 17:12 UTC (permalink / raw)
  To: Mark Wielaard; +Cc: elfutils-devel, Jose E. Marchesi, nickc

On Wed, Feb 22, 2023 at 05:42:45PM +0100, Mark Wielaard wrote:
> Hi,
> 

Hi Mark,

> On Tue, 2022-12-20 at 22:35 +0100, Mark Wielaard wrote:
> > On Wed, Jun 01, 2022 at 10:55:27AM -0500, Guillermo E. Martinez via Elfutils-devel wrote:
> > > This is the second version patch to avoid remove the CTF section in
> > > stripped files. Changes from v1:
> > > 
> > >   - Add description in tests/run-strip-remove-keep-ctf.sh
> > >     mentioning how to regenerate test input file (testfile-ctf)
> > > 
> > > Please let me know your thoughts.
> > > 
> > > [...]
> > > 
> > > CTF debug format was designed to be present in stripped files, so
> > > this section should not be removed, so a new --remove-ctf option
> > > is added to indicate explicitly that .ctf section will be stripped
> > > out from binary file.
> > 
> > Sorry, I see I never reviewed this v2 variant.  I know we tried to
> > coordinate with binutils so eu-strip and binutils strip would do the
> > same thing. And that Jose had an idea for a new section flag to
> > automatically detect what section should/shouldn't be stripped (into a
> > separate .debug file). What was the conclusion of that?
> 
> Any update on this?
> How should .ctf sections be dealt with by strip like tools?
> 

Sorry for late reply,

The conclusion was basically not use section flags to identify which
section should be stripped out or not, so, it requires other mechanisms
for explicitly specifying which sections should be removed, as eu-strip
does using arguments.

https://sourceware.org/bugzilla/show_bug.cgi?id=29737

Worth it mention here, that my last test shows that .ctf section is not
stripped by ue-strip because it doesn't have a "debug" section name. 

Thanks,
guillermo

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCHv2] strip: keep .ctf section in stripped file
  2023-02-22 17:12         ` Guillermo E. Martinez
@ 2023-02-22 23:04           ` Mark Wielaard
  2023-02-23 18:34             ` Guillermo E. Martinez
  0 siblings, 1 reply; 29+ messages in thread
From: Mark Wielaard @ 2023-02-22 23:04 UTC (permalink / raw)
  To: Guillermo E. Martinez; +Cc: elfutils-devel, Jose E. Marchesi, nickc

Hi,

On Wed, Feb 22, 2023 at 11:12:07AM -0600, Guillermo E. Martinez wrote:
> The conclusion was basically not use section flags to identify which
> section should be stripped out or not, so, it requires other mechanisms
> for explicitly specifying which sections should be removed, as eu-strip
> does using arguments.
> 
> https://sourceware.org/bugzilla/show_bug.cgi?id=29737

OK, thanks.

> Worth it mention here, that my last test shows that .ctf section is not
> stripped by ue-strip because it doesn't have a "debug" section name. 

Are you sure that is what happens? It might depend on whether or not
you give eu-strip -g or not.

With -g only debug symbols and .debug sections are removed, but it
keeps any other unused/unallocated symbol/section. Without -g I would
expect eu-strip to remove the .ctf section (unless it is an allocated
section or referenced from an allocated section/symbol table).

Cheers,

Mark

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCHv2] strip: keep .ctf section in stripped file
  2023-02-22 23:04           ` Mark Wielaard
@ 2023-02-23 18:34             ` Guillermo E. Martinez
  0 siblings, 0 replies; 29+ messages in thread
From: Guillermo E. Martinez @ 2023-02-23 18:34 UTC (permalink / raw)
  To: Mark Wielaard; +Cc: elfutils-devel, Jose E. Marchesi, nickc

On Thu, Feb 23, 2023 at 12:04:47AM +0100, Mark Wielaard wrote:
> Hi,

Hi Mark,

> 
> On Wed, Feb 22, 2023 at 11:12:07AM -0600, Guillermo E. Martinez wrote:
> > The conclusion was basically not use section flags to identify which
> > section should be stripped out or not, so, it requires other mechanisms
> > for explicitly specifying which sections should be removed, as eu-strip
> > does using arguments.
> > 
> > https://sourceware.org/bugzilla/show_bug.cgi?id=29737
> 
> OK, thanks.
> 
> > Worth it mention here, that my last test shows that .ctf section is not
> > stripped by ue-strip because it doesn't have a "debug" section name. 
> 
> Are you sure that is what happens? It might depend on whether or not
> you give eu-strip -g or not.
> 

Oh, sorry. Yes, you are right!. I looked what was wrong with my test
environment and I didn't realize the use of `-g' option  in my
find-debuginfo script.

> With -g only debug symbols and .debug sections are removed, but it
> keeps any other unused/unallocated symbol/section. Without -g I would
> expect eu-strip to remove the .ctf section (unless it is an allocated
> section or referenced from an allocated section/symbol table).
> 

I see, thanks for explanation!.

I'll send immediately PATCH-v3 rebased from master.

Kind regards,
guillermo

^ permalink raw reply	[flat|nested] 29+ messages in thread

* [PATCH v3] strip: keep .ctf section in stripped file
  2022-06-01 15:55   ` [PATCHv2] " Guillermo E. Martinez
  2022-12-20 21:35     ` Mark Wielaard
@ 2023-02-23 18:42     ` Guillermo E. Martinez
  2023-02-24 11:51       ` Mark Wielaard
  1 sibling, 1 reply; 29+ messages in thread
From: Guillermo E. Martinez @ 2023-02-23 18:42 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Guillermo E. Martinez

Hello,

This is the third version of the patch to avoid remove the CTF section in
stripped files. Changes from v2:

  - Rebased from master.

Please let me know your thoughts.

Kind regards,
guillermo
--

CTF debug format was designed to be present in stripped files, so
this section should not be removed, so a new --remove-ctf option
is added to indicate explicitly that .ctf section will be stripped
out from binary file.

Signed-off-by: Guillermo E. Martinez <guillermo.e.martinez@oracle.com>
---
 ChangeLog                          |  23 ++++
 libebl/eblsectionstripp.c          |   4 +-
 libebl/libebl.h                    |   2 +-
 libelf/elf-knowledge.h             |   7 +-
 libelf/elf32_checksum.c            |   2 +-
 src/elfcmp.c                       |   4 +-
 src/strip.c                        |  71 ++++++++--
 tests/Makefile.am                  |   5 +-
 tests/run-strip-remove-keep-ctf.sh | 212 +++++++++++++++++++++++++++++
 tests/testfile-ctf.bz2             | Bin 0 -> 2620 bytes
 10 files changed, 308 insertions(+), 22 deletions(-)
 create mode 100755 tests/run-strip-remove-keep-ctf.sh
 create mode 100755 tests/testfile-ctf.bz2

diff --git a/ChangeLog b/ChangeLog
index 53a1d292..eed54421 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,26 @@
+2023-02-23  Guillermo E. Martinez  <guillermo.e.martinez@oracle.com>
+
+	* libebl/eblsectionstripp.c (ebl_section_strip_p): Use
+	remove_ctf argument.
+	(SECTION_STRIP_P): Likewise.
+	* libebl/libebl.h (ebl_section_strip_p): Likewise.
+	* libelf/elf-knowledge.h (SECTION_STRIP_P): Update macro
+	definition to use remove_ctf to determine whether .ctf
+	section is stripped out.
+	* libelf/elf32_checksum.c (elfw2): Use false value for
+	remove_ctf parameter.
+	* src/elfcmp.c (main): Likewise.
+	* src/strip.c (options): Add --remove-ctf option set by
+	remove_ctf variable.
+	(set_remove_special_section_opt): Add new function.
+	(erratic_special_section_opt): Likewise.
+	(parse_opt): Parse new --remove-ctf option.
+	(handle_elf): Adjust .comment and use remove_ctf argument.
+	* tests/Makefile.am (TEST): Add run-strip-remove-keep-ctf.sh
+	and testfile-ctf.bz2.
+	* tests/run-strip-remove-keep-ctf.sh: Add new testcase.
+	* tests/testfile-ctf.bz2: Add new test harness.
+
 2023-02-23  Mark Wielaard  <mark@klomp.org>
 
 	* NEWS: Add old version code names.
diff --git a/libebl/eblsectionstripp.c b/libebl/eblsectionstripp.c
index a5624ffe..f26cc170 100644
--- a/libebl/eblsectionstripp.c
+++ b/libebl/eblsectionstripp.c
@@ -37,7 +37,7 @@
 bool
 ebl_section_strip_p (Ebl *ebl, const GElf_Shdr *shdr,
 		     const char *name, bool remove_comment,
-		     bool only_remove_debug)
+		     bool only_remove_debug, bool remove_ctf)
 {
   /* If only debug information should be removed check the name.  There
      is unfortunately no other way.  */
@@ -66,5 +66,5 @@ ebl_section_strip_p (Ebl *ebl, const GElf_Shdr *shdr,
       return false;
     }
 
-  return SECTION_STRIP_P (shdr, name, remove_comment);
+  return SECTION_STRIP_P (shdr, name, remove_comment, remove_ctf);
 }
diff --git a/libebl/libebl.h b/libebl/libebl.h
index 731001d3..067b769e 100644
--- a/libebl/libebl.h
+++ b/libebl/libebl.h
@@ -205,7 +205,7 @@ extern bool ebl_relative_reloc_p (Ebl *ebl, int reloc);
 /* Check whether section should be stripped.  */
 extern bool ebl_section_strip_p (Ebl *ebl,
 				 const GElf_Shdr *shdr, const char *name,
-				 bool remove_comment, bool only_remove_debug);
+				 bool remove_comment, bool only_remove_debug, bool remove_ctf);
 
 /* Check if backend uses a bss PLT in this file.  */
 extern bool ebl_bss_plt_p (Ebl *ebl);
diff --git a/libelf/elf-knowledge.h b/libelf/elf-knowledge.h
index 6e005fa5..903a0f4f 100644
--- a/libelf/elf-knowledge.h
+++ b/libelf/elf-knowledge.h
@@ -34,7 +34,7 @@
 
 
 /* Test whether a section can be stripped or not.  */
-#define SECTION_STRIP_P(shdr, name, remove_comment) \
+#define SECTION_STRIP_P(shdr, name, remove_comment, remove_ctf) \
   /* Sections which are allocated are not removed.  */			      \
   (((shdr)->sh_flags & SHF_ALLOC) == 0					      \
    /* We never remove .note sections.  */				      \
@@ -45,7 +45,10 @@
 	   && strncmp (name, ".gnu.warning.", sizeof ".gnu.warning." - 1) != 0\
 	   /* We remove .comment sections only if explicitly told to do so. */\
 	   && (remove_comment						      \
-	       || strcmp (name, ".comment") != 0))))
+	       || strcmp (name, ".comment") != 0)  \
+	   /* We remove .ctf sections only if explicitly told to do so. */\
+	   && (remove_ctf						      \
+	       || strcmp (name, ".ctf") != 0))))
 
 
 /* Test whether `sh_info' field in section header contains a section
diff --git a/libelf/elf32_checksum.c b/libelf/elf32_checksum.c
index a47b307d..8482eb07 100644
--- a/libelf/elf32_checksum.c
+++ b/libelf/elf32_checksum.c
@@ -104,7 +104,7 @@ elfw2(LIBELFBITS,checksum) (Elf *elf)
 
       if (SECTION_STRIP_P (shdr,
 			   INTUSE(elf_strptr) (elf, shstrndx, shdr->sh_name),
-			   true))
+			   true, false))
 	/* The section can be stripped.  Don't use it.  */
 	continue;
 
diff --git a/src/elfcmp.c b/src/elfcmp.c
index fba67e02..66d1b4b9 100644
--- a/src/elfcmp.c
+++ b/src/elfcmp.c
@@ -269,7 +269,7 @@ main (int argc, char *argv[])
 	    sname1 = elf_strptr (elf1, shstrndx1, shdr1->sh_name);
 	}
       while (scn1 != NULL && shdr1 != NULL
-	     && ebl_section_strip_p (ebl1, shdr1, sname1, true, false));
+	     && ebl_section_strip_p (ebl1, shdr1, sname1, true, false, false));
 
       GElf_Shdr shdr2_mem;
       GElf_Shdr *shdr2;
@@ -282,7 +282,7 @@ main (int argc, char *argv[])
 	    sname2 = elf_strptr (elf2, shstrndx2, shdr2->sh_name);
 	}
       while (scn2 != NULL && shdr2 != NULL
-	     && ebl_section_strip_p (ebl2, shdr2, sname2, true, false));
+	     && ebl_section_strip_p (ebl2, shdr2, sname2, true, false, false));
 
       if (scn1 == NULL || scn2 == NULL || shdr1 == NULL || shdr2 == NULL)
 	break;
diff --git a/src/strip.c b/src/strip.c
index 2a2cc801..68dfdc1f 100644
--- a/src/strip.c
+++ b/src/strip.c
@@ -61,6 +61,7 @@ ARGP_PROGRAM_BUG_ADDRESS_DEF = PACKAGE_BUGREPORT;
 #define OPT_RELOC_DEBUG 	0x103
 #define OPT_KEEP_SECTION 	0x104
 #define OPT_RELOC_DEBUG_ONLY    0x105
+#define OPT_REMOVE_CTF	        0x106
 
 
 /* Definitions of arguments for argp functions.  */
@@ -86,6 +87,8 @@ static const struct argp_option options[] =
     N_("Similar to --reloc-debug-sections, but resolve all trivial relocations between debug sections in place.  No other stripping is performed (operation is not reversible, incompatible with -f, -g, --remove-comment and --remove-section)"), 0 },
   { "remove-comment", OPT_REMOVE_COMMENT, NULL, 0,
     N_("Remove .comment section"), 0 },
+  { "remove-ctf", OPT_REMOVE_CTF, NULL, 0,
+    N_("Remove .ctf section"), 0 },
   { "remove-section", 'R', "SECTION", 0, N_("Remove the named section.  SECTION is an extended wildcard pattern.  May be given more than once.  Only non-allocated sections can be removed."), 0 },
   { "keep-section", OPT_KEEP_SECTION, "SECTION", 0, N_("Keep the named section.  SECTION is an extended wildcard pattern.  May be given more than once."), 0 },
   { "permissive", OPT_PERMISSIVE, NULL, 0,
@@ -149,6 +152,9 @@ static bool preserve_dates;
 /* If true .comment sections will be removed.  */
 static bool remove_comment;
 
+/* If true .ctf sections will be removed.  */
+static bool remove_ctf;
+
 /* If true remove all debug sections.  */
 static bool remove_debug;
 
@@ -216,6 +222,48 @@ section_name_matches (struct section_pattern *patterns, const char *name)
   return false;
 }
 
+static void
+set_remove_special_section_opt (const char *arg)
+{
+  if (fnmatch (arg, ".comment", FNM_EXTMATCH) == 0)
+    remove_comment = true;
+  else if (fnmatch (arg, ".ctf", FNM_EXTMATCH) == 0)
+    remove_ctf = true;
+}
+
+static error_t
+erratic_special_section_opt (struct argp_state *state)
+{
+  int s;
+  struct {
+    const char *name;
+    bool remove;
+  } special_secs[] = {
+      {
+        .name = ".comment",
+        .remove = remove_comment
+      },
+      {
+        .name = ".ctf",
+        .remove = remove_ctf
+      },
+      {
+        .name = NULL,
+      }
+  };
+
+  for (s = 0; special_secs[s].name; ++s)
+    if (special_secs[s].remove == true
+        && section_name_matches (keep_secs, special_secs[s].name))
+      {
+        argp_error (state,
+                    _("cannot both keep and remove %s section"),
+                    special_secs[s].name);
+        return EINVAL;
+      }
+
+  return 0;
+}
 
 int
 main (int argc, char *argv[])
@@ -324,9 +372,12 @@ parse_opt (int key, char *arg, struct argp_state *state)
       remove_comment = true;
       break;
 
+    case OPT_REMOVE_CTF:
+      remove_ctf = true;
+      break;
+
     case 'R':
-      if (fnmatch (arg, ".comment", FNM_EXTMATCH) == 0)
-	remove_comment = true;
+      set_remove_special_section_opt (arg);
       add_pattern (&remove_secs, arg);
       break;
 
@@ -352,13 +403,8 @@ parse_opt (int key, char *arg, struct argp_state *state)
       break;
 
     case ARGP_KEY_SUCCESS:
-      if (remove_comment == true
-	  && section_name_matches (keep_secs, ".comment"))
-	{
-	  argp_error (state,
-		      _("cannot both keep and remove .comment section"));
-	  return EINVAL;
-	}
+      if (erratic_special_section_opt (state))
+        return EINVAL;
       break;
 
     default:
@@ -1357,7 +1403,7 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname,
      all sections which are not used at runtime are stripped out.  But
      there are a few exceptions:
 
-     - special sections named ".comment" and ".note" are kept
+     - special sections named ".comment", ".note" and ".ctf" are kept
      - OS or architecture specific sections are kept since we might not
        know how to handle them
      - if a section is referred to from a section which is not removed
@@ -1370,7 +1416,7 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname,
     if (remove_shdrs ? !(shdr_info[cnt].shdr.sh_flags & SHF_ALLOC)
 	: (ebl_section_strip_p (ebl, &shdr_info[cnt].shdr,
 				shdr_info[cnt].name, remove_comment,
-				remove_debug)
+				remove_debug, remove_ctf)
 	   || cnt == shstrndx
 	   || section_name_matches (remove_secs, shdr_info[cnt].name)))
       {
@@ -1533,7 +1579,8 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname,
 						    &shdr_info[scnidx].shdr,
 						    shdr_info[scnidx].name,
 						    remove_comment,
-						    remove_debug)
+						    remove_debug,
+						    remove_ctf)
 			       && ebl_data_marker_symbol (ebl, sym,
 					elf_strptr (elf,
 						    shdr_info[cnt].shdr.sh_link,
diff --git a/tests/Makefile.am b/tests/Makefile.am
index fd58bf84..2267a364 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -207,7 +207,7 @@ TESTS = run-arextract.sh run-arsymtest.sh run-ar.sh newfile test-nlist \
 	$(asm_TESTS) run-disasm-bpf.sh run-low_high_pc-dw-form-indirect.sh \
 	run-nvidia-extended-linemap-libdw.sh run-nvidia-extended-linemap-readelf.sh \
 	run-readelf-dw-form-indirect.sh run-strip-largealign.sh \
-	run-readelf-Dd.sh
+	run-readelf-Dd.sh run-strip-remove-keep-ctf.sh
 
 if !BIARCH
 export ELFUTILS_DISABLE_BIARCH = 1
@@ -619,7 +619,8 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh run-ar.sh \
 	     run-nvidia-extended-linemap-libdw.sh run-nvidia-extended-linemap-readelf.sh \
 	     testfile_nvidia_linemap.bz2 \
 	     testfile-largealign.o.bz2 run-strip-largealign.sh \
-	     run-funcretval++11.sh
+	     run-funcretval++11.sh \
+	     testfile-ctf.bz2 run-strip-remove-keep-ctf.sh
 
 
 if USE_VALGRIND
diff --git a/tests/run-strip-remove-keep-ctf.sh b/tests/run-strip-remove-keep-ctf.sh
new file mode 100755
index 00000000..9a4fde72
--- /dev/null
+++ b/tests/run-strip-remove-keep-ctf.sh
@@ -0,0 +1,212 @@
+#! /bin/sh
+# Copyright (C) 2022 Oracle, 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
+
+# - testfile-ctf.c
+# int
+# main ()
+# {
+#   return 0;
+# }
+#
+# gcc -gctf -g -o testfile-ctf testfile-ctf.c
+# eu-strip testfile-ctf
+
+# strip -o output and -f debug files
+tempfiles testfile.elf testfile.debug
+
+# A random 32bit testfile
+testfiles testfile-ctf
+
+# strip should keep .ctf section
+echo strip testfile-ctf
+testrun ${abs_top_builddir}/src/strip -o testfile.elf -f testfile.debug testfile-ctf
+echo elflint testfile.elf
+testrun ${abs_top_builddir}/src/elflint --gnu testfile.elf
+echo elflint testfile.debug
+testrun ${abs_top_builddir}/src/elflint --gnu -d testfile.debug
+echo readelf testfile.elf
+testrun_compare ${abs_top_builddir}/src/readelf -S testfile.elf <<\EOF
+There are 28 section headers, starting at offset 0x31d8:
+
+Section Headers:
+[Nr] Name                 Type         Addr             Off      Size     ES Flags Lk Inf Al
+[ 0]                      NULL         0000000000000000 00000000 00000000  0        0   0  0
+[ 1] .interp              PROGBITS     0000000000400318 00000318 0000001c  0 A      0   0  1
+[ 2] .note.gnu.property   NOTE         0000000000400338 00000338 00000020  0 A      0   0  8
+[ 3] .note.ABI-tag        NOTE         0000000000400358 00000358 00000020  0 A      0   0  4
+[ 4] .hash                HASH         0000000000400378 00000378 00000018  4 A      6   0  8
+[ 5] .gnu.hash            GNU_HASH     0000000000400390 00000390 0000001c  0 A      6   0  8
+[ 6] .dynsym              DYNSYM       00000000004003b0 000003b0 00000048 24 A      7   1  8
+[ 7] .dynstr              STRTAB       00000000004003f8 000003f8 00000038  0 A      0   0  1
+[ 8] .gnu.version         GNU_versym   0000000000400430 00000430 00000006  2 A      6   0  2
+[ 9] .gnu.version_r       GNU_verneed  0000000000400438 00000438 00000020  0 A      7   1  8
+[10] .rela.dyn            RELA         0000000000400458 00000458 00000030 24 A      6   0  8
+[11] .init                PROGBITS     0000000000401000 00001000 00000017  0 AX     0   0  4
+[12] .text                PROGBITS     0000000000401020 00001020 00000191  0 AX     0   0 16
+[13] .fini                PROGBITS     00000000004011b4 000011b4 00000009  0 AX     0   0  4
+[14] .rodata              PROGBITS     0000000000402000 00002000 00000004  4 AM     0   0  4
+[15] .eh_frame_hdr        PROGBITS     0000000000402004 00002004 00000034  0 A      0   0  4
+[16] .eh_frame            PROGBITS     0000000000402038 00002038 000000d8  0 A      0   0  8
+[17] .init_array          INIT_ARRAY   0000000000403e40 00002e40 00000008  8 WA     0   0  8
+[18] .fini_array          FINI_ARRAY   0000000000403e48 00002e48 00000008  8 WA     0   0  8
+[19] .dynamic             DYNAMIC      0000000000403e50 00002e50 000001a0 16 WA     7   0  8
+[20] .got                 PROGBITS     0000000000403ff0 00002ff0 00000010  8 WA     0   0  8
+[21] .got.plt             PROGBITS     0000000000404000 00003000 00000018  8 WA     0   0  8
+[22] .data                PROGBITS     0000000000404018 00003018 00000010  0 WA     0   0  8
+[23] .bss                 NOBITS       0000000000404028 00003028 00000008  0 WA     0   0  1
+[24] .comment             PROGBITS     0000000000000000 00003028 0000002a  1 MS     0   0  1
+[25] .ctf                 PROGBITS     0000000000000000 00003052 00000071  0        0   0  1
+[26] .gnu_debuglink       PROGBITS     0000000000000000 000030c4 00000014  0        0   0  4
+[27] .shstrtab            STRTAB       0000000000000000 000030d8 000000fd  0        0   0  1
+
+EOF
+echo readelf testfile.debug
+testrun_compare ${abs_top_builddir}/src/readelf -S testfile.debug <<\EOF
+There are 35 section headers, starting at offset 0xb80:
+
+Section Headers:
+[Nr] Name                 Type         Addr             Off      Size     ES Flags Lk Inf Al
+[ 0]                      NULL         0000000000000000 00000000 00000000  0        0   0  0
+[ 1] .interp              NOBITS       0000000000400318 00000318 0000001c  0 A      0   0  1
+[ 2] .note.gnu.property   NOTE         0000000000400338 00000318 00000020  0 A      0   0  8
+[ 3] .note.ABI-tag        NOTE         0000000000400358 00000338 00000020  0 A      0   0  4
+[ 4] .hash                NOBITS       0000000000400378 00000358 00000018  4 A      6   0  8
+[ 5] .gnu.hash            NOBITS       0000000000400390 00000358 0000001c  0 A      6   0  8
+[ 6] .dynsym              NOBITS       00000000004003b0 00000358 00000048 24 A      7   1  8
+[ 7] .dynstr              NOBITS       00000000004003f8 00000358 00000038  0 A      0   0  1
+[ 8] .gnu.version         NOBITS       0000000000400430 00000358 00000006  2 A      6   0  2
+[ 9] .gnu.version_r       NOBITS       0000000000400438 00000358 00000020  0 A      7   1  8
+[10] .rela.dyn            NOBITS       0000000000400458 00000358 00000030 24 A      6   0  8
+[11] .init                NOBITS       0000000000401000 00000358 00000017  0 AX     0   0  4
+[12] .text                NOBITS       0000000000401020 00000360 00000191  0 AX     0   0 16
+[13] .fini                NOBITS       00000000004011b4 00000360 00000009  0 AX     0   0  4
+[14] .rodata              NOBITS       0000000000402000 00000360 00000004  4 AM     0   0  4
+[15] .eh_frame_hdr        NOBITS       0000000000402004 00000360 00000034  0 A      0   0  4
+[16] .eh_frame            NOBITS       0000000000402038 00000360 000000d8  0 A      0   0  8
+[17] .init_array          NOBITS       0000000000403e40 00000360 00000008  8 WA     0   0  8
+[18] .fini_array          NOBITS       0000000000403e48 00000360 00000008  8 WA     0   0  8
+[19] .dynamic             NOBITS       0000000000403e50 00000360 000001a0 16 WA     7   0  8
+[20] .got                 NOBITS       0000000000403ff0 00000360 00000010  8 WA     0   0  8
+[21] .got.plt             NOBITS       0000000000404000 00000360 00000018  8 WA     0   0  8
+[22] .data                NOBITS       0000000000404018 00000360 00000010  0 WA     0   0  8
+[23] .bss                 NOBITS       0000000000404028 00000360 00000008  0 WA     0   0  1
+[24] .comment             NOBITS       0000000000000000 00000360 0000002a  1 MS     0   0  1
+[25] .ctf                 NOBITS       0000000000000000 00000360 00000071  0        0   0  1
+[26] .debug_aranges       PROGBITS     0000000000000000 00000360 00000030  0        0   0  1
+[27] .debug_info          PROGBITS     0000000000000000 00000390 00000054  0        0   0  1
+[28] .debug_abbrev        PROGBITS     0000000000000000 000003e4 00000038  0        0   0  1
+[29] .debug_line          PROGBITS     0000000000000000 0000041c 0000004f  0        0   0  1
+[30] .debug_str           PROGBITS     0000000000000000 0000046b 0000005f  1 MS     0   0  1
+[31] .debug_line_str      PROGBITS     0000000000000000 000004ca 0000001c  1 MS     0   0  1
+[32] .symtab              SYMTAB       0000000000000000 000004e8 00000378 24       33  20  8
+[33] .strtab              STRTAB       0000000000000000 00000860 000001cb  0        0   0  1
+[34] .shstrtab            STRTAB       0000000000000000 00000a2b 0000014e  0        0   0  1
+
+EOF
+
+# gcc -gctf -g -o testfile-ctf testfile-ctf.c
+# eu-strip --remove-ctf testfile-ctf
+
+# Explicitly removes .ctf section
+echo strip --remove-ctf testfile-ctf
+testrun ${abs_top_builddir}/src/strip --remove-ctf -o testfile.elf -f testfile.debug testfile-ctf
+echo elflint testfile.elf
+testrun ${abs_top_builddir}/src/elflint --gnu testfile.elf
+echo elflint testfile.debug
+testrun ${abs_top_builddir}/src/elflint --gnu -d testfile.debug
+echo readelf testfile.elf
+testrun_compare ${abs_top_builddir}/src/readelf -S testfile.elf <<\EOF
+There are 27 section headers, starting at offset 0x3160:
+
+Section Headers:
+[Nr] Name                 Type         Addr             Off      Size     ES Flags Lk Inf Al
+[ 0]                      NULL         0000000000000000 00000000 00000000  0        0   0  0
+[ 1] .interp              PROGBITS     0000000000400318 00000318 0000001c  0 A      0   0  1
+[ 2] .note.gnu.property   NOTE         0000000000400338 00000338 00000020  0 A      0   0  8
+[ 3] .note.ABI-tag        NOTE         0000000000400358 00000358 00000020  0 A      0   0  4
+[ 4] .hash                HASH         0000000000400378 00000378 00000018  4 A      6   0  8
+[ 5] .gnu.hash            GNU_HASH     0000000000400390 00000390 0000001c  0 A      6   0  8
+[ 6] .dynsym              DYNSYM       00000000004003b0 000003b0 00000048 24 A      7   1  8
+[ 7] .dynstr              STRTAB       00000000004003f8 000003f8 00000038  0 A      0   0  1
+[ 8] .gnu.version         GNU_versym   0000000000400430 00000430 00000006  2 A      6   0  2
+[ 9] .gnu.version_r       GNU_verneed  0000000000400438 00000438 00000020  0 A      7   1  8
+[10] .rela.dyn            RELA         0000000000400458 00000458 00000030 24 A      6   0  8
+[11] .init                PROGBITS     0000000000401000 00001000 00000017  0 AX     0   0  4
+[12] .text                PROGBITS     0000000000401020 00001020 00000191  0 AX     0   0 16
+[13] .fini                PROGBITS     00000000004011b4 000011b4 00000009  0 AX     0   0  4
+[14] .rodata              PROGBITS     0000000000402000 00002000 00000004  4 AM     0   0  4
+[15] .eh_frame_hdr        PROGBITS     0000000000402004 00002004 00000034  0 A      0   0  4
+[16] .eh_frame            PROGBITS     0000000000402038 00002038 000000d8  0 A      0   0  8
+[17] .init_array          INIT_ARRAY   0000000000403e40 00002e40 00000008  8 WA     0   0  8
+[18] .fini_array          FINI_ARRAY   0000000000403e48 00002e48 00000008  8 WA     0   0  8
+[19] .dynamic             DYNAMIC      0000000000403e50 00002e50 000001a0 16 WA     7   0  8
+[20] .got                 PROGBITS     0000000000403ff0 00002ff0 00000010  8 WA     0   0  8
+[21] .got.plt             PROGBITS     0000000000404000 00003000 00000018  8 WA     0   0  8
+[22] .data                PROGBITS     0000000000404018 00003018 00000010  0 WA     0   0  8
+[23] .bss                 NOBITS       0000000000404028 00003028 00000008  0 WA     0   0  1
+[24] .comment             PROGBITS     0000000000000000 00003028 0000002a  1 MS     0   0  1
+[25] .gnu_debuglink       PROGBITS     0000000000000000 00003054 00000014  0        0   0  4
+[26] .shstrtab            STRTAB       0000000000000000 00003068 000000f8  0        0   0  1
+
+EOF
+echo readelf testfile.debug
+testrun_compare ${abs_top_builddir}/src/readelf -S testfile.debug <<\EOF
+There are 35 section headers, starting at offset 0xbf0:
+
+Section Headers:
+[Nr] Name                 Type         Addr             Off      Size     ES Flags Lk Inf Al
+[ 0]                      NULL         0000000000000000 00000000 00000000  0        0   0  0
+[ 1] .interp              NOBITS       0000000000400318 00000318 0000001c  0 A      0   0  1
+[ 2] .note.gnu.property   NOTE         0000000000400338 00000318 00000020  0 A      0   0  8
+[ 3] .note.ABI-tag        NOTE         0000000000400358 00000338 00000020  0 A      0   0  4
+[ 4] .hash                NOBITS       0000000000400378 00000358 00000018  4 A      6   0  8
+[ 5] .gnu.hash            NOBITS       0000000000400390 00000358 0000001c  0 A      6   0  8
+[ 6] .dynsym              NOBITS       00000000004003b0 00000358 00000048 24 A      7   1  8
+[ 7] .dynstr              NOBITS       00000000004003f8 00000358 00000038  0 A      0   0  1
+[ 8] .gnu.version         NOBITS       0000000000400430 00000358 00000006  2 A      6   0  2
+[ 9] .gnu.version_r       NOBITS       0000000000400438 00000358 00000020  0 A      7   1  8
+[10] .rela.dyn            NOBITS       0000000000400458 00000358 00000030 24 A      6   0  8
+[11] .init                NOBITS       0000000000401000 00000358 00000017  0 AX     0   0  4
+[12] .text                NOBITS       0000000000401020 00000360 00000191  0 AX     0   0 16
+[13] .fini                NOBITS       00000000004011b4 00000360 00000009  0 AX     0   0  4
+[14] .rodata              NOBITS       0000000000402000 00000360 00000004  4 AM     0   0  4
+[15] .eh_frame_hdr        NOBITS       0000000000402004 00000360 00000034  0 A      0   0  4
+[16] .eh_frame            NOBITS       0000000000402038 00000360 000000d8  0 A      0   0  8
+[17] .init_array          NOBITS       0000000000403e40 00000360 00000008  8 WA     0   0  8
+[18] .fini_array          NOBITS       0000000000403e48 00000360 00000008  8 WA     0   0  8
+[19] .dynamic             NOBITS       0000000000403e50 00000360 000001a0 16 WA     7   0  8
+[20] .got                 NOBITS       0000000000403ff0 00000360 00000010  8 WA     0   0  8
+[21] .got.plt             NOBITS       0000000000404000 00000360 00000018  8 WA     0   0  8
+[22] .data                NOBITS       0000000000404018 00000360 00000010  0 WA     0   0  8
+[23] .bss                 NOBITS       0000000000404028 00000360 00000008  0 WA     0   0  1
+[24] .comment             NOBITS       0000000000000000 00000360 0000002a  1 MS     0   0  1
+[25] .ctf                 PROGBITS     0000000000000000 00000360 00000071  0        0   0  1
+[26] .debug_aranges       PROGBITS     0000000000000000 000003d1 00000030  0        0   0  1
+[27] .debug_info          PROGBITS     0000000000000000 00000401 00000054  0        0   0  1
+[28] .debug_abbrev        PROGBITS     0000000000000000 00000455 00000038  0        0   0  1
+[29] .debug_line          PROGBITS     0000000000000000 0000048d 0000004f  0        0   0  1
+[30] .debug_str           PROGBITS     0000000000000000 000004dc 0000005f  1 MS     0   0  1
+[31] .debug_line_str      PROGBITS     0000000000000000 0000053b 0000001c  1 MS     0   0  1
+[32] .symtab              SYMTAB       0000000000000000 00000558 00000378 24       33  20  8
+[33] .strtab              STRTAB       0000000000000000 000008d0 000001cb  0        0   0  1
+[34] .shstrtab            STRTAB       0000000000000000 00000a9b 0000014e  0        0   0  1
+
+EOF
+
+exit 0
diff --git a/tests/testfile-ctf.bz2 b/tests/testfile-ctf.bz2
new file mode 100755
index 0000000000000000000000000000000000000000..f48bb9304f1e2194500f5091dbb3aa1a7b8806cc
GIT binary patch
literal 2620
zcmV-C3d8k6T4*^jL0KkKSvsAgApi-}fB*mg|Ns8~|NH;%|Np=L|N8&`;Z;EeM^^pq
z_0HDc|9{{JtX!7+2XAK`<!#%WuUv(84tmI*aL|NkDT(DN>U&iEGE>xgo=NORrc=hL
znN6sAhp5oWnwbMb5uh|_h-rjrlhgs}sQo1MJx^0Xrh`YQ+J=oiPbkwtrbm=$G=vGJ
zC!rXoDDsAY0i#W+kN^Mx0000D05kvq000000000015F4ZMD;NvDD)7?lT9?p27}TA
zLlK}F01r?Gni)Mn0B8UJ00E!?007Wv0Fe?yRX<ccsSO*-pQ=44>VN=#qGAR>(?9?X
zJx^01kkdv+Km$RL000dSP|yGX01W^#AOVoj$O9m0qd*M<Moj={#54^61|S1QfB*(Y
zgGNBaX`?}i8USb+000S1NvPCK4^tCNfDDZWhJXQ~pfnn20000D8UO&$01W}414e*o
z00001;ypR7ae}LJ-DdvTE<)S@J7ek0mS9RUCZFNNKtv)iK%TDyKrrvUCriBy)f!iW
zQ;OtoW$I9+)t0j9NIGdVyE%;GLS#{64G~2-;g6Yn!y;>06NGd&)x^;TUA44rNDV3Q
z8XD{(SEz0JYYRxvTbFBNLR~OuM)rMC@rIIETcW_w_LmZ#tuVu4%?>FlqLIEWUP&io
zB1H%iMYXk6Cb?$X^OU&+QJ54bd!o)_<5Ohj-cM6+E1JQBGi1Md&&xYXE;|<7%sHbb
zj)uh>Rv9lBqT7dds$J4mOIPMa*8i|KR6_tOWlwLo#^>{$FLv97$;{2Ek-*W6oBIm6
z6S$bvGc>M&Z?`}J0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hr?u{Wj0#~-~(;5
z3h9#_<$rLjh=U>Uve1UavPE=CiG+(ZwnL^`OpqdI5s?{M!U+>js7nHcOT-F7vW!I(
zg~p8z2(qDC0fK~4dlFUH9g1RL!luAaA$(>?gQNf=&<M+BFsm2<8o&(#cbXLm?z}-#
zU6=w0FdRFFb=5#rNq`do?lT>8d{ZD$r+$3JD(-`XSE!E3G!p~@NKlYti9%2m*_OlH
zLi($leuaxfas^2V!KrFmZZgDI&|p+4!YD|iSb&{O?jcCfCN;?>OHVd}b#>M!i~_$c
z2+3s<7d}~n>|=y9G_<OotITJo&Hcu-U`jQ&Zwcn~eM4;&mrP03P#J<Js1~ikJ53T?
z8E1^dv{38eFE5q!9-C1MS>EokmMNa6n^)qfVRV)q<@KX{9Qep;rOD6FlQIZ|>ZxJC
zG!Gxy{IguUv>}k0(J#OqDk?%7M9BiLdV^wQ%>d9u173S3x73>Rb_m2=M8+!@_`ttH
eHW{(i1h|K>n&{ifS>W^k_`8xR!i0g;?HLHGprbti

literal 0
HcmV?d00001

-- 
2.39.1


^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH v3] strip: keep .ctf section in stripped file
  2023-02-23 18:42     ` [PATCH v3] " Guillermo E. Martinez
@ 2023-02-24 11:51       ` Mark Wielaard
  2023-02-24 16:48         ` Guillermo E. Martinez
  0 siblings, 1 reply; 29+ messages in thread
From: Mark Wielaard @ 2023-02-24 11:51 UTC (permalink / raw)
  To: Guillermo E. Martinez; +Cc: elfutils-devel

Hi Guillermo,

On Thu, Feb 23, 2023 at 12:42:37PM -0600, Guillermo E. Martinez via Elfutils-devel wrote:
> This is the third version of the patch to avoid remove the CTF section in
> stripped files. Changes from v2:
> 
>   - Rebased from master.
> 
> Please let me know your thoughts.
> 
> CTF debug format was designed to be present in stripped files, so
> this section should not be removed, so a new --remove-ctf option
> is added to indicate explicitly that .ctf section will be stripped
> out from binary file.

Since the way to recognize a CTF section is by name ".ctf" does it
really need a new option? eu-strip already has:

    --keep-section=SECTION Keep the named section.  SECTION is an extended
                           wildcard pattern.  May be given more than once.

-R, --remove-section=SECTION   Remove the named section.  SECTION is an
                           extended wildcard pattern.  May be given more than
                           once.  Only non-allocated sections can be
                           removed.

Do you really need a new option? Or could you use an explicit
--keep-section=.ctf and/or --remove-section=.ctf ?

Thanks,

Mark

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH v3] strip: keep .ctf section in stripped file
  2023-02-24 11:51       ` Mark Wielaard
@ 2023-02-24 16:48         ` Guillermo E. Martinez
  2023-02-28 12:24           ` Mark Wielaard
  0 siblings, 1 reply; 29+ messages in thread
From: Guillermo E. Martinez @ 2023-02-24 16:48 UTC (permalink / raw)
  To: Mark Wielaard; +Cc: elfutils-devel

On Fri, Feb 24, 2023 at 12:51:25PM +0100, Mark Wielaard wrote:
> Hi Guillermo,
> 

Hi Mark,

> On Thu, Feb 23, 2023 at 12:42:37PM -0600, Guillermo E. Martinez via Elfutils-devel wrote:
> > This is the third version of the patch to avoid remove the CTF section in
> > stripped files. Changes from v2:
> > 
> >   - Rebased from master.
> > 
> > Please let me know your thoughts.
> > 
> > CTF debug format was designed to be present in stripped files, so
> > this section should not be removed, so a new --remove-ctf option
> > is added to indicate explicitly that .ctf section will be stripped
> > out from binary file.
> 
> Since the way to recognize a CTF section is by name ".ctf" does it
> really need a new option? eu-strip already has:
> 
>     --keep-section=SECTION Keep the named section.  SECTION is an extended
>                            wildcard pattern.  May be given more than once.
> 
> -R, --remove-section=SECTION   Remove the named section.  SECTION is an
>                            extended wildcard pattern.  May be given more than
>                            once.  Only non-allocated sections can be
>                            removed.
> 
> Do you really need a new option? Or could you use an explicit
> --keep-section=.ctf and/or --remove-section=.ctf ?
> 

Oh, I see, thanks for your comment!. My intention with this patch is to
replicate the same proceeding by _default_ implemented in `binutils strip'
tool, it is: not remove CTF section, except it is indicated explicitly.

Of course, if you think it is not really a good idea, I can propose a
patch to change the invocation of `eu-strip' in `find-debuginfo.sh' to
preserve CTF section as you showed above, when it generates debug
packages.


Kinds regards,
guyillermo

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH v3] strip: keep .ctf section in stripped file
  2023-02-24 16:48         ` Guillermo E. Martinez
@ 2023-02-28 12:24           ` Mark Wielaard
  2023-02-28 12:45             ` Nick Clifton
  2023-02-28 12:59             ` Nick Clifton
  0 siblings, 2 replies; 29+ messages in thread
From: Mark Wielaard @ 2023-02-28 12:24 UTC (permalink / raw)
  To: Guillermo E. Martinez; +Cc: elfutils-devel, nickc

Hi Guillermo,

CCed Nick to see if he knows why binutils strip does what it does.

On Fri, 2023-02-24 at 10:48 -0600, Guillermo E. Martinez wrote:
> On Fri, Feb 24, 2023 at 12:51:25PM +0100, Mark Wielaard wrote:
> 
> 
> > On Thu, Feb 23, 2023 at 12:42:37PM -0600, Guillermo E. Martinez via Elfutils-devel wrote:
> > > This is the third version of the patch to avoid remove the CTF section in
> > > stripped files. Changes from v2:
> > > 
> > >   - Rebased from master.
> > > 
> > > Please let me know your thoughts.
> > > 
> > > CTF debug format was designed to be present in stripped files, so
> > > this section should not be removed, so a new --remove-ctf option
> > > is added to indicate explicitly that .ctf section will be stripped
> > > out from binary file.
> > 
> > Since the way to recognize a CTF section is by name ".ctf" does it
> > really need a new option? eu-strip already has:
> > 
> >     --keep-section=SECTION Keep the named section.  SECTION is an extended
> >                            wildcard pattern.  May be given more than once.
> > 
> > -R, --remove-section=SECTION   Remove the named section.  SECTION is an
> >                            extended wildcard pattern.  May be given more than
> >                            once.  Only non-allocated sections can be
> >                            removed.
> > 
> > Do you really need a new option? Or could you use an explicit
> > --keep-section=.ctf and/or --remove-section=.ctf ?
> > 
> 
> Oh, I see, thanks for your comment!. My intention with this patch is to
> replicate the same proceeding by _default_ implemented in `binutils strip'
> tool, it is: not remove CTF section, except it is indicated explicitly.

O, this surprises me. I wasn't aware binutils strip keeps unallocated
sections by default. But apparently it does. It doesn't seem specific
to ".ctf". Do you know why? This seems counter to how strip is supposed
to behave, at least how I understand it.

eu-strip removes any non-allocated section (unless -g is given) which
isn't referenced through a sh_link or sh_info (with SHF_INFO_LINK set)
from a section that isn't removed. I assumed binutils strip would
behave the same. See also
http://www.linker-aliens.org/blogs/ali/entry/how_to_strip_an_elf/
(So one idea might be to reference the .ctf section through sh_link
from e.g. the .text or .data section to signal it should be kept?)

> Of course, if you think it is not really a good idea, I can propose a
> patch to change the invocation of `eu-strip' in `find-debuginfo.sh' to
> preserve CTF section as you showed above, when it generates debug
> packages.

Note that find-debuginfo already has:

   Use --keep-section SECTION or --remove-section SECTION to explicitly
   keep a (non-allocated) section in the main executable or explicitly
   remove it into the .debug file. SECTION is an extended wildcard
   pattern.  Both options can be given more than once.
   
Cheers,

Mark


^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH v3] strip: keep .ctf section in stripped file
  2023-02-28 12:24           ` Mark Wielaard
@ 2023-02-28 12:45             ` Nick Clifton
  2023-02-28 12:59             ` Nick Clifton
  1 sibling, 0 replies; 29+ messages in thread
From: Nick Clifton @ 2023-02-28 12:45 UTC (permalink / raw)
  To: Mark Wielaard, Guillermo E. Martinez; +Cc: elfutils-devel

Hi Mark,

>> Oh, I see, thanks for your comment!. My intention with this patch is to
>> replicate the same proceeding by _default_ implemented in `binutils strip'
>> tool, it is: not remove CTF section, except it is indicated explicitly.
> 
> O, this surprises me. I wasn't aware binutils strip keeps unallocated
> sections by default. But apparently it does. It doesn't seem specific
> to ".ctf". Do you know why? This seems counter to how strip is supposed
> to behave, at least how I understand it.

I do not know why and I agree that it looks like a bug.  Hmm,  do you have
a specific example in mind ?

Cheers
   Nick


^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH v3] strip: keep .ctf section in stripped file
  2023-02-28 12:24           ` Mark Wielaard
  2023-02-28 12:45             ` Nick Clifton
@ 2023-02-28 12:59             ` Nick Clifton
  2023-02-28 14:27               ` Mark Wielaard
  1 sibling, 1 reply; 29+ messages in thread
From: Nick Clifton @ 2023-02-28 12:59 UTC (permalink / raw)
  To: Mark Wielaard, Guillermo E. Martinez; +Cc: elfutils-devel

Hi Mark,

> O, this surprises me. I wasn't aware binutils strip keeps unallocated
> sections by default. But apparently it does. It doesn't seem specific
> to ".ctf". Do you know why? This seems counter to how strip is supposed
> to behave, at least how I understand it.

Actually thinking about it, there are a few important un-allocated sections
that ought to be kept in a binary.  For example .gnu_debuglink and .shstrtab.
So maybe deleting unallocated sections by default is not such a good idea.

Cheers
   Nick


^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH v3] strip: keep .ctf section in stripped file
  2023-02-28 12:59             ` Nick Clifton
@ 2023-02-28 14:27               ` Mark Wielaard
  2023-03-03  2:40                 ` Guillermo E. Martinez
  0 siblings, 1 reply; 29+ messages in thread
From: Mark Wielaard @ 2023-02-28 14:27 UTC (permalink / raw)
  To: Nick Clifton, Guillermo E. Martinez; +Cc: elfutils-devel

Hi Nick,

On Tue, 2023-02-28 at 12:59 +0000, Nick Clifton wrote:
> > O, this surprises me. I wasn't aware binutils strip keeps unallocated
> > sections by default. But apparently it does. It doesn't seem specific
> > to ".ctf". Do you know why? This seems counter to how strip is supposed
> > to behave, at least how I understand it.
> 
> Actually thinking about it, there are a few important un-allocated sections
> that ought to be kept in a binary.  For example .gnu_debuglink and .shstrtab.
> So maybe deleting unallocated sections by default is not such a good idea.

Sure, but both are those are actually added or rewritten during
stripping.

There are some exceptions to the general rule in eu-strip of dropping
not referenced, non-allocated, SHT_PROGBIT sections. SHT_NOTE sections
are never removed (even if they aren't allocated), as are non-
SHT_PROGBIT sections. ".gnu.warning." sections also aren't (even if
they are non-allocated SHT_PROGBIT sections). And ".comment" sections
aren't if not explicitly told to.

Guillermo's patch proposes to make ".ctf" another special case
(defaulting to keeping).

I am mainly wondering why binutils strip already seems to keep ".ctf"
sections (even without -g).

Cheers,

Mark

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH v3] strip: keep .ctf section in stripped file
  2023-02-28 14:27               ` Mark Wielaard
@ 2023-03-03  2:40                 ` Guillermo E. Martinez
  2023-03-03 12:15                   ` Mark Wielaard
  0 siblings, 1 reply; 29+ messages in thread
From: Guillermo E. Martinez @ 2023-03-03  2:40 UTC (permalink / raw)
  To: Mark Wielaard; +Cc: Nick Clifton, elfutils-devel

Hello Mark,

On Tue, Feb 28, 2023 at 03:27:13PM +0100, Mark Wielaard wrote:
> Hi Nick,
> 
> On Tue, 2023-02-28 at 12:59 +0000, Nick Clifton wrote:
> > > O, this surprises me. I wasn't aware binutils strip keeps unallocated
> > > sections by default. But apparently it does. It doesn't seem specific
> > > to ".ctf". Do you know why? This seems counter to how strip is supposed
> > > to behave, at least how I understand it.
> > 
> > Actually thinking about it, there are a few important un-allocated sections
> > that ought to be kept in a binary.  For example .gnu_debuglink and .shstrtab.
> > So maybe deleting unallocated sections by default is not such a good idea.
> 
> Sure, but both are those are actually added or rewritten during
> stripping.
> 
> There are some exceptions to the general rule in eu-strip of dropping
> not referenced, non-allocated, SHT_PROGBIT sections. SHT_NOTE sections
> are never removed (even if they aren't allocated), as are non-
> SHT_PROGBIT sections. ".gnu.warning." sections also aren't (even if
> they are non-allocated SHT_PROGBIT sections). And ".comment" sections
> aren't if not explicitly told to.
> 
> Guillermo's patch proposes to make ".ctf" another special case
> (defaulting to keeping).
> 
> I am mainly wondering why binutils strip already seems to keep ".ctf"
> sections (even without -g).
> 

I'm not plenty sure, but I can tell that it was done so, because CTF was
designed having in mind a lightweight debug format being shipped along with
the other allocated ELF sections:

	"CTF and DWARF data can coexist in the same ELF file, she said, since the
	CTF data has its own dedicated section. The CTF data is naturally
	smaller, but the format also includes compression to reduce the size
	requirements further. The result is that this data, unlike DWARF
	information, need not be stripped to get the executable file down to a
	reasonable size."

https://lwn.net/Articles/795384/

Kind regards,
guillermo

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH v3] strip: keep .ctf section in stripped file
  2023-03-03  2:40                 ` Guillermo E. Martinez
@ 2023-03-03 12:15                   ` Mark Wielaard
  2023-03-03 12:24                     ` Nick Clifton
  0 siblings, 1 reply; 29+ messages in thread
From: Mark Wielaard @ 2023-03-03 12:15 UTC (permalink / raw)
  To: Guillermo E. Martinez; +Cc: Nick Clifton, elfutils-devel

Hi Guillermo,

On Thu, 2023-03-02 at 20:40 -0600, Guillermo E. Martinez wrote:
> On Tue, Feb 28, 2023 at 03:27:13PM +0100, Mark Wielaard wrote:
> > There are some exceptions to the general rule in eu-strip of dropping
> > not referenced, non-allocated, SHT_PROGBIT sections. SHT_NOTE sections
> > are never removed (even if they aren't allocated), as are non-
> > SHT_PROGBIT sections. ".gnu.warning." sections also aren't (even if
> > they are non-allocated SHT_PROGBIT sections). And ".comment" sections
> > aren't if not explicitly told to.
> > 
> > Guillermo's patch proposes to make ".ctf" another special case
> > (defaulting to keeping).
> > 
> > I am mainly wondering why binutils strip already seems to keep ".ctf"
> > sections (even without -g).
> > 
> 
> I'm not plenty sure, but I can tell that it was done so, because CTF was
> designed having in mind a lightweight debug format being shipped along with
> the other allocated ELF sections:
> 
> 	"CTF and DWARF data can coexist in the same ELF file, she said, since the
> 	CTF data has its own dedicated section. The CTF data is naturally
> 	smaller, but the format also includes compression to reduce the size
> 	requirements further. The result is that this data, unlike DWARF
> 	information, need not be stripped to get the executable file down to a
> 	reasonable size."
> 
> https://lwn.net/Articles/795384/

Right. But I am wondering how that mechanism works with binutils strip.
Apparently we do something different in eu-strip which makes it
necessary to add a --keep-ctf option based on the section name. It
would be good if we figured out how/what we can do to keep the
different strip utilities in sync.

Cheers,

Mark

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH v3] strip: keep .ctf section in stripped file
  2023-03-03 12:15                   ` Mark Wielaard
@ 2023-03-03 12:24                     ` Nick Clifton
  2023-03-04 14:00                       ` Guillermo E. Martinez
  0 siblings, 1 reply; 29+ messages in thread
From: Nick Clifton @ 2023-03-03 12:24 UTC (permalink / raw)
  To: Mark Wielaard, Guillermo E. Martinez; +Cc: elfutils-devel

Hi Mark,

>>> I am mainly wondering why binutils strip already seems to keep ".ctf"
>>> sections (even without -g).

> Right. But I am wondering how that mechanism works with binutils strip.
> Apparently we do something different in eu-strip which makes it
> necessary to add a --keep-ctf option based on the section name. It
> would be good if we figured out how/what we can do to keep the
> different strip utilities in sync.

I think that the function that does this is "is_strip_section_1" in
binutils/objcopy.c.  If an input section has the BSF_DEBUGGING flag
set (an internal flag to he BFD library, but basically it should be
set for all debug sections, including .ctf sections I think), then
the basic decision is to keep the section unless -g is used.

Cheers
   Nick


^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH v3] strip: keep .ctf section in stripped file
  2023-03-03 12:24                     ` Nick Clifton
@ 2023-03-04 14:00                       ` Guillermo E. Martinez
  2023-03-07 14:50                         ` Mark Wielaard
  0 siblings, 1 reply; 29+ messages in thread
From: Guillermo E. Martinez @ 2023-03-04 14:00 UTC (permalink / raw)
  To: Nick Clifton; +Cc: Mark Wielaard, elfutils-devel

Hello,

On Fri, Mar 03, 2023 at 12:24:19PM +0000, Nick Clifton wrote:
> Hi Mark,
> 
> > > > I am mainly wondering why binutils strip already seems to keep ".ctf"
> > > > sections (even without -g).
> 
> > Right. But I am wondering how that mechanism works with binutils strip.
> > Apparently we do something different in eu-strip which makes it
> > necessary to add a --keep-ctf option based on the section name. It
> > would be good if we figured out how/what we can do to keep the
> > different strip utilities in sync.
> 
> I think that the function that does this is "is_strip_section_1" in

That's right, this function decided whether the section will be striped
out by default, if it has set `SEC_DEBUGGING' in BFD section flags then
section is removed by the default.  For `.ctf' this flag is not set
because in `_bfd_elf_make_section_from_shdr' when BFD sections are
building it uses the section's name: ".debug", ".gnu.debuglto_.debug_",
".gnu.linkonce.wi.", ".zdebug", "lines", ".stab", etc, to set
`SEC_DEBUGGING' flag.

> binutils/objcopy.c.  If an input section has the BSF_DEBUGGING flag
> set (an internal flag to he BFD library, but basically it should be
> set for all debug sections, including .ctf sections I think), then
> the basic decision is to keep the section unless -g is used.
> 
> Cheers
>   Nick
> 

Kind regards,
guillermo

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH v3] strip: keep .ctf section in stripped file
  2023-03-04 14:00                       ` Guillermo E. Martinez
@ 2023-03-07 14:50                         ` Mark Wielaard
  2023-03-07 20:47                           ` Guillermo E. Martinez
  2023-03-08 17:45                           ` Nix
  0 siblings, 2 replies; 29+ messages in thread
From: Mark Wielaard @ 2023-03-07 14:50 UTC (permalink / raw)
  To: Guillermo E. Martinez, Nick Clifton; +Cc: elfutils-devel

Hi Nick, Hi Guillermo,

On Sat, 2023-03-04 at 08:00 -0600, Guillermo E. Martinez wrote:
> Hello,
> 
> On Fri, Mar 03, 2023 at 12:24:19PM +0000, Nick Clifton wrote:
> > Hi Mark,
> > 
> > > > > I am mainly wondering why binutils strip already seems to keep ".ctf"
> > > > > sections (even without -g).
> > 
> > > Right. But I am wondering how that mechanism works with binutils strip.
> > > Apparently we do something different in eu-strip which makes it
> > > necessary to add a --keep-ctf option based on the section name. It
> > > would be good if we figured out how/what we can do to keep the
> > > different strip utilities in sync.
> > 
> > I think that the function that does this is "is_strip_section_1" in
> 
> That's right, this function decided whether the section will be striped
> out by default, if it has set `SEC_DEBUGGING' in BFD section flags then
> section is removed by the default.  For `.ctf' this flag is not set
> because in `_bfd_elf_make_section_from_shdr' when BFD sections are
> building it uses the section's name: ".debug", ".gnu.debuglto_.debug_",
> ".gnu.linkonce.wi.", ".zdebug", "lines", ".stab", etc, to set
> `SEC_DEBUGGING' flag.
> 
> > binutils/objcopy.c.  If an input section has the BSF_DEBUGGING flag
> > set (an internal flag to he BFD library, but basically it should be
> > set for all debug sections, including .ctf sections I think), then
> > the basic decision is to keep the section unless -g is used.

OK, that is interesting. So given the .ctf section is NOT marked as
SEC_DEBUGGING binutils strip basically never strips it.

While eu-strip does strip it by default (since it is a non-loadable
PROGBITS section), but keeps it with -g (which only strips the
explicitly named .debug sections).

But both binutils strip and eu-strip do have --keep-section=.ctf which
would explicitly keep it even without -g, and both have --remove-
section=.ctf which always removes the section.

So binutils strip and eu-strip aren't totally identical with the
default flags, but with --keep-section=.ctf and --remove-section=.ctf
they seem to do the same thing.

So I am not sure we really need a --keep-ctf flag for eu-strip (unless
we also get it for binutils strip). My preference would be to just
recommend a user use --keep-section=.ctf or --remove-section=.ctf to
indicate what they want.

Cheers,

Mark

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH v3] strip: keep .ctf section in stripped file
  2023-03-07 14:50                         ` Mark Wielaard
@ 2023-03-07 20:47                           ` Guillermo E. Martinez
  2023-03-08 17:45                           ` Nix
  1 sibling, 0 replies; 29+ messages in thread
From: Guillermo E. Martinez @ 2023-03-07 20:47 UTC (permalink / raw)
  To: Mark Wielaard; +Cc: Nick Clifton, elfutils-devel

On Tue, Mar 07, 2023 at 03:50:01PM +0100, Mark Wielaard wrote:
> Hi Nick, Hi Guillermo,
> 

Hi Mark, 

> On Sat, 2023-03-04 at 08:00 -0600, Guillermo E. Martinez wrote:
> > Hello,
> > 
> > On Fri, Mar 03, 2023 at 12:24:19PM +0000, Nick Clifton wrote:
> > > Hi Mark,
> > > 
> > > > > > I am mainly wondering why binutils strip already seems to keep ".ctf"
> > > > > > sections (even without -g).
> > > 
> > > > Right. But I am wondering how that mechanism works with binutils strip.
> > > > Apparently we do something different in eu-strip which makes it
> > > > necessary to add a --keep-ctf option based on the section name. It
> > > > would be good if we figured out how/what we can do to keep the
> > > > different strip utilities in sync.
> > > 
> > > I think that the function that does this is "is_strip_section_1" in
> > 
> > That's right, this function decided whether the section will be striped
> > out by default, if it has set `SEC_DEBUGGING' in BFD section flags then
> > section is removed by the default.  For `.ctf' this flag is not set
> > because in `_bfd_elf_make_section_from_shdr' when BFD sections are
> > building it uses the section's name: ".debug", ".gnu.debuglto_.debug_",
> > ".gnu.linkonce.wi.", ".zdebug", "lines", ".stab", etc, to set
> > `SEC_DEBUGGING' flag.
> > 
> > > binutils/objcopy.c.  If an input section has the BSF_DEBUGGING flag
> > > set (an internal flag to he BFD library, but basically it should be
> > > set for all debug sections, including .ctf sections I think), then
> > > the basic decision is to keep the section unless -g is used.
> 
> OK, that is interesting. So given the .ctf section is NOT marked as
> SEC_DEBUGGING binutils strip basically never strips it.
> 
> While eu-strip does strip it by default (since it is a non-loadable
> PROGBITS section), but keeps it with -g (which only strips the
> explicitly named .debug sections).
> 
> But both binutils strip and eu-strip do have --keep-section=.ctf which
> would explicitly keep it even without -g, and both have --remove-
> section=.ctf which always removes the section.
> 
> So binutils strip and eu-strip aren't totally identical with the
> default flags, but with --keep-section=.ctf and --remove-section=.ctf
> they seem to do the same thing.
> 
> So I am not sure we really need a --keep-ctf flag for eu-strip (unless
> we also get it for binutils strip). My preference would be to just
> recommend a user use --keep-section=.ctf or --remove-section=.ctf to
> indicate what they want.
> 

Oh, I see. My first motivation to add `--keep-ctf' in `eu-strip' is
because it's used by `find-debuginfo.sh' script  to build the debug RPM
packages:

	`eu-strip --remove-comment $r $g ${keep_remove_args} -f "$1" "$2" || exit'

So, `eu-strip' removes `.ctf' section by default.

In this case I'll prepare a patch updating `find-debuginfo.sh' to add
`--keep-section=.ctf' to `eu-strip' to preserve such section.

Thanks for your comments!
guillermo

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH v3] strip: keep .ctf section in stripped file
  2023-03-07 14:50                         ` Mark Wielaard
  2023-03-07 20:47                           ` Guillermo E. Martinez
@ 2023-03-08 17:45                           ` Nix
  2023-03-09 23:08                             ` Mark Wielaard
  1 sibling, 1 reply; 29+ messages in thread
From: Nix @ 2023-03-08 17:45 UTC (permalink / raw)
  To: Mark Wielaard; +Cc: Guillermo E. Martinez, Nick Clifton, elfutils-devel

On 7 Mar 2023, Mark Wielaard said:

> Hi Nick, Hi Guillermo,
>
> On Sat, 2023-03-04 at 08:00 -0600, Guillermo E. Martinez wrote:
>> Hello,
>> 
>> On Fri, Mar 03, 2023 at 12:24:19PM +0000, Nick Clifton wrote:
>> > Hi Mark,
>> > 
>> > > > > I am mainly wondering why binutils strip already seems to keep ".ctf"
>> > > > > sections (even without -g).
>> > 
>> > > Right. But I am wondering how that mechanism works with binutils strip.
>> > > Apparently we do something different in eu-strip which makes it
>> > > necessary to add a --keep-ctf option based on the section name. It
>> > > would be good if we figured out how/what we can do to keep the
>> > > different strip utilities in sync.
>> > 
>> > I think that the function that does this is "is_strip_section_1" in
>> 
>> That's right, this function decided whether the section will be striped
>> out by default, if it has set `SEC_DEBUGGING' in BFD section flags then
>> section is removed by the default.  For `.ctf' this flag is not set
>> because in `_bfd_elf_make_section_from_shdr' when BFD sections are
>> building it uses the section's name: ".debug", ".gnu.debuglto_.debug_",
>> ".gnu.linkonce.wi.", ".zdebug", "lines", ".stab", etc, to set
>> `SEC_DEBUGGING' flag.
>> 
>> > binutils/objcopy.c.  If an input section has the BSF_DEBUGGING flag
>> > set (an internal flag to he BFD library, but basically it should be
>> > set for all debug sections, including .ctf sections I think), then
>> > the basic decision is to keep the section unless -g is used.
>
> OK, that is interesting. So given the .ctf section is NOT marked as
> SEC_DEBUGGING binutils strip basically never strips it.

Can I chime in?

This behaviour is in line with the intended purpose of CTF, which is to
give C programs introspection into into their type systems at all times,
via libctf, so we can use it for ABI checking, shared library interface
construction at runtime (for dlopen()) and things like that. This is why
keeping CTF small is basically our sole format priority: if it's big,
people will be tempted to strip it out, and the format becomes useless.
(This is also why it's not loadable -- libctf reads it itself so that
it doesn't cost time paging it in if it's not used.)

(This is also why libctf doesn't follow gnu_debuglink pointers: it can
only read CTF from the ELF object itself.)

> While eu-strip does strip it by default (since it is a non-loadable
> PROGBITS section), but keeps it with -g (which only strips the
> explicitly named .debug sections).

It should probably keep it regardless, unless you do some sort of
"really brutal strip" that strips out literally everything not needed
for the program to start at all. It might well be necessary at runtime
(in future, anyway).

> So binutils strip and eu-strip aren't totally identical with the
> default flags, but with --keep-section=.ctf and --remove-section=.ctf
> they seem to do the same thing.

Yeah, this is a bug -- I simply forgot that eu-strip existed :/ sorry!

> So I am not sure we really need a --keep-ctf flag for eu-strip (unless
> we also get it for binutils strip). My preference would be to just
> recommend a user use --keep-section=.ctf or --remove-section=.ctf to
> indicate what they want.

My strong preference would be to make eu-strip do what binutils strip
does. If CTF is not in the binary, the whole format is useless. If
you've got room for the DWARF, the CTF is a strict subset of it anyway
(it's generated from it, after all).

-- 
NULL && (void)

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH v3] strip: keep .ctf section in stripped file
  2023-03-08 17:45                           ` Nix
@ 2023-03-09 23:08                             ` Mark Wielaard
  0 siblings, 0 replies; 29+ messages in thread
From: Mark Wielaard @ 2023-03-09 23:08 UTC (permalink / raw)
  To: Nix; +Cc: Guillermo E. Martinez, Nick Clifton, elfutils-devel

Hi Nix,

On Wed, Mar 08, 2023 at 05:45:02PM +0000, Nix wrote:
> > On Sat, 2023-03-04 at 08:00 -0600, Guillermo E. Martinez wrote:
> >> On Fri, Mar 03, 2023 at 12:24:19PM +0000, Nick Clifton wrote:
> >> > > > > I am mainly wondering why binutils strip already seems to keep ".ctf"
> >> > > > > sections (even without -g).
> >> > 
> >> > > Right. But I am wondering how that mechanism works with binutils strip.
> >> > > Apparently we do something different in eu-strip which makes it
> >> > > necessary to add a --keep-ctf option based on the section name. It
> >> > > would be good if we figured out how/what we can do to keep the
> >> > > different strip utilities in sync.
> >> > 
> >> > I think that the function that does this is "is_strip_section_1" in
> >> 
> >> That's right, this function decided whether the section will be striped
> >> out by default, if it has set `SEC_DEBUGGING' in BFD section flags then
> >> section is removed by the default.  For `.ctf' this flag is not set
> >> because in `_bfd_elf_make_section_from_shdr' when BFD sections are
> >> building it uses the section's name: ".debug", ".gnu.debuglto_.debug_",
> >> ".gnu.linkonce.wi.", ".zdebug", "lines", ".stab", etc, to set
> >> `SEC_DEBUGGING' flag.
> >> 
> >> > binutils/objcopy.c.  If an input section has the BSF_DEBUGGING flag
> >> > set (an internal flag to he BFD library, but basically it should be
> >> > set for all debug sections, including .ctf sections I think), then
> >> > the basic decision is to keep the section unless -g is used.
> >
> > OK, that is interesting. So given the .ctf section is NOT marked as
> > SEC_DEBUGGING binutils strip basically never strips it.
> 
> Can I chime in?

Yes please!
 
> This behaviour is in line with the intended purpose of CTF, which is to
> give C programs introspection into into their type systems at all times,
> via libctf, so we can use it for ABI checking, shared library interface
> construction at runtime (for dlopen()) and things like that. This is why
> keeping CTF small is basically our sole format priority: if it's big,
> people will be tempted to strip it out, and the format becomes useless.
> (This is also why it's not loadable -- libctf reads it itself so that
> it doesn't cost time paging it in if it's not used.)
> 
> (This is also why libctf doesn't follow gnu_debuglink pointers: it can
> only read CTF from the ELF object itself.)

Yes, this all makes sense.

> > While eu-strip does strip it by default (since it is a non-loadable
> > PROGBITS section), but keeps it with -g (which only strips the
> > explicitly named .debug sections).
> 
> It should probably keep it regardless, unless you do some sort of
> "really brutal strip" that strips out literally everything not needed
> for the program to start at all. It might well be necessary at runtime
> (in future, anyway).

Well, strip without any argument is "really brutal strip". Adding -g
makes it a "soft" strip that only strips explicitly debug sections and
symbols e.g. symtab is normally stripped, as are, at least with
eu-strip, any PROGBIT sections that aren't needed at runtime, aka
aren't marked as allocated and aren't (indirectly) referenced from any
such section, but those are kept with -g.

> > So binutils strip and eu-strip aren't totally identical with the
> > default flags, but with --keep-section=.ctf and --remove-section=.ctf
> > they seem to do the same thing.
> 
> Yeah, this is a bug -- I simply forgot that eu-strip existed :/ sorry!

I am not entirely sure where the bug is. I would call it a bug in
binutils strip if it keeps such sections when -g isn't given.

> > So I am not sure we really need a --keep-ctf flag for eu-strip (unless
> > we also get it for binutils strip). My preference would be to just
> > recommend a user use --keep-section=.ctf or --remove-section=.ctf to
> > indicate what they want.
> 
> My strong preference would be to make eu-strip do what binutils strip
> does. If CTF is not in the binary, the whole format is useless. If
> you've got room for the DWARF, the CTF is a strict subset of it anyway
> (it's generated from it, after all).

But why does binutils strip do that? To be honest it doesn't really
make sense to me. I don't see the logic.

If you really do want to keep the .ctf section even with eu-strip
(without -g) then you really should mark the section in some way that
shows it is needed (at runtime).

Assuming you don't want to mark the section, my suggestion would be to
use an explicit SHT_GNU_CTF section type. That will also help other
tools to know that this isn't a generic PROGBITS section but has to be
handled specially.

Cheers,

Mark

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH] strip: keep .ctf section in stripped file
  2022-06-07 13:23 [PATCH] " Nick Clifton
@ 2022-06-30 19:31 ` Jose E. Marchesi
  0 siblings, 0 replies; 29+ messages in thread
From: Jose E. Marchesi @ 2022-06-30 19:31 UTC (permalink / raw)
  To: Nick Clifton via Elfutils-devel
  Cc: Jose E. Marchesi, Mark Wielaard, Nick Clifton


> Hi Guys,
>
>   I apologise - I know that Jose CC'ed me on this topic, but I have lost
>   the email, so I am creating this post instead.
>
>> What about using an OS-specific section flag in elf.h, something like:
>> #define SHF_GNU_PERSISTENT 0x0ff00001 /* Section must not be
>> stripped.  */
>
>   I rather like this idea.  It would certainly make things easier.
>   Assuming that is that there is a convenient way to set the flag.  Ie
>   we need to teach the assembler about it, and probably the linker too
>   (so that it can be used in linker scripts).
>
>   It might also be a nice idea to have a complimentary flag to indicate
>   sections that expect to be stripped, even if they might otherwise be
>   retained.  For example:
>
>   #define SHF_GNU_TREAT_AS_DEBUG 0x0ff00002 /* Treat as a debug info
>    section.  Strip with other debug sections and move to a separate
>    debug info file when creating such files.  */
>
>   This could be added to note sections for example, where the notes
>   will not be needed at run-time.

I am, _very slowly_, working on this.

Along with other 100 gazillion things to do, but unless someone else
beats me to it, I will send patches at some point.

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH] strip: keep .ctf section in stripped file
@ 2022-06-07 13:23 Nick Clifton
  2022-06-30 19:31 ` Jose E. Marchesi
  0 siblings, 1 reply; 29+ messages in thread
From: Nick Clifton @ 2022-06-07 13:23 UTC (permalink / raw)
  To: elfutils-devel, Jose E. Marchesi, Mark Wielaard

Hi Guys,

   I apologise - I know that Jose CC'ed me on this topic, but I have lost
   the email, so I am creating this post instead.

> What about using an OS-specific section flag in elf.h, something like:
> 
> #define SHF_GNU_PERSISTENT 0x0ff00001 /* Section must not be stripped.  */

   I rather like this idea.  It would certainly make things easier.
   Assuming that is that there is a convenient way to set the flag.  Ie
   we need to teach the assembler about it, and probably the linker too
   (so that it can be used in linker scripts).

   It might also be a nice idea to have a complimentary flag to indicate
   sections that expect to be stripped, even if they might otherwise be
   retained.  For example:

   #define SHF_GNU_TREAT_AS_DEBUG 0x0ff00002 /* Treat as a debug info section.  Strip with other debug sections and move to a separate debug info file when creating such 
files.  */

   This could be added to note sections for example, where the notes
   will not be needed at run-time.

Cheers
   Nick


^ permalink raw reply	[flat|nested] 29+ messages in thread

end of thread, other threads:[~2023-03-09 23:08 UTC | newest]

Thread overview: 29+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-31  2:26 [PATCH] strip: keep .ctf section in stripped file Guillermo E. Martinez
2022-05-31  7:06 ` Mark Wielaard
2022-05-31 10:26   ` Jose E. Marchesi
2022-05-31 12:50     ` Jose E. Marchesi
2022-06-01  4:34   ` Guillermo E. Martinez
2022-06-01 15:55   ` [PATCHv2] " Guillermo E. Martinez
2022-12-20 21:35     ` Mark Wielaard
2023-02-22 16:42       ` Mark Wielaard
2023-02-22 16:59         ` Jose E. Marchesi
2023-02-22 17:12         ` Guillermo E. Martinez
2023-02-22 23:04           ` Mark Wielaard
2023-02-23 18:34             ` Guillermo E. Martinez
2023-02-23 18:42     ` [PATCH v3] " Guillermo E. Martinez
2023-02-24 11:51       ` Mark Wielaard
2023-02-24 16:48         ` Guillermo E. Martinez
2023-02-28 12:24           ` Mark Wielaard
2023-02-28 12:45             ` Nick Clifton
2023-02-28 12:59             ` Nick Clifton
2023-02-28 14:27               ` Mark Wielaard
2023-03-03  2:40                 ` Guillermo E. Martinez
2023-03-03 12:15                   ` Mark Wielaard
2023-03-03 12:24                     ` Nick Clifton
2023-03-04 14:00                       ` Guillermo E. Martinez
2023-03-07 14:50                         ` Mark Wielaard
2023-03-07 20:47                           ` Guillermo E. Martinez
2023-03-08 17:45                           ` Nix
2023-03-09 23:08                             ` Mark Wielaard
2022-06-07 13:23 [PATCH] " Nick Clifton
2022-06-30 19:31 ` Jose E. Marchesi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).