binutils-gdb/ld/emultempl/ticoff.em
H.J. Lu a92613915e ld: Add emultempl/emulation.em
Add emultempl/emulation.em to define ld_${EMULATION_NAME}_emulation so
that new emulation hooks can be added easily.

	* emultempl/aix.em (LDEMUL_AFTER_OPEN): New.
	(LDEMUL_SET_OUTPUT_ARCH): Likewise.
	(LDEMUL_CHOOSE_TARGET): Likewise.
	(LDEMUL_BEFORE_ALLOCATION): Likewise.
	(LDEMUL_CREATE_OUTPUT_SECTION_STATEMENTS): Likewise.
	(LDEMUL_OPEN_DYNAMIC_ARCHIVE): Likewise.
	(LDEMUL_PARSE_ARGS): Likewise.
	(LDEMUL_ADD_OPTIONS): Likewise.
	(LDEMUL_HANDLE_OPTION): Likewise.
	(LDEMUL_UNRECOGNIZED_FILE): Likewise.
	(LDEMUL_PRINT_SYMBOL): Likewise.
	(ld_${EMULATION_NAME}_emulation): Removed.
	Source ${srcdir}/emultempl/emulation.em.
	* emultempl/beos.em (gld_${EMULATION_NAME}_before_parse):
	Renamed to ...
	(gld${EMULATION_NAME}_before_parse): This.
	(gld_${EMULATION_NAME}_set_symbols): Renamed to ...
	(gld${EMULATION_NAME}_set_symbols): This.
	(gld_${EMULATION_NAME}_after_open): Renamed to ...
	(gld${EMULATION_NAME}_after_open): This.
	(gld_${EMULATION_NAME}_before_allocation): Renamed to ...
	(gld${EMULATION_NAME}_before_allocation): This.
	(gld_${EMULATION_NAME}_get_script): Renamed to ...
	(gld${EMULATION_NAME}_get_script): This.
	(LDEMUL_AFTER_OPEN): New.
	(LDEMUL_BEFORE_ALLOCATION): Likewise.
	(LDEMUL_PLACE_ORPHAN): Likewise.
	(LDEMUL_SET_SYMBOLS): Likewise.
	(LDEMUL_ADD_OPTIONS): Likewise.
	(LDEMUL_HANDLE_OPTION): Likewise.
	(ld_${EMULATION_NAME}_emulation): Removed.
	Source ${srcdir}/emultempl/emulation.em.
	* emultempl/elf.em (LDEMUL_AFTER_PARSE): New.
	(LDEMUL_AFTER_OPEN): Likewise.
	(LDEMUL_BEFORE_PLACE_ORPHANS): Likewise.
	(LDEMUL_AFTER_ALLOCATION): Likewise.
	(LDEMUL_SET_OUTPUT_ARCH): Likewise.
	(LDEMUL_BEFORE_ALLOCATION): Likewise.
	(LDEMUL_OPEN_DYNAMIC_ARCHIVE): Likewise.
	(LDEMUL_PLACE_ORPHAN): Likewise.
	(LDEMUL_ADD_OPTIONS): Likewise.
	(LDEMUL_HANDLE_OPTION): Likewise.
	(LDEMUL_LIST_OPTIONS): Likewise.
	(LDEMUL_UNRECOGNIZED_FILE): Likewise.
	(ld_${EMULATION_NAME}_emulation): Removed.
	Source ${srcdir}/emultempl/emulation.em.
	* emultempl/emulation.em: New file.
	* emultempl/generic.em (ld_${EMULATION_NAME}_emulation): Removed.
	Source ${srcdir}/emultempl/emulation.em.
	* emultempl/msp430.em (LDEMUL_AFTER_OPEN): New.
	(LDEMUL_AFTER_ALLOCATION): Likewise.
	(LDEMUL_PLACE_ORPHAN): Likewise.
	(LDEMUL_FINISH): Likewise.
	(LDEMUL_ADD_OPTIONS): Likewise.
	(LDEMUL_HANDLE_OPTION): Likewise.
	(LDEMUL_LIST_OPTIONS): Likewise.
	(ld_${EMULATION_NAME}_emulation): Removed.
	Source ${srcdir}/emultempl/emulation.em.
	* emultempl/pe.em (gld_${EMULATION_NAME}_before_parse): Renamed
	to ...
	(gld${EMULATION_NAME}_before_parse): This.
	(gld_${EMULATION_NAME}_list_options): Renamed to ...
	(gld${EMULATION_NAME}_list_options): This.
	(gld_${EMULATION_NAME}_set_symbols): Renamed to ...
	(gld${EMULATION_NAME}_set_symbols): This.
	(gld_${EMULATION_NAME}_after_parse): Renamed to ...
	(gld${EMULATION_NAME}_after_parse): This.
	(gld_${EMULATION_NAME}_after_open): Renamed to ...
	(gld${EMULATION_NAME}_after_open): This.
	(gld_${EMULATION_NAME}_before_allocation): Renamed to ...
	(gld${EMULATION_NAME}_before_allocation): This.
	(gld_${EMULATION_NAME}_unrecognized_file): Renamed to ...
	(gld${EMULATION_NAME}_unrecognized_file): This.
	(gld_${EMULATION_NAME}_recognized_file): Renamed to ...
	(gld${EMULATION_NAME}_recognized_file): This.
	(gld_${EMULATION_NAME}_finish): Renamed to ...
	(gld${EMULATION_NAME}_finish): This.
	(gld_${EMULATION_NAME}_place_orphan): Renamed to ...
	(gld${EMULATION_NAME}_place_orphan): This.
	(gld_${EMULATION_NAME}_open_dynamic_archive): Renamed to ...
	(gld${EMULATION_NAME}_open_dynamic_archive): This.
	(gld_${EMULATION_NAME}_find_potential_libraries): Renamed to ...
	(gld${EMULATION_NAME}_find_potential_libraries): This.
	(gld_${EMULATION_NAME}_get_script): Renamed to ...
	(gld${EMULATION_NAME}_get_script): This.
	(LDEMUL_AFTER_PARSE): New.
	(LDEMUL_AFTER_OPEN): Likewise.
	(LDEMUL_BEFORE_ALLOCATION): Likewise.
	(LDEMUL_FINISH=): Likewise.
	(LDEMUL_OPEN_DYNAMIC_ARCHIVE): Likewise.
	(LDEMUL_PLACE_ORPHAN): Likewise.
	(LDEMUL_SET_SYMBOLS): Likewise.
	(LDEMUL_ADD_OPTIONS): Likewise.
	(LDEMUL_HANDLE_OPTION): Likewise.
	(LDEMUL_UNRECOGNIZED_FILE): Likewise.
	(LDEMUL_LIST_OPTIONS): Likewise.
	(LDEMUL_RECOGNIZED_FILE): Likewise.
	(LDEMUL_FIND_POTENTIAL_LIBRARIES): Likewise.
	(ld_${EMULATION_NAME}_emulation): Removed.
	Source ${srcdir}/emultempl/emulation.em.
	* emultempl/pep.em (gld_${EMULATION_NAME}_before_parse): Renamed
	to ...
	(gld${EMULATION_NAME}_before_parse): This.
	(gld_${EMULATION_NAME}_list_options): Renamed to ...
	(gld${EMULATION_NAME}_list_options): This.
	(gld_${EMULATION_NAME}_set_symbols): Renamed to ...
	(gld${EMULATION_NAME}_set_symbols): This.
	(gld_${EMULATION_NAME}_after_parse): Renamed to ...
	(gld${EMULATION_NAME}_after_parse): This.
	(gld_${EMULATION_NAME}_after_open): Renamed to ...
	(gld${EMULATION_NAME}_after_open): This.
	(gld_${EMULATION_NAME}_before_allocation): Renamed to ...
	(gld${EMULATION_NAME}_before_allocation): This.
	(gld_${EMULATION_NAME}_unrecognized_file): Renamed to ...
	(gld${EMULATION_NAME}_unrecognized_file): This.
	(gld_${EMULATION_NAME}_recognized_file): Renamed to ...
	(gld${EMULATION_NAME}_recognized_file): This.
	(gld_${EMULATION_NAME}_finish): Renamed to ...
	(gld${EMULATION_NAME}_finish): This.
	(gld_${EMULATION_NAME}_place_orphan): Renamed to ...
	(gld${EMULATION_NAME}_place_orphan): This.
	(gld_${EMULATION_NAME}_open_dynamic_archive): Renamed to ...
	(gld${EMULATION_NAME}_open_dynamic_archive): This.
	(gld_${EMULATION_NAME}_find_potential_libraries): Renamed to ...
	(gld${EMULATION_NAME}_find_potential_libraries): This.
	(gld_${EMULATION_NAME}_get_script): Renamed to ...
	(gld${EMULATION_NAME}_get_script): This.
	(LDEMUL_AFTER_PARSE): New.
	(LDEMUL_AFTER_OPEN): Likewise.
	(LDEMUL_BEFORE_ALLOCATION): Likewise.
	(LDEMUL_FINISH=): Likewise.
	(LDEMUL_OPEN_DYNAMIC_ARCHIVE): Likewise.
	(LDEMUL_PLACE_ORPHAN): Likewise.
	(LDEMUL_SET_SYMBOLS): Likewise.
	(LDEMUL_ADD_OPTIONS): Likewise.
	(LDEMUL_HANDLE_OPTION): Likewise.
	(LDEMUL_UNRECOGNIZED_FILE): Likewise.
	(LDEMUL_LIST_OPTIONS): Likewise.
	(LDEMUL_RECOGNIZED_FILE): Likewise.
	(LDEMUL_FIND_POTENTIAL_LIBRARIES): Likewise.
	(ld_${EMULATION_NAME}_emulation): Removed.
	Source ${srcdir}/emultempl/emulation.em.
	* emultempl/ticoff.em (gld_${EMULATION_NAME}_list_options):
	Renamed to ...
	(gld${EMULATION_NAME}_list_options): This.
	(gld_${EMULATION_NAME}_before_parse): Renamed to ...
	(gld_${EMULATION_NAME}_get_script): Renamed to ...
	(gld${EMULATION_NAME}_get_script): This.
	(LDEMUL_ADD_OPTIONS): New.
	(LDEMUL_HANDLE_OPTION): Likewise.
	(LDEMUL_LIST_OPTIONS): Likewise.
	(ld_${EMULATION_NAME}_emulation): Removed.
	Source ${srcdir}/emultempl/emulation.em.
	* emultempl/vanilla.em (LDEMUL_BEFORE_PARSE): New.
	(LDEMUL_SET_OUTPUT_ARCH): Likewise.
	(LDEMUL_GET_SCRIPT): Likewise.
	(EMULATION_NAME): Likewise.
	(OUTPUT_FORMAT): Likewise.
	(ld_vanilla_emulation): Removed.
	Source ${srcdir}/emultempl/emulation.em.
2022-02-06 06:25:41 -08:00

162 lines
4.3 KiB
Plaintext

# This shell script emits a C file. -*- C -*-
# It does some substitutions.
(echo;echo;echo;echo)>e${EMULATION_NAME}.c # there, now line numbers match ;-)
fragment <<EOF
/* This file is part of GLD, the Gnu Linker.
Copyright (C) 1999-2022 Free Software Foundation, Inc.
This file is part of the GNU Binutils.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
MA 02110-1301, USA. */
/* For TI COFF */
/* Need to determine load and run pages for output sections */
#define TARGET_IS_${EMULATION_NAME}
#include "sysdep.h"
#include "bfd.h"
#include "bfdlink.h"
#include "ctf-api.h"
#include "getopt.h"
#include "ld.h"
#include "ldmain.h"
#include "ldmisc.h"
#include "ldexp.h"
#include "ldlang.h"
#include "ldfile.h"
#include "ldemul.h"
static int coff_version;
/* TI COFF extra command line options */
#define OPTION_COFF_FORMAT (300 + 1)
static void
gld${EMULATION_NAME}_add_options
(int ns ATTRIBUTE_UNUSED, char **shortopts ATTRIBUTE_UNUSED, int nl,
struct option **longopts, int nrl ATTRIBUTE_UNUSED,
struct option **really_longopts ATTRIBUTE_UNUSED)
{
static const struct option xtra_long[] = {
/* TI COFF options */
{"format", required_argument, NULL, OPTION_COFF_FORMAT },
{NULL, no_argument, NULL, 0}
};
*longopts = (struct option *)
xrealloc (*longopts, nl * sizeof (struct option) + sizeof (xtra_long));
memcpy (*longopts + nl, &xtra_long, sizeof (xtra_long));
}
static void
gld${EMULATION_NAME}_list_options (FILE * file)
{
fprintf (file, _(" --format 0|1|2 Specify which COFF version to use\n"));
}
static bool
gld${EMULATION_NAME}_handle_option (int optc)
{
switch (optc)
{
default:
return false;
case OPTION_COFF_FORMAT:
if ((*optarg == '0' || *optarg == '1' || *optarg == '2')
&& optarg[1] == '\0')
{
static char buf[] = "coffX-${OUTPUT_FORMAT_TEMPLATE}";
coff_version = *optarg - '0';
buf[4] = *optarg;
lang_add_output_format (buf, NULL, NULL, 0);
}
else
{
einfo (_("%F%P: invalid COFF format version %s\n"), optarg);
}
break;
}
return false;
}
static void
gld${EMULATION_NAME}_before_parse(void)
{
#ifndef TARGET_ /* I.e., if not generic. */
ldfile_set_output_arch ("`echo ${ARCH}`", bfd_arch_unknown);
#endif /* not TARGET_ */
}
static char *
gld${EMULATION_NAME}_get_script (int *isfile)
EOF
if test x"$COMPILE_IN" = xyes
then
# Scripts compiled in.
# sed commands to quote an ld script as a C string.
sc='s/["\\]/\\&/g
s/$/\\n\\/
1s/^/"/
$s/$/n"/
'
fragment <<EOF
{
*isfile = 0;
if (bfd_link_relocatable (&link_info) && config.build_constructors)
return `sed "$sc" ldscripts/${EMULATION_NAME}.xu`;
else if (bfd_link_relocatable (&link_info))
return `sed "$sc" ldscripts/${EMULATION_NAME}.xr`;
else if (!config.text_read_only)
return `sed "$sc" ldscripts/${EMULATION_NAME}.xbn`;
else if (!config.magic_demand_paged)
return `sed "$sc" ldscripts/${EMULATION_NAME}.xn`;
else
return `sed "$sc" ldscripts/${EMULATION_NAME}.x`;
}
EOF
else
# Scripts read from the filesystem.
fragment <<EOF
{
*isfile = 1;
if (bfd_link_relocatable (&link_info) && config.build_constructors)
return "ldscripts/${EMULATION_NAME}.xu";
else if (bfd_link_relocatable (&link_info))
return "ldscripts/${EMULATION_NAME}.xr";
else if (!config.text_read_only)
return "ldscripts/${EMULATION_NAME}.xbn";
else if (!config.magic_demand_paged)
return "ldscripts/${EMULATION_NAME}.xn";
else
return "ldscripts/${EMULATION_NAME}.x";
}
EOF
fi
LDEMUL_ADD_OPTIONS=gld${EMULATION_NAME}_add_options
LDEMUL_HANDLE_OPTION=gld${EMULATION_NAME}_handle_option
LDEMUL_LIST_OPTIONS=gld${EMULATION_NAME}_list_options
source_em ${srcdir}/emultempl/emulation.em