RISC-V: Disallow output format changes.
[deliverable/binutils-gdb.git] / ld / emultempl / riscvelf.em
index a284c6303f3d2d09178bc0a7c2f64fe76f057e19..eaaf4c58b54ce61e50e53f002ca30ed15812e089 100644 (file)
@@ -62,7 +62,27 @@ gld${EMULATION_NAME}_after_allocation (void)
   gld${EMULATION_NAME}_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
This page took 0.03477 seconds and 4 git commands to generate.