public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Tatsuyuki Ishi <ishitatsuyuki@gmail.com>
To: binutils@sourceware.org
Cc: amodra@gmail.com, jbeulich@suse.com, i@maskray.me,
	Tatsuyuki Ishi <ishitatsuyuki@gmail.com>
Subject: [PATCH v2 3/6] objcopy: Remove SHT_LLVM_ADDRSIG sections by default.
Date: Fri, 24 Jun 2022 00:13:51 +0900	[thread overview]
Message-ID: <20220623151353.62139-4-ishitatsuyuki@gmail.com> (raw)
In-Reply-To: <20220623151353.62139-1-ishitatsuyuki@gmail.com>

addrsig entries copied by objcopy has historically been ignored by lld [1],
due to known caveats in case the symbol table is modified without updating
the addrsig section as well.

Now that bfd is able to insert the respective sh_link entry for the
section, the heuristic for broken addrsig section in [1] no longer works
and we need to explicitly remove the section to prevent silent corruption.
We also warn the user about this, so they will be aware of the caveat.

[1]: https://github.com/llvm/llvm-project/blob/09c2b7c35af8c4bad39f03e9f60df8bd07323028/lld/ELF/InputFiles.cpp#L540-L554
---
 binutils/objcopy.c | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)

diff --git a/binutils/objcopy.c b/binutils/objcopy.c
index df87712df98..57d39558099 100644
--- a/binutils/objcopy.c
+++ b/binutils/objcopy.c
@@ -1316,10 +1316,20 @@ is_mergeable_note_section (bfd * abfd, asection * sec)
   return false;
 }
 
+static bool
+is_addrsig_section (bfd *abfd, asection *sec)
+{
+  if (bfd_get_flavour (abfd) == bfd_target_elf_flavour
+      && elf_section_data (sec)->this_hdr.sh_type == SHT_LLVM_ADDRSIG)
+    return true;
+
+  return false;
+}
+
 /* See if a non-group section is being removed.  */
 
 static bool
-is_strip_section_1 (bfd *abfd ATTRIBUTE_UNUSED, asection *sec)
+is_strip_section_1 (bfd *abfd, asection *sec)
 {
   if (find_section_list (bfd_section_name (sec), false, SECTION_CONTEXT_KEEP)
       != NULL)
@@ -1348,6 +1358,20 @@ is_strip_section_1 (bfd *abfd ATTRIBUTE_UNUSED, asection *sec)
 	return true;
     }
 
+  /* addrsig needs to be updated if the symtab is altered, but we don't know
+     how to read nor write it, so just throw it away to not confuse
+     downstream tools.  */
+  if (is_addrsig_section (abfd, sec))
+    {
+      non_fatal (_ ("warning: removing section %s to prevent corrupt addrsig "
+                    "information"),
+                 bfd_section_name (sec));
+      non_fatal (_ ("pass --remove-section=%1$s to suppress warning, or "
+                    "--keep-section=%1$s to override"),
+                 bfd_section_name (sec));
+      return true;
+    }
+
   if ((bfd_section_flags (sec) & SEC_DEBUGGING) != 0)
     {
       if (strip_symbols == STRIP_DEBUG
-- 
2.36.1


  parent reply	other threads:[~2022-06-23 15:14 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-23 15:13 [PATCH v2 0/6] gas: Add support for LLVM addrsig and addrsig_sym Tatsuyuki Ishi
2022-06-23 15:13 ` [PATCH v2 1/6] elf: Add definition for SHT_LLVM_ADDRSIG Tatsuyuki Ishi
2022-06-23 15:13 ` [PATCH v2 2/6] bfd: Output SH_LINK to .symtab " Tatsuyuki Ishi
2022-06-23 15:13 ` Tatsuyuki Ishi [this message]
2022-06-23 15:40   ` [PATCH v2 3/6] objcopy: Remove SHT_LLVM_ADDRSIG sections by default Jan Beulich
2022-06-24  5:28     ` Tatsuyuki Ishi
2022-06-23 15:13 ` [PATCH v2 4/6] ld: Discard LLVM_ADDRSIG sections Tatsuyuki Ishi
2022-06-23 15:13 ` [PATCH v2 5/6] gas: Add support for LLVM addrsig and addrsig_sym directives on ELF Tatsuyuki Ishi
2022-06-23 15:13 ` [PATCH v2 6/6] gas: Add basic test for addrsig Tatsuyuki Ishi
2022-06-28  9:20 ` [PATCH v2 0/6] gas: Add support for LLVM addrsig and addrsig_sym Alan Modra
2022-06-29  1:27   ` Tatsuyuki Ishi
2022-06-29  2:56     ` Alan Modra
2022-06-30 20:59       ` Fangrui Song

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220623151353.62139-4-ishitatsuyuki@gmail.com \
    --to=ishitatsuyuki@gmail.com \
    --cc=amodra@gmail.com \
    --cc=binutils@sourceware.org \
    --cc=i@maskray.me \
    --cc=jbeulich@suse.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).