From 92b93329b58c744ea269b50f6278ed99416941a9 Mon Sep 17 00:00:00 2001 From: Roland McGrath Date: Thu, 19 Jul 2007 19:56:10 +0000 Subject: [PATCH] 2007-07-19 Roland McGrath * genscripts.sh (source_em, fragment): New sh functions. Truncate e${EMULATION_NAME}.c file before .em script fills it. Use source_em in place of . for the .em script. * emultempl/generic.em: Use fragment and source_em functions. * emultempl/aix.em: Likewise. * emultempl/alphaelf.em: Likewise. * emultempl/armcoff.em: Likewise. * emultempl/armelf.em: Likewise. * emultempl/avrelf.em: Likewise. * emultempl/beos.em: Likewise. * emultempl/cr16elf.em: Likewise. * emultempl/crxelf.em: Likewise. * emultempl/elf-generic.em: Likewise. * emultempl/elf32.em: Likewise. * emultempl/genelf.em: Likewise. * emultempl/gld960.em: Likewise. * emultempl/gld960c.em: Likewise. * emultempl/hppaelf.em: Likewise. * emultempl/ia64elf.em: Likewise. * emultempl/irix.em: Likewise. * emultempl/linux.em: Likewise. * emultempl/lnk960.em: Likewise. * emultempl/m68hc1xelf.em: Likewise. * emultempl/m68kcoff.em: Likewise. * emultempl/m68kelf.em: Likewise. * emultempl/mipsecoff.em: Likewise. * emultempl/mipself.em: Likewise. * emultempl/mmix-elfnmmo.em: Likewise. * emultempl/mmixelf.em: Likewise. * emultempl/mmo.em: Likewise. * emultempl/needrelax.em: Likewise. * emultempl/netbsd.em: Likewise. * emultempl/pe.em: Likewise. * emultempl/pep.em: Likewise. * emultempl/ppc32elf.em: Likewise. * emultempl/ppc64elf.em: Likewise. * emultempl/scoreelf.em: Likewise. * emultempl/sh64elf.em: Likewise. * emultempl/spuelf.em: Likewise. * emultempl/sunos.em: Likewise. * emultempl/ticoff.em: Likewise. * emultempl/vanilla.em: Likewise. * emultempl/vxworks.em: Likewise. * emultempl/xtensaelf.em: Likewise. * emultempl/z80.em: Likewise. --- ld/emultempl/aix.em | 8 +-- ld/emultempl/alphaelf.em | 2 +- ld/emultempl/armcoff.em | 8 +-- ld/emultempl/armelf.em | 4 +- ld/emultempl/avrelf.em | 22 +++---- ld/emultempl/beos.em | 6 +- ld/emultempl/cr16elf.em | 3 +- ld/emultempl/crxelf.em | 3 +- ld/emultempl/elf-generic.em | 2 +- ld/emultempl/elf32.em | 122 +++++++++++++++++------------------ ld/emultempl/genelf.em | 6 +- ld/emultempl/generic.em | 14 ++-- ld/emultempl/gld960.em | 8 +-- ld/emultempl/gld960c.em | 8 +-- ld/emultempl/hppaelf.em | 2 +- ld/emultempl/ia64elf.em | 4 +- ld/emultempl/irix.em | 4 +- ld/emultempl/linux.em | 8 +-- ld/emultempl/lnk960.em | 8 +-- ld/emultempl/m68hc1xelf.em | 2 +- ld/emultempl/m68kcoff.em | 8 +-- ld/emultempl/m68kelf.em | 2 +- ld/emultempl/mipsecoff.em | 2 +- ld/emultempl/mipself.em | 2 +- ld/emultempl/mmix-elfnmmo.em | 2 +- ld/emultempl/mmixelf.em | 4 +- ld/emultempl/mmo.em | 8 +-- ld/emultempl/needrelax.em | 2 +- ld/emultempl/netbsd.em | 2 +- ld/emultempl/pe.em | 14 ++-- ld/emultempl/pep.em | 12 ++-- ld/emultempl/ppc32elf.em | 4 +- ld/emultempl/ppc64elf.em | 4 +- ld/emultempl/scoreelf.em | 5 +- ld/emultempl/sh64elf.em | 2 +- ld/emultempl/spuelf.em | 6 +- ld/emultempl/sunos.em | 16 ++--- ld/emultempl/ticoff.em | 8 +-- ld/emultempl/vanilla.em | 2 +- ld/emultempl/vxworks.em | 6 +- ld/emultempl/xtensaelf.em | 29 ++++----- ld/emultempl/z80.em | 16 ++--- ld/genscripts.sh | 30 ++++++++- 43 files changed, 227 insertions(+), 203 deletions(-) diff --git a/ld/emultempl/aix.em b/ld/emultempl/aix.em index df983b14a8e..9aa0d500aee 100644 --- a/ld/emultempl/aix.em +++ b/ld/emultempl/aix.em @@ -5,7 +5,7 @@ if [ -z "$MACHINE" ]; then else OUTPUT_ARCH=${ARCH}:${MACHINE} fi -cat >e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <> e${EMULATION_NAME}.c else # Scripts read from the filesystem. -cat >>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <> e${EMULATION_NAME}.c else # Scripts read from the filesystem. -cat >>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <the_bfd, avr_stub_section, flags)) goto err_ret; avr_stub_section->alignment_power = 1; - + ldlang_add_file (stub_file); return; @@ -147,7 +147,7 @@ avr_elf_create_output_section_statements (void) static void avr_elf_finish (void) -{ +{ if (!avr_no_stubs) { /* Now build the linker stubs. */ @@ -185,15 +185,15 @@ PARSE_AND_LIST_PROLOGUE=' ' PARSE_AND_LIST_LONGOPTS=' - { "no-call-ret-replacement", no_argument, + { "no-call-ret-replacement", no_argument, NULL, OPTION_NO_CALL_RET_REPLACEMENT}, - { "pmem-wrap-around", required_argument, + { "pmem-wrap-around", required_argument, NULL, OPTION_PMEM_WRAP_AROUND}, - { "no-stubs", no_argument, + { "no-stubs", no_argument, NULL, OPTION_NO_STUBS}, - { "debug-stubs", no_argument, + { "debug-stubs", no_argument, NULL, OPTION_DEBUG_STUBS}, - { "debug-relax", no_argument, + { "debug-relax", no_argument, NULL, OPTION_DEBUG_RELAX}, ' @@ -227,7 +227,7 @@ PARSE_AND_LIST_OPTIONS=' PARSE_AND_LIST_ARGS_CASES=' case OPTION_PMEM_WRAP_AROUND: - { + { /* This variable is defined in the bfd library. */ if ((!strcmp (optarg,"32k")) || (!strcmp (optarg,"32K"))) avr_pc_wrap_around = 32768; diff --git a/ld/emultempl/beos.em b/ld/emultempl/beos.em index 34becadc383..23d3849c5d7 100644 --- a/ld/emultempl/beos.em +++ b/ld/emultempl/beos.em @@ -5,7 +5,7 @@ if [ -z "$MACHINE" ]; then else OUTPUT_ARCH=${ARCH}:${MACHINE} fi -cat >e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <> e${EMULATION_NAME}.c sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c echo '; }' >> e${EMULATION_NAME}.c -cat >>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c < #endif @@ -81,9 +81,9 @@ fi # Import any needed special functions and/or overrides. # -. ${srcdir}/emultempl/elf-generic.em +source_em ${srcdir}/emultempl/elf-generic.em if test -n "$EXTRA_EM_FILE" ; then -. ${srcdir}/emultempl/${EXTRA_EM_FILE}.em + source_em ${srcdir}/emultempl/${EXTRA_EM_FILE}.em fi # Functions in this file can be overridden by setting the LDEMUL_* shell @@ -93,7 +93,7 @@ fi # as presumably it is called from the overriding function. # if test x"$LDEMUL_BEFORE_PARSE" != xgld"$EMULATION_NAME"_before_parse; then -cat >>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c < @@ -598,7 +598,7 @@ EOF ;; *-*-linux-* | *-*-k*bsd*-*) - cat >>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <next) @@ -1247,7 +1247,7 @@ fi if [ "x${USE_LIBPATH}" = xyes ] ; then case ${target} in *-*-freebsd* | *-*-dragonfly*) - cat >>e${EMULATION_NAME}.c <name, force)) break; EOF @@ -1256,7 +1256,7 @@ EOF *-*-linux-* | *-*-k*bsd*-*) # Linux - cat >>e${EMULATION_NAME}.c <name, force)) break; @@ -1264,7 +1264,7 @@ EOF ;; esac fi -cat >>e${EMULATION_NAME}.c <name); for (search = search_head; search != NULL; search = search->next) { @@ -1282,7 +1282,7 @@ cat >>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <> e${EMULATION_NAME}.c else # Scripts read from the filesystem. -cat >>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <> e${EMULATION_NAME}.c else # Scripts read from the filesystem. -cat >>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <> e${EMULATION_NAME}.c else # Scripts read from the filesystem. -cat >>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <> e${EMULATION_NAME}.c else # Scripts read from the filesystem. -cat >>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <> e${EMULATION_NAME}.c else # Scripts read from the filesystem. -cat >>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <> e${EMULATION_NAME}.c else # Scripts read from the filesystem. -cat >>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <> e${EMULATION_NAME}.c else # Scripts read from the filesystem. -cat >>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <e${EMULATION_NAME}.c # there, now line numbers match ;-) -cat >>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <flags & SEC_CODE) && sec->reloc_count) stub_sec = sec; } - + if (is_imp && stub_sec) { long symsize; @@ -1780,7 +1780,7 @@ gld_${EMULATION_NAME}_open_dynamic_archive For backwards compatibility, libfoo.a needs to precede libfoo.dll and foo.dll in the search. */ { "lib%s.a", FALSE }, - /* The 'native' spelling of an import lib name is "foo.lib". */ + /* The 'native' spelling of an import lib name is "foo.lib". */ { "%s.lib", FALSE }, #ifdef DLL_SUPPORT /* Try "foo.dll" (preferred dll name, if specified). */ @@ -1837,7 +1837,7 @@ gld_${EMULATION_NAME}_open_dynamic_archive for (i = 0; libname_fmt[i].format; i++) { -#ifdef DLL_SUPPORT +#ifdef DLL_SUPPORT if (libname_fmt[i].use_prefix) { if (!pe_dll_search_prefix) @@ -1877,7 +1877,7 @@ EOF # sed commands to quote an ld script as a C string. sc="-f stringify.sed" -cat >>e${EMULATION_NAME}.c <> e${EMULATION_NAME}.c sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c echo '; }' >> e${EMULATION_NAME}.c -cat >>e${EMULATION_NAME}.c <e${EMULATION_NAME}.c # there, now line numbers match ;-) -cat >>e${EMULATION_NAME}.c <foo.dll" (preferred dll name, if specified). */ @@ -1616,7 +1616,7 @@ gld_${EMULATION_NAME}_open_dynamic_archive for (i = 0; libname_fmt[i].format; i++) { -#ifdef DLL_SUPPORT +#ifdef DLL_SUPPORT if (libname_fmt[i].use_prefix) { if (!pep_dll_search_prefix) @@ -1656,7 +1656,7 @@ EOF # sed commands to quote an ld script as a C string. sc="-f stringify.sed" -cat >>e${EMULATION_NAME}.c <> e${EMULATION_NAME}.c sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c echo '; }' >> e${EMULATION_NAME}.c -cat >>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <> e${EMULATION_NAME}.c -cat >>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c < #include diff --git a/ld/emultempl/sunos.em b/ld/emultempl/sunos.em index 2aa23524ade..00d949ffef7 100644 --- a/ld/emultempl/sunos.em +++ b/ld/emultempl/sunos.em @@ -5,7 +5,7 @@ if [ -z "$MACHINE" ]; then else OUTPUT_ARCH=${ARCH}:${MACHINE} fi -cat >e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <next) @@ -961,7 +961,7 @@ then # sed commands to quote an ld script as a C string. sc="-f stringify.sed" -cat >>e${EMULATION_NAME}.c <> e${EMULATION_NAME} else # Scripts read from the filesystem. -cat >>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <e${EMULATION_NAME}.c # there, now line numbers match ;-) -cat >>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c < #include "../bfd/elf-bfd.h" @@ -104,7 +104,7 @@ replace_insn_sec_with_prop_sec (bfd *abfd, Elf_Internal_Shdr *symtab_hdr; Elf_Internal_Rela *internal_relocs = NULL; unsigned reloc_count; - + *error_message = ""; insn_sec = bfd_get_section_by_name (abfd, insn_sec_name); if (insn_sec == NULL) @@ -117,7 +117,7 @@ replace_insn_sec_with_prop_sec (bfd *abfd, *error_message = _("file already has property tables"); return FALSE; } - + if (insn_sec->size != 0) { insn_contents = (bfd_byte *) bfd_malloc (insn_sec->size); @@ -144,7 +144,7 @@ replace_insn_sec_with_prop_sec (bfd *abfd, *error_message = _("could not create new section"); goto cleanup; } - + prop_sec->size = entry_count * 12; prop_contents = (bfd_byte *) bfd_zalloc (abfd, prop_sec->size); elf_section_data (prop_sec)->this_hdr.contents = prop_contents; @@ -153,7 +153,7 @@ replace_insn_sec_with_prop_sec (bfd *abfd, the number of relocations since it does not use reloc_count. */ elf_section_data (prop_sec)->rel_hdr.sh_entsize = sizeof (Elf32_External_Rela); - elf_section_data (prop_sec)->rel_hdr.sh_size = + elf_section_data (prop_sec)->rel_hdr.sh_size = elf_section_data (insn_sec)->rel_hdr.sh_size; if (prop_contents == NULL && prop_sec->size != 0) @@ -169,12 +169,12 @@ replace_insn_sec_with_prop_sec (bfd *abfd, /* If there is already an internal_reloc, then save it so that the read_relocs function freshly allocates a copy. */ Elf_Internal_Rela *saved_relocs = elf_section_data (insn_sec)->relocs; - + elf_section_data (insn_sec)->relocs = NULL; - internal_relocs = + internal_relocs = _bfd_elf_link_read_relocs (abfd, insn_sec, NULL, NULL, FALSE); elf_section_data (insn_sec)->relocs = saved_relocs; - + if (internal_relocs == NULL) { *error_message = _("out of memory"); @@ -188,7 +188,7 @@ replace_insn_sec_with_prop_sec (bfd *abfd, elf_section_data (prop_sec)->relocs = internal_relocs; prop_sec->reloc_count = reloc_count; } - + /* Now copy each insn table entry to the prop table entry with appropriate flags. */ for (entry = 0; entry < entry_count; ++entry) @@ -218,7 +218,7 @@ replace_insn_sec_with_prop_sec (bfd *abfd, rela = &internal_relocs[i]; - /* If this relocation is to the .xt.insn section, + /* If this relocation is to the .xt.insn section, change the section number and the offset. */ r_offset = rela->r_offset; r_offset += 4 * (r_offset / 8); @@ -227,10 +227,10 @@ replace_insn_sec_with_prop_sec (bfd *abfd, } remove_section (abfd, insn_sec); - + if (insn_contents) free (insn_contents); - + return TRUE; cleanup: @@ -258,7 +258,7 @@ replace_instruction_table_sections (bfd *abfd, asection *sec) char *prop_sec_name = NULL; char *owned_prop_sec_name = NULL; const char *sec_name; - + sec_name = bfd_get_section_name (abfd, sec); if (strcmp (sec_name, INSN_SEC_BASE_NAME) == 0) { @@ -297,7 +297,7 @@ elf_xtensa_after_open (void) { /* First call the ELF version. */ gld${EMULATION_NAME}_after_open (); - + /* Now search the input files looking for instruction table sections. */ LANG_FOR_EACH_INPUT_STATEMENT (f) { @@ -2024,4 +2024,3 @@ LDEMUL_BEFORE_PARSE=elf_xtensa_before_parse LDEMUL_AFTER_OPEN=elf_xtensa_after_open LDEMUL_CHOOSE_TARGET=elf_xtensa_choose_target LDEMUL_BEFORE_ALLOCATION=elf_xtensa_before_allocation - diff --git a/ld/emultempl/z80.em b/ld/emultempl/z80.em index 98b45787e4f..7b17e8fc2b1 100644 --- a/ld/emultempl/z80.em +++ b/ld/emultempl/z80.em @@ -23,7 +23,7 @@ LDEMUL_BEFORE_PARSE=gldz80_before_parse LDEMUL_RECOGNIZED_FILE=gldz80_recognized_file LDEMUL_AFTER_OPEN=gldz80_after_open -cat >>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <the_bfd); - switch (mach_type) + switch (mach_type) { - case bfd_mach_z80strict: - result_mach_type |= M_Z80STRICT; + case bfd_mach_z80strict: + result_mach_type |= M_Z80STRICT; break; case bfd_mach_z80: - result_mach_type |= M_Z80; + result_mach_type |= M_Z80; break; case bfd_mach_z80full: - result_mach_type |= M_Z80FULL; + result_mach_type |= M_Z80FULL; break; case bfd_mach_r800: - result_mach_type |= M_R800; + result_mach_type |= M_R800; break; default: result_mach_type |= M_Z80ANY; diff --git a/ld/genscripts.sh b/ld/genscripts.sh index f4c4709d694..17c516c4790 100755 --- a/ld/genscripts.sh +++ b/ld/genscripts.sh @@ -393,5 +393,33 @@ case " $EMULATION_LIBPATH " in *" ${EMULATION_NAME} "*) COMPILE_IN=true;; esac +if test -n "${BASH+set}"; then + source_em() + { + local current_script="$em_script" + em_script=$1 + . $em_script + em_script=$current_script + } + fragment() + { + local lineno=$[${BASH_LINENO[0]} + 1] + echo >> e${EMULATION_NAME}.c "#line $lineno \"$em_script\"" + cat >> e${EMULATION_NAME}.c + } +else + source_em() + { + . $1 + } + fragment() + { + cat >> e${EMULATION_NAME}.c + } +fi + # Generate e${EMULATION_NAME}.c. -. ${srcdir}/emultempl/${TEMPLATE_NAME-generic}.em +# Start with an empty file, then the sourced .em script +# can use the "fragment" function to append. +> e${EMULATION_NAME}.c +source_em ${srcdir}/emultempl/${TEMPLATE_NAME-generic}.em -- 2.30.2