ld message translation for emultempl and emulparams
[deliverable/binutils-gdb.git] / ld / emultempl / cr16elf.em
CommitLineData
3d3d428f 1# This shell script emits a C file. -*- C -*-
219d1afa 2# Copyright (C) 2007-2018 Free Software Foundation, Inc.
3d3d428f
NC
3# Contributed by M R Swami Reddy <MR.Swami.Reddy@nsc.com>
4#
f96b4a7b 5# This file is part of the GNU Binutils.
3d3d428f
NC
6#
7# This program is free software; you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
f96b4a7b 9# the Free Software Foundation; either version 3 of the License, or
3d3d428f
NC
10# (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with this program; if not, write to the Free Software
f96b4a7b
NC
19# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20# MA 02110-1301, USA.
3d3d428f
NC
21#
22
23# This file is sourced from elf32.em, and defines extra cr16-elf
24# specific routines.
25#
92b93329 26fragment <<EOF
3d3d428f
NC
27
28#include "ldctor.h"
29
7251ccbf
SR
30static void check_sections (bfd *, asection *, void *);
31
32
33/* This function is run after all the input files have been opened. */
34
35static void
36cr16_elf_after_open (void)
37{
38 /* Call the standard elf routine. */
39 gld${EMULATION_NAME}_after_open ();
40
d003af55
AM
41 if (command_line.embedded_relocs
42 && !bfd_link_relocatable (&link_info))
43 {
44 bfd *abfd;
7251ccbf
SR
45
46 /* In the embedded relocs mode we create a .emreloc section for each
47 input file with a nonzero .data section. The BFD backend will fill in
48 these sections with magic numbers which can be used to relocate the
49 data section at run time. */
c72f2fb2 50 for (abfd = link_info.input_bfds; abfd != NULL; abfd = abfd->link.next)
7251ccbf
SR
51 {
52 asection *datasec;
53
54 /* As first-order business, make sure that each input BFD is either
55 COFF or ELF. We need to call a special BFD backend function to
56 generate the embedded relocs, and we have such functions only for
57 COFF and ELF. */
58 if (bfd_get_flavour (abfd) != bfd_target_coff_flavour
59 && bfd_get_flavour (abfd) != bfd_target_elf_flavour)
871b3ab2 60 einfo (_("%F%pB: all input objects must be COFF or ELF "
d003af55 61 "for --embedded-relocs\n"));
7251ccbf
SR
62
63 datasec = bfd_get_section_by_name (abfd, ".data.rel");
64
65 /* Note that we assume that the reloc_count field has already
66 been set up. We could call bfd_get_reloc_upper_bound, but
67 that returns the size of a memory buffer rather than a reloc
68 count. We do not want to call bfd_canonicalize_reloc,
69 because although it would always work it would force us to
70 read in the relocs into BFD canonical form, which would waste
71 a significant amount of time and memory. */
72 if (datasec != NULL && datasec->reloc_count > 0)
73 {
74 asection *relsec;
75
76 relsec = bfd_make_section (abfd, ".emreloc");
77 if (relsec == NULL
78 || ! bfd_set_section_flags (abfd, relsec,
79 (SEC_ALLOC
80 | SEC_LOAD
81 | SEC_HAS_CONTENTS
82 | SEC_IN_MEMORY))
83 || ! bfd_set_section_alignment (abfd, relsec, 2)
84 || ! bfd_set_section_size (abfd, relsec,
85 datasec->reloc_count * 8))
871b3ab2 86 einfo (_("%F%pB: can not create .emreloc section: %E\n"));
7251ccbf
SR
87 }
88
89 /* Double check that all other data sections are empty, as is
90 required for embedded PIC code. */
e4492aa0 91 bfd_map_over_sections (abfd, check_sections, datasec);
7251ccbf
SR
92 }
93 }
94}
95
96/* Check that of the data sections, only the .data section has
97 relocs. This is called via bfd_map_over_sections. */
98
99static void
100check_sections (bfd *abfd, asection *sec, void *datasec)
101{
102 if ((strncmp (bfd_get_section_name (abfd, sec), ".data.rel", 9) == 0)
d003af55
AM
103 && sec != datasec
104 && sec->reloc_count == 0 )
871b3ab2 105 einfo (_("%pB%X: section %s has relocs; can not use --embedded-relocs\n"),
7251ccbf
SR
106 abfd, bfd_get_section_name (abfd, sec));
107}
108
3d3d428f
NC
109static void
110cr16elf_after_parse (void)
111{
112 /* Always behave as if called with --sort-common command line
113 option.
114 This is to emulate the CRTools' method of keeping variables
115 of different alignment in separate sections. */
116 config.sort_common = TRUE;
117
118 /* Don't create a demand-paged executable, since this feature isn't
119 meaninful in CR16 embedded systems. Moreover, when magic_demand_paged
120 is true the link sometimes fails. */
121 config.magic_demand_paged = FALSE;
97b11f40 122
5fe2850d 123 gld${EMULATION_NAME}_after_parse ();
3d3d428f
NC
124}
125
126/* This is called after the sections have been attached to output
127 sections, but before any sizes or addresses have been set. */
128
129static void
130cr16elf_before_allocation (void)
131{
132 /* Call the default first. */
133 gld${EMULATION_NAME}_before_allocation ();
134
d003af55
AM
135 if (command_line.embedded_relocs
136 && (!bfd_link_relocatable (&link_info)))
137 {
7251ccbf 138
d003af55 139 bfd *abfd;
7251ccbf 140
d003af55 141 /* If we are generating embedded relocs, call a special BFD backend
7251ccbf 142 routine to do the work. */
d003af55
AM
143 for (abfd = link_info.input_bfds; abfd != NULL; abfd = abfd->link.next)
144 {
7251ccbf
SR
145 asection *datasec, *relsec;
146 char *errmsg;
147
148 datasec = bfd_get_section_by_name (abfd, ".data.rel");
149
150 if (datasec == NULL || datasec->reloc_count == 0)
151 continue;
152
153 relsec = bfd_get_section_by_name (abfd, ".emreloc");
154 ASSERT (relsec != NULL);
155
156 if (! bfd_cr16_elf32_create_embedded_relocs (abfd, &link_info,
d003af55
AM
157 datasec, relsec,
158 &errmsg))
159 {
160 if (errmsg == NULL)
871b3ab2 161 einfo (_("%pB%X: can not create runtime reloc information: %E\n"),
d003af55
AM
162 abfd);
163 else
871b3ab2 164 einfo (_("%X%pB: can not create runtime reloc information: %s\n"),
d003af55
AM
165 abfd, errmsg);
166 }
167 }
168 }
7251ccbf 169
3d3d428f
NC
170 /* Enable relaxation by default if the "--no-relax" option was not
171 specified. This is done here instead of in the before_parse hook
172 because there is a check in main() to prohibit use of --relax and
173 -r together. */
28d5f677
NC
174 if (RELAXATION_DISABLED_BY_DEFAULT)
175 ENABLE_RELAXATION;
3d3d428f
NC
176}
177
178EOF
179
3d3d428f
NC
180# Put these extra cr16-elf routines in ld_${EMULATION_NAME}_emulation
181#
7251ccbf 182LDEMUL_AFTER_OPEN=cr16_elf_after_open
3d3d428f
NC
183LDEMUL_AFTER_PARSE=cr16elf_after_parse
184LDEMUL_BEFORE_ALLOCATION=cr16elf_before_allocation
This page took 0.455917 seconds and 4 git commands to generate.