This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
ld: How to build + install a 2nd set of default linker scripts?
- From: Georg-Johann Lay <avr at gjlay dot de>
- To: Binutils Development <binutils at sourceware dot org>
- Date: Fri, 12 May 2017 12:10:59 +0200
- Subject: ld: How to build + install a 2nd set of default linker scripts?
- Authentication-results: sourceware.org; auth=none
In order to support default linker description files which
can be selected by a command line option, I added the following
hook and option avr_no_rodata_in_ram to emultempl/avrelf.em:
diff --git a/ld/emultempl/avrelf.em b/ld/emultempl/avrelf.em
index 2072124..7781e9f 100644
--- a/ld/emultempl/avrelf.em
+++ b/ld/emultempl/avrelf.em
@@ ...
@@ -60,6 +61,37 @@ avr_elf_set_global_bfd_parameters (void)
avr_replace_call_ret_sequences);
}
+static char *
+gld${EMULATION_NAME}_get_script (int *isfile)
+{
+ *isfile = 1;
+
+ if (avr_no_rodata_in_ram
+ && 0 == strcmp ("avrxmega2", "${EMULATION_NAME}"))
+ {
+ if (bfd_link_relocatable (&link_info) && config.build_constructors)
+ return "ldscripts/${EMULATION_NAME}-rodata.xu";
+ else if (bfd_link_relocatable (&link_info))
+ return "ldscripts/${EMULATION_NAME}-rodata.xr";
+ else if (!config.text_read_only)
+ return "ldscripts/${EMULATION_NAME}-rodata.xbn";
+ else if (!config.magic_demand_paged)
+ return "ldscripts/${EMULATION_NAME}-rodata.xn";
+ else
+ return "ldscripts/${EMULATION_NAME}-rodata.x";
+ }
+
+ if (bfd_link_relocatable (&link_info) && config.build_constructors)
+ return "ldscripts/${EMULATION_NAME}.xu";
+ else if (bfd_link_relocatable (&link_info))
+ return "ldscripts/${EMULATION_NAME}.xr";
+ else if (!config.text_read_only)
+ return "ldscripts/${EMULATION_NAME}.xbn";
+ else if (!config.magic_demand_paged)
+ return "ldscripts/${EMULATION_NAME}.xn";
+ else
+ return "ldscripts/${EMULATION_NAME}.x";
+}
/* Makes a conservative estimate of the trampoline section size that could
be corrected later on. */
@@ ...
@@ -311,3 +350,4 @@
LDEMUL_BEFORE_ALLOCATION=avr_elf_${EMULATION_NAME}_before_allocation
LDEMUL_AFTER_ALLOCATION=avr_elf_after_allocation
LDEMUL_CREATE_OUTPUT_SECTION_STATEMENTS=avr_elf_create_output_section_statements
LDEMUL_FINISH=avr_finish
+LDEMUL_GET_SCRIPT=gld${EMULATION_NAME}_get_script
The purpose it to introduce a new command line option to use the
${EMULATION_NAME}-rodata.x* set of default ld files instead of the
common ${EMULATION_NAME}-rodata.x* ones.
All this works out as expected, but where I am stuck is how to
build and install that new flavour of default scripts.
I extended scripttempl/avr.sc so that it can generate the two
variants depending on whether a specific variable is set,
but how / where do I generate the 2nd flavour of scripts?
Skimming genscripts.sh doesn't give much of a clue, and as I
don't want to extend that script I am asking here for some
guidance on how to achieve $subject.
As I was told that introducing a new emulation is the wrong
thing to do, I am stuck...
Johann