diff --git a/tools/toolchains/gcc.py b/tools/toolchains/gcc.py index 3186cbb76ff..54fdbd567c5 100644 --- a/tools/toolchains/gcc.py +++ b/tools/toolchains/gcc.py @@ -15,7 +15,7 @@ limitations under the License. """ import re -from os.path import join, basename, splitext +from os.path import join, basename, splitext, dirname from tools.toolchains import mbedToolchain, TOOLCHAIN_PATHS from tools.hooks import hook_tool @@ -93,6 +93,7 @@ def __init__(self, target, notify=None, macros=None, self.flags['ld'] += self.cpu self.ld = [join(tool_path, "arm-none-eabi-gcc")] + self.flags['ld'] self.sys_libs = ["stdc++", "supc++", "m", "c", "gcc"] + self.preproc = [join(tool_path, "arm-none-eabi-cpp"), "-E", "-P"] self.ar = join(tool_path, "arm-none-eabi-ar") self.elf2bin = join(tool_path, "arm-none-eabi-objcopy") @@ -213,6 +214,15 @@ def link(self, output, objects, libraries, lib_dirs, mem_map): libs.append("-l%s" % name[3:]) libs.extend(["-l%s" % l for l in self.sys_libs]) + # Preprocess + if mem_map: + preproc_output = join(dirname(output), ".link_script.ld") + cmd = (self.preproc + [mem_map] + self.ld[1:] + + [ "-o", preproc_output]) + self.cc_verbose("Preproc: %s" % ' '.join(cmd)) + self.default_cmd(cmd) + mem_map = preproc_output + # Build linker command map_file = splitext(output)[0] + ".map" cmd = self.ld + ["-o", output, "-Wl,-Map=%s" % map_file] + objects + ["-Wl,--start-group"] + libs + ["-Wl,--end-group"]