Add more targets to the list of architectures not supporting format changing during linking. Fix seg-faults triggered when this is attempted.

PR ld/21884
	* testsuite/ld-elf/pr21884.d: Add AVR, HPPA, IA64, M68HC1x and
	SCORE to list of targets not supporting file format changes during
	linking.
	* testsuite/ld-unique/pr21529.d: Likewise.
	* emultempl/avrelf.em (_before_allocation): Skip for non-ELF
	output formats.
	(avr_elf_create_output_section_statements): Fail if the output
	format is not ELF.
	(avr_finish): Do not access the ELF header in non-ELF format
	output bfds.
	* emultempl/m68hc1xelf.em (_before_allocation): Skip for non-ELF
	output formats.
	(m68hc11elf_create_output_section_statements): Fail if the putput
	format is not ELF.
	(m68hc11elf_after_allocation): Skip for non-ELF output formats.
This commit is contained in:
Nick Clifton 2017-08-03 11:59:32 +01:00
parent 2e9246e077
commit fd9770d81f
5 changed files with 67 additions and 19 deletions

View File

@ -1,3 +1,22 @@
2017-08-03 Nick Clifton <nickc@redhat.com>
PR ld/21884
* testsuite/ld-elf/pr21884.d: Add AVR, HPPA, IA64, M68HC1x and
SCORE to list of targets not supporting file format changes during
linking.
* testsuite/ld-unique/pr21529.d: Likewise.
* emultempl/avrelf.em (_before_allocation): Skip for non-ELF
output formats.
(avr_elf_create_output_section_statements): Fail if the output
format is not ELF.
(avr_finish): Do not access the ELF header in non-ELF format
output bfds.
* emultempl/m68hc1xelf.em (_before_allocation): Skip for non-ELF
output formats.
(m68hc11elf_create_output_section_statements): Fail if the putput
format is not ELF.
(m68hc11elf_after_allocation): Skip for non-ELF output formats.
2017-08-03 Alan Modra <amodra@gmail.com>
PR ld/21884

View File

@ -71,6 +71,12 @@ avr_elf_${EMULATION_NAME}_before_allocation (void)
gld${EMULATION_NAME}_before_allocation ();
if (bfd_get_flavour (link_info.output_bfd) != bfd_target_elf_flavour)
{
avr_no_stubs = TRUE;
return;
}
/* We only need stubs for avr6, avrxmega6, and avrxmega7. */
if (strcmp ("${EMULATION_NAME}","avr6")
&& strcmp ("${EMULATION_NAME}","avrxmega6")
@ -108,6 +114,12 @@ avr_elf_create_output_section_statements (void)
{
flagword flags;
if (bfd_get_flavour (link_info.output_bfd) != bfd_target_elf_flavour)
{
einfo ("%X%P: changing output format whilst linking is not supported\n");
return;
}
stub_file = lang_add_input_file ("linker stubs",
lang_input_file_is_fake_enum,
NULL);
@ -204,10 +216,14 @@ avr_finish (void)
}
abfd = link_info.output_bfd;
if (avr_link_relax)
elf_elfheader (abfd)->e_flags |= EF_AVR_LINKRELAX_PREPARED;
else
elf_elfheader (abfd)->e_flags &= ~EF_AVR_LINKRELAX_PREPARED;
if (bfd_get_flavour (link_info.output_bfd) == bfd_target_elf_flavour)
{
if (avr_link_relax)
elf_elfheader (abfd)->e_flags |= EF_AVR_LINKRELAX_PREPARED;
else
elf_elfheader (abfd)->e_flags &= ~EF_AVR_LINKRELAX_PREPARED;
}
finish_default ();
}

View File

@ -66,6 +66,9 @@ m68hc11_elf_${EMULATION_NAME}_before_allocation (void)
gld${EMULATION_NAME}_before_allocation ();
if (bfd_get_flavour (link_info.output_bfd) != bfd_target_elf_flavour)
return;
/* If generating a relocatable output file, then we don't
have to generate the trampolines. */
if (bfd_link_relocatable (&link_info))
@ -141,6 +144,12 @@ m68hc11_elf_${EMULATION_NAME}_before_allocation (void)
static void
m68hc11elf_create_output_section_statements (void)
{
if (bfd_get_flavour (link_info.output_bfd) != bfd_target_elf_flavour)
{
einfo ("%X%P: changing output format whilst linking is not supported\n");
return;
}
stub_file = lang_add_input_file ("linker stubs",
lang_input_file_is_fake_enum,
NULL);
@ -286,22 +295,25 @@ m68hc11elf_add_stub_section (const char *stub_sec_name,
static void
m68hc11elf_after_allocation (void)
{
/* Now build the linker stubs. */
if (stub_file->the_bfd->sections != NULL)
if (bfd_get_flavour (link_info.output_bfd) == bfd_target_elf_flavour)
{
/* Call again the trampoline analyzer to initialize the trampoline
stubs with the correct symbol addresses. Since there could have
been relaxation, the symbol addresses that were found during
first call may no longer be correct. */
if (!elf32_m68hc11_size_stubs (link_info.output_bfd,
stub_file->the_bfd,
&link_info, 0))
/* Now build the linker stubs. */
if (stub_file->the_bfd->sections != NULL)
{
einfo ("%X%P: can not size stub section: %E\n");
return;
/* Call again the trampoline analyzer to initialize the trampoline
stubs with the correct symbol addresses. Since there could have
been relaxation, the symbol addresses that were found during
first call may no longer be correct. */
if (!elf32_m68hc11_size_stubs (link_info.output_bfd,
stub_file->the_bfd,
&link_info, 0))
{
einfo ("%X%P: can not size stub section: %E\n");
return;
}
if (!elf32_m68hc11_build_stubs (link_info.output_bfd, &link_info))
einfo ("%X%P: can not build stubs: %E\n");
}
if (!elf32_m68hc11_build_stubs (link_info.output_bfd, &link_info))
einfo ("%X%P: can not build stubs: %E\n");
}
gld${EMULATION_NAME}_after_allocation ();

View File

@ -2,7 +2,7 @@
#source: pr21884b.s
#ld: -T pr21884.t
#objdump: -b binary -s
#notarget: aarch64*-*-* arm*-*-* nds32*-*-*
#notarget: aarch64*-*-* arm*-*-* avr-*-* hppa-*-* ia64-*-* m68hc1*-*-* nds32*-*-* score-*-*
# Skip targets which can't change output format to binary.
.*: file format binary

View File

@ -1,5 +1,6 @@
#ld: --oformat binary -T pr21529.ld -e main
#objdump: -s -b binary
#xfail: aarch64*-*-* arm*-*-* hppa-*-* ia64-*-* nds32*-*-* score-*-*
#notarget: aarch64*-*-* arm*-*-* avr-*-* hppa-*-* ia64-*-* m68hc1*-*-* nds32*-*-* score-*-*
# Skip targets which can't change output format to binary.
#pass