xref: /netbsd-src/external/gpl3/binutils.old/dist/ld/emultempl/scoreelf.em (revision 4439cfd0acf9c7dc90625e5cd83b2317a9ab8967)
1# This shell script emits a C file. -*- C -*-
2#   Copyright (C) 2006-2022 Free Software Foundation, Inc.
3#   Contributed by:
4#   Brain.lin (brain.lin@sunplusct.com)
5#   Mei Ligang (ligang@sunnorth.com.cn)
6#   Pei-Lin Tsai (pltsai@sunplus.com)
7
8# This file is part of the GNU Binutils.
9#
10# This program is free software; you can redistribute it and/or modify
11# it under the terms of the GNU General Public License as published by
12# the Free Software Foundation; either version 3 of the License, or
13# (at your option) any later version.
14#
15# This program is distributed in the hope that it will be useful,
16# but WITHOUT ANY WARRANTY; without even the implied warranty of
17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18# GNU General Public License for more details.
19#
20# You should have received a copy of the GNU General Public License
21# along with this program; if not, write to the Free Software
22# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
23# MA 02110-1301, USA.
24#
25
26# This file is sourced from elf.em, and defines extra score-elf
27# specific routines.
28#
29fragment <<EOF
30
31#include "elf32-score.h"
32
33static void
34gld${EMULATION_NAME}_before_parse (void)
35{
36#ifndef TARGET_			/* I.e., if not generic.  */
37  ldfile_set_output_arch ("`echo ${ARCH}`", bfd_arch_unknown);
38#endif /* not TARGET_ */
39  input_flags.dynamic = ${DYNAMIC_LINK-true};
40  config.has_shared = `if test -n "$GENERATE_SHLIB_SCRIPT" ; then echo true ; else echo false ; fi`;
41  config.separate_code = `if test "x${SEPARATE_CODE}" = xyes ; then echo true ; else echo false ; fi`;
42  link_info.check_relocs_after_open_input = true;
43EOF
44if test -n "$COMMONPAGESIZE"; then
45fragment <<EOF
46  link_info.relro = DEFAULT_LD_Z_RELRO;
47EOF
48fi
49fragment <<EOF
50  link_info.separate_code = DEFAULT_LD_Z_SEPARATE_CODE;
51  link_info.warn_execstack = DEFAULT_LD_WARN_EXECSTACK;
52  link_info.no_warn_rwx_segments = ! DEFAULT_LD_WARN_RWX_SEGMENTS;
53  link_info.default_execstack = DEFAULT_LD_EXECSTACK;
54}
55
56static void
57score_elf_after_open (void)
58{
59  if (strstr (bfd_get_target (link_info.output_bfd), "score") == NULL)
60    {
61      /* The score backend needs special fields in the output hash structure.
62	 These will only be created if the output format is an score format,
63	 hence we do not support linking and changing output formats at the
64	 same time.  Use a link followed by objcopy to change output formats.  */
65      einfo (_("%F%P: error: cannot change output format "
66	       "whilst linking %s binaries\n"), "S+core");
67      return;
68    }
69
70  /* Call the standard elf routine.  */
71  gld${EMULATION_NAME}_after_open ();
72}
73
74EOF
75
76# Define some shell vars to insert bits of code into the standard elf
77# parse_args and list_options functions.
78#
79PARSE_AND_LIST_PROLOGUE=''
80PARSE_AND_LIST_SHORTOPTS=
81PARSE_AND_LIST_LONGOPTS=''
82PARSE_AND_LIST_OPTIONS=''
83PARSE_AND_LIST_ARGS_CASES=''
84
85# We have our own after_open and before_allocation functions, but they call
86# the standard routines, so give them a different name.
87LDEMUL_AFTER_OPEN=score_elf_after_open
88
89# Replace the elf before_parse function with our own.
90LDEMUL_BEFORE_PARSE=gld"${EMULATION_NAME}"_before_parse
91