Skip to content

Commit

Permalink
Use the C Pre-Processor on GCC Linker scirpts
Browse files Browse the repository at this point in the history
This allows us to define parts of the linker script outside of the
linker script itself. In particular, we are interested in restricting
ROM to a subsection.
  • Loading branch information
theotherjimmy committed Feb 8, 2017
1 parent 160455c commit af4d848
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion tools/toolchains/gcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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"]
Expand Down

0 comments on commit af4d848

Please sign in to comment.