This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
[PATCH/RFA] Merge non visibility STO attribute
- From: kaz Kojima <kkojima at rr dot iij4u dot or dot jp>
- To: binutils at sources dot redhat dot com
- Date: Mon, 13 Oct 2003 23:23:06 +0900 (JST)
- Subject: [PATCH/RFA] Merge non visibility STO attribute
Hi,
I've written a tiny test which calls a function in a shared libirary
on sh64-elf. It fails because of two problems. The first is an SH
specific one that some SHmedia relocations aren't handled correctly
for the dynamic symbol.
The second problem is that elf_link_add_object_symbols doesn't merge
any STO attributes of the symbol from a dynamic object. The attached
patch fixes these and adds the above new test. I've tested the patch
on i686-pc-linux-gnu and sh64-elf and there are no new regressions.
OK to the trunk?
Regards,
kaz
--
2003-10-13 Kaz Kojima <kkojima@rr.iij4u.or.jp>
[bfd/ChangeLog]
* bfd/elflink.h (elf_link_add_object_symbols): Merge non visibility
attribute of the symbol from a dynamic object.
* bfd/elf32-sh.c (sh_elf_relocate_section): Handle R_SH_IMM_*_PCREL
relocations.
(sh_elf_check_relocs): Likewise.
[ld/testsuite/ChangeLog]
* ld-sh/sh64/rd-sh64.exp: If the test matches *-dso.d, copy
the output of linker to the file tmpdir/*-dso.so.
* ld-sh/sh64/stobin-0-dso.d: New.
* ld-sh/sh64/stobin-1.d: New.
* ld-sh/sh64/stobin.s: New.
* ld-sh/sh64/stolib.s: New.
diff -u3prN ORIG/src/bfd/elflink.h LOCAL/src/bfd/elflink.h
--- ORIG/src/bfd/elflink.h Sat Oct 11 11:57:08 2003
+++ LOCAL/src/bfd/elflink.h Mon Oct 13 14:16:57 2003
@@ -1261,7 +1261,7 @@ elf_link_add_object_symbols (bfd *abfd,
/* If st_other has a processor-specific meaning, specific
code might be needed here. We never merge the visibility
attribute with the one from a dynamic object. */
- if (isym->st_other != 0 && !dynamic)
+ if (isym->st_other != 0)
{
unsigned char hvis, symvis, other, nvis;
@@ -1271,13 +1271,18 @@ elf_link_add_object_symbols (bfd *abfd,
/* Combine visibilities, using the most constraining one. */
hvis = ELF_ST_VISIBILITY (h->other);
- symvis = ELF_ST_VISIBILITY (isym->st_other);
- if (! hvis)
- nvis = symvis;
- else if (! symvis)
- nvis = hvis;
+ if (!dynamic)
+ {
+ symvis = ELF_ST_VISIBILITY (isym->st_other);
+ if (! hvis)
+ nvis = symvis;
+ else if (! symvis)
+ nvis = hvis;
+ else
+ nvis = hvis < symvis ? hvis : symvis;
+ }
else
- nvis = hvis < symvis ? hvis : symvis;
+ nvis = hvis;
h->other = other | nvis;
}
diff -u3prN ORIG/src/bfd/elf32-sh.c LOCAL/src/bfd/elf32-sh.c
--- ORIG/src/bfd/elf32-sh.c Wed Sep 24 14:48:17 2003
+++ LOCAL/src/bfd/elf32-sh.c Mon Oct 13 16:51:23 2003
@@ -5081,13 +5081,19 @@ sh_elf_relocate_section (bfd *output_bfd
case R_SH_DIR32:
case R_SH_REL32:
+#ifdef INCLUDE_SHMEDIA
+ case R_SH_IMM_LOW16_PCREL:
+ case R_SH_IMM_MEDLOW16_PCREL:
+ case R_SH_IMM_MEDHI16_PCREL:
+ case R_SH_IMM_HI16_PCREL:
+#endif
if (info->shared
&& (h == NULL
|| ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
|| h->root.type != bfd_link_hash_undefweak)
&& r_symndx != 0
&& (input_section->flags & SEC_ALLOC) != 0
- && (r_type != R_SH_REL32
+ && (r_type == R_SH_DIR32
|| !SYMBOL_CALLS_LOCAL (info, h)))
{
Elf_Internal_Rela outrel;
@@ -5140,6 +5146,17 @@ sh_elf_relocate_section (bfd *output_bfd
outrel.r_addend
= bfd_get_32 (input_bfd, contents + rel->r_offset);
}
+#ifdef INCLUDE_SHMEDIA
+ else if (r_type == R_SH_IMM_LOW16_PCREL
+ || r_type == R_SH_IMM_MEDLOW16_PCREL
+ || r_type == R_SH_IMM_MEDHI16_PCREL
+ || r_type == R_SH_IMM_HI16_PCREL)
+ {
+ BFD_ASSERT (h != NULL && h->dynindx != -1);
+ outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
+ outrel.r_addend = addend;
+ }
+#endif
else
{
/* h->dynindx may be -1 if this symbol was marked to
@@ -6655,6 +6672,12 @@ sh_elf_check_relocs (bfd *abfd, struct b
case R_SH_DIR32:
case R_SH_REL32:
+#ifdef INCLUDE_SHMEDIA
+ case R_SH_IMM_LOW16_PCREL:
+ case R_SH_IMM_MEDLOW16_PCREL:
+ case R_SH_IMM_MEDHI16_PCREL:
+ case R_SH_IMM_HI16_PCREL:
+#endif
if (h != NULL && ! info->shared)
{
h->elf_link_hash_flags |= ELF_LINK_NON_GOT_REF;
@@ -6772,7 +6795,14 @@ sh_elf_check_relocs (bfd *abfd, struct b
}
p->count += 1;
- if (r_type == R_SH_REL32)
+ if (r_type == R_SH_REL32
+#ifdef INCLUDE_SHMEDIA
+ || r_type == R_SH_IMM_LOW16_PCREL
+ || r_type == R_SH_IMM_MEDLOW16_PCREL
+ || r_type == R_SH_IMM_MEDHI16_PCREL
+ || r_type == R_SH_IMM_HI16_PCREL
+#endif
+ )
p->pc_count += 1;
}
diff -u3prN ORIG/src/ld/testsuite/ld-sh/sh64/rd-sh64.exp LOCAL/src/ld/testsuite/ld-sh/sh64/rd-sh64.exp
--- ORIG/src/ld/testsuite/ld-sh/sh64/rd-sh64.exp Fri Aug 23 17:14:06 2002
+++ LOCAL/src/ld/testsuite/ld-sh/sh64/rd-sh64.exp Mon Oct 13 14:16:57 2003
@@ -27,4 +27,15 @@ foreach sh64test $rd_test_list {
# We need to strip the ".d", but can leave the dirname.
verbose [file rootname $sh64test]
run_dump_test [file rootname $sh64test]
+ if [string match $srcdir/$subdir/*-dso.d $sh64test] {
+ # Copy the output of the DSO-createing test to .so file.
+ # Notice that a DSO-creating test must preceed the tests
+ # which need that DSO in sort-order by name.
+ set cmd "cp tmpdir/dump \
+ tmpdir/[file rootname [file tail $sh64test]].so"
+ send_log "$cmd\n"
+ set cmdret [catch "exec $cmd" comp_output]
+ send_log "$comp_output\n"
+ # FIXME: What if it fails? Need we do something?
+ }
}
diff -u3prN ORIG/src/ld/testsuite/ld-sh/sh64/stobin-0-dso.d LOCAL/src/ld/testsuite/ld-sh/sh64/stobin-0-dso.d
--- ORIG/src/ld/testsuite/ld-sh/sh64/stobin-0-dso.d Thu Jan 1 09:00:00 1970
+++ LOCAL/src/ld/testsuite/ld-sh/sh64/stobin-0-dso.d Mon Oct 13 14:16:57 2003
@@ -0,0 +1,9 @@
+#source: stolib.s
+#as: --abi=32 --isa=SHmedia
+#ld: -shared -mshelf32
+#objdump: -drj.text
+#target: sh64-*-elf
+
+.*: +file format elf32-sh64.*
+
+#pass
diff -u3prN ORIG/src/ld/testsuite/ld-sh/sh64/stobin-1.d LOCAL/src/ld/testsuite/ld-sh/sh64/stobin-1.d
--- ORIG/src/ld/testsuite/ld-sh/sh64/stobin-1.d Thu Jan 1 09:00:00 1970
+++ LOCAL/src/ld/testsuite/ld-sh/sh64/stobin-1.d Mon Oct 13 16:44:32 2003
@@ -0,0 +1,15 @@
+#source: stobin.s
+#as: --abi=32 --isa=SHmedia
+#ld: -mshelf32 tmpdir/stobin-0-dso.so
+#objdump: -drj.text
+#target: sh64-*-elf
+
+.*: +file format elf32-sh64.*
+
+Disassembly of section \.text:
+
+0+[0-9a-f]+ <start>:
+ [0-9a-f]+: cffffd90 movi -1,r25
+ [0-9a-f]+: cbfee590 shori 65465,r25 ! 0xffffffb9 .*
+ [0-9a-f]+: 6bf56600 ptrel/l r25,tr0
+ [0-9a-f]+: 4401fff0 blink tr0,r63
diff -u3prN ORIG/src/ld/testsuite/ld-sh/sh64/stobin.s LOCAL/src/ld/testsuite/ld-sh/sh64/stobin.s
--- ORIG/src/ld/testsuite/ld-sh/sh64/stobin.s Thu Jan 1 09:00:00 1970
+++ LOCAL/src/ld/testsuite/ld-sh/sh64/stobin.s Mon Oct 13 14:16:57 2003
@@ -0,0 +1,5 @@
+ .text
+ .globl start
+start:
+ pt bar, tr0
+ blink tr0, r63
diff -u3prN ORIG/src/ld/testsuite/ld-sh/sh64/stolib.s LOCAL/src/ld/testsuite/ld-sh/sh64/stolib.s
--- ORIG/src/ld/testsuite/ld-sh/sh64/stolib.s Thu Jan 1 09:00:00 1970
+++ LOCAL/src/ld/testsuite/ld-sh/sh64/stolib.s Mon Oct 13 14:16:57 2003
@@ -0,0 +1,7 @@
+ .text
+ .globl bar
+ .type bar,@function
+bar:
+ ptabs r18, tr0
+ blink tr0, r63
+ .Lfe_bar: .size bar,.Lfe_bar-X