This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Support 'exclude' in objcopy --set-section-flags


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

commit 18ae9cc1db45e2e7f6467b91d8abbc5eb45fbaa5 makes SHF_EXCLUDE
generic, not like other SHF_MASKPROC flags. So we do not preserve
SHF_EXCLUDE when setting sh_flags.

--set-section-flags .foo= => clear SHF_EXCLUDE
--set-section-flags .foo=exclude => set SHF_EXCLUDE
>From cddb761804cf4e4bf3b67fef1ef0af3dbe07cd2b Mon Sep 17 00:00:00 2001
From: Fangrui Song <maskray@google.com>
Date: Thu, 16 Jan 2020 00:43:14 -0800
Subject: [PATCH] Support 'exclude' in objcopy --set-section-flags
To: binutils@sourceware.org

---
 bfd/elf.c                  | 2 +-
 binutils/ChangeLog         | 4 ++++
 binutils/doc/binutils.texi | 8 ++++----
 binutils/objcopy.c         | 3 ++-
 4 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/bfd/elf.c b/bfd/elf.c
index 08aaab644a..9849d2d53c 100644
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -7766,7 +7766,7 @@ _bfd_elf_init_private_section_data (bfd *ibfd,
 
   /* FIXME: Is this correct for all OS/PROC specific flags?  */
   elf_section_flags (osec) |= (elf_section_flags (isec)
-			       & (SHF_MASKOS | SHF_MASKPROC));
+                              & (SHF_MASKOS | SHF_MASKPROC) & ~SHF_EXCLUDE);
 
   /* Copy sh_info from input for mbind section.  */
   if ((elf_tdata (ibfd)->has_gnu_osabi & elf_gnu_osabi_mbind) != 0
diff --git a/binutils/ChangeLog b/binutils/ChangeLog
index 3737672832..398531ecb2 100644
--- a/binutils/ChangeLog
+++ b/binutils/ChangeLog
@@ -1,3 +1,7 @@
+2020-01-16  Fangrui Song  <maskray@google.com>
+
+	* objcopy.c (parse_flags): Handle "exclude".
+
 2020-01-13  Nick Clifton  <nickc@redhat.com>
 
 	* objdump.c (disassemble_bytes): Remove C99-ism.
diff --git a/binutils/doc/binutils.texi b/binutils/doc/binutils.texi
index 669bee968f..289d7b14a3 100644
--- a/binutils/doc/binutils.texi
+++ b/binutils/doc/binutils.texi
@@ -1644,10 +1644,10 @@ Set the flags for any sections matching @var{sectionpattern}.  The
 @var{flags} argument is a comma separated string of flag names.  The
 recognized names are @samp{alloc}, @samp{contents}, @samp{load},
 @samp{noload}, @samp{readonly}, @samp{code}, @samp{data}, @samp{rom},
-@samp{share}, and @samp{debug}.  You can set the @samp{contents} flag
-for a section which does not have contents, but it is not meaningful
-to clear the @samp{contents} flag of a section which does have
-contents--just remove the section instead.  Not all flags are
+@samp{exclude}, @samp{share}, and @samp{debug}.  You can set the
+@samp{contents} flag for a section which does not have contents, but it
+is not meaningful to clear the @samp{contents} flag of a section which
+does have contents--just remove the section instead.  Not all flags are
 meaningful for all object file formats.
 
 @item --set-section-alignment @var{sectionpattern}=@var{align}
diff --git a/binutils/objcopy.c b/binutils/objcopy.c
index ef3b693be4..3cee65de50 100644
--- a/binutils/objcopy.c
+++ b/binutils/objcopy.c
@@ -780,6 +780,7 @@ parse_flags (const char *s)
       PARSE_FLAG ("code", SEC_CODE);
       PARSE_FLAG ("data", SEC_DATA);
       PARSE_FLAG ("rom", SEC_ROM);
+      PARSE_FLAG ("exclude", SEC_EXCLUDE);
       PARSE_FLAG ("share", SEC_COFF_SHARED);
       PARSE_FLAG ("contents", SEC_HAS_CONTENTS);
       PARSE_FLAG ("merge", SEC_MERGE);
@@ -794,7 +795,7 @@ parse_flags (const char *s)
 	  copy[len] = '\0';
 	  non_fatal (_("unrecognized section flag `%s'"), copy);
 	  fatal (_("supported flags: %s"),
-		 "alloc, load, noload, readonly, debug, code, data, rom, share, contents, merge, strings");
+		 "alloc, load, noload, readonly, debug, code, data, rom, exclude, share, contents, merge, strings");
 	}
 
       s = snext;
-- 
2.25.0


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]