X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=ld%2Femultempl%2Friscvelf.em;h=da5c934d25d163225627bc4627977064931b4554;hb=39a7b38fac0e6e90baa3d661a271377db3ba1765;hp=a284c6303f3d2d09178bc0a7c2f64fe76f057e19;hpb=219d1afa89d0d53ca93a684cac341f16470f3ca0;p=deliverable%2Fbinutils-gdb.git diff --git a/ld/emultempl/riscvelf.em b/ld/emultempl/riscvelf.em index a284c6303f..da5c934d25 100644 --- a/ld/emultempl/riscvelf.em +++ b/ld/emultempl/riscvelf.em @@ -1,5 +1,5 @@ # This shell script emits a C file. -*- C -*- -# Copyright (C) 2004-2018 Free Software Foundation, Inc. +# Copyright (C) 2004-2020 Free Software Foundation, Inc. # # This file is part of the GNU Binutils. # @@ -33,11 +33,14 @@ riscv_elf_before_allocation (void) if (link_info.discard == discard_sec_merge) link_info.discard = discard_l; - /* We always need at least some relaxation to handle code alignment. */ - if (RELAXATION_DISABLED_BY_USER) - TARGET_ENABLE_RELAXATION; - else - ENABLE_RELAXATION; + if (!bfd_link_relocatable (&link_info)) + { + /* We always need at least some relaxation to handle code alignment. */ + if (RELAXATION_DISABLED_BY_USER) + TARGET_ENABLE_RELAXATION; + else + ENABLE_RELAXATION; + } link_info.relax_pass = 3; } @@ -59,10 +62,30 @@ gld${EMULATION_NAME}_after_allocation (void) } } - gld${EMULATION_NAME}_map_segments (need_layout); + ldelf_map_segments (need_layout); +} + +/* This is a convenient point to tell BFD about target specific flags. + After the output has been created, but before inputs are read. */ + +static void +riscv_create_output_section_statements (void) +{ + /* See PR 22920 for an example of why this is necessary. */ + if (strstr (bfd_get_target (link_info.output_bfd), "riscv") == NULL) + { + /* The RISC-V backend needs special fields in the output hash structure. + These will only be created if the output format is a RISC-V format, + hence we do not support linking and changing output formats at the + same time. Use a link followed by objcopy to change output formats. */ + einfo (_("%F%P: error: cannot change output format" + " whilst linking %s binaries\n"), "RISC-V"); + return; + } } EOF LDEMUL_BEFORE_ALLOCATION=riscv_elf_before_allocation LDEMUL_AFTER_ALLOCATION=gld${EMULATION_NAME}_after_allocation +LDEMUL_CREATE_OUTPUT_SECTION_STATEMENTS=riscv_create_output_section_statements