aboutsummaryrefslogtreecommitdiff
path: root/bfd
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2005-02-06 18:11:30 +0000
committerH.J. Lu <hjl.tools@gmail.com>2005-02-06 18:11:30 +0000
commit90f487dfe075092afbd0be376bd3c1cd5cfb8276 (patch)
treee9afc5d1b623ce6255fe1f5428d78c502d2a6ad0 /bfd
parent5b90c7b5ebca2697d381a2da54383662b47874bb (diff)
downloadfsf-binutils-gdb-90f487dfe075092afbd0be376bd3c1cd5cfb8276.zip
fsf-binutils-gdb-90f487dfe075092afbd0be376bd3c1cd5cfb8276.tar.gz
fsf-binutils-gdb-90f487dfe075092afbd0be376bd3c1cd5cfb8276.tar.bz2
2005-02-06 H.J. Lu <hongjiu.lu@intel.com>
* elf32-i386.c (elf_i386_relocate_section): Disallow R_386_GOTOFF against protected function when building shared library. PR 584 * elf64-x86-64.c (is_32bit_relative_branch): New. (elf64_x86_64_relocate_section): Alllow R_X86_64_PC32 on a protected function symbol when building shared library for 32bit relative branch instruction.
Diffstat (limited to 'bfd')
-rw-r--r--bfd/ChangeLog11
-rw-r--r--bfd/elf32-i386.c16
-rw-r--r--bfd/elf64-x86-64.c43
3 files changed, 64 insertions, 6 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 32eb9cd..461b27c 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,14 @@
+2005-02-06 H.J. Lu <hongjiu.lu@intel.com>
+
+ * elf32-i386.c (elf_i386_relocate_section): Disallow R_386_GOTOFF
+ against protected function when building shared library.
+
+ PR 584
+ * elf64-x86-64.c (is_32bit_relative_branch): New.
+ (elf64_x86_64_relocate_section): Alllow R_X86_64_PC32 on a
+ protected function symbol when building shared library for
+ 32bit relative branch instruction.
+
2005-02-06 Alan Modra <amodra@bigpond.net.au>
* elf64-ppc.c (add_symbol_adjust): Don't create fake descriptor
diff --git a/bfd/elf32-i386.c b/bfd/elf32-i386.c
index 4785552..9bab9be 100644
--- a/bfd/elf32-i386.c
+++ b/bfd/elf32-i386.c
@@ -2274,6 +2274,22 @@ elf_i386_relocate_section (bfd *output_bfd,
/* Relocation is relative to the start of the global offset
table. */
+ /* Check to make sure it isn't a protected function symbol
+ for shared library since it may not be local when used
+ as function address. */
+ if (info->shared
+ && h
+ && h->def_regular
+ && h->type == STT_FUNC
+ && ELF_ST_VISIBILITY (h->other) == STV_PROTECTED)
+ {
+ (*_bfd_error_handler)
+ (_("%B: relocation R_386_GOTOFF against protected function `%s' can not be used when making a shared object"),
+ input_bfd, h->root.root.string);
+ bfd_set_error (bfd_error_bad_value);
+ return FALSE;
+ }
+
/* Note that sgot is not involved in this
calculation. We always want the start of .got.plt. If we
defined _GLOBAL_OFFSET_TABLE_ in a different way, as is
diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c
index d5b38d8..08e610b 100644
--- a/bfd/elf64-x86-64.c
+++ b/bfd/elf64-x86-64.c
@@ -1745,6 +1745,24 @@ tpoff (struct bfd_link_info *info, bfd_vma address)
return address - htab->tls_size - htab->tls_sec->vma;
}
+/* Is the instruction before OFFSET in CONTENTS a 32bit relative
+ branch? */
+
+static bfd_boolean
+is_32bit_relative_branch (bfd_byte *contents, bfd_vma offset)
+{
+ /* Opcode Instruction
+ 0xe8 call
+ 0xe9 jump
+ 0x0f 0x8x conditional jump */
+ return ((offset > 0
+ && (contents [offset - 1] == 0xe8
+ || contents [offset - 1] == 0xe9))
+ || (offset > 1
+ && contents [offset - 2] == 0x0f
+ && (contents [offset - 1] & 0xf0) == 0x80));
+}
+
/* Relocate an x86_64 ELF section. */
static bfd_boolean
@@ -1950,13 +1968,26 @@ elf64_x86_64_relocate_section (bfd *output_bfd, struct bfd_link_info *info,
if (info->shared
&& !SYMBOL_REFERENCES_LOCAL (info, h)
&& (input_section->flags & SEC_ALLOC) != 0
- && (input_section->flags & SEC_READONLY) != 0)
+ && (input_section->flags & SEC_READONLY) != 0
+ && (!h->def_regular
+ || r_type != R_X86_64_PC32
+ || h->type != STT_FUNC
+ || ELF_ST_VISIBILITY (h->other) != STV_PROTECTED
+ || !is_32bit_relative_branch (contents,
+ rel->r_offset)))
{
- (*_bfd_error_handler)
- (_("%B: relocation %s against `%s' can not be used when making a shared object; recompile with -fPIC"),
- input_bfd,
- x86_64_elf_howto_table[r_type].name,
- (h) ? h->root.root.string : "a local symbol");
+ if (h->def_regular
+ && r_type == R_X86_64_PC32
+ && h->type == STT_FUNC
+ && ELF_ST_VISIBILITY (h->other) == STV_PROTECTED)
+ (*_bfd_error_handler)
+ (_("%B: relocation R_X86_64_PC32 against protected function `%s' can not be used when making a shared object"),
+ input_bfd, h->root.root.string);
+ else
+ (*_bfd_error_handler)
+ (_("%B: relocation %s against `%s' can not be used when making a shared object; recompile with -fPIC"),
+ input_bfd, x86_64_elf_howto_table[r_type].name,
+ h->root.root.string);
bfd_set_error (bfd_error_bad_value);
return FALSE;
}