This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
PATCH: Remove duplication of code to create a dynamic reloc section
- From: Nick Clifton <nickc at redhat dot com>
- To: binutils at sourceware dot org
- Date: Tue, 25 Nov 2008 13:00:25 +0000
- Subject: PATCH: Remove duplication of code to create a dynamic reloc section
Hi Guys,
Most of the ELF based linker targets have very similar pieces of
code to create and name a section to hold dynamic relocs. So I am
going to apply the attached patch to replace all of these duplicated
sections of code with calls to a couple of new elflinker functions.
(I also have an ulterior motive in that I want to extend the dynamic
reloc functionality, but that can wait for a later patch).
Tested by rebuilding and regression testing all 106 of my local
toolchains.
Cheers
Nick
bfd/ChangeLog
2008-11-25 Nick Clifton <nickc@redhat.com>
* elflink.c (is_reloc_section): New function. Returns true if the
given name matches the name of the reloc-containing section
associated with the given section.
(get_dynamic_reloc_section_name): New function. Computes the name
of the section that contains the dynamic relocs associated with
the given section.
(_bfd_elf_get_dynamic_reloc_section): New function. Returns a
pointer to the section containing the dynamic relocs associated
with the given section.
(_bfd_elf_make_dynamic_reloc_section): New function. Creates a
section to contain the dynamic relocs associated with a given
section.
* elf-bfd.h: Prototype the new functions.
* elf-m10300.c (mn10300_elf_check_relocs): Use new functions.
(mn10300_elf_final_link_relocs): Likewise.
* elf32-arm.c (reloc_section_p): Delete - replaced by new
functions.
(elf32_arm_final_link_relocate): Use new functions.
(elf32_arm_check_relocs): Likewise.
* elf32-cris.c (cris_elf_relocate_section): Likewise.
(elf_cris_check_relocs): Likewise.
* elf32-hppa.c (elf32_hppa_check_relocs): Likewise.
* elf32-i370.c (i370_elf_check_relocs): Likewise.
(i370_elf_relocate_section): Likewise.
* elf32-i386.c (elf_i386_check_relocs): Likewise.
* elf32-m32r.c (m32r_elf_relocate_section): Likewise.
(m32r_elf_check_relocs): Likewise.
* elf32-m68k.c (elf_m68k_check_relocs): Likewise.
* elf32_ppc.c (ppc_elf_check_relocs): Likewise.
(ppc_elf_relocate_section): Likewise.
* elf32-s390.c (elf_s390_check_relocs): Likewise.
* elf32-sh.c (sh_elf_relocate_section): Likewise.
(sh_elf_check_relocs): Likewise.
* elf32-vax.c (elf_vax_check_relocs): Likewise.
(elf_vax_relocate_section): Likewise.
* elf64-alpha.c (elf64_alpha_check_relocs): Likewise.
* elf64-ppc.c (ppc64_elf_check_relocs): Likewise.
* elf64-s390.c (elf_s390_check_relocs): Likewise.
* elf64-sh64.c (sh_elf64_relocate_section): Likewise.
* elf64-x86-64.c (elf64_x86_64_check_relocs): Likewise.
* elfxx-sparc.c (_bfd_sparc_elf_check_relocs): Likewise.
* elf32-bfin.c (bfin_check_relocs): Remove redundant local
variable 'sreloc'.
(bfin_relocate_section): Likewise.
* elf32-v850.c (v850_elf_check_relocs): Likewise.
Index: bfd/elf-bfd.h
===================================================================
RCS file: /cvs/src/src/bfd/elf-bfd.h,v
retrieving revision 1.269
diff -c -3 -p -r1.269 elf-bfd.h
*** bfd/elf-bfd.h 21 Nov 2008 00:02:37 -0000 1.269
--- bfd/elf-bfd.h 25 Nov 2008 12:33:04 -0000
*************** extern long _bfd_elf_get_reloc_upper_bou
*** 1764,1769 ****
--- 1764,1773 ----
(bfd *, sec_ptr);
extern long _bfd_elf_canonicalize_reloc
(bfd *, sec_ptr, arelent **, asymbol **);
+ extern asection * _bfd_elf_get_dynamic_reloc_section
+ (bfd *, asection *, bfd_boolean);
+ extern asection * _bfd_elf_make_dynamic_reloc_section
+ (asection *, bfd *, unsigned int, bfd *, bfd_boolean);
extern long _bfd_elf_get_dynamic_reloc_upper_bound
(bfd *);
extern long _bfd_elf_canonicalize_dynamic_reloc
Index: bfd/elf-m10300.c
===================================================================
RCS file: /cvs/src/src/bfd/elf-m10300.c,v
retrieving revision 1.95
diff -c -3 -p -r1.95 elf-m10300.c
*** bfd/elf-m10300.c 15 Jul 2008 18:48:07 -0000 1.95
--- bfd/elf-m10300.c 25 Nov 2008 12:33:05 -0000
*************** mn10300_elf_check_relocs (bfd *abfd,
*** 917,948 ****
section in dynobj and make room for this reloc. */
if (sreloc == NULL)
{
! const char * name;
!
! name = (bfd_elf_string_from_elf_section
! (abfd,
! elf_elfheader (abfd)->e_shstrndx,
! elf_section_data (sec)->rel_hdr.sh_name));
! if (name == NULL)
! goto fail;
!
! BFD_ASSERT (CONST_STRNEQ (name, ".rela")
! && streq (bfd_get_section_name (abfd, sec), name + 5));
!
! sreloc = bfd_get_section_by_name (dynobj, name);
if (sreloc == NULL)
! {
! flagword flags;
!
! flags = (SEC_HAS_CONTENTS | SEC_READONLY
! | SEC_IN_MEMORY | SEC_LINKER_CREATED);
! if ((sec->flags & SEC_ALLOC) != 0)
! flags |= SEC_ALLOC | SEC_LOAD;
! sreloc = bfd_make_section_with_flags (dynobj, name, flags);
! if (sreloc == NULL
! || ! bfd_set_section_alignment (dynobj, sreloc, 2))
! goto fail;
! }
}
sreloc->size += sizeof (Elf32_External_Rela);
--- 917,926 ----
section in dynobj and make room for this reloc. */
if (sreloc == NULL)
{
! sreloc = _bfd_elf_make_dynamic_reloc_section
! (sec, dynobj, 2, abfd, /*rela?*/ TRUE);
if (sreloc == NULL)
! goto fail;
}
sreloc->size += sizeof (Elf32_External_Rela);
*************** mn10300_elf_final_link_relocate (reloc_h
*** 1108,1129 ****
time. */
if (sreloc == NULL)
{
! const char * name;
!
! name = (bfd_elf_string_from_elf_section
! (input_bfd,
! elf_elfheader (input_bfd)->e_shstrndx,
! elf_section_data (input_section)->rel_hdr.sh_name));
! if (name == NULL)
return FALSE;
-
- BFD_ASSERT (CONST_STRNEQ (name, ".rela")
- && streq (bfd_get_section_name (input_bfd,
- input_section),
- name + 5));
-
- sreloc = bfd_get_section_by_name (dynobj, name);
- BFD_ASSERT (sreloc != NULL);
}
skip = FALSE;
--- 1086,1095 ----
time. */
if (sreloc == NULL)
{
! sreloc = _bfd_elf_get_dynamic_reloc_section
! (input_bfd, input_section, /*rela?*/ TRUE);
! if (sreloc == NULL)
return FALSE;
}
skip = FALSE;
Index: bfd/elf32-arm.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-arm.c,v
retrieving revision 1.158
diff -c -3 -p -r1.158 elf32-arm.c
*** bfd/elf32-arm.c 18 Nov 2008 15:45:02 -0000 1.158
--- bfd/elf32-arm.c 25 Nov 2008 12:33:07 -0000
*************** stub_hash_newfunc (struct bfd_hash_entry
*** 2466,2484 ****
return entry;
}
- /* Return true if NAME is the name of the relocation section associated
- with S. */
-
- static bfd_boolean
- reloc_section_p (struct elf32_arm_link_hash_table *htab,
- const char *name, asection *s)
- {
- if (htab->use_rel)
- return CONST_STRNEQ (name, ".rel") && strcmp (s->name, name + 4) == 0;
- else
- return CONST_STRNEQ (name, ".rela") && strcmp (s->name, name + 5) == 0;
- }
-
/* Create .got, .gotplt, and .rel(a).got sections in DYNOBJ, and set up
shortcuts to them in our hash table. */
--- 2466,2471 ----
*************** elf32_arm_final_link_relocate (reloc_how
*** 5960,5978 ****
if (sreloc == NULL)
{
! const char * name;
! name = (bfd_elf_string_from_elf_section
! (input_bfd,
! elf_elfheader (input_bfd)->e_shstrndx,
! elf_section_data (input_section)->rel_hdr.sh_name));
! if (name == NULL)
return bfd_reloc_notsupported;
-
- BFD_ASSERT (reloc_section_p (globals, name, input_section));
-
- sreloc = bfd_get_section_by_name (dynobj, name);
- BFD_ASSERT (sreloc != NULL);
}
skip = FALSE;
--- 5947,5957 ----
if (sreloc == NULL)
{
! sreloc = _bfd_elf_get_dynamic_reloc_section (input_bfd, input_section,
! ! globals->use_rel);
! if (sreloc == NULL)
return bfd_reloc_notsupported;
}
skip = FALSE;
*************** elf32_arm_check_relocs (bfd *abfd, struc
*** 9278,9317 ****
/* When creating a shared object, we must copy these
reloc types into the output file. We create a reloc
section in dynobj and make room for this reloc. */
! if (sreloc == NULL)
{
! const char * name;
! name = (bfd_elf_string_from_elf_section
! (abfd,
! elf_elfheader (abfd)->e_shstrndx,
! elf_section_data (sec)->rel_hdr.sh_name));
! if (name == NULL)
return FALSE;
! BFD_ASSERT (reloc_section_p (htab, name, sec));
!
! sreloc = bfd_get_section_by_name (dynobj, name);
! if (sreloc == NULL)
{
! flagword flags;
! flags = (SEC_HAS_CONTENTS | SEC_READONLY
! | SEC_IN_MEMORY | SEC_LINKER_CREATED);
! if ((sec->flags & SEC_ALLOC) != 0
! /* BPABI objects never have dynamic
! relocations mapped. */
! && !htab->symbian_p)
! flags |= SEC_ALLOC | SEC_LOAD;
! sreloc = bfd_make_section_with_flags (dynobj,
! name,
! flags);
! if (sreloc == NULL
! || ! bfd_set_section_alignment (dynobj, sreloc, 2))
! return FALSE;
}
-
- elf_section_data (sec)->sreloc = sreloc;
}
/* If this is a global symbol, we count the number of
--- 9257,9279 ----
/* When creating a shared object, we must copy these
reloc types into the output file. We create a reloc
section in dynobj and make room for this reloc. */
! if (sreloc == NULL)
{
! sreloc = _bfd_elf_make_dynamic_reloc_section
! (sec, dynobj, 2, abfd, ! htab->use_rel);
! if (sreloc == NULL)
return FALSE;
! /* BPABI objects never have dynamic relocations mapped. */
! if (! htab->symbian_p)
{
! flagword flags;
! flags = bfd_get_section_flags (dynobj, sreloc);
! flags &= ~(SEC_LOAD | SEC_ALLOC);
! bfd_set_section_flags (dynobj, sreloc, flags);
}
}
/* If this is a global symbol, we count the number of
Index: bfd/elf32-bfin.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-bfin.c,v
retrieving revision 1.34
diff -c -3 -p -r1.34 elf32-bfin.c
*** bfd/elf32-bfin.c 16 Jul 2008 15:27:05 -0000 1.34
--- bfd/elf32-bfin.c 25 Nov 2008 12:33:09 -0000
*************** bfin_check_relocs (bfd * abfd,
*** 1150,1156 ****
const Elf_Internal_Rela *rel_end;
asection *sgot;
asection *srelgot;
- asection *sreloc;
if (info->relocatable)
return TRUE;
--- 1150,1155 ----
*************** bfin_check_relocs (bfd * abfd,
*** 1161,1167 ****
sgot = NULL;
srelgot = NULL;
- sreloc = NULL;
rel_end = relocs + sec->reloc_count;
for (rel = relocs; rel < rel_end; rel++)
--- 1160,1165 ----
*************** bfin_relocate_section (bfd * output_bfd,
*** 1363,1369 ****
struct elf_link_hash_entry **sym_hashes;
bfd_vma *local_got_offsets;
asection *sgot;
- asection *sreloc;
Elf_Internal_Rela *rel;
Elf_Internal_Rela *relend;
int i = 0;
--- 1361,1366 ----
*************** bfin_relocate_section (bfd * output_bfd,
*** 1374,1380 ****
local_got_offsets = elf_local_got_offsets (input_bfd);
sgot = NULL;
- sreloc = NULL;
rel = relocs;
relend = relocs + input_section->reloc_count;
--- 1371,1376 ----
Index: bfd/elf32-cris.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-cris.c,v
retrieving revision 1.87
diff -c -3 -p -r1.87 elf32-cris.c
*** bfd/elf32-cris.c 25 Nov 2008 04:02:12 -0000 1.87
--- bfd/elf32-cris.c 25 Nov 2008 12:33:10 -0000
*************** cris_elf_relocate_section (output_bfd, i
*** 1500,1532 ****
if (sreloc == NULL)
{
! const char *name;
!
! name = (bfd_elf_string_from_elf_section
! (input_bfd,
! elf_elfheader (input_bfd)->e_shstrndx,
! elf_section_data (input_section)->rel_hdr.sh_name));
! if (name == NULL)
! return FALSE;
!
! BFD_ASSERT (CONST_STRNEQ (name, ".rela")
! && strcmp (bfd_get_section_name (input_bfd,
! input_section),
! name + 5) == 0);
!
! sreloc = bfd_get_section_by_name (dynobj, name);
!
! /* That section should have been created in
! cris_elf_check_relocs, but that function will not be
! called for objects which fail in
cris_elf_merge_private_bfd_data. */
if (sreloc == NULL)
{
- (*_bfd_error_handler)
- (_("%B: Internal inconsistency; no relocation section %s"),
- input_bfd,
- name);
-
bfd_set_error (bfd_error_bad_value);
return FALSE;
}
--- 1500,1512 ----
if (sreloc == NULL)
{
! sreloc = _bfd_elf_get_dynamic_reloc_section
! (input_bfd, input_section, /*rela?*/ TRUE);
! /* The section should have been created in cris_elf_check_relocs,
! but that function will not be called for objects which fail in
cris_elf_merge_private_bfd_data. */
if (sreloc == NULL)
{
bfd_set_error (bfd_error_bad_value);
return FALSE;
}
*************** cris_elf_check_relocs (abfd, info, sec,
*** 3507,3543 ****
}
}
! /* We create a reloc section in dynobj and make room for this
! reloc. */
if (sreloc == NULL)
{
! const char *name;
! name = (bfd_elf_string_from_elf_section
! (abfd,
! elf_elfheader (abfd)->e_shstrndx,
! elf_section_data (sec)->rel_hdr.sh_name));
! if (name == NULL)
return FALSE;
- BFD_ASSERT (CONST_STRNEQ (name, ".rela")
- && strcmp (bfd_get_section_name (abfd, sec),
- name + 5) == 0);
-
- sreloc = bfd_get_section_by_name (dynobj, name);
- if (sreloc == NULL)
- {
- sreloc = bfd_make_section_with_flags (dynobj, name,
- (SEC_ALLOC
- | SEC_LOAD
- | SEC_HAS_CONTENTS
- | SEC_IN_MEMORY
- | SEC_LINKER_CREATED
- | SEC_READONLY));
- if (sreloc == NULL
- || !bfd_set_section_alignment (dynobj, sreloc, 2))
- return FALSE;
- }
if (sec->flags & SEC_READONLY)
info->flags |= DF_TEXTREL;
}
--- 3487,3502 ----
}
}
! /* We may need to create a reloc section in the dynobj and made room
! for this reloc. */
if (sreloc == NULL)
{
! sreloc = _bfd_elf_make_dynamic_reloc_section
! (sec, dynobj, 2, abfd, /*rela?*/ TRUE);
! if (sreloc == NULL)
return FALSE;
if (sec->flags & SEC_READONLY)
info->flags |= DF_TEXTREL;
}
Index: bfd/elf32-hppa.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-hppa.c,v
retrieving revision 1.163
diff -c -3 -p -r1.163 elf32-hppa.c
*** bfd/elf32-hppa.c 12 Mar 2008 08:36:58 -0000 1.163
--- bfd/elf32-hppa.c 25 Nov 2008 12:33:11 -0000
*************** elf32_hppa_check_relocs (bfd *abfd,
*** 1505,1548 ****
this reloc. */
if (sreloc == NULL)
{
- char *name;
- bfd *dynobj;
-
- name = (bfd_elf_string_from_elf_section
- (abfd,
- elf_elfheader (abfd)->e_shstrndx,
- elf_section_data (sec)->rel_hdr.sh_name));
- if (name == NULL)
- {
- (*_bfd_error_handler)
- (_("Could not find relocation section for %s"),
- sec->name);
- bfd_set_error (bfd_error_bad_value);
- return FALSE;
- }
-
if (htab->etab.dynobj == NULL)
htab->etab.dynobj = abfd;
! dynobj = htab->etab.dynobj;
! sreloc = bfd_get_section_by_name (dynobj, name);
if (sreloc == NULL)
{
! flagword flags;
!
! flags = (SEC_HAS_CONTENTS | SEC_READONLY
! | SEC_IN_MEMORY | SEC_LINKER_CREATED);
! if ((sec->flags & SEC_ALLOC) != 0)
! flags |= SEC_ALLOC | SEC_LOAD;
! sreloc = bfd_make_section_with_flags (dynobj,
! name,
! flags);
! if (sreloc == NULL
! || !bfd_set_section_alignment (dynobj, sreloc, 2))
! return FALSE;
}
-
- elf_section_data (sec)->sreloc = sreloc;
}
/* If this is a global symbol, we count the number of
--- 1505,1521 ----
this reloc. */
if (sreloc == NULL)
{
if (htab->etab.dynobj == NULL)
htab->etab.dynobj = abfd;
! sreloc = _bfd_elf_make_dynamic_reloc_section
! (sec, htab->etab.dynobj, 2, abfd, /*rela?*/ TRUE);
!
if (sreloc == NULL)
{
! bfd_set_error (bfd_error_bad_value);
! return FALSE;
}
}
/* If this is a global symbol, we count the number of
Index: bfd/elf32-i370.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-i370.c,v
retrieving revision 1.62
diff -c -3 -p -r1.62 elf32-i370.c
*** bfd/elf32-i370.c 3 Jul 2007 14:26:41 -0000 1.62
--- bfd/elf32-i370.c 25 Nov 2008 12:33:12 -0000
*************** i370_elf_check_relocs (bfd *abfd,
*** 852,884 ****
#endif
if (sreloc == NULL)
{
! const char *name;
- name = (bfd_elf_string_from_elf_section
- (abfd,
- elf_elfheader (abfd)->e_shstrndx,
- elf_section_data (sec)->rel_hdr.sh_name));
- if (name == NULL)
- return FALSE;
-
- BFD_ASSERT (CONST_STRNEQ (name, ".rela")
- && strcmp (bfd_get_section_name (abfd, sec), name + 5) == 0);
-
- sreloc = bfd_get_section_by_name (dynobj, name);
if (sreloc == NULL)
! {
! flagword flags;
!
! flags = (SEC_HAS_CONTENTS | SEC_READONLY
! | SEC_IN_MEMORY | SEC_LINKER_CREATED);
! if ((sec->flags & SEC_ALLOC) != 0)
! flags |= SEC_ALLOC | SEC_LOAD;
! sreloc = bfd_make_section_with_flags (dynobj, name,
! flags);
! if (sreloc == NULL
! || ! bfd_set_section_alignment (dynobj, sreloc, 2))
! return FALSE;
! }
}
sreloc->size += sizeof (Elf32_External_Rela);
--- 852,862 ----
#endif
if (sreloc == NULL)
{
! sreloc = _bfd_elf_make_dynamic_reloc_section
! (sec, dynobj, 2, abfd, /*rela?*/ TRUE);
if (sreloc == NULL)
! return FALSE;
}
sreloc->size += sizeof (Elf32_External_Rela);
*************** i370_elf_relocate_section (bfd *output_b
*** 1064,1070 ****
{
Elf_Internal_Shdr *symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
struct elf_link_hash_entry **sym_hashes = elf_sym_hashes (input_bfd);
- bfd *dynobj = elf_hash_table (info)->dynobj;
Elf_Internal_Rela *rel = relocs;
Elf_Internal_Rela *relend = relocs + input_section->reloc_count;
asection *sreloc = NULL;
--- 1042,1047 ----
*************** i370_elf_relocate_section (bfd *output_b
*** 1232,1253 ****
if (sreloc == NULL)
{
! const char *name;
!
! name = (bfd_elf_string_from_elf_section
! (input_bfd,
! elf_elfheader (input_bfd)->e_shstrndx,
! elf_section_data (input_section)->rel_hdr.sh_name));
! if (name == NULL)
return FALSE;
-
- BFD_ASSERT (CONST_STRNEQ (name, ".rela")
- && strcmp (bfd_get_section_name (input_bfd,
- input_section),
- name + 5) == 0);
-
- sreloc = bfd_get_section_by_name (dynobj, name);
- BFD_ASSERT (sreloc != NULL);
}
skip = 0;
--- 1209,1218 ----
if (sreloc == NULL)
{
! sreloc = _bfd_elf_get_dynamic_reloc_section
! (input_bfd, input_section, /*rela?*/ TRUE);
! if (sreloc == NULL)
return FALSE;
}
skip = 0;
Index: bfd/elf32-i386.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-i386.c,v
retrieving revision 1.188
diff -c -3 -p -r1.188 elf32-i386.c
*** bfd/elf32-i386.c 28 Jul 2008 18:07:05 -0000 1.188
--- bfd/elf32-i386.c 25 Nov 2008 12:33:15 -0000
*************** elf_i386_check_relocs (bfd *abfd,
*** 1462,1506 ****
this reloc. */
if (sreloc == NULL)
{
- const char *name;
- bfd *dynobj;
- unsigned int strndx = elf_elfheader (abfd)->e_shstrndx;
- unsigned int shnam = elf_section_data (sec)->rel_hdr.sh_name;
-
- name = bfd_elf_string_from_elf_section (abfd, strndx, shnam);
- if (name == NULL)
- return FALSE;
-
- if (! CONST_STRNEQ (name, ".rel")
- || strcmp (bfd_get_section_name (abfd, sec),
- name + 4) != 0)
- {
- (*_bfd_error_handler)
- (_("%B: bad relocation section name `%s\'"),
- abfd, name);
- }
-
if (htab->elf.dynobj == NULL)
htab->elf.dynobj = abfd;
! dynobj = htab->elf.dynobj;
! sreloc = bfd_get_section_by_name (dynobj, name);
! if (sreloc == NULL)
! {
! flagword flags;
! flags = (SEC_HAS_CONTENTS | SEC_READONLY
! | SEC_IN_MEMORY | SEC_LINKER_CREATED);
! if ((sec->flags & SEC_ALLOC) != 0)
! flags |= SEC_ALLOC | SEC_LOAD;
! sreloc = bfd_make_section_with_flags (dynobj,
! name,
! flags);
! if (sreloc == NULL
! || ! bfd_set_section_alignment (dynobj, sreloc, 2))
! return FALSE;
! }
! elf_section_data (sec)->sreloc = sreloc;
}
/* If this is a global symbol, we count the number of
--- 1462,1475 ----
this reloc. */
if (sreloc == NULL)
{
if (htab->elf.dynobj == NULL)
htab->elf.dynobj = abfd;
! sreloc = _bfd_elf_make_dynamic_reloc_section
! (sec, htab->elf.dynobj, 2, abfd, /*rela?*/ FALSE);
! if (sreloc == NULL)
! return FALSE;
}
/* If this is a global symbol, we count the number of
Index: bfd/elf32-m32r.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-m32r.c,v
retrieving revision 1.91
diff -c -3 -p -r1.91 elf32-m32r.c
*** bfd/elf32-m32r.c 11 Jan 2008 09:07:03 -0000 1.91
--- bfd/elf32-m32r.c 25 Nov 2008 12:33:16 -0000
*************** m32r_elf_relocate_section (bfd *output_b
*** 2911,2932 ****
time. */
if (sreloc == NULL)
{
! const char *name;
!
! name = (bfd_elf_string_from_elf_section
! (input_bfd,
! elf_elfheader (input_bfd)->e_shstrndx,
! elf_section_data (input_section)->rel_hdr.sh_name));
! if (name == NULL)
! return FALSE;
!
! BFD_ASSERT (CONST_STRNEQ (name, ".rela")
! && strcmp (bfd_get_section_name (input_bfd,
! input_section),
! name + 5) == 0);
!
! sreloc = bfd_get_section_by_name (dynobj, name);
! BFD_ASSERT (sreloc != NULL);
}
skip = FALSE;
--- 2911,2920 ----
time. */
if (sreloc == NULL)
{
! sreloc = _bfd_elf_get_dynamic_reloc_section
! (input_bfd, input_section, /*rela?*/ TRUE);
! if (sreloc == NULL)
! return FALSE;
}
skip = FALSE;
*************** m32r_elf_check_relocs (bfd *abfd,
*** 3950,3985 ****
section in dynobj and make room for the reloc. */
if (sreloc == NULL)
{
! const char *name;
!
! name = (bfd_elf_string_from_elf_section
! (abfd,
! elf_elfheader (abfd)->e_shstrndx,
! elf_section_data (sec)->rel_hdr.sh_name));
! if (name == NULL)
! return FALSE;
!
! BFD_ASSERT (CONST_STRNEQ (name, ".rela")
! && strcmp (bfd_get_section_name (abfd, sec),
! name + 5) == 0);
! sreloc = bfd_get_section_by_name (dynobj, name);
! if (sreloc == NULL)
! {
! flagword flags;
!
! flags = (SEC_HAS_CONTENTS | SEC_READONLY
! | SEC_IN_MEMORY | SEC_LINKER_CREATED);
! if ((sec->flags & SEC_ALLOC) != 0)
! flags |= SEC_ALLOC | SEC_LOAD;
! sreloc = bfd_make_section_with_flags (dynobj,
! name,
! flags);
! if (sreloc == NULL
! || ! bfd_set_section_alignment (dynobj, sreloc, 2))
! return FALSE;
! }
! elf_section_data (sec)->sreloc = sreloc;
}
/* If this is a global symbol, we count the number of
--- 3938,3948 ----
section in dynobj and make room for the reloc. */
if (sreloc == NULL)
{
! sreloc = _bfd_elf_make_dynamic_reloc_section
! (sec, dynobj, 2, abfd, /*rela?*/ TRUE);
! if (sreloc == NULL)
! return FALSE;
}
/* If this is a global symbol, we count the number of
Index: bfd/elf32-m68k.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-m68k.c,v
retrieving revision 1.108
diff -c -3 -p -r1.108 elf32-m68k.c
*** bfd/elf32-m68k.c 29 Jun 2008 12:56:40 -0000 1.108
--- bfd/elf32-m68k.c 25 Nov 2008 12:33:16 -0000
*************** elf_m68k_check_relocs (abfd, info, sec,
*** 2368,2402 ****
section in dynobj and make room for this reloc. */
if (sreloc == NULL)
{
! const char *name;
- name = (bfd_elf_string_from_elf_section
- (abfd,
- elf_elfheader (abfd)->e_shstrndx,
- elf_section_data (sec)->rel_hdr.sh_name));
- if (name == NULL)
- return FALSE;
-
- BFD_ASSERT (CONST_STRNEQ (name, ".rela")
- && strcmp (bfd_get_section_name (abfd, sec),
- name + 5) == 0);
-
- sreloc = bfd_get_section_by_name (dynobj, name);
if (sreloc == NULL)
! {
! sreloc = bfd_make_section_with_flags (dynobj,
! name,
! (SEC_ALLOC
! | SEC_LOAD
! | SEC_HAS_CONTENTS
! | SEC_IN_MEMORY
! | SEC_LINKER_CREATED
! | SEC_READONLY));
! if (sreloc == NULL
! || !bfd_set_section_alignment (dynobj, sreloc, 2))
! return FALSE;
! }
! elf_section_data (sec)->sreloc = sreloc;
}
if (sec->flags & SEC_READONLY
--- 2368,2378 ----
section in dynobj and make room for this reloc. */
if (sreloc == NULL)
{
! sreloc = _bfd_elf_make_dynamic_reloc_section
! (sec, dynobj, 2, abfd, /*rela?*/ TRUE);
if (sreloc == NULL)
! return FALSE;
}
if (sec->flags & SEC_READONLY
Index: bfd/elf32-ppc.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-ppc.c,v
retrieving revision 1.248
diff -c -3 -p -r1.248 elf32-ppc.c
*** bfd/elf32-ppc.c 20 Nov 2008 08:47:10 -0000 1.248
--- bfd/elf32-ppc.c 25 Nov 2008 12:33:17 -0000
*************** ppc_elf_check_relocs (bfd *abfd,
*** 3768,3805 ****
#endif
if (sreloc == NULL)
{
- const char *name;
-
- name = (bfd_elf_string_from_elf_section
- (abfd,
- elf_elfheader (abfd)->e_shstrndx,
- elf_section_data (sec)->rel_hdr.sh_name));
- if (name == NULL)
- return FALSE;
-
- BFD_ASSERT (CONST_STRNEQ (name, ".rela")
- && strcmp (bfd_get_section_name (abfd, sec),
- name + 5) == 0);
-
if (htab->elf.dynobj == NULL)
htab->elf.dynobj = abfd;
- sreloc = bfd_get_section_by_name (htab->elf.dynobj, name);
- if (sreloc == NULL)
- {
- flagword flags;
! flags = (SEC_HAS_CONTENTS | SEC_READONLY
! | SEC_IN_MEMORY | SEC_LINKER_CREATED
! | SEC_ALLOC | SEC_LOAD);
! sreloc = bfd_make_section_with_flags (htab->elf.dynobj,
! name,
! flags);
! if (sreloc == NULL
! || ! bfd_set_section_alignment (htab->elf.dynobj,
! sreloc, 2))
! return FALSE;
! }
! elf_section_data (sec)->sreloc = sreloc;
}
/* If this is a global symbol, we count the number of
--- 3768,3781 ----
#endif
if (sreloc == NULL)
{
if (htab->elf.dynobj == NULL)
htab->elf.dynobj = abfd;
! sreloc = _bfd_elf_make_dynamic_reloc_section
! (sec, htab->elf.dynobj, 2, abfd, /*rela?*/ TRUE);
!
! if (sreloc == NULL)
! return FALSE;
}
/* If this is a global symbol, we count the number of
*************** ppc_elf_relocate_section (bfd *output_bf
*** 6836,6857 ****
time. */
if (sreloc == NULL)
{
! const char *name;
!
! name = (bfd_elf_string_from_elf_section
! (input_bfd,
! elf_elfheader (input_bfd)->e_shstrndx,
! elf_section_data (input_section)->rel_hdr.sh_name));
! if (name == NULL)
return FALSE;
-
- BFD_ASSERT (CONST_STRNEQ (name, ".rela")
- && strcmp (bfd_get_section_name (input_bfd,
- input_section),
- name + 5) == 0);
-
- sreloc = bfd_get_section_by_name (htab->elf.dynobj, name);
- BFD_ASSERT (sreloc != NULL);
}
skip = 0;
--- 6812,6821 ----
time. */
if (sreloc == NULL)
{
! sreloc = _bfd_elf_get_dynamic_reloc_section
! (input_bfd, input_section, /*rela?*/ TRUE);
! if (sreloc == NULL)
return FALSE;
}
skip = 0;
Index: bfd/elf32-s390.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-s390.c,v
retrieving revision 1.97
diff -c -3 -p -r1.97 elf32-s390.c
*** bfd/elf32-s390.c 12 Feb 2008 11:32:30 -0000 1.97
--- bfd/elf32-s390.c 25 Nov 2008 12:33:17 -0000
*************** elf_s390_check_relocs (abfd, info, sec,
*** 1279,1324 ****
this reloc. */
if (sreloc == NULL)
{
- const char *name;
- bfd *dynobj;
-
- name = (bfd_elf_string_from_elf_section
- (abfd,
- elf_elfheader (abfd)->e_shstrndx,
- elf_section_data (sec)->rel_hdr.sh_name));
- if (name == NULL)
- return FALSE;
-
- if (! CONST_STRNEQ (name, ".rela")
- || strcmp (bfd_get_section_name (abfd, sec),
- name + 5) != 0)
- {
- (*_bfd_error_handler)
- (_("%B: bad relocation section name `%s\'"),
- abfd, name);
- }
-
if (htab->elf.dynobj == NULL)
htab->elf.dynobj = abfd;
! dynobj = htab->elf.dynobj;
! sreloc = bfd_get_section_by_name (dynobj, name);
! if (sreloc == NULL)
! {
! flagword flags;
! flags = (SEC_HAS_CONTENTS | SEC_READONLY
! | SEC_IN_MEMORY | SEC_LINKER_CREATED);
! if ((sec->flags & SEC_ALLOC) != 0)
! flags |= SEC_ALLOC | SEC_LOAD;
! sreloc = bfd_make_section_with_flags (dynobj,
! name,
! flags);
! if (sreloc == NULL
! || ! bfd_set_section_alignment (dynobj, sreloc, 2))
! return FALSE;
! }
! elf_section_data (sec)->sreloc = sreloc;
}
/* If this is a global symbol, we count the number of
--- 1279,1292 ----
this reloc. */
if (sreloc == NULL)
{
if (htab->elf.dynobj == NULL)
htab->elf.dynobj = abfd;
! sreloc = _bfd_elf_make_dynamic_reloc_section
! (sec, htab->elf.dynobj, 2, abfd, /*rela?*/ TRUE);
! if (sreloc == NULL)
! return FALSE;
}
/* If this is a global symbol, we count the number of
Index: bfd/elf32-sh.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-sh.c,v
retrieving revision 1.157
diff -c -3 -p -r1.157 elf32-sh.c
*** bfd/elf32-sh.c 25 Mar 2008 18:56:01 -0000 1.157
--- bfd/elf32-sh.c 25 Nov 2008 12:33:19 -0000
*************** sh_elf_relocate_section (bfd *output_bfd
*** 3626,3647 ****
if (sreloc == NULL)
{
! const char *name;
!
! name = (bfd_elf_string_from_elf_section
! (input_bfd,
! elf_elfheader (input_bfd)->e_shstrndx,
! elf_section_data (input_section)->rel_hdr.sh_name));
! if (name == NULL)
return FALSE;
-
- BFD_ASSERT (CONST_STRNEQ (name, ".rela")
- && strcmp (bfd_get_section_name (input_bfd,
- input_section),
- name + 5) == 0);
-
- sreloc = bfd_get_section_by_name (dynobj, name);
- BFD_ASSERT (sreloc != NULL);
}
skip = FALSE;
--- 3626,3635 ----
if (sreloc == NULL)
{
! sreloc = _bfd_elf_get_dynamic_reloc_section
! (input_bfd, input_section, /*rela?*/ TRUE);
! if (sreloc == NULL)
return FALSE;
}
skip = FALSE;
*************** sh_elf_relocate_section (bfd *output_bfd
*** 4352,4373 ****
if (sreloc == NULL)
{
! const char *name;
!
! name = (bfd_elf_string_from_elf_section
! (input_bfd,
! elf_elfheader (input_bfd)->e_shstrndx,
! elf_section_data (input_section)->rel_hdr.sh_name));
! if (name == NULL)
return FALSE;
-
- BFD_ASSERT (CONST_STRNEQ (name, ".rela")
- && strcmp (bfd_get_section_name (input_bfd,
- input_section),
- name + 5) == 0);
-
- sreloc = bfd_get_section_by_name (dynobj, name);
- BFD_ASSERT (sreloc != NULL);
}
if (h == NULL || h->dynindx == -1)
--- 4340,4349 ----
if (sreloc == NULL)
{
! sreloc = _bfd_elf_get_dynamic_reloc_section
! (input_bfd, input_section, /*rela?*/ TRUE);
! if (sreloc == NULL)
return FALSE;
}
if (h == NULL || h->dynindx == -1)
*************** sh_elf_check_relocs (bfd *abfd, struct b
*** 5223,5259 ****
section in dynobj and make room for this reloc. */
if (sreloc == NULL)
{
! const char *name;
- name = (bfd_elf_string_from_elf_section
- (abfd,
- elf_elfheader (abfd)->e_shstrndx,
- elf_section_data (sec)->rel_hdr.sh_name));
- if (name == NULL)
- return FALSE;
-
- BFD_ASSERT (CONST_STRNEQ (name, ".rela")
- && strcmp (bfd_get_section_name (abfd, sec),
- name + 5) == 0);
-
- sreloc = bfd_get_section_by_name (htab->root.dynobj, name);
if (sreloc == NULL)
! {
! flagword flags;
!
! flags = (SEC_HAS_CONTENTS | SEC_READONLY
! | SEC_IN_MEMORY | SEC_LINKER_CREATED);
! if ((sec->flags & SEC_ALLOC) != 0)
! flags |= SEC_ALLOC | SEC_LOAD;
! sreloc = bfd_make_section_with_flags (htab->root.dynobj,
! name,
! flags);
! if (sreloc == NULL
! || ! bfd_set_section_alignment (htab->root.dynobj,
! sreloc, 2))
! return FALSE;
! }
! elf_section_data (sec)->sreloc = sreloc;
}
/* If this is a global symbol, we count the number of
--- 5199,5209 ----
section in dynobj and make room for this reloc. */
if (sreloc == NULL)
{
! sreloc = _bfd_elf_make_dynamic_reloc_section
! (sec, htab->root.dynobj, 2, abfd, /*rela?*/ TRUE);
if (sreloc == NULL)
! return FALSE;
}
/* If this is a global symbol, we count the number of
Index: bfd/elf32-v850.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-v850.c,v
retrieving revision 1.71
diff -c -3 -p -r1.71 elf32-v850.c
*** bfd/elf32-v850.c 26 Sep 2007 13:45:32 -0000 1.71
--- bfd/elf32-v850.c 25 Nov 2008 12:33:20 -0000
*************** v850_elf_check_relocs (bfd *abfd,
*** 52,58 ****
struct elf_link_hash_entry **sym_hashes;
const Elf_Internal_Rela *rel;
const Elf_Internal_Rela *rel_end;
- asection *sreloc;
enum v850_reloc_type r_type;
int other = 0;
const char *common = NULL;
--- 52,57 ----
*************** v850_elf_check_relocs (bfd *abfd,
*** 68,74 ****
dynobj = elf_hash_table (info)->dynobj;
symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
sym_hashes = elf_sym_hashes (abfd);
- sreloc = NULL;
rel_end = relocs + sec->reloc_count;
for (rel = relocs; rel < rel_end; rel++)
--- 67,72 ----
Index: bfd/elf32-vax.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-vax.c,v
retrieving revision 1.47
diff -c -3 -p -r1.47 elf32-vax.c
*** bfd/elf32-vax.c 11 Jan 2008 09:07:03 -0000 1.47
--- bfd/elf32-vax.c 25 Nov 2008 12:33:20 -0000
*************** elf_vax_check_relocs (bfd *abfd, struct
*** 738,771 ****
section in dynobj and make room for this reloc. */
if (sreloc == NULL)
{
! const char *name;
! name = (bfd_elf_string_from_elf_section
! (abfd,
! elf_elfheader (abfd)->e_shstrndx,
! elf_section_data (sec)->rel_hdr.sh_name));
! if (name == NULL)
return FALSE;
- BFD_ASSERT (CONST_STRNEQ (name, ".rela")
- && strcmp (bfd_get_section_name (abfd, sec),
- name + 5) == 0);
-
- sreloc = bfd_get_section_by_name (dynobj, name);
- if (sreloc == NULL)
- {
- sreloc = bfd_make_section_with_flags (dynobj,
- name,
- (SEC_ALLOC
- | SEC_LOAD
- | SEC_HAS_CONTENTS
- | SEC_IN_MEMORY
- | SEC_LINKER_CREATED
- | SEC_READONLY));
- if (sreloc == NULL
- || !bfd_set_section_alignment (dynobj, sreloc, 2))
- return FALSE;
- }
if (sec->flags & SEC_READONLY)
info->flags |= DF_TEXTREL;
}
--- 738,749 ----
section in dynobj and make room for this reloc. */
if (sreloc == NULL)
{
! sreloc = _bfd_elf_make_dynamic_reloc_section
! (sec, dynobj, 2, abfd, /*rela?*/ TRUE);
! if (sreloc == NULL)
return FALSE;
if (sec->flags & SEC_READONLY)
info->flags |= DF_TEXTREL;
}
*************** elf_vax_relocate_section (bfd *output_bf
*** 1622,1643 ****
time. */
if (sreloc == NULL)
{
! const char *name;
!
! name = (bfd_elf_string_from_elf_section
! (input_bfd,
! elf_elfheader (input_bfd)->e_shstrndx,
! elf_section_data (input_section)->rel_hdr.sh_name));
! if (name == NULL)
return FALSE;
-
- BFD_ASSERT (CONST_STRNEQ (name, ".rela")
- && strcmp (bfd_get_section_name (input_bfd,
- input_section),
- name + 5) == 0);
-
- sreloc = bfd_get_section_by_name (dynobj, name);
- BFD_ASSERT (sreloc != NULL);
}
skip = FALSE;
--- 1600,1609 ----
time. */
if (sreloc == NULL)
{
! sreloc = _bfd_elf_get_dynamic_reloc_section
! (input_bfd, input_section, /*rela?*/ TRUE);
! if (sreloc == NULL)
return FALSE;
}
skip = FALSE;
Index: bfd/elf64-alpha.c
===================================================================
RCS file: /cvs/src/src/bfd/elf64-alpha.c,v
retrieving revision 1.165
diff -c -3 -p -r1.165 elf64-alpha.c
*** bfd/elf64-alpha.c 15 Feb 2008 03:35:52 -0000 1.165
--- bfd/elf64-alpha.c 25 Nov 2008 12:33:22 -0000
*************** elf64_alpha_check_relocs (bfd *abfd, str
*** 1748,1754 ****
{
bfd *dynobj;
asection *sreloc;
- const char *rel_sec_name;
Elf_Internal_Shdr *symtab_hdr;
struct alpha_elf_link_hash_entry **sym_hashes;
const Elf_Internal_Rela *rel, *relend;
--- 1748,1753 ----
*************** elf64_alpha_check_relocs (bfd *abfd, str
*** 1773,1779 ****
elf_hash_table (info)->dynobj = dynobj = abfd;
sreloc = NULL;
- rel_sec_name = NULL;
symtab_hdr = &elf_symtab_hdr (abfd);
sym_hashes = alpha_elf_sym_hashes (abfd);
--- 1772,1777 ----
*************** elf64_alpha_check_relocs (bfd *abfd, str
*** 1923,1963 ****
if (need & NEED_DYNREL)
{
- if (rel_sec_name == NULL)
- {
- rel_sec_name = (bfd_elf_string_from_elf_section
- (abfd, elf_elfheader(abfd)->e_shstrndx,
- elf_section_data(sec)->rel_hdr.sh_name));
- if (rel_sec_name == NULL)
- return FALSE;
-
- BFD_ASSERT (CONST_STRNEQ (rel_sec_name, ".rela")
- && strcmp (bfd_get_section_name (abfd, sec),
- rel_sec_name+5) == 0);
- }
-
/* We need to create the section here now whether we eventually
use it or not so that it gets mapped to an output section by
! the linker. If not used, we'll kill it in
! size_dynamic_sections. */
if (sreloc == NULL)
{
! sreloc = bfd_get_section_by_name (dynobj, rel_sec_name);
! if (sreloc == NULL)
! {
! flagword flags;
! flags = (SEC_HAS_CONTENTS | SEC_IN_MEMORY
! | SEC_LINKER_CREATED | SEC_READONLY);
! if (sec->flags & SEC_ALLOC)
! flags |= SEC_ALLOC | SEC_LOAD;
! sreloc = bfd_make_section_with_flags (dynobj,
! rel_sec_name,
! flags);
! if (sreloc == NULL
! || !bfd_set_section_alignment (dynobj, sreloc, 3))
! return FALSE;
! }
}
if (h)
--- 1921,1936 ----
if (need & NEED_DYNREL)
{
/* We need to create the section here now whether we eventually
use it or not so that it gets mapped to an output section by
! the linker. If not used, we'll kill it in size_dynamic_sections. */
if (sreloc == NULL)
{
! sreloc = _bfd_elf_make_dynamic_reloc_section
! (sec, dynobj, 3, abfd, /*rela?*/ TRUE);
! if (sreloc == NULL)
! return FALSE;
}
if (h)
Index: bfd/elf64-ppc.c
===================================================================
RCS file: /cvs/src/src/bfd/elf64-ppc.c,v
retrieving revision 1.288
diff -c -3 -p -r1.288 elf64-ppc.c
*** bfd/elf64-ppc.c 20 Oct 2008 11:05:47 -0000 1.288
--- bfd/elf64-ppc.c 25 Nov 2008 12:33:24 -0000
*************** ppc64_elf_check_relocs (bfd *abfd, struc
*** 5028,5070 ****
this reloc. */
if (sreloc == NULL)
{
! const char *name;
! bfd *dynobj;
- name = (bfd_elf_string_from_elf_section
- (abfd,
- elf_elfheader (abfd)->e_shstrndx,
- elf_section_data (sec)->rel_hdr.sh_name));
- if (name == NULL)
- return FALSE;
-
- if (! CONST_STRNEQ (name, ".rela")
- || strcmp (bfd_get_section_name (abfd, sec),
- name + 5) != 0)
- {
- (*_bfd_error_handler)
- (_("%B: bad relocation section name `%s\'"),
- abfd, name);
- bfd_set_error (bfd_error_bad_value);
- }
-
- dynobj = htab->elf.dynobj;
- sreloc = bfd_get_section_by_name (dynobj, name);
if (sreloc == NULL)
! {
! flagword flags;
!
! flags = (SEC_HAS_CONTENTS | SEC_READONLY
! | SEC_IN_MEMORY | SEC_LINKER_CREATED
! | SEC_ALLOC | SEC_LOAD);
! sreloc = bfd_make_section_with_flags (dynobj,
! name,
! flags);
! if (sreloc == NULL
! || ! bfd_set_section_alignment (dynobj, sreloc, 3))
! return FALSE;
! }
! elf_section_data (sec)->sreloc = sreloc;
}
/* If this is a global symbol, we count the number of
--- 5028,5038 ----
this reloc. */
if (sreloc == NULL)
{
! sreloc = _bfd_elf_make_dynamic_reloc_section
! (sec, htab->elf.dynobj, 3, abfd, /*rela?*/ TRUE);
if (sreloc == NULL)
! return FALSE;
}
/* If this is a global symbol, we count the number of
Index: bfd/elf64-s390.c
===================================================================
RCS file: /cvs/src/src/bfd/elf64-s390.c,v
retrieving revision 1.98
diff -c -3 -p -r1.98 elf64-s390.c
*** bfd/elf64-s390.c 12 Feb 2008 11:32:31 -0000 1.98
--- bfd/elf64-s390.c 25 Nov 2008 12:33:25 -0000
*************** elf_s390_check_relocs (abfd, info, sec,
*** 1246,1291 ****
this reloc. */
if (sreloc == NULL)
{
! const char *name;
! bfd *dynobj;
- name = (bfd_elf_string_from_elf_section
- (abfd,
- elf_elfheader (abfd)->e_shstrndx,
- elf_section_data (sec)->rel_hdr.sh_name));
- if (name == NULL)
- return FALSE;
-
- if (! CONST_STRNEQ (name, ".rela")
- || strcmp (bfd_get_section_name (abfd, sec),
- name + 5) != 0)
- {
- (*_bfd_error_handler)
- (_("%B: bad relocation section name `%s\'"),
- abfd, name);
- }
-
- if (htab->elf.dynobj == NULL)
- htab->elf.dynobj = abfd;
-
- dynobj = htab->elf.dynobj;
- sreloc = bfd_get_section_by_name (dynobj, name);
if (sreloc == NULL)
! {
! flagword flags;
!
! flags = (SEC_HAS_CONTENTS | SEC_READONLY
! | SEC_IN_MEMORY | SEC_LINKER_CREATED);
! if ((sec->flags & SEC_ALLOC) != 0)
! flags |= SEC_ALLOC | SEC_LOAD;
! sreloc = bfd_make_section_with_flags (dynobj,
! name,
! flags);
! if (sreloc == NULL
! || ! bfd_set_section_alignment (dynobj, sreloc, 3))
! return FALSE;
! }
! elf_section_data (sec)->sreloc = sreloc;
}
/* If this is a global symbol, we count the number of
--- 1246,1256 ----
this reloc. */
if (sreloc == NULL)
{
! sreloc = _bfd_elf_make_dynamic_reloc_section
! (sec, htab->elf.dynobj, 3, abfd, /*rela?*/ TRUE);
if (sreloc == NULL)
! return FALSE;
}
/* If this is a global symbol, we count the number of
Index: bfd/elf64-sh64.c
===================================================================
RCS file: /cvs/src/src/bfd/elf64-sh64.c,v
retrieving revision 1.81
diff -c -3 -p -r1.81 elf64-sh64.c
*** bfd/elf64-sh64.c 11 Mar 2008 23:23:23 -0000 1.81
--- bfd/elf64-sh64.c 25 Nov 2008 12:33:26 -0000
*************** sh_elf64_relocate_section (bfd *output_b
*** 1725,1746 ****
if (sreloc == NULL)
{
! const char *name;
!
! name = (bfd_elf_string_from_elf_section
! (input_bfd,
! elf_elfheader (input_bfd)->e_shstrndx,
! elf_section_data (input_section)->rel_hdr.sh_name));
! if (name == NULL)
return FALSE;
-
- BFD_ASSERT (CONST_STRNEQ (name, ".rela")
- && strcmp (bfd_get_section_name (input_bfd,
- input_section),
- name + 5) == 0);
-
- sreloc = bfd_get_section_by_name (dynobj, name);
- BFD_ASSERT (sreloc != NULL);
}
skip = FALSE;
--- 1725,1734 ----
if (sreloc == NULL)
{
! sreloc = _bfd_elf_get_dynamic_reloc_section
! (input_bfd, input_section, /*rela?*/ TRUE);
! if (sreloc == NULL)
return FALSE;
}
skip = FALSE;
*************** sh_elf64_check_relocs (bfd *abfd, struct
*** 2711,2745 ****
section in dynobj and make room for this reloc. */
if (sreloc == NULL)
{
! const char *name;
!
! name = (bfd_elf_string_from_elf_section
! (abfd,
! elf_elfheader (abfd)->e_shstrndx,
! elf_section_data (sec)->rel_hdr.sh_name));
! if (name == NULL)
! return FALSE;
- BFD_ASSERT (CONST_STRNEQ (name, ".rela")
- && strcmp (bfd_get_section_name (abfd, sec),
- name + 5) == 0);
-
- sreloc = bfd_get_section_by_name (dynobj, name);
if (sreloc == NULL)
! {
! flagword flags;
!
! flags = (SEC_HAS_CONTENTS | SEC_READONLY
! | SEC_IN_MEMORY | SEC_LINKER_CREATED);
! if ((sec->flags & SEC_ALLOC) != 0)
! flags |= SEC_ALLOC | SEC_LOAD;
! sreloc = bfd_make_section_with_flags (dynobj,
! name,
! flags);
! if (sreloc == NULL
! || ! bfd_set_section_alignment (dynobj, sreloc, 2))
! return FALSE;
! }
}
sreloc->size += sizeof (Elf64_External_Rela);
--- 2699,2709 ----
section in dynobj and make room for this reloc. */
if (sreloc == NULL)
{
! sreloc = _bfd_elf_make_dynamic_reloc_section
! (sec, dynobj, 2, abfd, /*rela?*/ TRUE);
if (sreloc == NULL)
! return FALSE;
}
sreloc->size += sizeof (Elf64_External_Rela);
Index: bfd/elf64-x86-64.c
===================================================================
RCS file: /cvs/src/src/bfd/elf64-x86-64.c,v
retrieving revision 1.148
diff -c -3 -p -r1.148 elf64-x86-64.c
*** bfd/elf64-x86-64.c 28 Jul 2008 18:07:05 -0000 1.148
--- bfd/elf64-x86-64.c 25 Nov 2008 12:33:27 -0000
*************** elf64_x86_64_check_relocs (bfd *abfd, st
*** 1281,1327 ****
this reloc. */
if (sreloc == NULL)
{
- const char *name;
- bfd *dynobj;
-
- name = (bfd_elf_string_from_elf_section
- (abfd,
- elf_elfheader (abfd)->e_shstrndx,
- elf_section_data (sec)->rel_hdr.sh_name));
- if (name == NULL)
- return FALSE;
-
- if (! CONST_STRNEQ (name, ".rela")
- || strcmp (bfd_get_section_name (abfd, sec),
- name + 5) != 0)
- {
- (*_bfd_error_handler)
- (_("%B: bad relocation section name `%s\'"),
- abfd, name);
- }
-
if (htab->elf.dynobj == NULL)
htab->elf.dynobj = abfd;
! dynobj = htab->elf.dynobj;
- sreloc = bfd_get_section_by_name (dynobj, name);
if (sreloc == NULL)
! {
! flagword flags;
!
! flags = (SEC_HAS_CONTENTS | SEC_READONLY
! | SEC_IN_MEMORY | SEC_LINKER_CREATED);
! if ((sec->flags & SEC_ALLOC) != 0)
! flags |= SEC_ALLOC | SEC_LOAD;
! sreloc = bfd_make_section_with_flags (dynobj,
! name,
! flags);
! if (sreloc == NULL
! || ! bfd_set_section_alignment (dynobj, sreloc, 3))
! return FALSE;
! }
! elf_section_data (sec)->sreloc = sreloc;
}
/* If this is a global symbol, we count the number of
--- 1281,1294 ----
this reloc. */
if (sreloc == NULL)
{
if (htab->elf.dynobj == NULL)
htab->elf.dynobj = abfd;
! sreloc = _bfd_elf_make_dynamic_reloc_section
! (sec, htab->elf.dynobj, 3, abfd, /*rela?*/ TRUE);
if (sreloc == NULL)
! return FALSE;
}
/* If this is a global symbol, we count the number of
Index: bfd/elflink.c
===================================================================
RCS file: /cvs/src/src/bfd/elflink.c,v
retrieving revision 1.316
diff -c -3 -p -r1.316 elflink.c
*** bfd/elflink.c 21 Nov 2008 00:02:37 -0000 1.316
--- bfd/elflink.c 25 Nov 2008 12:33:30 -0000
*************** _bfd_elf_default_got_elt_size (bfd *abfd
*** 12269,12271 ****
--- 12269,12396 ----
const struct elf_backend_data *bed = get_elf_backend_data (abfd);
return bed->s->arch_size / 8;
}
+
+ /* Routines to support the creation of dynamic relocs. */
+
+ /* Return true if NAME is a name of a relocation
+ section associated with section S. */
+
+ static bfd_boolean
+ is_reloc_section (bfd_boolean rela, const char * name, asection * s)
+ {
+ if (rela)
+ return CONST_STRNEQ (name, ".rela")
+ && strcmp (bfd_get_section_name (NULL, s), name + 5) == 0;
+
+ return CONST_STRNEQ (name, ".rel")
+ && strcmp (bfd_get_section_name (NULL, s), name + 4) == 0;
+ }
+
+ /* Returns the name of the dynamic reloc section associated with SEC. */
+
+ static const char *
+ get_dynamic_reloc_section_name (bfd * abfd,
+ asection * sec,
+ bfd_boolean is_rela)
+ {
+ const char * name;
+ unsigned int strndx = elf_elfheader (abfd)->e_shstrndx;
+ unsigned int shnam = elf_section_data (sec)->rel_hdr.sh_name;
+
+ name = bfd_elf_string_from_elf_section (abfd, strndx, shnam);
+ if (name == NULL)
+ return NULL;
+
+ if (! is_reloc_section (is_rela, name, sec))
+ {
+ static bfd_boolean complained = FALSE;
+
+ if (! complained)
+ {
+ (*_bfd_error_handler)
+ (_("%B: bad relocation section name `%s\'"), abfd, name);
+ complained = TRUE;
+ }
+ name = NULL;
+ }
+
+ return name;
+ }
+
+ /* Returns the dynamic reloc section associated with SEC.
+ If necessary compute the name of the dynamic reloc section based
+ on SEC's name (looked up in ABFD's string table) and the setting
+ of IS_RELA. */
+
+ asection *
+ _bfd_elf_get_dynamic_reloc_section (bfd * abfd,
+ asection * sec,
+ bfd_boolean is_rela)
+ {
+ asection * reloc_sec = elf_section_data (sec)->sreloc;
+
+ if (reloc_sec == NULL)
+ {
+ const char * name = get_dynamic_reloc_section_name (abfd, sec, is_rela);
+
+ if (name != NULL)
+ {
+ reloc_sec = bfd_get_section_by_name (abfd, name);
+
+ if (reloc_sec != NULL)
+ elf_section_data (sec)->sreloc = reloc_sec;
+ }
+ }
+
+ return reloc_sec;
+ }
+
+ /* Returns the dynamic reloc section associated with SEC. If the
+ section does not exist it is created and attached to the DYNOBJ
+ bfd and stored in the SRELOC field of SEC's elf_section_data
+ structure.
+
+ ALIGNMENT is the alignment for the newly created section and
+ IS_RELA defines whether the name should be .rela.<SEC's name>
+ or .rel.<SEC's name>. The section name is looked up in the
+ string table associated with ABFD. */
+
+ asection *
+ _bfd_elf_make_dynamic_reloc_section (asection * sec,
+ bfd * dynobj,
+ unsigned int alignment,
+ bfd * abfd,
+ bfd_boolean is_rela)
+ {
+ asection * reloc_sec = elf_section_data (sec)->sreloc;
+
+ if (reloc_sec == NULL)
+ {
+ const char * name = get_dynamic_reloc_section_name (abfd, sec, is_rela);
+
+ if (name == NULL)
+ return NULL;
+
+ reloc_sec = bfd_get_section_by_name (dynobj, name);
+
+ if (reloc_sec == NULL)
+ {
+ flagword flags;
+
+ flags = (SEC_HAS_CONTENTS | SEC_READONLY | SEC_IN_MEMORY | SEC_LINKER_CREATED);
+ if ((sec->flags & SEC_ALLOC) != 0)
+ flags |= SEC_ALLOC | SEC_LOAD;
+
+ reloc_sec = bfd_make_section_with_flags (dynobj, name, flags);
+ if (reloc_sec != NULL)
+ {
+ if (! bfd_set_section_alignment (dynobj, reloc_sec, alignment))
+ reloc_sec = NULL;
+ }
+ }
+
+ elf_section_data (sec)->sreloc = reloc_sec;
+ }
+
+ return reloc_sec;
+ }
Index: bfd/elfxx-sparc.c
===================================================================
RCS file: /cvs/src/src/bfd/elfxx-sparc.c,v
retrieving revision 1.41
diff -c -3 -p -r1.41 elfxx-sparc.c
*** bfd/elfxx-sparc.c 19 Nov 2008 09:25:56 -0000 1.41
--- bfd/elfxx-sparc.c 25 Nov 2008 12:33:31 -0000
*************** _bfd_sparc_elf_check_relocs (bfd *abfd,
*** 1451,1492 ****
section in dynobj and make room for the reloc. */
if (sreloc == NULL)
{
- const char *name;
- bfd *dynobj;
-
- name = (bfd_elf_string_from_elf_section
- (abfd,
- elf_elfheader (abfd)->e_shstrndx,
- elf_section_data (sec)->rel_hdr.sh_name));
- if (name == NULL)
- return FALSE;
-
- BFD_ASSERT (CONST_STRNEQ (name, ".rela")
- && strcmp (bfd_get_section_name (abfd, sec),
- name + 5) == 0);
-
if (htab->elf.dynobj == NULL)
htab->elf.dynobj = abfd;
- dynobj = htab->elf.dynobj;
! sreloc = bfd_get_section_by_name (dynobj, name);
! if (sreloc == NULL)
! {
! flagword flags;
! flags = (SEC_HAS_CONTENTS | SEC_READONLY
! | SEC_IN_MEMORY | SEC_LINKER_CREATED);
! if ((sec->flags & SEC_ALLOC) != 0)
! flags |= SEC_ALLOC | SEC_LOAD;
! sreloc = bfd_make_section_with_flags (dynobj,
! name,
! flags);
! if (sreloc == NULL
! || ! bfd_set_section_alignment (dynobj, sreloc,
! htab->word_align_power))
! return FALSE;
! }
! elf_section_data (sec)->sreloc = sreloc;
}
/* If this is a global symbol, we count the number of
--- 1451,1465 ----
section in dynobj and make room for the reloc. */
if (sreloc == NULL)
{
if (htab->elf.dynobj == NULL)
htab->elf.dynobj = abfd;
! sreloc = _bfd_elf_make_dynamic_reloc_section
! (sec, htab->elf.dynobj, htab->word_align_power,
! abfd, /*rela?*/ TRUE);
! if (sreloc == NULL)
! return FALSE;
}
/* If this is a global symbol, we count the number of