Skip to content

Commit af4d848

Browse files
committed
Use the C Pre-Processor on GCC Linker scirpts
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.
1 parent 160455c commit af4d848

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

tools/toolchains/gcc.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
limitations under the License.
1616
"""
1717
import re
18-
from os.path import join, basename, splitext
18+
from os.path import join, basename, splitext, dirname
1919

2020
from tools.toolchains import mbedToolchain, TOOLCHAIN_PATHS
2121
from tools.hooks import hook_tool
@@ -93,6 +93,7 @@ def __init__(self, target, notify=None, macros=None,
9393
self.flags['ld'] += self.cpu
9494
self.ld = [join(tool_path, "arm-none-eabi-gcc")] + self.flags['ld']
9595
self.sys_libs = ["stdc++", "supc++", "m", "c", "gcc"]
96+
self.preproc = [join(tool_path, "arm-none-eabi-cpp"), "-E", "-P"]
9697

9798
self.ar = join(tool_path, "arm-none-eabi-ar")
9899
self.elf2bin = join(tool_path, "arm-none-eabi-objcopy")
@@ -213,6 +214,15 @@ def link(self, output, objects, libraries, lib_dirs, mem_map):
213214
libs.append("-l%s" % name[3:])
214215
libs.extend(["-l%s" % l for l in self.sys_libs])
215216

217+
# Preprocess
218+
if mem_map:
219+
preproc_output = join(dirname(output), ".link_script.ld")
220+
cmd = (self.preproc + [mem_map] + self.ld[1:] +
221+
[ "-o", preproc_output])
222+
self.cc_verbose("Preproc: %s" % ' '.join(cmd))
223+
self.default_cmd(cmd)
224+
mem_map = preproc_output
225+
216226
# Build linker command
217227
map_file = splitext(output)[0] + ".map"
218228
cmd = self.ld + ["-o", output, "-Wl,-Map=%s" % map_file] + objects + ["-Wl,--start-group"] + libs + ["-Wl,--end-group"]

0 commit comments

Comments
 (0)