* bfd.c (_bfd_get_gp_value): New function.

(_bfd_set_gp_value): New function.
	* libbfd-in.h (_bfd_get_gp_value): Declare.
	(_bfd_set_gp_value): Declare.
	* libbfd.h: Rebuild.
	* coff-alpha.c (alpha_ecoff_get_relocated_section_contents): Use
	_bfd_get_gp_value and _bfd_set_gp_value rather than referring
	directly to the fields in the tdata information.
	(alpha_relocate_section): Likewise.
	* coff-mips.c (mips_adjust_reloc_in): Likewise.
	(mips_gprel_reloc): Likewise.
	(mips_relocate_section): Likewise.
	* elf32-mips.c (mips_elf_hi16_reloc): Likewise.
	(mips_elf_lo16_reloc): Likewise.
	(mips_elf_final_gp): Likewise.
	(mips_elf_gprel16_reloc): Likewise.
	(mips_elf_gprel32_reloc): Likewise.
	(mips_elf_relocate_section): Likewise.
	(mips_elf_finish_dynamic_symbol): Likewise.
PR 8449.
This commit is contained in:
Ian Lance Taylor 1996-02-16 19:29:01 +00:00
parent 803108ab64
commit cba3f8a9be
4 changed files with 74 additions and 43 deletions

View File

@ -1,5 +1,25 @@
Fri Feb 16 12:46:18 1996 Ian Lance Taylor <ian@cygnus.com> Fri Feb 16 12:46:18 1996 Ian Lance Taylor <ian@cygnus.com>
* bfd.c (_bfd_get_gp_value): New function.
(_bfd_set_gp_value): New function.
* libbfd-in.h (_bfd_get_gp_value): Declare.
(_bfd_set_gp_value): Declare.
* libbfd.h: Rebuild.
* coff-alpha.c (alpha_ecoff_get_relocated_section_contents): Use
_bfd_get_gp_value and _bfd_set_gp_value rather than referring
directly to the fields in the tdata information.
(alpha_relocate_section): Likewise.
* coff-mips.c (mips_adjust_reloc_in): Likewise.
(mips_gprel_reloc): Likewise.
(mips_relocate_section): Likewise.
* elf32-mips.c (mips_elf_hi16_reloc): Likewise.
(mips_elf_lo16_reloc): Likewise.
(mips_elf_final_gp): Likewise.
(mips_elf_gprel16_reloc): Likewise.
(mips_elf_gprel32_reloc): Likewise.
(mips_elf_relocate_section): Likewise.
(mips_elf_finish_dynamic_symbol): Likewise.
* bout.c (b_out_set_arch_mach): Recognize bfd_mach_i960_jx. * bout.c (b_out_set_arch_mach): Recognize bfd_mach_i960_jx.
Thu Feb 15 11:29:13 1996 Ian Lance Taylor <ian@cygnus.com> Thu Feb 15 11:29:13 1996 Ian Lance Taylor <ian@cygnus.com>

View File

@ -1,5 +1,5 @@
/* BFD back-end for ALPHA Extended-Coff files. /* BFD back-end for ALPHA Extended-Coff files.
Copyright 1993, 1994 Free Software Foundation, Inc. Copyright 1993, 1994, 1995, 1996 Free Software Foundation, Inc.
Modified from coff-mips.c by Steve Chamberlain <sac@cygnus.com> and Modified from coff-mips.c by Steve Chamberlain <sac@cygnus.com> and
Ian Lance Taylor <ian@cygnus.com>. Ian Lance Taylor <ian@cygnus.com>.
@ -785,7 +785,7 @@ alpha_ecoff_get_relocated_section_contents (abfd, link_info, link_order,
/* Get the GP value for the output BFD. */ /* Get the GP value for the output BFD. */
gp_undefined = false; gp_undefined = false;
if (ecoff_data (abfd)->gp == 0) if (_bfd_get_gp_value (abfd) == 0)
{ {
if (relocateable != false) if (relocateable != false)
{ {
@ -804,7 +804,7 @@ alpha_ecoff_get_relocated_section_contents (abfd, link_info, link_order,
|| strcmp (sec->name, ".lita") == 0)) || strcmp (sec->name, ".lita") == 0))
lo = sec->vma; lo = sec->vma;
} }
ecoff_data (abfd)->gp = lo + 0x8000; _bfd_set_gp_value (abfd, lo + 0x8000);
} }
else else
{ {
@ -816,12 +816,13 @@ alpha_ecoff_get_relocated_section_contents (abfd, link_info, link_order,
|| h->type != bfd_link_hash_defined) || h->type != bfd_link_hash_defined)
gp_undefined = true; gp_undefined = true;
else else
ecoff_data (abfd)->gp = (h->u.def.value _bfd_set_gp_value (abfd,
+ h->u.def.section->output_section->vma (h->u.def.value
+ h->u.def.section->output_offset); + h->u.def.section->output_section->vma
+ h->u.def.section->output_offset));
} }
} }
gp = ecoff_data (abfd)->gp; gp = _bfd_get_gp_value (abfd);
for (; *reloc_vector != (arelent *) NULL; reloc_vector++) for (; *reloc_vector != (arelent *) NULL; reloc_vector++)
{ {
@ -1430,7 +1431,7 @@ alpha_relocate_section (output_bfd, info, input_bfd, input_section,
output, the .lita section is limited to 64KB. . */ output, the .lita section is limited to 64KB. . */
lita_sec = symndx_to_section[RELOC_SECTION_LITA]; lita_sec = symndx_to_section[RELOC_SECTION_LITA];
gp = ecoff_data (output_bfd)->gp; gp = _bfd_get_gp_value (output_bfd);
if (! info->relocateable && lita_sec != NULL) if (! info->relocateable && lita_sec != NULL)
{ {
struct ecoff_section_tdata *lita_sec_data; struct ecoff_section_tdata *lita_sec_data;
@ -1489,7 +1490,7 @@ alpha_relocate_section (output_bfd, info, input_bfd, input_section,
lita_sec_data->gp = gp; lita_sec_data->gp = gp;
} }
ecoff_data (output_bfd)->gp = gp; _bfd_set_gp_value (output_bfd, gp);
} }
gp_undefined = (gp == 0); gp_undefined = (gp == 0);
@ -1979,7 +1980,8 @@ alpha_relocate_section (output_bfd, info, input_bfd, input_section,
input_bfd, input_section, r_vaddr - input_section->vma))) input_bfd, input_section, r_vaddr - input_section->vma)))
return false; return false;
/* Only give the error once per link. */ /* Only give the error once per link. */
ecoff_data (output_bfd)->gp = gp = 4; gp = 4;
_bfd_set_gp_value (output_bfd, gp);
gp_undefined = false; gp_undefined = false;
} }
} }
@ -2257,7 +2259,7 @@ static const struct ecoff_backend_data alpha_ecoff_backend_data =
alpha_ecoff_bad_format_hook, _bfd_ecoff_set_arch_mach_hook, alpha_ecoff_bad_format_hook, _bfd_ecoff_set_arch_mach_hook,
alpha_ecoff_mkobject_hook, _bfd_ecoff_styp_to_sec_flags, alpha_ecoff_mkobject_hook, _bfd_ecoff_styp_to_sec_flags,
_bfd_ecoff_set_alignment_hook, _bfd_ecoff_slurp_symbol_table, _bfd_ecoff_set_alignment_hook, _bfd_ecoff_slurp_symbol_table,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
}, },
/* Supported architecture. */ /* Supported architecture. */
bfd_arch_alpha, bfd_arch_alpha,

View File

@ -1,5 +1,5 @@
/* BFD back-end for MIPS Extended-Coff files. /* BFD back-end for MIPS Extended-Coff files.
Copyright 1990, 1991, 1992, 1993, 1994 Free Software Foundation, Inc. Copyright 1990, 91, 92, 93, 94, 95, 1996 Free Software Foundation, Inc.
Original version by Per Bothner. Original version by Per Bothner.
Full support added by Ian Lance Taylor, ian@cygnus.com. Full support added by Ian Lance Taylor, ian@cygnus.com.
@ -538,7 +538,7 @@ mips_adjust_reloc_in (abfd, intern, rptr)
if (! intern->r_extern if (! intern->r_extern
&& (intern->r_type == MIPS_R_GPREL && (intern->r_type == MIPS_R_GPREL
|| intern->r_type == MIPS_R_LITERAL)) || intern->r_type == MIPS_R_LITERAL))
rptr->addend += ecoff_data (abfd)->gp; rptr->addend += _bfd_get_gp_value (abfd);
/* If the type is MIPS_R_IGNORE, make sure this is a reference to /* If the type is MIPS_R_IGNORE, make sure this is a reference to
the absolute section so that the reloc is ignored. */ the absolute section so that the reloc is ignored. */
@ -794,15 +794,15 @@ mips_gprel_reloc (abfd,
BFD. If we can't find it, we're stuck. We cache it in the ECOFF BFD. If we can't find it, we're stuck. We cache it in the ECOFF
target data. We don't need to adjust the symbol value for an target data. We don't need to adjust the symbol value for an
external symbol if we are producing relocateable output. */ external symbol if we are producing relocateable output. */
if (ecoff_data (output_bfd)->gp == 0 if (_bfd_get_gp_value (output_bfd) == 0
&& (relocateable == false && (relocateable == false
|| (symbol->flags & BSF_SECTION_SYM) != 0)) || (symbol->flags & BSF_SECTION_SYM) != 0))
{ {
if (relocateable != false) if (relocateable != false)
{ {
/* Make up a value. */ /* Make up a value. */
ecoff_data (output_bfd)->gp = _bfd_set_gp_value (output_bfd,
symbol->section->output_section->vma + 0x4000; symbol->section->output_section->vma + 0x4000);
} }
else else
{ {
@ -824,7 +824,8 @@ mips_gprel_reloc (abfd,
name = bfd_asymbol_name (*sym); name = bfd_asymbol_name (*sym);
if (*name == '_' && strcmp (name, "_gp") == 0) if (*name == '_' && strcmp (name, "_gp") == 0)
{ {
ecoff_data (output_bfd)->gp = bfd_asymbol_value (*sym); _bfd_set_gp_value (output_bfd,
bfd_asymbol_value (*sym));
break; break;
} }
} }
@ -833,7 +834,7 @@ mips_gprel_reloc (abfd,
if (i >= count) if (i >= count)
{ {
/* Only get the error once. */ /* Only get the error once. */
ecoff_data (output_bfd)->gp = 4; _bfd_set_gp_value (output_bfd, 4);
*error_message = *error_message =
(char *) "GP relative relocation when _gp not defined"; (char *) "GP relative relocation when _gp not defined";
return bfd_reloc_dangerous; return bfd_reloc_dangerous;
@ -864,7 +865,7 @@ mips_gprel_reloc (abfd,
an external symbol. */ an external symbol. */
if (relocateable == false if (relocateable == false
|| (symbol->flags & BSF_SECTION_SYM) != 0) || (symbol->flags & BSF_SECTION_SYM) != 0)
val += relocation - ecoff_data (output_bfd)->gp; val += relocation - _bfd_get_gp_value (output_bfd);
insn = (insn &~ 0xffff) | (val & 0xffff); insn = (insn &~ 0xffff) | (val & 0xffff);
bfd_put_32 (abfd, insn, (bfd_byte *) data + reloc_entry->address); bfd_put_32 (abfd, insn, (bfd_byte *) data + reloc_entry->address);
@ -1237,7 +1238,7 @@ mips_relocate_section (output_bfd, info, input_bfd, input_section,
sym_hashes = ecoff_data (input_bfd)->sym_hashes; sym_hashes = ecoff_data (input_bfd)->sym_hashes;
gp = ecoff_data (output_bfd)->gp; gp = _bfd_get_gp_value (output_bfd);
if (gp == 0) if (gp == 0)
gp_undefined = true; gp_undefined = true;
else else
@ -1356,7 +1357,8 @@ mips_relocate_section (output_bfd, info, input_bfd, input_section,
int_rel.r_vaddr - input_section->vma))) int_rel.r_vaddr - input_section->vma)))
return false; return false;
/* Only give the error once per link. */ /* Only give the error once per link. */
ecoff_data (output_bfd)->gp = gp = 4; gp = 4;
_bfd_set_gp_value (output_bfd, gp);
gp_undefined = false; gp_undefined = false;
} }
if (! int_rel.r_extern) if (! int_rel.r_extern)
@ -2421,7 +2423,7 @@ static const struct ecoff_backend_data mips_ecoff_backend_data =
mips_ecoff_bad_format_hook, _bfd_ecoff_set_arch_mach_hook, mips_ecoff_bad_format_hook, _bfd_ecoff_set_arch_mach_hook,
_bfd_ecoff_mkobject_hook, _bfd_ecoff_styp_to_sec_flags, _bfd_ecoff_mkobject_hook, _bfd_ecoff_styp_to_sec_flags,
_bfd_ecoff_set_alignment_hook, _bfd_ecoff_slurp_symbol_table, _bfd_ecoff_set_alignment_hook, _bfd_ecoff_slurp_symbol_table,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
}, },
/* Supported architecture. */ /* Supported architecture. */
bfd_arch_mips, bfd_arch_mips,

View File

@ -776,7 +776,7 @@ mips_elf_hi16_reloc (abfd,
if (ret != bfd_reloc_ok) if (ret != bfd_reloc_ok)
return ret; return ret;
relocation = elf_gp (output_bfd) - reloc_entry->address; relocation = _bfd_get_gp_value (output_bfd) - reloc_entry->address;
} }
else else
{ {
@ -878,7 +878,7 @@ mips_elf_lo16_reloc (abfd,
if (ret != bfd_reloc_ok) if (ret != bfd_reloc_ok)
return ret; return ret;
relocation = elf_gp (output_bfd) - reloc_entry->address; relocation = _bfd_get_gp_value (output_bfd) - reloc_entry->address;
relocation += symbol->section->output_section->vma; relocation += symbol->section->output_section->vma;
relocation += symbol->section->output_offset; relocation += symbol->section->output_offset;
relocation += reloc_entry->addend; relocation += reloc_entry->addend;
@ -967,15 +967,15 @@ mips_elf_final_gp (output_bfd, symbol, relocateable, error_message)
if (output_bfd->xvec->flavour != bfd_target_elf_flavour) if (output_bfd->xvec->flavour != bfd_target_elf_flavour)
abort (); abort ();
if (elf_gp (output_bfd) == 0 if (_bfd_get_gp_value (output_bfd) == 0
&& (! relocateable && (! relocateable
|| (symbol->flags & BSF_SECTION_SYM) != 0)) || (symbol->flags & BSF_SECTION_SYM) != 0))
{ {
if (relocateable) if (relocateable)
{ {
/* Make up a value. */ /* Make up a value. */
elf_gp (output_bfd) = _bfd_set_gp_value (output_bfd,
symbol->section->output_section->vma + 0x4000; symbol->section->output_section->vma + 0x4000);
} }
else else
{ {
@ -997,7 +997,7 @@ mips_elf_final_gp (output_bfd, symbol, relocateable, error_message)
name = bfd_asymbol_name (*sym); name = bfd_asymbol_name (*sym);
if (*name == '_' && strcmp (name, "_gp") == 0) if (*name == '_' && strcmp (name, "_gp") == 0)
{ {
elf_gp (output_bfd) = bfd_asymbol_value (*sym); _bfd_set_gp_value (output_bfd, bfd_asymbol_value (*sym));
break; break;
} }
} }
@ -1006,7 +1006,7 @@ mips_elf_final_gp (output_bfd, symbol, relocateable, error_message)
if (i >= count) if (i >= count)
{ {
/* Only get the error once. */ /* Only get the error once. */
elf_gp (output_bfd) = 4; _bfd_set_gp_value (output_bfd, 4);
*error_message = *error_message =
(char *) "GP relative relocation when _gp not defined"; (char *) "GP relative relocation when _gp not defined";
return bfd_reloc_dangerous; return bfd_reloc_dangerous;
@ -1071,7 +1071,8 @@ mips_elf_gprel16_reloc (abfd,
return ret; return ret;
return gprel16_with_gp (abfd, symbol, reloc_entry, input_section, return gprel16_with_gp (abfd, symbol, reloc_entry, input_section,
relocateable, data, elf_gp (output_bfd)); relocateable, data,
_bfd_get_gp_value (output_bfd));
} }
static bfd_reloc_status_type static bfd_reloc_status_type
@ -1180,7 +1181,8 @@ mips_elf_gprel32_reloc (abfd,
} }
return gprel32_with_gp (abfd, symbol, reloc_entry, input_section, return gprel32_with_gp (abfd, symbol, reloc_entry, input_section,
relocateable, data, elf_gp (output_bfd)); relocateable, data,
_bfd_get_gp_value (output_bfd));
} }
static bfd_reloc_status_type static bfd_reloc_status_type
@ -3801,6 +3803,7 @@ mips_elf_relocate_section (output_bfd, info, input_bfd, input_section,
reloc_howto_type *howto; reloc_howto_type *howto;
unsigned long r_symndx; unsigned long r_symndx;
bfd_vma addend; bfd_vma addend;
bfd_vma gp;
struct elf_link_hash_entry *h; struct elf_link_hash_entry *h;
asection *sec; asection *sec;
Elf_Internal_Sym *sym; Elf_Internal_Sym *sym;
@ -3835,6 +3838,8 @@ mips_elf_relocate_section (output_bfd, info, input_bfd, input_section,
r_symndx = ELF32_R_SYM (rel->r_info); r_symndx = ELF32_R_SYM (rel->r_info);
gp = _bfd_get_gp_value (output_bfd);
/* Mix in the change in GP address for a GP relative reloc. */ /* Mix in the change in GP address for a GP relative reloc. */
if (r_type != R_MIPS_GPREL16 if (r_type != R_MIPS_GPREL16
&& r_type != R_MIPS_LITERAL && r_type != R_MIPS_LITERAL
@ -3842,7 +3847,7 @@ mips_elf_relocate_section (output_bfd, info, input_bfd, input_section,
addend = 0; addend = 0;
else else
{ {
if (elf_gp (output_bfd) == 0) if (gp == 0)
{ {
if (! ((*info->callbacks->reloc_dangerous) if (! ((*info->callbacks->reloc_dangerous)
(info, (info,
@ -3851,7 +3856,8 @@ mips_elf_relocate_section (output_bfd, info, input_bfd, input_section,
rel->r_offset))) rel->r_offset)))
return false; return false;
/* Only give the error once per link. */ /* Only give the error once per link. */
elf_gp (output_bfd) = 4; gp = 4;
_bfd_set_gp_value (output_bfd, gp);
} }
if (r_symndx < extsymoff if (r_symndx < extsymoff
@ -3864,7 +3870,7 @@ mips_elf_relocate_section (output_bfd, info, input_bfd, input_section,
must change this to be the difference between the must change this to be the difference between the
final definition (which will end up in RELOCATION) final definition (which will end up in RELOCATION)
and the GP value of OUTPUT_BFD (which is in GP). */ and the GP value of OUTPUT_BFD (which is in GP). */
addend = elf_gp (input_bfd) - elf_gp (output_bfd); addend = elf_gp (input_bfd) - gp;
} }
else if (! info->relocateable) else if (! info->relocateable)
{ {
@ -3874,7 +3880,7 @@ mips_elf_relocate_section (output_bfd, info, input_bfd, input_section,
hold the difference between the final definition of hold the difference between the final definition of
the symbol (which will end up in RELOCATION) and the the symbol (which will end up in RELOCATION) and the
GP value of OUTPUT_BFD (which is in GP). */ GP value of OUTPUT_BFD (which is in GP). */
addend = - elf_gp (output_bfd); addend = - gp;
} }
else else
{ {
@ -3965,7 +3971,7 @@ mips_elf_relocate_section (output_bfd, info, input_bfd, input_section,
h = (struct elf_link_hash_entry *) h->root.u.i.link; h = (struct elf_link_hash_entry *) h->root.u.i.link;
if (strcmp (h->root.root.string, "_gp_disp") == 0) if (strcmp (h->root.root.string, "_gp_disp") == 0)
{ {
if (elf_gp (output_bfd) == 0) if (gp == 0)
{ {
if (! ((*info->callbacks->reloc_dangerous) if (! ((*info->callbacks->reloc_dangerous)
(info, (info,
@ -3974,19 +3980,20 @@ mips_elf_relocate_section (output_bfd, info, input_bfd, input_section,
rel->r_offset))) rel->r_offset)))
return false; return false;
/* Only give the error once per link. */ /* Only give the error once per link. */
elf_gp (output_bfd) = 4; gp = 4;
_bfd_set_gp_value (output_bfd, gp);
relocation = 0; relocation = 0;
} }
else else
{ {
sec = input_section; sec = input_section;
if (sec->output_section != NULL) if (sec->output_section != NULL)
relocation = (elf_gp (output_bfd) relocation = (gp
- (rel->r_offset - (rel->r_offset
+ sec->output_section->vma + sec->output_section->vma
+ sec->output_offset)); + sec->output_offset));
else else
relocation = elf_gp (output_bfd) - rel->r_offset; relocation = gp - rel->r_offset;
if (r_type == R_MIPS_LO16) if (r_type == R_MIPS_LO16)
relocation += 4; relocation += 4;
} }
@ -4076,7 +4083,7 @@ mips_elf_relocate_section (output_bfd, info, input_bfd, input_section,
bfd_put_32 (output_bfd, relocation + addend, bfd_put_32 (output_bfd, relocation + addend,
sgot->contents + offset); sgot->contents + offset);
offset = (sgot->output_section->vma + sgot->output_offset offset = (sgot->output_section->vma + sgot->output_offset
+ offset - elf_gp (output_bfd)); + offset - gp);
mips_elf_relocate_global_got (input_bfd, rel, contents, mips_elf_relocate_global_got (input_bfd, rel, contents,
offset); offset);
r = bfd_reloc_ok; r = bfd_reloc_ok;
@ -4101,7 +4108,7 @@ mips_elf_relocate_section (output_bfd, info, input_bfd, input_section,
bfd_put_32 (output_bfd, relocation + addend, bfd_put_32 (output_bfd, relocation + addend,
sgot->contents + offset); sgot->contents + offset);
offset = (sgot->output_section->vma + sgot->output_offset offset = (sgot->output_section->vma + sgot->output_offset
+ offset - elf_gp (output_bfd)); + offset - gp);
mips_elf_relocate_hi16 (input_bfd, rel, rel + 1, contents, mips_elf_relocate_hi16 (input_bfd, rel, rel + 1, contents,
offset); offset);
r = bfd_reloc_ok; r = bfd_reloc_ok;
@ -4251,7 +4258,7 @@ mips_elf_relocate_section (output_bfd, info, input_bfd, input_section,
case R_MIPS_LITERAL: case R_MIPS_LITERAL:
case R_MIPS_GPREL32: case R_MIPS_GPREL32:
mips_elf_set_cr_type (cptrel, CRT_MIPS_GPHI_LO); mips_elf_set_cr_type (cptrel, CRT_MIPS_GPHI_LO);
cptrel.konst = elf_gp (output_bfd) - cptrel.vaddr; cptrel.konst = gp - cptrel.vaddr;
mips_elf_set_cr_dist2to (cptrel, 4); mips_elf_set_cr_dist2to (cptrel, 4);
cr = scpt->contents + sizeof (Elf32_External_compact_rel); cr = scpt->contents + sizeof (Elf32_External_compact_rel);
bfd_elf32_swap_crinfo_out (output_bfd, &cptrel, bfd_elf32_swap_crinfo_out (output_bfd, &cptrel,
@ -5231,7 +5238,7 @@ mips_elf_finish_dynamic_symbol (output_bfd, info, h, sym)
{ {
sym->st_shndx = SHN_ABS; sym->st_shndx = SHN_ABS;
sym->st_info = ELF_ST_INFO (STB_GLOBAL, STT_SECTION); sym->st_info = ELF_ST_INFO (STB_GLOBAL, STT_SECTION);
sym->st_value = elf_gp (output_bfd); sym->st_value = _bfd_get_gp_value (output_bfd);
} }
else if (strcmp (name, mips_elf_dynsym_rtproc_names[0]) == 0 else if (strcmp (name, mips_elf_dynsym_rtproc_names[0]) == 0
|| strcmp (name, mips_elf_dynsym_rtproc_names[1]) == 0) || strcmp (name, mips_elf_dynsym_rtproc_names[1]) == 0)