diff options
author | Mark Mitchell <mark@codesourcery.com> | 1999-06-02 13:01:04 +0000 |
---|---|---|
committer | Mark Mitchell <mark@codesourcery.com> | 1999-06-02 13:01:04 +0000 |
commit | bf572ba0b9deeeba341d197a3412a3c0b44d819f (patch) | |
tree | ca0102a08126c8ccfea30b798468cc30711e95a7 | |
parent | 3fe702fddf7a4fc4eef46bcee1bcfada94e72627 (diff) | |
download | gdb-bf572ba0b9deeeba341d197a3412a3c0b44d819f.zip gdb-bf572ba0b9deeeba341d197a3412a3c0b44d819f.tar.gz gdb-bf572ba0b9deeeba341d197a3412a3c0b44d819f.tar.bz2 |
* 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.
(_bfd_elf_copy_private_section_data): Copy 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.
-rw-r--r-- | bfd/ChangeLog | 19 | ||||
-rw-r--r-- | bfd/elf-bfd.h | 24 | ||||
-rw-r--r-- | bfd/elf.c | 26 | ||||
-rw-r--r-- | bfd/elfcode.h | 12 | ||||
-rw-r--r-- | bfd/elflink.c | 7 | ||||
-rw-r--r-- | bfd/elfxx-target.h | 30 |
6 files changed, 96 insertions, 22 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 258a118..7178248 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,22 @@ +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. + (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. + (_bfd_elf_copy_private_section_data): Copy 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. + Wed Jun 2 12:38:49 1999 Miodrag Vallat <miodrag@multimania.com> * hosts/alphalinux.h (TRAD_CORE_EXTRA_SIZE_ALLOWED): Expand to 4096. diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h index 218780d..0f16456 100644 --- a/bfd/elf-bfd.h +++ b/bfd/elf-bfd.h @@ -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) @@ -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, failedptrarg) 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, failedptrarg) 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; @@ -3837,6 +3842,9 @@ _bfd_elf_copy_private_section_data (ibfd, isec, obfd, osec) || 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; } diff --git a/bfd/elfcode.h b/bfd/elfcode.h index 22f6488..0426da2 100644 --- a/bfd/elfcode.h +++ b/bfd/elfcode.h @@ -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; @@ -757,6 +757,16 @@ write_relocs (abfd, sec, data) 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) { diff --git a/bfd/elflink.c b/bfd/elflink.c index dc0b042..e85f595 100644 --- a/bfd/elflink.c +++ b/bfd/elflink.c @@ -147,7 +147,8 @@ _bfd_elf_create_dynamic_sections (abfd, info) 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, info) 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)) diff --git a/bfd/elfxx-target.h b/bfd/elfxx-target.h index dc116ef..976e68b 100644 --- a/bfd/elfxx-target.h +++ b/bfd/elfxx-target.h @@ -294,6 +294,28 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #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_elfNN_size_info; 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 elfNN_bed = 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, |