diff --git ld/emultempl/avrelf.em ld/emultempl/avrelf.em index 90894a1..5f064b2 100644 --- ld/emultempl/avrelf.em +++ ld/emultempl/avrelf.em @@ -29,6 +29,8 @@ fragment </../avr/lib/defs */ + /* first step is to get the parent directory of avr-ld */ + char* binpath = make_relative_prefix(program_name,".","."); + + /*Allocate a string to construct a full path */ + char *defs_path = malloc (strlen(binpath) + strlen("../lib/defs/") + strlen(device_name)); + + /* Now construct the path */ + strcpy(defs_path, binpath); + strcat(defs_path, "../lib/defs/"); /* Check if this path actually exists and if it doesn't then warn/error/ what ? + strcat(defs_path,device_name); + + /* free allocated variables. Note that we also free the global variable device_name, which is used only here. */ + free(binpath); + free(device_name); + + /* Now add the file as a input to the list of bfd's that will be processed */ + lang_add_input_file(defs_path , lang_input_file_is_file_enum, NULL); +} + +static void +avr_elf_after_parse (void) +{ + add_device_specific_linker_configuration_to_bfd(); +} + EOF @@ -186,6 +223,8 @@ PARSE_AND_LIST_PROLOGUE=' #define OPTION_NO_STUBS 303 #define OPTION_DEBUG_STUBS 304 #define OPTION_DEBUG_RELAX 305 +#define OPTION_MCU_PARAMETER 306 + ' PARSE_AND_LIST_LONGOPTS=' @@ -199,6 +238,8 @@ PARSE_AND_LIST_LONGOPTS=' NULL, OPTION_DEBUG_STUBS}, { "debug-relax", no_argument, NULL, OPTION_DEBUG_RELAX}, + { "part", required_argument, + NULL, OPTION_MCU_PARAMETER}, ' PARSE_AND_LIST_OPTIONS=' @@ -228,6 +269,8 @@ PARSE_AND_LIST_OPTIONS=' "Used for debugging avr-ld.\n")); fprintf (file, _(" --debug-relax " "Used for debugging avr-ld.\n")); + fprintf (file, _(" --part " + "The mcu parameter as passed from the compiler. This should be explicitly mentioned when invoking the linker separately.\n")); ' PARSE_AND_LIST_ARGS_CASES=' @@ -266,6 +309,17 @@ PARSE_AND_LIST_ARGS_CASES=' avr_replace_call_ret_sequences = FALSE; } break; + case OPTION_MCU_PARAMETER: + { + /* cache the name of the device here. Then use it in after_parse, where we try to construct the path to the device specific linker configuration file. + */ + if(optarg) + { + /* cache optarg */ + device_name=malloc(strlen(optarg)); + strcpy(device_name,optarg); + } + } ' # @@ -275,3 +329,4 @@ LDEMUL_BEFORE_PARSE=avr_elf_before_parse 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_AFTER_PARSE=avr_elf_after_parse