public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Fangrui Song <maskray@google.com>
To: Joseph Myers <josmyers@redhat.com>,
	Alexandre Oliva <oliva@adacore.com>,
	binutils@sourceware.org
Cc: Fangrui Song <maskray@gcc.gnu.org>
Subject: [PATCH] sh: Make protected symbols local for FDPIC -shared
Date: Sun, 18 Feb 2024 23:09:40 -0800	[thread overview]
Message-ID: <20240219070941.2254076-1-maskray@google.com> (raw)

From: Fangrui Song <maskray@gcc.gnu.org>

    __attribute__((visibility("protected"))) void protected_fun() {}
    void *get_protected_fun() { return protected_fun; }

links fine in the non-FDPIC mode but not in the FDPIC mode:

    R_SH_GOTOFFFUNCDESC relocation against external symbol "protected_fun"

The issue is similar to the x86 issue fixed by commit
d19a265487eda186b6977d9d15648cda9fad3298 ("x86: Make protected symbols
local for -shared").

SYMBOL_FUNCDESC_LOCAL in the R_SH_GOTOFFFUNCDESC check unnecessarily
considers protected symbols non-local.  elf32-frv.c:FRVFDPIC_SYM_LOCAL
avoids the issue by setting local_protected.  Set local_protected for sh
as well. It seems that the condition `! elf_hash_table
(INFO)->dynamic_sections_created` is redundant as `h->dynindx` should be
-1.  Let's remove the condition.
---
 bfd/elf32-sh.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/bfd/elf32-sh.c b/bfd/elf32-sh.c
index bf4cb2a8242..7d35144cdc3 100644
--- a/bfd/elf32-sh.c
+++ b/bfd/elf32-sh.c
@@ -64,8 +64,7 @@ static bfd_vma tpoff
    not.  If the symbol is protected, we want the local address, but
    its function descriptor must be assigned by the dynamic linker.  */
 #define SYMBOL_FUNCDESC_LOCAL(INFO, H) \
-  (SYMBOL_REFERENCES_LOCAL (INFO, H) \
-   || ! elf_hash_table (INFO)->dynamic_sections_created)
+  _bfd_elf_symbol_refs_local_p (H, INFO, 1)
 \f
 #define SH_PARTIAL32 true
 #define SH_SRC_MASK32 0xffffffff
-- 
2.44.0.rc0.258.g7320e95886-goog


             reply	other threads:[~2024-02-19  7:09 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-19  7:09 Fangrui Song [this message]
2024-02-20 22:10 ` Alan Modra

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=20240219070941.2254076-1-maskray@google.com \
    --to=maskray@google.com \
    --cc=binutils@sourceware.org \
    --cc=josmyers@redhat.com \
    --cc=maskray@gcc.gnu.org \
    --cc=oliva@adacore.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).