* [PATCH] sh: Make protected symbols local for FDPIC -shared
@ 2024-02-19 7:09 Fangrui Song
2024-02-20 22:10 ` Alan Modra
0 siblings, 1 reply; 2+ messages in thread
From: Fangrui Song @ 2024-02-19 7:09 UTC (permalink / raw)
To: Joseph Myers, Alexandre Oliva, binutils; +Cc: Fangrui Song
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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] sh: Make protected symbols local for FDPIC -shared
2024-02-19 7:09 [PATCH] sh: Make protected symbols local for FDPIC -shared Fangrui Song
@ 2024-02-20 22:10 ` Alan Modra
0 siblings, 0 replies; 2+ messages in thread
From: Alan Modra @ 2024-02-20 22:10 UTC (permalink / raw)
To: Fangrui Song; +Cc: Joseph Myers, Alexandre Oliva, binutils, Fangrui Song
On Sun, Feb 18, 2024 at 11:09:40PM -0800, Fangrui Song wrote:
> 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"
>
Right.
$ sh4-linux-gnu-gcc -fPIC -mfdpic -c fundesc.c
$ ld/ld-new -m shlelf_fd -shared -o fundesc.so fundesc.o
ld/ld-new: fundesc.o(.text+0x24): R_SH_GOTOFFFUNCDESC relocation against external symbol "protected_fun"
ld/ld-new: final link failed
> 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.
Are you sure the dynamic_sections_created test is redundant?
_bfd_elf_symbol_refs_local_p returns false for undefined syms. BTW, I
think it is better to write SYMBOL_CALLS_LOCAL rather than expanding
to _bfd_elf_symbol_refs_local_p. The name conveys meaning.
This isn't an ack or a nack on the patch, I'll leave that to Alexandre
since I really don't know enough about the sh fdpic ABI without
spending quite a lot of time checking, but I suspect the patch isn't
complete due to code like
else if (SYMBOL_CALLS_LOCAL (info, h)
&& ! SYMBOL_FUNCDESC_LOCAL (info, h))
{
/* If the symbol needs a non-local function descriptor
but binds locally (i.e., its visibility is
protected), emit a dynamic relocation decayed to
section+offset. This is an optimization; the dynamic
linker would resolve our function descriptor request
to our copy of the function anyway. */
dynindx = elf_section_data (h->root.u.def.section
->output_section)->dynindx;
relocation += h->root.u.def.section->output_offset
+ h->root.u.def.value;
}
That would be an "else if (0)" after your patch.
> ---
> 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
--
Alan Modra
Australia Development Lab, IBM
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-02-20 22:10 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-19 7:09 [PATCH] sh: Make protected symbols local for FDPIC -shared Fangrui Song
2024-02-20 22:10 ` Alan Modra
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).