From mboxrd@z Thu Jan 1 00:00:00 1970 From: Mark Mitchell To: ian@zembu.com Cc: binutils@sourceware.cygnus.com Subject: Re: PATCH for using both RELA and REL relocations in the samebackend Date: Thu, 01 Jul 1999 00:00:00 -0000 Message-id: <19990602124907L.mitchell@codesourcery.com> References: <19990601202858Z.mitchell@codesourcery.com> <19990602042017.7450.qmail@daffy.airs.com> <19990602042017.7450.qmail@daffy.airs.com> X-SW-Source: 1999-q2/msg00102.html >>>>> "Ian" == Ian Lance Taylor writes: Ian> My feeling is that it would be cleaner to store the Ian> information in the ELF data and to copy it in the Ian> copy_private_section_data entry point. See Ian> _bfd_elf_copy_private_section_data in bfd/elf.c. Here is a revised patch which addresses the two issues you raised with the previous version. -- Mark Mitchell mark@codesourcery.com CodeSourcery, LLC http://www.codesourcery.com 1999-05-31 Mark Mitchell * elf-bfd.h (elf_backend_data): Remove use_rela_p. Add may_use_rel_p, may_use_rela_p, default_use_rela_p. (bfd_elf_section_data): Add use_rela_p. * elf.c (bfd_section_from_shdr): Set use_rela_p appropriately. (_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. (_bfd_elf_copy_private_section_data): Copy use_rela_p. * 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: /cvs/binutils/binutils/bfd/elf-bfd.h,v retrieving revision 1.2 diff -u -p -r1.2 elf-bfd.h --- elf-bfd.h 1999/05/28 13:24:32 1.2 +++ elf-bfd.h 1999/06/02 19:42:53 @@ -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; @@ -540,6 +535,23 @@ struct elf_backend_data 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; unsigned want_plt_sym : 1; @@ -582,6 +594,8 @@ struct bfd_elf_section_data PTR stab_info; /* A pointer available for the processor specific ELF backend. */ PTR tdata; + /* Nonzero if this section uses RELA relocations, rather than REL. */ + unsigned int use_rela_p:1; }; #define elf_section_data(sec) ((struct bfd_elf_section_data*)sec->used_by_bfd) Index: elf.c =================================================================== RCS file: /cvs/binutils/binutils/bfd/elf.c,v retrieving revision 1.4 diff -u -p -r1.4 elf.c --- elf.c 1999/05/28 13:24:31 1.4 +++ elf.c 1999/06/02 19:42:56 @@ -1265,6 +1265,10 @@ 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. */ + elf_section_data (target_sect)->use_rela_p + = (hdr->sh_type == SHT_RELA); abfd->flags |= HAS_RELOC; return true; } @@ -1329,6 +1333,11 @@ _bfd_elf_new_section_hook (abfd, sec) return false; sec->used_by_bfd = (PTR) sdata; memset (sdata, 0, sizeof (*sdata)); + + /* Indicate whether or not this section should use RELA relocations. */ + sdata->use_rela_p + = get_elf_backend_data (abfd)->default_use_rela_p; + return true; } @@ -1491,13 +1500,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 +1567,15 @@ 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 = elf_section_data (asect)->use_rela_p; char *name; rela_hdr = &elf_section_data (asect)->rel_hdr; @@ -3836,6 +3841,9 @@ _bfd_elf_copy_private_section_data (ibfd || ihdr->sh_type == SHT_GNU_verneed || ihdr->sh_type == SHT_GNU_verdef) ohdr->sh_info = ihdr->sh_info; + + elf_section_data (osec)->use_rela_p + = elf_section_data (isec)->use_rela_p; return true; } Index: elfcode.h =================================================================== RCS file: /cvs/binutils/binutils/bfd/elfcode.h,v retrieving revision 1.1.1.1 diff -u -p -r1.1.1.1 elfcode.h --- elfcode.h 1999/05/03 07:28:57 1.1.1.1 +++ elfcode.h 1999/06/02 19:42:56 @@ -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: /cvs/binutils/binutils/bfd/elflink.c,v retrieving revision 1.1.1.1 diff -u -p -r1.1.1.1 elflink.c --- elflink.c 1999/05/03 07:28:57 1.1.1.1 +++ elflink.c 1999/06/02 19:42:57 @@ -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: /cvs/binutils/binutils/bfd/elfxx-target.h,v retrieving revision 1.2 diff -u -p -r1.2 elfxx-target.h --- elfxx-target.h 1999/05/28 13:24:33 1.2 +++ elfxx-target.h 1999/06/02 19:42:57 @@ -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,