aboutsummaryrefslogtreecommitdiff
path: root/bfd
diff options
context:
space:
mode:
authorNick Clifton <nickc@redhat.com>2011-06-10 14:04:25 +0000
committerNick Clifton <nickc@redhat.com>2011-06-10 14:04:25 +0000
commit894891db7f1ff09f021a0d2c8bb471f3a73a776a (patch)
tree92496b5fd1ebc0c60c95f341ca77699e87569545 /bfd
parent12af614e24384fa939bbc1b55e40cfc28322c3a4 (diff)
downloadgdb-894891db7f1ff09f021a0d2c8bb471f3a73a776a.zip
gdb-894891db7f1ff09f021a0d2c8bb471f3a73a776a.tar.gz
gdb-894891db7f1ff09f021a0d2c8bb471f3a73a776a.tar.bz2
* elflink.c (_bfd_elf_link_create_dynamic_sections): If the
backend does not provide a function for creating dynamic sections then fail. (bfd_elf_final_link): Issue a warning message if a dynamic section has the SHT_NOTE type. (bfd_elf_final_link): Do not look for dynamic strings in a section that does not have the SHT_STRTAB type or the name .dynstr. * elf32-arm.c (elf32_arm_finish_dynamic_sections): Fail if the got section is not in the output binary. * elf32-hppa.c (elf32_hppa_finish_dynamic_sections): Likewise. * ld-elf/elf.exp: Add test for linking a shared library with a broken linker script that marks dynamic sections as being notes. * ld-elf/note-3.s: New test source file. * ld-elf/note-3.t: New test linker script. * ld-elf/note-3.l: Expected output from the linker. * lib/ld-lib.exp (run_ld_link_tests): Improve description.
Diffstat (limited to 'bfd')
-rw-r--r--bfd/ChangeLog13
-rw-r--r--bfd/elf32-arm.c4
-rw-r--r--bfd/elf32-hppa.c19
-rw-r--r--bfd/elflink.c12
-rw-r--r--bfd/linker.c2
5 files changed, 42 insertions, 8 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 58aa6e7..1e72bf2 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,16 @@
+2011-06-10 Nick Clifton <nickc@redhat.com>
+
+ * elflink.c (_bfd_elf_link_create_dynamic_sections): If the
+ backend does not provide a function for creating dynamic sections
+ then fail.
+ (bfd_elf_final_link): Issue a warning message if a dynamic section
+ has the SHT_NOTE type.
+ (bfd_elf_final_link): Do not look for dynamic strings in a section
+ that does not have the SHT_STRTAB type or the name .dynstr.
+ * elf32-arm.c (elf32_arm_finish_dynamic_sections): Fail if the got
+ section is not in the output binary.
+ * elf32-hppa.c (elf32_hppa_finish_dynamic_sections): Likewise.
+
2011-06-09 Tristan Gingold <gingold@adacore.com>
* elfnn-ia64.c (elfNN_ia64_relax_section, elfNN_ia64_choose_gp)
diff --git a/bfd/elf32-arm.c b/bfd/elf32-arm.c
index d5a4a4e..8ace48a 100644
--- a/bfd/elf32-arm.c
+++ b/bfd/elf32-arm.c
@@ -13744,6 +13744,10 @@ elf32_arm_finish_dynamic_sections (bfd * output_bfd, struct bfd_link_info * info
dynobj = elf_hash_table (info)->dynobj;
sgot = htab->root.sgotplt;
+ /* A broken linker script might have discarded the dynamic sections.
+ Catch this here so that we do not seg-fault later on. */
+ if (sgot != NULL && bfd_is_abs_section (sgot->output_section))
+ return FALSE;
sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
if (elf_hash_table (info)->dynamic_sections_created)
diff --git a/bfd/elf32-hppa.c b/bfd/elf32-hppa.c
index 81bc042..e70d7e5 100644
--- a/bfd/elf32-hppa.c
+++ b/bfd/elf32-hppa.c
@@ -4498,6 +4498,7 @@ elf32_hppa_finish_dynamic_sections (bfd *output_bfd,
bfd *dynobj;
struct elf32_hppa_link_hash_table *htab;
asection *sdyn;
+ asection * sgot;
htab = hppa_link_hash_table (info);
if (htab == NULL)
@@ -4505,6 +4506,12 @@ elf32_hppa_finish_dynamic_sections (bfd *output_bfd,
dynobj = htab->etab.dynobj;
+ sgot = htab->sgot;
+ /* A broken linker script might have discarded the dynamic sections.
+ Catch this here so that we do not seg-fault later on. */
+ if (sgot != NULL && bfd_is_abs_section (sgot->output_section))
+ return FALSE;
+
sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
if (htab->etab.dynamic_sections_created)
@@ -4569,19 +4576,19 @@ elf32_hppa_finish_dynamic_sections (bfd *output_bfd,
}
}
- if (htab->sgot != NULL && htab->sgot->size != 0)
+ if (sgot != NULL && sgot->size != 0)
{
/* Fill in the first entry in the global offset table.
We use it to point to our dynamic section, if we have one. */
bfd_put_32 (output_bfd,
sdyn ? sdyn->output_section->vma + sdyn->output_offset : 0,
- htab->sgot->contents);
+ sgot->contents);
/* The second entry is reserved for use by the dynamic linker. */
- memset (htab->sgot->contents + GOT_ENTRY_SIZE, 0, GOT_ENTRY_SIZE);
+ memset (sgot->contents + GOT_ENTRY_SIZE, 0, GOT_ENTRY_SIZE);
/* Set .got entry size. */
- elf_section_data (htab->sgot->output_section)
+ elf_section_data (sgot->output_section)
->this_hdr.sh_entsize = GOT_ENTRY_SIZE;
}
@@ -4601,8 +4608,8 @@ elf32_hppa_finish_dynamic_sections (bfd *output_bfd,
if ((htab->splt->output_offset
+ htab->splt->output_section->vma
+ htab->splt->size)
- != (htab->sgot->output_offset
- + htab->sgot->output_section->vma))
+ != (sgot->output_offset
+ + sgot->output_section->vma))
{
(*_bfd_error_handler)
(_(".got section not immediately after .plt section"));
diff --git a/bfd/elflink.c b/bfd/elflink.c
index 639c3e7..ef7a524 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -286,7 +286,8 @@ _bfd_elf_link_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
/* Let the backend create the rest of the sections. This lets the
backend set the right flags. The backend will normally create
the .got and .plt sections. */
- if (! (*bed->elf_backend_create_dynamic_sections) (abfd, info))
+ if (bed->elf_backend_create_dynamic_sections == NULL
+ || ! (*bed->elf_backend_create_dynamic_sections) (abfd, info))
return FALSE;
elf_hash_table (info)->dynamic_sections_created = TRUE;
@@ -11148,6 +11149,13 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info)
(_("%B: could not find output section %s"), abfd, name);
goto error_return;
}
+ if (elf_section_data (o->output_section)->this_hdr.sh_type == SHT_NOTE)
+ {
+ (*_bfd_error_handler)
+ (_("warning: section '%s' is being made into a note"), name);
+ bfd_set_error (bfd_error_nonrepresentable_section);
+ goto error_return;
+ }
dyn.d_un.d_ptr = o->vma;
break;
@@ -11235,7 +11243,7 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info)
continue;
if ((elf_section_data (o->output_section)->this_hdr.sh_type
!= SHT_STRTAB)
- || strcmp (bfd_get_section_name (abfd, o), ".dynstr") != 0)
+ && (strcmp (bfd_get_section_name (abfd, o), ".dynstr") != 0))
{
/* FIXME: octets_per_byte. */
if (! bfd_set_section_contents (abfd, o->output_section,
diff --git a/bfd/linker.c b/bfd/linker.c
index 90ab63e..bac5417 100644
--- a/bfd/linker.c
+++ b/bfd/linker.c
@@ -1566,6 +1566,8 @@ _bfd_generic_link_add_one_symbol (struct bfd_link_info *info,
struct bfd_link_hash_entry *h;
bfd_boolean cycle;
+ BFD_ASSERT (section != NULL);
+
if (bfd_is_ind_section (section)
|| (flags & BSF_INDIRECT) != 0)
row = INDR_ROW;