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.
pull/3706/head
Jimmy Brisson 2017-02-01 15:59:27 -06:00
parent 160455c972
commit af4d848144
1 changed files with 11 additions and 1 deletions

View File

@ -15,7 +15,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
""" """
import re 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.toolchains import mbedToolchain, TOOLCHAIN_PATHS
from tools.hooks import hook_tool from tools.hooks import hook_tool
@ -93,6 +93,7 @@ class GCC(mbedToolchain):
self.flags['ld'] += self.cpu self.flags['ld'] += self.cpu
self.ld = [join(tool_path, "arm-none-eabi-gcc")] + self.flags['ld'] self.ld = [join(tool_path, "arm-none-eabi-gcc")] + self.flags['ld']
self.sys_libs = ["stdc++", "supc++", "m", "c", "gcc"] 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.ar = join(tool_path, "arm-none-eabi-ar")
self.elf2bin = join(tool_path, "arm-none-eabi-objcopy") self.elf2bin = join(tool_path, "arm-none-eabi-objcopy")
@ -213,6 +214,15 @@ class GCC(mbedToolchain):
libs.append("-l%s" % name[3:]) libs.append("-l%s" % name[3:])
libs.extend(["-l%s" % l for l in self.sys_libs]) 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 # Build linker command
map_file = splitext(output)[0] + ".map" map_file = splitext(output)[0] + ".map"
cmd = self.ld + ["-o", output, "-Wl,-Map=%s" % map_file] + objects + ["-Wl,--start-group"] + libs + ["-Wl,--end-group"] cmd = self.ld + ["-o", output, "-Wl,-Map=%s" % map_file] + objects + ["-Wl,--start-group"] + libs + ["-Wl,--end-group"]