This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
[PATCH] Allow MIPS16 symbols to have nondefault visiblity
- From: Richard Sandiford <rdsandiford at googlemail dot com>
- To: binutils at sourceware dot org
- Date: Sat, 28 Jun 2008 17:15:54 +0100
- Subject: [PATCH] Allow MIPS16 symbols to have nondefault visiblity
The STO_MIPS16 handling currently tests st_other for equality.
This means that MIPS16 symbols can't have non-default visiblity.
I think it makes sense for MIPS16ness and visibility to be
separate properties, so this patch removes that restriction.
Tested on mips64-linux-gnu and mips64el-linux-gnu. OK to install?
Richard
include/elf/
* mips.h (ELF_ST_IS_MIPS16, ELF_ST_SET_MIPS16): New macros.
bfd/
* elfxx-mips.c (mips_elf_check_mips16_stubs): Use ELF_ST_IS_MIPS16.
(mips_elf_calculate_relocation): Likewise.
(_bfd_mips_elf_add_symbol_hook): Likewise.
(_bfd_mips_elf_finish_dynamic_symbol): Likewise.
(_bfd_mips_vxworks_finish_dynamic_symbol): Likewise.
opcodes/
* mips-dis.c (_print_insn_mips): Use ELF_ST_IS_MIPS16.
gas/
* config/tc-mips.c (mips16_mark_labels): Use ELF_ST_SET_MIPS16.
(mips_fix_adjustable): Likewise.
(mips_frob_file_after_relocs): Likewise.
gas/testsuite/
* gas/mips/mips16-vis-1.d, gas/mips/mips16-vis-1.s: New tests.
* gas/mips/mips.exp: Run them.
Index: include/elf/mips.h
===================================================================
--- include/elf/mips.h 2008-06-28 17:09:29.000000000 +0100
+++ include/elf/mips.h 2008-06-28 17:14:12.000000000 +0100
@@ -725,6 +725,8 @@ #define STO_PROTECTED STV_PROTECTED
/* This value is used for a mips16 .text symbol. */
#define STO_MIPS16 0xf0
+#define ELF_ST_IS_MIPS16(OTHER) (((OTHER) & 0xf0) == STO_MIPS16)
+#define ELF_ST_SET_MIPS16(OTHER) (((OTHER) & ~0xf0) | STO_MIPS16)
/* This bit is used on Irix to indicate a symbol whose definition
is optional - if, at final link time, it cannot be found, no
Index: bfd/elfxx-mips.c
===================================================================
--- bfd/elfxx-mips.c 2008-06-28 17:09:29.000000000 +0100
+++ bfd/elfxx-mips.c 2008-06-28 17:14:12.000000000 +0100
@@ -1172,7 +1172,7 @@ mips_elf_check_mips16_stubs (struct mips
}
if (h->call_stub != NULL
- && h->root.other == STO_MIPS16)
+ && ELF_ST_IS_MIPS16 (h->root.other))
{
/* We don't need the call_stub; this is a 16 bit function, so
calls from other 16 bit functions are OK. Clobber the size
@@ -1184,7 +1184,7 @@ mips_elf_check_mips16_stubs (struct mips
}
if (h->call_fp_stub != NULL
- && h->root.other == STO_MIPS16)
+ && ELF_ST_IS_MIPS16 (h->root.other))
{
/* We don't need the call_stub; this is a 16 bit function, so
calls from other 16 bit functions are OK. Clobber the size
@@ -4182,7 +4182,7 @@ mips_elf_calculate_relocation (bfd *abfd
}
/* MIPS16 text labels should be treated as odd. */
- if (sym->st_other == STO_MIPS16)
+ if (ELF_ST_IS_MIPS16 (sym->st_other))
++symbol;
/* Record the name of this symbol, for our caller. */
@@ -4192,7 +4192,7 @@ mips_elf_calculate_relocation (bfd *abfd
if (*namep == '\0')
*namep = bfd_section_name (input_bfd, sec);
- target_is_16_bit_code_p = (sym->st_other == STO_MIPS16);
+ target_is_16_bit_code_p = ELF_ST_IS_MIPS16 (sym->st_other);
}
else
{
@@ -4288,7 +4288,7 @@ mips_elf_calculate_relocation (bfd *abfd
symbol = 0;
}
- target_is_16_bit_code_p = (h->root.other == STO_MIPS16);
+ target_is_16_bit_code_p = ELF_ST_IS_MIPS16 (h->root.other);
}
/* If this is a 32- or 64-bit call to a 16-bit function with a stub, we
@@ -6119,7 +6119,7 @@ _bfd_mips_elf_add_symbol_hook (bfd *abfd
/* If this is a mips16 text symbol, add 1 to the value to make it
odd. This will cause something like .word SYM to come up with
the right value when it is loaded into the PC. */
- if (sym->st_other == STO_MIPS16)
+ if (ELF_ST_IS_MIPS16 (sym->st_other))
++*valp;
return TRUE;
@@ -6142,7 +6142,7 @@ _bfd_mips_elf_add_symbol_hook (bfd *abfd
&& strcmp (input_sec->name, ".scommon") == 0)
sym->st_shndx = SHN_MIPS_SCOMMON;
- if (sym->st_other == STO_MIPS16)
+ if (ELF_ST_IS_MIPS16 (sym->st_other))
sym->st_value &= ~1;
return TRUE;
@@ -8719,7 +8719,7 @@ _bfd_mips_elf_finish_dynamic_symbol (bfd
}
/* If this is a mips16 symbol, force the value to be even. */
- if (sym->st_other == STO_MIPS16)
+ if (ELF_ST_IS_MIPS16 (sym->st_other))
sym->st_value &= ~1;
return TRUE;
@@ -8891,7 +8891,7 @@ _bfd_mips_vxworks_finish_dynamic_symbol
}
/* If this is a mips16 symbol, force the value to be even. */
- if (sym->st_other == STO_MIPS16)
+ if (ELF_ST_IS_MIPS16 (sym->st_other))
sym->st_value &= ~1;
return TRUE;
Index: opcodes/mips-dis.c
===================================================================
--- opcodes/mips-dis.c 2008-06-28 17:09:29.000000000 +0100
+++ opcodes/mips-dis.c 2008-06-28 17:14:12.000000000 +0100
@@ -2041,8 +2041,8 @@ _print_insn_mips (bfd_vma memaddr,
if (info->mach == bfd_mach_mips16
|| (info->flavour == bfd_target_elf_flavour
&& info->symbols != NULL
- && ((*(elf_symbol_type **) info->symbols)->internal_elf_sym.st_other
- == STO_MIPS16)))
+ && ELF_ST_IS_MIPS16 ((*(elf_symbol_type **) info->symbols)
+ ->internal_elf_sym.st_other)))
return print_insn_mips16 (memaddr, info);
#endif
Index: gas/config/tc-mips.c
===================================================================
--- gas/config/tc-mips.c 2008-06-28 17:09:29.000000000 +0100
+++ gas/config/tc-mips.c 2008-06-28 17:14:12.000000000 +0100
@@ -2297,7 +2297,7 @@ mips16_mark_labels (void)
#if defined(OBJ_ELF) || defined(OBJ_MAYBE_ELF)
if (IS_ELF)
- S_SET_OTHER (label, STO_MIPS16);
+ S_SET_OTHER (label, ELF_ST_SET_MIPS16 (S_GET_OTHER (label)));
#endif
if ((S_GET_VALUE (label) & 1) == 0
/* Don't adjust the address if the label is global or weak, or
@@ -13783,7 +13783,7 @@ mips_fix_adjustable (fixS *fixp)
that we have for MIPS16 symbols. */
if (IS_ELF
&& fixp->fx_subsy == NULL
- && (S_GET_OTHER (fixp->fx_addsy) == STO_MIPS16
+ && (ELF_ST_IS_MIPS16 (S_GET_OTHER (fixp->fx_addsy))
|| *symbol_get_tc (fixp->fx_addsy)))
return 0;
#endif
@@ -14260,7 +14260,7 @@ mips_frob_file_after_relocs (void)
count = bfd_get_symcount (stdoutput);
for (i = 0; i < count; i++, syms++)
{
- if (elf_symbol (*syms)->internal_elf_sym.st_other == STO_MIPS16
+ if (ELF_ST_IS_MIPS16 (elf_symbol (*syms)->internal_elf_sym.st_other)
&& ((*syms)->value & 1) != 0)
{
(*syms)->value &= ~1;
Index: gas/testsuite/gas/mips/mips16-vis-1.d
===================================================================
--- /dev/null 2008-06-21 07:33:38.548096750 +0100
+++ gas/testsuite/gas/mips/mips16-vis-1.d 2008-06-28 17:14:12.000000000 +0100
@@ -0,0 +1,3 @@
+# readelf: --symbols
+#...
+.*: 0+0 * 2 * FUNC * GLOBAL * HIDDEN \[MIPS16\] * [0-9]+ foo
Index: gas/testsuite/gas/mips/mips16-vis-1.s
===================================================================
--- /dev/null 2008-06-21 07:33:38.548096750 +0100
+++ gas/testsuite/gas/mips/mips16-vis-1.s 2008-06-28 17:14:12.000000000 +0100
@@ -0,0 +1,7 @@
+ .set mips16
+ .globl foo
+ .hidden foo
+ .ent foo
+foo:
+ nop
+ .end foo
Index: gas/testsuite/gas/mips/mips.exp
===================================================================
--- gas/testsuite/gas/mips/mips.exp 2008-06-28 17:09:29.000000000 +0100
+++ gas/testsuite/gas/mips/mips.exp 2008-06-28 17:14:12.000000000 +0100
@@ -819,4 +819,6 @@ if { [istarget mips*-*-vxworks*] } {
run_list_test_arches "mips-double-float-flag" \
"-32 -msingle-float -mdouble-float" \
[mips_arch_list_matching mips1]
+
+ run_dump_test "mips16-vis-1"
}