1 # This shell script emits a C file. -*- C -*-
2 # Copyright (C) 2004-2019 Free Software Foundation, Inc.
4 # This file is part of the GNU Binutils.
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
25 #include "elf/riscv.h"
26 #include "elfxx-riscv.h"
29 riscv_elf_before_allocation (void)
31 gld${EMULATION_NAME}_before_allocation ();
33 if (link_info.discard == discard_sec_merge)
34 link_info.discard = discard_l;
36 if (!bfd_link_relocatable (&link_info))
38 /* We always need at least some relaxation to handle code alignment. */
39 if (RELAXATION_DISABLED_BY_USER)
40 TARGET_ENABLE_RELAXATION;
45 link_info.relax_pass = 3;
49 gld${EMULATION_NAME}_after_allocation (void)
53 /* Don't attempt to discard unused .eh_frame sections until the final link,
54 as we can't reliably tell if they're used until after relaxation. */
55 if (!bfd_link_relocatable (&link_info))
57 need_layout = bfd_elf_discard_info (link_info.output_bfd, &link_info);
60 einfo (_("%X%P: .eh_frame/.stab edit: %E\n"));
65 gld${EMULATION_NAME}_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 riscv_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), "riscv") == NULL)
77 /* The RISC-V backend needs special fields in the output hash structure.
78 These will only be created if the output format is a RISC-V format,
79 hence we do not support linking and changing output formats at the
80 same time. Use a link followed by objcopy to change output formats. */
81 einfo (_("%F%P: error: cannot change output format"
82 " whilst linking %s binaries\n"), "RISC-V");
89 LDEMUL_BEFORE_ALLOCATION=riscv_elf_before_allocation
90 LDEMUL_AFTER_ALLOCATION=gld${EMULATION_NAME}_after_allocation
91 LDEMUL_CREATE_OUTPUT_SECTION_STATEMENTS=riscv_create_output_section_statements