This is the mail archive of the
binutils@sourceware.cygnus.com
mailing list for the binutils project.
PATCH for using both RELA and REL relocations in the samebackend
- To: binutils@sourceware.cygnus.com
- Subject: PATCH for using both RELA and REL relocations in the samebackend
- From: Mark Mitchell <mark@codesourcery.com>
- Date: Tue, 01 Jun 1999 20:28:58 -0700
- Organization: CodeSourcery, LLC
On IRIX6, some relocation sections use RELA relocations and some use
REL relocations. Here's a patch to support this kind of behavior in
general.
--
Mark Mitchell mark@codesourcery.com
CodeSourcery, LLC http://www.codesourcery.com
1999-05-31 Mark Mitchell <mark@codesourcery.com>
* elf-bfd.h (elf_backend_data): Remove use_rela_p. Add
may_use_rel_p, may_use_rela_p, default_use_rela_p.
* section.c (SEC_ELF_USE_RELA): New constant.
* elf.c (bfd_section_from_shdr): Set or clear SEC_ELF_USE_RELA.
(_bfd_elf_new_section_hook): Likewise.
(elf_fake_sections): Use may_use_rela_p, etc., instead of
use_rela_p.
* elfcode.h (write_relocs): Determine whether or not use rela
relocs based on the relocation section header.
* elflink.c (_bfd_elf_create_dynamic_sections): Use default_use_rela_p
instead of use_rela_p.
* elfxx-target.h (elf_backend_may_use_relp): New macro.
(elf_backend_may_use_rela_p): Likewise.
(elf_backend_default_use_rela_p): Likewise.
(elfNN_bed): Use them.
Index: elf-bfd.h
===================================================================
RCS file: /usr/local/Repository/binutils/bfd/elf-bfd.h,v
retrieving revision 1.5
diff -u -p -r1.5 elf-bfd.h
--- elf-bfd.h 1999/05/31 20:46:40 1.5
+++ elf-bfd.h 1999/05/31 21:12:48
@@ -255,11 +255,6 @@ struct elf_size_info {
struct elf_backend_data
{
- /* Whether the backend uses REL or RELA relocations. FIXME: some
- ELF backends use both. When we need to support one, this whole
- approach will need to be changed. */
- int use_rela_p;
-
/* The architecture for this backend. */
enum bfd_architecture arch;
@@ -539,6 +534,23 @@ struct elf_backend_data
the so-called reserved entries on some systems. */
bfd_vma got_header_size;
bfd_vma plt_header_size;
+
+ /* Whether the backend may use REL relocations. (Some backends use
+ both REL and RELA relocations, and this flag is set for those
+ backends.) */
+ unsigned may_use_rel_p : 1;
+
+ /* Whether the backend may use RELA relocations. (Some backends use
+ both REL and RELA relocations, and this flag is set for those
+ backends.) */
+ unsigned may_use_rela_p : 1;
+
+ /* Whether the default relocation type is RELA. If a backend with
+ this flag set wants REL relocations for a particular section,
+ it must note that explicitly. Similarly, if this flag is clear,
+ and the backend wants RELA relocations for a particular
+ section. */
+ unsigned default_use_rela_p : 1;
unsigned want_got_plt : 1;
unsigned plt_readonly : 1;
Index: section.c
===================================================================
RCS file: /usr/local/Repository/binutils/bfd/section.c,v
retrieving revision 1.4
diff -u -p -r1.4 section.c
--- section.c 1999/05/31 20:46:41 1.4
+++ section.c 1999/05/31 21:12:48
@@ -307,6 +307,14 @@ CODE_FRAGMENT
. {* This section should not be subject to garbage collection. *}
.#define SEC_KEEP 0x1000000
.
+.#define SEC_ELF_USE_RELA 0x2000000
+. {* The relocations for this section are of the RELA, rather
+. than the REL, variety. As indicated by the name, this
+. flag is Elf-specific. It is store in FLAGS, rather than in
+. the Elf-specific data, because some programs (like objcopy)
+. copy all the attributes of a section by copying its
+. flags. *}
+.
. {* End of section flags. *}
.
. {* Some internal packed boolean fields. *}
Index: elf.c
===================================================================
RCS file: /usr/local/Repository/binutils/bfd/elf.c,v
retrieving revision 1.5
diff -u -p -r1.5 elf.c
--- elf.c 1999/05/31 20:46:40 1.5
+++ elf.c 1999/05/31 21:17:33
@@ -1265,6 +1265,12 @@ bfd_section_from_shdr (abfd, shindex)
target_sect->flags |= SEC_RELOC;
target_sect->relocation = NULL;
target_sect->rel_filepos = hdr->sh_offset;
+ /* In the section to which the relocations apply, mark whether
+ its relocations are of the REL or RELA variety. */
+ if (hdr->sh_type == SHT_RELA)
+ target_sect->flags |= SEC_ELF_USE_RELA;
+ else
+ target_sect->flags &= ~SEC_ELF_USE_RELA;
abfd->flags |= HAS_RELOC;
return true;
}
@@ -1323,12 +1329,19 @@ _bfd_elf_new_section_hook (abfd, sec)
asection *sec;
{
struct bfd_elf_section_data *sdata;
+ flagword f;
sdata = (struct bfd_elf_section_data *) bfd_alloc (abfd, sizeof (*sdata));
if (!sdata)
return false;
sec->used_by_bfd = (PTR) sdata;
memset (sdata, 0, sizeof (*sdata));
+
+ /* Indicate whether or not this section should use RELA relocations. */
+ f = bfd_get_section_flags (abfd, sec);
+ if (get_elf_backend_data (abfd)->default_use_rela_p)
+ f |= SEC_ELF_USE_RELA;
+
return true;
}
@@ -1491,13 +1504,13 @@ elf_fake_sections (abfd, asect, failedpt
this_hdr->sh_entsize = bed->s->sizeof_dyn;
}
else if (strncmp (asect->name, ".rela.", 6) == 0
- && get_elf_backend_data (abfd)->use_rela_p)
+ && get_elf_backend_data (abfd)->may_use_rela_p)
{
this_hdr->sh_type = SHT_RELA;
this_hdr->sh_entsize = bed->s->sizeof_rela;
}
else if (strncmp (asect->name, ".rel.", 5) == 0
- && ! get_elf_backend_data (abfd)->use_rela_p)
+ && get_elf_backend_data (abfd)->may_use_rel_p)
{
this_hdr->sh_type = SHT_REL;
this_hdr->sh_entsize = bed->s->sizeof_rel;
@@ -1558,19 +1571,16 @@ elf_fake_sections (abfd, asect, failedpt
this_hdr->sh_flags |= SHF_EXECINSTR;
/* Check for processor-specific section types. */
- {
- struct elf_backend_data *bed = get_elf_backend_data (abfd);
-
- if (bed->elf_backend_fake_sections)
- (*bed->elf_backend_fake_sections) (abfd, this_hdr, asect);
- }
+ if (bed->elf_backend_fake_sections)
+ (*bed->elf_backend_fake_sections) (abfd, this_hdr, asect);
/* If the section has relocs, set up a section header for the
SHT_REL[A] section. */
if ((asect->flags & SEC_RELOC) != 0)
{
Elf_Internal_Shdr *rela_hdr;
- int use_rela_p = get_elf_backend_data (abfd)->use_rela_p;
+ int use_rela_p
+ = bfd_get_section_flags (abfd, asect) & SEC_ELF_USE_RELA;
char *name;
rela_hdr = &elf_section_data (asect)->rel_hdr;
@@ -3952,8 +3962,8 @@ swap_out_syms (abfd, sttp, relocatable_p
flagword flags = syms[idx]->flags;
int type;
- if (flags & BSF_SECTION_SYM)
- /* Section symbols have no names. */
+ if ((flags & BSF_SECTION_SYM) && !syms[idx]->name)
+ /* Some section symbols have no names. */
sym.st_name = 0;
else
{
Index: elfcode.h
===================================================================
RCS file: /usr/local/Repository/binutils/bfd/elfcode.h,v
retrieving revision 1.5
diff -u -p -r1.5 elfcode.h
--- elfcode.h 1999/05/31 20:46:41 1.5
+++ elfcode.h 1999/05/31 21:12:48
@@ -729,7 +729,7 @@ write_relocs (abfd, sec, data)
Elf_External_Rela *outbound_relocas;
Elf_External_Rel *outbound_relocs;
unsigned int idx;
- int use_rela_p = get_elf_backend_data (abfd)->use_rela_p;
+ int use_rela_p;
asymbol *last_sym = 0;
int last_sym_idx = 0;
@@ -756,6 +756,16 @@ write_relocs (abfd, sec, data)
*failedp = true;
return;
}
+
+ /* Figure out whether the relocations are RELA or REL relocations. */
+ if (rela_hdr->sh_type == SHT_RELA)
+ use_rela_p = true;
+ else if (rela_hdr->sh_type == SHT_REL)
+ use_rela_p = false;
+ else
+ /* Every relocation section should be either an SHT_RELA or an
+ SHT_REL section. */
+ abort ();
/* orelocation has the data, reloc_count has the count... */
if (use_rela_p)
Index: elflink.c
===================================================================
RCS file: /usr/local/Repository/binutils/bfd/elflink.c,v
retrieving revision 1.3
diff -u -p -r1.3 elflink.c
--- elflink.c 1999/05/31 20:46:41 1.3
+++ elflink.c 1999/05/31 21:12:48
@@ -147,7 +147,8 @@ _bfd_elf_create_dynamic_sections (abfd,
return false;
}
- s = bfd_make_section (abfd, bed->use_rela_p ? ".rela.plt" : ".rel.plt");
+ s = bfd_make_section (abfd,
+ bed->default_use_rela_p ? ".rela.plt" : ".rel.plt");
if (s == NULL
|| ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
|| ! bfd_set_section_alignment (abfd, s, ptralign))
@@ -180,7 +181,9 @@ _bfd_elf_create_dynamic_sections (abfd,
copy relocs. */
if (! info->shared)
{
- s = bfd_make_section (abfd, bed->use_rela_p ? ".rela.bss" : ".rel.bss");
+ s = bfd_make_section (abfd,
+ bed->default_use_rela_p
+ ? ".rela.bss" : ".rel.bss");
if (s == NULL
|| ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
|| ! bfd_set_section_alignment (abfd, s, ptralign))
Index: elfxx-target.h
===================================================================
RCS file: /usr/local/Repository/binutils/bfd/elfxx-target.h,v
retrieving revision 1.4
diff -u -p -r1.4 elfxx-target.h
--- elfxx-target.h 1999/05/31 20:46:41 1.4
+++ elfxx-target.h 1999/05/31 21:15:40
@@ -294,6 +294,28 @@ Foundation, Inc., 59 Temple Place - Suit
#define elf_backend_post_process_headers NULL
#endif
+/* Previously, backends could only use SHT_REL or SHT_RELA relocation
+ sections, but not both. They defined USE_REL to indicate SHT_REL
+ sections, and left it undefined to indicated SHT_RELA sections.
+ For backwards compatibility, we still support this usage. */
+#ifndef USE_REL
+#define USE_REL 0
+#else
+#undef USE_REL
+#define USE_REL 1
+#endif
+
+/* Use these in new code. */
+#ifndef elf_backend_may_use_rel_p
+#define elf_backend_may_use_rel_p USE_REL
+#endif
+#ifndef elf_backend_may_use_rela_p
+#define elf_backend_may_use_rela_p !USE_REL
+#endif
+#ifndef elf_backend_default_use_rela_p
+#define elf_backend_default_use_rela_p !USE_REL
+#endif
+
#ifndef ELF_MACHINE_ALT1
#define ELF_MACHINE_ALT1 0
#endif
@@ -310,11 +332,6 @@ extern const struct elf_size_info _bfd_e
static CONST struct elf_backend_data elfNN_bed =
{
-#ifdef USE_REL
- 0, /* use_rela_p */
-#else
- 1, /* use_rela_p */
-#endif
ELF_ARCH, /* arch */
ELF_MACHINE_CODE, /* elf_machine_code */
ELF_MAXPAGESIZE, /* maxpagesize */
@@ -355,6 +372,9 @@ static CONST struct elf_backend_data elf
elf_backend_got_symbol_offset,
elf_backend_got_header_size,
elf_backend_plt_header_size,
+ elf_backend_may_use_rel_p,
+ elf_backend_may_use_rela_p,
+ elf_backend_default_use_rela_p,
elf_backend_want_got_plt,
elf_backend_plt_readonly,
elf_backend_want_plt_sym,