1 # This shell script emits a C file. -*- C -*-
2 # Copyright (C) 2021-2022 Free Software Foundation, Inc.
3 # Contributed by Loongson Ltd.
5 # This file is part of the GNU Binutils.
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
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
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.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; see the file COPYING3. If not,
19 # see <http://www.gnu.org/licenses/>.
25 #include "elf/loongarch.h"
28 larch_elf_before_allocation (void)
30 gld${EMULATION_NAME}_before_allocation ();
32 if (link_info.discard == discard_sec_merge)
33 link_info.discard = discard_l;
35 if (!bfd_link_relocatable (&link_info))
37 /* We always need at least some relaxation to handle code alignment. */
38 if (RELAXATION_DISABLED_BY_USER)
39 TARGET_ENABLE_RELAXATION;
44 link_info.relax_pass = 3;
48 gld${EMULATION_NAME}_after_allocation (void)
52 /* Don't attempt to discard unused .eh_frame sections until the final link,
53 as we can't reliably tell if they're used until after relaxation. */
54 if (!bfd_link_relocatable (&link_info))
56 need_layout = bfd_elf_discard_info (link_info.output_bfd, &link_info);
59 einfo (_("%X%P: .eh_frame/.stab edit: %E\n"));
64 /* gld${EMULATION_NAME}_map_segments (need_layout); */
65 ldelf_map_segments (need_layout);
68 /* This is a convenient point to tell BFD about target specific flags.
69 After the output has been created, but before inputs are read. */
72 larch_create_output_section_statements (void)
74 /* See PR 22920 for an example of why this is necessary. */
75 if (strstr (bfd_get_target (link_info.output_bfd), "loong") == NULL)
77 einfo (_("%F%P: error: cannot change output format"
78 " whilst linking %s binaries\n"), "LoongArch");
85 LDEMUL_BEFORE_ALLOCATION=larch_elf_before_allocation
86 LDEMUL_AFTER_ALLOCATION=gld${EMULATION_NAME}_after_allocation
87 LDEMUL_CREATE_OUTPUT_SECTION_STATEMENTS=larch_create_output_section_statements