diff options
author | H.J. Lu <hjl.tools@gmail.com> | 2015-08-18 05:51:03 -0700 |
---|---|---|
committer | H.J. Lu <hjl.tools@gmail.com> | 2015-08-18 05:51:19 -0700 |
commit | 0e1862bb401f47716446aef143b2bf7a4563f541 (patch) | |
tree | 8410cdece79e8df2f1394b53d1e992736323baac /bfd/elf32-nios2.c | |
parent | b2a33439909493f5bf93ada871bd588f365d61f4 (diff) | |
download | fsf-binutils-gdb-0e1862bb401f47716446aef143b2bf7a4563f541.zip fsf-binutils-gdb-0e1862bb401f47716446aef143b2bf7a4563f541.tar.gz fsf-binutils-gdb-0e1862bb401f47716446aef143b2bf7a4563f541.tar.bz2 |
Add output_type to bfd_link_info
The "shared" field in bfd_link_info is set for both DSO and and PIE.
There are separate fields for executable and relocatable outputs. This
patch adds an "output_type" field:
enum output_type
{
type_unknown = 0,
type_executable,
type_dll,
type_relocatable
};
and a "pic" field to bfd_link_info to replace shared, executable and
relocatable fields so that we can use the "output_type" field to check
for output type and the "pic" field check if output is PIC. Macros,
bfd_link_executable, bfd_link_dll, bfd_link_relocatable, bfd_link_pic
and bfd_link_pie, are provided to check for output features.
bfd/
* bfd/aoutx.h: Replace shared, executable, relocatable and pie
fields with bfd_link_executable, bfd_link_dll,
bfd_link_relocatable, bfd_link_pic and bfd_link_pie.
* bfd/bout.c: Likewise.
* bfd/coff-alpha.c: Likewise.
* bfd/coff-arm.c: Likewise.
* bfd/coff-i386.c: Likewise.
* bfd/coff-i960.c: Likewise.
* bfd/coff-m68k.c: Likewise.
* bfd/coff-mcore.c: Likewise.
* bfd/coff-mips.c: Likewise.
* bfd/coff-ppc.c: Likewise.
* bfd/coff-rs6000.c: Likewise.
* bfd/coff-sh.c: Likewise.
* bfd/coff-tic80.c: Likewise.
* bfd/coff-x86_64.c: Likewise.
* bfd/coff64-rs6000.c: Likewise.
* bfd/coffgen.c: Likewise.
* bfd/cofflink.c: Likewise.
* bfd/ecoff.c: Likewise.
* bfd/ecofflink.c: Likewise.
* bfd/elf-bfd.h: Likewise.
* bfd/elf-eh-frame.c: Likewise.
* bfd/elf-ifunc.c: Likewise.
* bfd/elf-m10200.c: Likewise.
* bfd/elf-m10300.c: Likewise.
* bfd/elf-s390-common.c: Likewise.
* bfd/elf-vxworks.c: Likewise.
* bfd/elf.c: Likewise.
* bfd/elf32-arm.c: Likewise.
* bfd/elf32-avr.c: Likewise.
* bfd/elf32-bfin.c: Likewise.
* bfd/elf32-cr16.c: Likewise.
* bfd/elf32-cr16c.c: Likewise.
* bfd/elf32-cris.c: Likewise.
* bfd/elf32-crx.c: Likewise.
* bfd/elf32-d10v.c: Likewise.
* bfd/elf32-dlx.c: Likewise.
* bfd/elf32-epiphany.c: Likewise.
* bfd/elf32-fr30.c: Likewise.
* bfd/elf32-frv.c: Likewise.
* bfd/elf32-ft32.c: Likewise.
* bfd/elf32-h8300.c: Likewise.
* bfd/elf32-hppa.c: Likewise.
* bfd/elf32-i370.c: Likewise.
* bfd/elf32-i386.c: Likewise.
* bfd/elf32-i860.c: Likewise.
* bfd/elf32-ip2k.c: Likewise.
* bfd/elf32-iq2000.c: Likewise.
* bfd/elf32-lm32.c: Likewise.
* bfd/elf32-m32c.c: Likewise.
* bfd/elf32-m32r.c: Likewise.
* bfd/elf32-m68hc11.c: Likewise.
* bfd/elf32-m68hc1x.c: Likewise.
* bfd/elf32-m68k.c: Likewise.
* bfd/elf32-mcore.c: Likewise.
* bfd/elf32-mep.c: Likewise.
* bfd/elf32-metag.c: Likewise.
* bfd/elf32-microblaze.c: Likewise.
* bfd/elf32-moxie.c: Likewise.
* bfd/elf32-msp430.c: Likewise.
* bfd/elf32-mt.c: Likewise.
* bfd/elf32-nds32.c: Likewise.
* bfd/elf32-nios2.c: Likewise.
* bfd/elf32-or1k.c: Likewise.
* bfd/elf32-ppc.c: Likewise.
* bfd/elf32-rl78.c: Likewise.
* bfd/elf32-rx.c: Likewise.
* bfd/elf32-s390.c: Likewise.
* bfd/elf32-score.c: Likewise.
* bfd/elf32-score7.c: Likewise.
* bfd/elf32-sh-symbian.c: Likewise.
* bfd/elf32-sh.c: Likewise.
* bfd/elf32-sh64.c: Likewise.
* bfd/elf32-spu.c: Likewise.
* bfd/elf32-tic6x.c: Likewise.
* bfd/elf32-tilepro.c: Likewise.
* bfd/elf32-v850.c: Likewise.
* bfd/elf32-vax.c: Likewise.
* bfd/elf32-visium.c: Likewise.
* bfd/elf32-xc16x.c: Likewise.
* bfd/elf32-xstormy16.c: Likewise.
* bfd/elf32-xtensa.c: Likewise.
* bfd/elf64-alpha.c: Likewise.
* bfd/elf64-hppa.c: Likewise.
* bfd/elf64-ia64-vms.c: Likewise.
* bfd/elf64-mmix.c: Likewise.
* bfd/elf64-ppc.c: Likewise.
* bfd/elf64-s390.c: Likewise.
* bfd/elf64-sh64.c: Likewise.
* bfd/elf64-x86-64.c: Likewise.
* bfd/elflink.c: Likewise.
* bfd/elfnn-aarch64.c: Likewise.
* bfd/elfnn-ia64.c: Likewise.
* bfd/elfxx-mips.c: Likewise.
* bfd/elfxx-sparc.c: Likewise.
* bfd/elfxx-tilegx.c: Likewise.
* bfd/i386linux.c: Likewise.
* bfd/linker.c: Likewise.
* bfd/m68klinux.c: Likewise.
* bfd/pdp11.c: Likewise.
* bfd/pe-mips.c: Likewise.
* bfd/peXXigen.c: Likewise.
* bfd/reloc.c: Likewise.
* bfd/reloc16.c: Likewise.
* bfd/sparclinux.c: Likewise.
* bfd/sunos.c: Likewise.
* bfd/vms-alpha.c: Likewise.
* bfd/xcofflink.c: Likewise.
include/
* include/bfdlink.h (output_type): New enum.
(bfd_link_executable): New macro.
(bfd_link_dll): Likewise.
(bfd_link_relocatable): Likewise.
(bfd_link_pic): Likewise.
(bfd_link_pie): Likewise.
(bfd_link_info): Remove shared, executable, pie and relocatable.
Add output_type and pic.
ld/
* ld/ldctor.c: Replace shared, executable, relocatable and pie
fields with bfd_link_executable, bfd_link_dll,
bfd_link_relocatable, bfd_link_pic and bfd_link_pie.
* ld/ldemul.c: Likewise.
* ld/ldfile.c: Likewise.
* ld/ldlang.c: Likewise.
* ld/ldmain.c: Likewise.
* ld/ldwrite.c: Likewise.
* ld/lexsup.c: Likewise.
* ld/pe-dll.c: Likewise.
* ld/plugin.c: Likewise.
* ld/emultempl/aarch64elf.em: Likewise.
* ld/emultempl/aix.em: Likewise.
* ld/emultempl/alphaelf.em: Likewise.
* ld/emultempl/armcoff.em: Likewise.
* ld/emultempl/armelf.em: Likewise.
* ld/emultempl/avrelf.em: Likewise.
* ld/emultempl/beos.em: Likewise.
* ld/emultempl/cr16elf.em: Likewise.
* ld/emultempl/elf-generic.em: Likewise.
* ld/emultempl/elf32.em: Likewise.
* ld/emultempl/genelf.em: Likewise.
* ld/emultempl/generic.em: Likewise.
* ld/emultempl/gld960.em: Likewise.
* ld/emultempl/gld960c.em: Likewise.
* ld/emultempl/hppaelf.em: Likewise.
* ld/emultempl/irix.em: Likewise.
* ld/emultempl/linux.em: Likewise.
* ld/emultempl/lnk960.em: Likewise.
* ld/emultempl/m68hc1xelf.em: Likewise.
* ld/emultempl/m68kcoff.em: Likewise.
* ld/emultempl/m68kelf.em: Likewise.
* ld/emultempl/metagelf.em: Likewise.
* ld/emultempl/mipself.em: Likewise.
* ld/emultempl/mmo.em: Likewise.
* ld/emultempl/msp430.em: Likewise.
* ld/emultempl/nds32elf.em: Likewise.
* ld/emultempl/needrelax.em: Likewise.
* ld/emultempl/nios2elf.em: Likewise.
* ld/emultempl/pe.em: Likewise.
* ld/emultempl/pep.em: Likewise.
* ld/emultempl/ppc32elf.em: Likewise.
* ld/emultempl/ppc64elf.em: Likewise.
* ld/emultempl/sh64elf.em: Likewise.
* ld/emultempl/solaris2.em: Likewise.
* ld/emultempl/spuelf.em: Likewise.
* ld/emultempl/sunos.em: Likewise.
* ld/emultempl/tic6xdsbt.em: Likewise.
* ld/emultempl/ticoff.em: Likewise.
* ld/emultempl/v850elf.em: Likewise.
* ld/emultempl/vms.em: Likewise.
* ld/emultempl/vxworks.em: Likewise.
Diffstat (limited to 'bfd/elf32-nios2.c')
-rw-r--r-- | bfd/elf32-nios2.c | 80 |
1 files changed, 42 insertions, 38 deletions
diff --git a/bfd/elf32-nios2.c b/bfd/elf32-nios2.c index 8bd2524..fd70007 100644 --- a/bfd/elf32-nios2.c +++ b/bfd/elf32-nios2.c @@ -2779,7 +2779,7 @@ nios2_elf32_size_stubs (bfd *output_bfd, bfd *stub_bfd, } else if (hh->root.root.type == bfd_link_hash_undefweak) { - if (! info->shared) + if (! bfd_link_pic (info)) continue; } else if (hh->root.root.type == bfd_link_hash_undefined) @@ -3759,7 +3759,7 @@ nios2_elf32_relocate_section (bfd *output_bfd, rel, 1, relend, howto, 0, contents); /* Nothing more to do unless this is a final link. */ - if (info->relocatable) + if (bfd_link_relocatable (info)) continue; if (sec && sec->output_section) @@ -3986,8 +3986,10 @@ nios2_elf32_relocate_section (bfd *output_bfd, off = h->got.offset; BFD_ASSERT (off != (bfd_vma) -1); dyn = elf_hash_table (info)->dynamic_sections_created; - if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h) - || (info->shared + if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, + bfd_link_pic (info), + h) + || (bfd_link_pic (info) && SYMBOL_REFERENCES_LOCAL (info, h)) || (ELF_ST_VISIBILITY (h->other) && h->root.type == bfd_link_hash_undefweak)) @@ -4031,7 +4033,7 @@ nios2_elf32_relocate_section (bfd *output_bfd, bfd_put_32 (output_bfd, relocation, sgot->contents + off); - if (info->shared) + if (bfd_link_pic (info)) { asection *srelgot; Elf_Internal_Rela outrel; @@ -4055,7 +4057,7 @@ nios2_elf32_relocate_section (bfd *output_bfd, } } - if (use_plt && info->shared) + if (use_plt && bfd_link_pic (info)) { off = ((h->plt.offset - 24) / 12 + 3) * 4; relocation = (htab->root.sgotplt->output_offset + off @@ -4156,7 +4158,7 @@ nios2_elf32_relocate_section (bfd *output_bfd, { /* If we don't know the module number, create a relocation for it. */ - if (info->shared) + if (bfd_link_pic (info)) { Elf_Internal_Rela outrel; bfd_byte *loc; @@ -4203,8 +4205,10 @@ nios2_elf32_relocate_section (bfd *output_bfd, { bfd_boolean dyn; dyn = htab->root.dynamic_sections_created; - if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h) - && (!info->shared + if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, + bfd_link_pic (info), + h) + && (!bfd_link_pic (info) || !SYMBOL_REFERENCES_LOCAL (info, h))) { unresolved_reloc = FALSE; @@ -4239,7 +4243,7 @@ nios2_elf32_relocate_section (bfd *output_bfd, now, and emit any relocations. If both an IE GOT and a GD GOT are necessary, we emit the GD first. */ - if ((info->shared || indx != 0) + if ((bfd_link_pic (info) || indx != 0) && (h == NULL || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT || h->root.type != bfd_link_hash_undefweak)) @@ -4348,7 +4352,7 @@ nios2_elf32_relocate_section (bfd *output_bfd, break; case R_NIOS2_TLS_LE16: - if (info->shared && !info->pie) + if (bfd_link_pic (info) && !bfd_link_pie (info)) { (*_bfd_error_handler) (_("%B(%A+0x%lx): R_NIOS2_TLS_LE16 relocation not " @@ -4366,7 +4370,7 @@ nios2_elf32_relocate_section (bfd *output_bfd, break; case R_NIOS2_BFD_RELOC_32: - if (info->shared + if (bfd_link_pic (info) && (input_section->flags & SEC_ALLOC) != 0 && (h == NULL || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT @@ -4397,7 +4401,7 @@ nios2_elf32_relocate_section (bfd *output_bfd, memset (&outrel, 0, sizeof outrel); else if (h != NULL && h->dynindx != -1 - && (!info->shared + && (!bfd_link_pic (info) || !SYMBOLIC_BIND (info, h) || !h->def_regular)) { @@ -4594,7 +4598,7 @@ nios2_elf32_create_dynamic_sections (bfd *dynobj, struct bfd_link_info *info) htab->sdynbss = bfd_get_linker_section (dynobj, ".dynbss"); if (!htab->sdynbss) return FALSE; - if (!info->shared) + if (!bfd_link_pic (info)) { htab->srelbss = bfd_get_linker_section (dynobj, ".rela.bss"); if (!htab->srelbss) @@ -4699,7 +4703,7 @@ nios2_elf32_check_relocs (bfd *abfd, struct bfd_link_info *info, asection *sreloc = NULL; bfd_signed_vma *local_got_refcounts; - if (info->relocatable) + if (bfd_link_relocatable (info)) return TRUE; dynobj = elf_hash_table (info)->dynobj; @@ -4786,7 +4790,7 @@ nios2_elf32_check_relocs (bfd *abfd, struct bfd_link_info *info, } if (srelgot == NULL - && (h != NULL || info->shared)) + && (h != NULL || bfd_link_pic (info))) { srelgot = htab->root.srelgot; BFD_ASSERT (srelgot != NULL); @@ -4892,7 +4896,7 @@ nios2_elf32_check_relocs (bfd *abfd, struct bfd_link_info *info, sections have not yet been mapped to output sections. Tentatively set the flag for now, and correct in adjust_dynamic_symbol. */ - if (!info->shared) + if (!bfd_link_pic (info)) h->non_got_ref = 1; /* Make sure a plt entry is created for this symbol if it @@ -4905,7 +4909,7 @@ nios2_elf32_check_relocs (bfd *abfd, struct bfd_link_info *info, /* If we are creating a shared library, we need to copy the reloc into the shared library. */ - if (info->shared + if (bfd_link_pic (info) && (sec->flags & SEC_ALLOC) != 0 && (r_type == R_NIOS2_BFD_RELOC_32 || (h != NULL && ! h->needs_plt @@ -5012,7 +5016,7 @@ nios2_elf32_gc_sweep_hook (bfd *abfd, const Elf_Internal_Rela *rel, *relend; bfd *dynobj; - if (info->relocatable) + if (bfd_link_relocatable (info)) return TRUE; elf_section_data (sec)->local_dynrel = NULL; @@ -5138,7 +5142,7 @@ nios2_elf32_finish_dynamic_symbol (bfd *output_bfd, BFD_ASSERT (splt != NULL && sgotplt != NULL && srela != NULL); /* Emit the PLT entry. */ - if (info->shared) + if (bfd_link_pic (info)) { nios2_elf32_install_data (splt, nios2_so_plt_entry, h->plt.offset, 3); @@ -5228,7 +5232,7 @@ nios2_elf32_finish_dynamic_symbol (bfd *output_bfd, The entry in the global offset table will already have been initialized in the relocate_section function. */ - if (info->shared && SYMBOL_REFERENCES_LOCAL (info, h)) + if (bfd_link_pic (info) && SYMBOL_REFERENCES_LOCAL (info, h)) { rela.r_info = ELF32_R_INFO (0, R_NIOS2_RELATIVE); rela.r_addend = bfd_get_signed_32 (output_bfd, @@ -5377,7 +5381,7 @@ nios2_elf32_finish_dynamic_sections (bfd *output_bfd, { bfd_vma got_address = (sgotplt->output_section->vma + sgotplt->output_offset); - if (info->shared) + if (bfd_link_pic (info)) { bfd_vma corrected = got_address - (splt->output_section->vma + splt->output_offset + 4); @@ -5506,7 +5510,7 @@ nios2_elf32_adjust_dynamic_symbol (struct bfd_link_info *info, only references to the symbol are via the global offset table. For such cases we need not do anything here; the relocations will be handled correctly by relocate_section. */ - if (info->shared) + if (bfd_link_pic (info)) return TRUE; if (h->size == 0) @@ -5623,14 +5627,14 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, PTR inf) && !bfd_elf_link_record_dynamic_symbol (info, h)) return FALSE; - if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info->shared, h)) + if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, bfd_link_pic (info), h)) { asection *s = htab->root.splt; /* Allocate room for the header. */ if (s->size == 0) { - if (info->shared) + if (bfd_link_pic (info)) s->size = 24; else s->size = 28; @@ -5643,7 +5647,7 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, PTR inf) location in the .plt. This is required to make function pointers compare as equal between the normal executable and the shared library. */ - if (! info->shared + if (! bfd_link_pic (info) && !h->def_regular) { h->root.u.def.section = s; @@ -5711,13 +5715,13 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, PTR inf) dyn = htab->root.dynamic_sections_created; indx = 0; - if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h) - && (!info->shared + if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, bfd_link_pic (info), h) + && (!bfd_link_pic (info) || !SYMBOL_REFERENCES_LOCAL (info, h))) indx = h->dynindx; if (tls_type != GOT_NORMAL - && (info->shared || indx != 0) + && (bfd_link_pic (info) || indx != 0) && (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT || h->root.type != bfd_link_hash_undefweak)) { @@ -5733,7 +5737,7 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, PTR inf) else if ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT || h->root.type != bfd_link_hash_undefweak) && !use_plt - && (info->shared + && (bfd_link_pic (info) || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h))) htab->root.srelgot->size += sizeof (Elf32_External_Rela); } @@ -5749,7 +5753,7 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, PTR inf) space for pc-relative relocs that have become local due to symbol visibility changes. */ - if (info->shared) + if (bfd_link_pic (info)) { if (h->def_regular && (h->forced_local || SYMBOLIC_BIND (info, h))) @@ -5845,7 +5849,7 @@ nios2_elf32_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED, if (elf_hash_table (info)->dynamic_sections_created) { /* Set the contents of the .interp section to the interpreter. */ - if (info->executable) + if (bfd_link_executable (info)) { s = bfd_get_linker_section (dynobj, ".interp"); BFD_ASSERT (s != NULL); @@ -5926,7 +5930,7 @@ nios2_elf32_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED, if (*local_tls_type == GOT_NORMAL) s->size += 4; - if (info->shared || *local_tls_type == GOT_TLS_GD) + if (bfd_link_pic (info) || *local_tls_type == GOT_TLS_GD) srel->size += sizeof (Elf32_External_Rela); } else @@ -5940,7 +5944,7 @@ nios2_elf32_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED, for R_NIOS2_TLS_LDM16 relocations. */ htab->tls_ldm_got.offset = htab->root.sgot->size; htab->root.sgot->size += 8; - if (info->shared) + if (bfd_link_pic (info)) htab->root.srelgot->size += sizeof (Elf32_External_Rela); } else @@ -5983,7 +5987,7 @@ nios2_elf32_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED, plt = s->size != 0; /* Correct for the number of res_N branches. */ - if (plt && !info->shared) + if (plt && !bfd_link_pic (info)) { htab->res_n_size = (s->size-28) / 3; s->size += htab->res_n_size; @@ -6050,7 +6054,7 @@ nios2_elf32_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED, #define add_dynamic_entry(TAG, VAL) \ _bfd_elf_add_dynamic_entry (info, TAG, VAL) - if (!info->shared && !add_dynamic_entry (DT_DEBUG, 0)) + if (!bfd_link_pic (info) && !add_dynamic_entry (DT_DEBUG, 0)) return FALSE; if (got && !add_dynamic_entry (DT_PLTGOT, 0)) @@ -6068,7 +6072,7 @@ nios2_elf32_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED, || !add_dynamic_entry (DT_RELAENT, sizeof (Elf32_External_Rela)))) return FALSE; - if (!info->shared && !add_dynamic_entry (DT_NIOS2_GP, 0)) + if (!bfd_link_pic (info) && !add_dynamic_entry (DT_NIOS2_GP, 0)) return FALSE; if ((info->flags & DF_TEXTREL) != 0 @@ -6166,7 +6170,7 @@ nios2_elf_add_symbol_hook (bfd *abfd, bfd *dynobj; if (sym->st_shndx == SHN_COMMON - && !info->relocatable + && !bfd_link_relocatable (info) && sym->st_size <= elf_gp_size (abfd) && is_nios2_elf_target (info->output_bfd->xvec)) { |