public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Xi Ruoyao <xry111@mengyan1223.wang>
To: binutils@sourceware.org
Cc: Wu Xiaotian <yetist@gmail.com>, Wang Xuerui <i@xen0n.name>,
	Xi Ruoyao <xry111@mengyan1223.wang>,
	Chenghua Xu <xuchenghua@loongson.cn>,
	Zhensong Liu <liuzhensong@loongson.cn>
Subject: [PATCH] loongarch: Don't check ABI flags if no code section
Date: Fri, 29 Apr 2022 01:25:20 +0800	[thread overview]
Message-ID: <1999c15884a7c2a8c164b7008a2dc6c7af112122.camel@mengyan1223.wang> (raw)

Various packages (glib and gtk4 for example) produces data-only objects
using `ld -r -b binary` or `objcopy`, with no elf header flags set.  But
these files also have no code sections, so they should be compatible
with all ABIs.

bfd/
	* elfnn-loongarch.c (elfNN_loongarch_merge_private_bfd_data):
	Skip ABI checks if the input has no code sections.

Reported-by: Wu Xiaotian <yetist@gmail.com>
Suggested-by: Wang Xuerui <i@xen0n.name>
Signed-off-by: Xi Ruoyao <xry111@mengyan1223.wang>
---
 bfd/elfnn-loongarch.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/bfd/elfnn-loongarch.c b/bfd/elfnn-loongarch.c
index 3c7268c02b8..307757f5dd5 100644
--- a/bfd/elfnn-loongarch.c
+++ b/bfd/elfnn-loongarch.c
@@ -389,6 +389,27 @@ elfNN_loongarch_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info)
   if (!_bfd_elf_merge_object_attributes (ibfd, info))
     return false;
 
+  /* If the input BFD is not a dynamic object and it does not contain any
+     non-data sections, do not account its ABI.  For example, various
+     packages produces such data-only relocatable objects with
+     `ld -r -b binary` or `objcopy`, and these objects have zero e_flags.
+     But they are compatible with all ABIs.  */
+  if (!(ibfd->flags & DYNAMIC))
+    {
+      asection *sec;
+      bool have_code_sections = false;
+      for (sec = ibfd->sections; sec != NULL; sec = sec->next)
+	if ((bfd_section_flags (sec)
+	     & (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS))
+	    == (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS))
+	  {
+	    have_code_sections = true;
+	    break;
+	  }
+      if (!have_code_sections)
+	return true;
+    }
+
   if (!elf_flags_init (obfd))
     {
       elf_flags_init (obfd) = true;
-- 
2.36.0



             reply	other threads:[~2022-04-28 17:25 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-28 17:25 Xi Ruoyao [this message]
2022-05-05 11:04 ` liuzhensong

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=1999c15884a7c2a8c164b7008a2dc6c7af112122.camel@mengyan1223.wang \
    --to=xry111@mengyan1223.wang \
    --cc=binutils@sourceware.org \
    --cc=i@xen0n.name \
    --cc=liuzhensong@loongson.cn \
    --cc=xuchenghua@loongson.cn \
    --cc=yetist@gmail.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).