Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: toolchains/gcc.py
- Revision:
- 13:ab47a20b66f0
- Parent:
- 7:5af61d55adbe
- Child:
- 20:835f6355470d
--- a/toolchains/gcc.py Tue Jun 14 11:33:06 2016 +0100
+++ b/toolchains/gcc.py Thu Jul 14 20:21:19 2016 +0100
@@ -23,16 +23,28 @@
from tools.hooks import hook_tool
class GCC(mbedToolchain):
- PROFILE = {}
LINKER_EXT = '.ld'
LIBRARY_EXT = '.a'
STD_LIB_NAME = "lib%s.a"
- CIRCULAR_DEPENDENCIES = True
- DIAGNOSTIC_PATTERN = re.compile('((?P<line>\d+):)(\d+:)? (?P<severity>warning|error): (?P<message>.+)')
+ DIAGNOSTIC_PATTERN = re.compile('((?P<file>[^:]+):(?P<line>\d+):)(\d+:)? (?P<severity>warning|error): (?P<message>.+)')
- def __init__(self, target, options=None, notify=None, macros=None, silent=False, tool_path="", extra_verbose=False, profile=None):
- mbedToolchain.__init__(self, target, options, notify, macros, silent, extra_verbose=extra_verbose, profile=profile)
+ DEFAULT_FLAGS = {
+ 'common': ["-c", "-Wall", "-Wextra",
+ "-Wno-unused-parameter", "-Wno-missing-field-initializers",
+ "-fmessage-length=0", "-fno-exceptions", "-fno-builtin",
+ "-ffunction-sections", "-fdata-sections", "-funsigned-char",
+ "-MMD", "-fno-delete-null-pointer-checks", "-fomit-frame-pointer"
+ ],
+ 'asm': ["-x", "assembler-with-cpp"],
+ 'c': ["-std=gnu99"],
+ 'cxx': ["-std=gnu++98", "-fno-rtti", "-Wvla"],
+ 'ld': ["-Wl,--gc-sections", "-Wl,--wrap,main",
+ "-Wl,--wrap,_malloc_r", "-Wl,--wrap,_free_r", "-Wl,--wrap,_realloc_r"],
+ }
+
+ def __init__(self, target, options=None, notify=None, macros=None, silent=False, tool_path="", extra_verbose=False):
+ mbedToolchain.__init__(self, target, options, notify, macros, silent, extra_verbose=extra_verbose)
if target.core == "Cortex-M0+":
cpu = "cortex-m0plus"
@@ -40,6 +52,8 @@
cpu = "cortex-m4"
elif target.core == "Cortex-M7F":
cpu = "cortex-m7"
+ elif target.core == "Cortex-M7FD":
+ cpu = "cortex-m7"
else:
cpu = target.core.lower()
@@ -47,13 +61,19 @@
if target.core.startswith("Cortex"):
self.cpu.append("-mthumb")
+ # FPU handling, M7 possibly to have double FPU
if target.core == "Cortex-M4F":
self.cpu.append("-mfpu=fpv4-sp-d16")
self.cpu.append("-mfloat-abi=softfp")
elif target.core == "Cortex-M7F":
+ self.cpu.append("-mfpu=fpv5-sp-d16")
+ self.cpu.append("-mfloat-abi=softfp")
+ elif target.core == "Cortex-M7FD":
self.cpu.append("-mfpu=fpv5-d16")
self.cpu.append("-mfloat-abi=softfp")
+
+
if target.core == "Cortex-A9":
self.cpu.append("-mthumb-interwork")
self.cpu.append("-marm")
@@ -62,31 +82,34 @@
self.cpu.append("-mfloat-abi=hard")
self.cpu.append("-mno-unaligned-access")
+
# Note: We are using "-O2" instead of "-Os" to avoid this known GCC bug:
# http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46762
- common_flags = self.PROFILE.get('COMMON_FLAGS', ["-c", "-O2",
- "-Wall", "-Wextra", "-Wno-unused-parameter", "-Wno-missing-field-initializers",
- "-fmessage-length=0", "-fno-exceptions", "-fno-builtin",
- "-ffunction-sections", "-fdata-sections",
- "-fno-delete-null-pointer-checks", "-fomit-frame-pointer"
- ]) + self.cpu
+ self.flags["common"] += self.cpu
if "save-asm" in self.options:
- common_flags.append("-save-temps")
+ self.flags["common"].append("-save-temps")
+
if "debug-info" in self.options:
- common_flags.remove("-O3")
- common_flags.remove("-O2")
- common_flags.remove("-O1")
- common_flags.append("-O0")
+ self.flags["common"].append("-g")
+ self.flags["common"].append("-O0")
+ else:
+ self.flags["common"].append("-O2")
- # add debug symbols for all builds
- common_flags.append("-g")
+ main_cc = join(tool_path, "arm-none-eabi-gcc")
+ main_cppc = join(tool_path, "arm-none-eabi-g++")
+ self.asm = [main_cc] + self.flags['asm'] + self.flags["common"]
+ if not "analyze" in self.options:
+ self.cc = [main_cc]
+ self.cppc =[main_cppc]
+ else:
+ self.cc = [join(GOANNA_PATH, "goannacc"), "--with-cc=" + main_cc.replace('\\', '/'), "--dialect=gnu", '--output-format="%s"' % self.GOANNA_FORMAT]
+ self.cppc= [join(GOANNA_PATH, "goannac++"), "--with-cxx=" + main_cppc.replace('\\', '/'), "--dialect=gnu", '--output-format="%s"' % self.GOANNA_FORMAT]
+ self.cc += self.flags['c'] + self.flags['common']
+ self.cppc += self.flags['cxx'] + self.flags['common']
- self.asm = [join(tool_path, "arm-none-eabi-gcc")] + self.PROFILE.get('COMMON_ASM_FLAGS', ["-x", "assembler-with-cpp"]) + common_flags
- self.cc = [join(tool_path, "arm-none-eabi-gcc")] + self.PROFILE.get('COMMON_CC_FLAGS', ["-std=gnu99"]) + common_flags
- self.cppc =[join(tool_path, "arm-none-eabi-g++")] + self.PROFILE.get('COMMON_CPP_FLAGS', ["-std=gnu++98", "-fno-rtti"]) + common_flags
- self.ld = [join(tool_path, "arm-none-eabi-gcc")] + self.PROFILE.get('COMMON_LD_FLAGS', ["-Wl,--gc-sections", "-Wl,--wrap,main"]) + self.cpu
-
+ 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.ar = join(tool_path, "arm-none-eabi-ar")
@@ -133,27 +156,16 @@
)
continue
- # Each line should start with the file information: "filepath: ..."
- # i should point past the file path ^
- # avoid the first column in Windows (C:\)
- i = line.find(':', 2)
- if i == -1: continue
- if state == WHERE:
- file = line[:i]
- message = line[i+1:].strip() + ' '
- state = WHAT
-
- elif state == WHAT:
- match = GCC.DIAGNOSTIC_PATTERN.match(line[i+1:])
- if match is None:
- state = WHERE
- continue
-
+ match = GCC.DIAGNOSTIC_PATTERN.match(line)
+ if match is not None:
self.cc_info(
- match.group('severity'),
- file, match.group('line'),
- message + match.group('message')
+ match.group('severity').lower(),
+ match.group('file'),
+ match.group('line'),
+ match.group('message'),
+ target_name=self.target.name,
+ toolchain_name=self.name
)
def get_dep_option(self, object):
@@ -161,8 +173,15 @@
dep_path = base + '.d'
return ["-MD", "-MF", dep_path]
+ def get_config_option(self, config_header):
+ return ['-include', config_header]
+
def get_compile_options(self, defines, includes):
- return ['-D%s' % d for d in defines] + ['@%s' % self.get_inc_file(includes)]
+ opts = ['-D%s' % d for d in defines] + ['@%s' % self.get_inc_file(includes)]
+ config_header = self.get_config_header()
+ if config_header is not None:
+ opts = opts + self.get_config_option(config_header)
+ return opts
@hook_tool
def assemble(self, source, object, includes):
@@ -183,7 +202,7 @@
cmd.extend(self.get_dep_option(object))
cmd.extend(["-o", object, source])
-
+
# Call cmdline hook
cmd = self.hook.get_cmdline_compiler(cmd)
@@ -203,20 +222,12 @@
libs.append("-l%s" % name[3:])
libs.extend(["-l%s" % l for l in self.sys_libs])
- # NOTE: There is a circular dependency between the mbed library and the clib
- # We could define a set of week symbols to satisfy the clib dependencies in "sys.o",
- # but if an application uses only clib symbols and not mbed symbols, then the final
- # image is not correctly retargeted
- if self.CIRCULAR_DEPENDENCIES:
- libs.extend(libs)
-
# Build linker command
map_file = splitext(output)[0] + ".map"
- cmd = self.ld + ["-o", output, "-Wl,-Map=%s" % map_file] + objects
-
+ cmd = self.ld + ["-o", output, "-Wl,-Map=%s" % map_file] + objects + ["-Wl,--start-group"] + libs + ["-Wl,--end-group"]
if mem_map:
cmd.extend(['-T', mem_map])
-
+
for L in lib_dirs:
cmd.extend(['-L', L])
cmd.extend(libs)
@@ -231,7 +242,7 @@
cmd_list = []
for c in cmd[1:]:
if c:
- cmd_list.append(('"%s"' % c) if not c.startswith('-') else c)
+ cmd_list.append(('"%s"' % c) if not c.startswith('-') else c)
string = " ".join(cmd_list).replace("\\", "/")
f.write(string)
@@ -244,7 +255,7 @@
with open(archive_files, "wb") as f:
o_list = []
for o in objects:
- o_list.append('"%s"' % o)
+ o_list.append('"%s"' % o)
string = " ".join(o_list).replace("\\", "/")
f.write(string)
@@ -264,22 +275,41 @@
class GCC_ARM(GCC):
- def __init__(self, target, options=None, notify=None, macros=None, silent=False, extra_verbose=False, profile=None):
- GCC.__init__(self, target, options, notify, macros, silent, GCC_ARM_PATH, extra_verbose=extra_verbose, profile=profile)
+ def __init__(self, target, options=None, notify=None, macros=None, silent=False, extra_verbose=False):
+ GCC.__init__(self, target, options, notify, macros, silent, GCC_ARM_PATH, extra_verbose=extra_verbose)
# Use latest gcc nanolib
- self.ld.append("--specs=nano.specs")
- if target.name in ["LPC1768", "LPC4088", "LPC4088_DM", "LPC4330", "UBLOX_C027", "LPC2368"]:
+ if "big-build" in self.options:
+ use_nano = False
+ elif "small-build" in self.options:
+ use_nano = True
+ elif target.default_build == "standard":
+ use_nano = False
+ elif target.default_build == "small":
+ use_nano = True
+ else:
+ use_nano = False
+
+ if use_nano:
+ self.ld.append("--specs=nano.specs")
+ self.flags['ld'].append("--specs=nano.specs")
+ self.cc += ["-DMBED_RTOS_SINGLE_THREAD"]
+ self.cppc += ["-DMBED_RTOS_SINGLE_THREAD"]
+ self.macros.extend(["MBED_RTOS_SINGLE_THREAD"])
+
+ if target.name in ["LPC1768", "LPC4088", "LPC4088_DM", "LPC4330", "UBLOX_C027", "LPC2368", "ARM_BEETLE_SOC"]:
self.ld.extend(["-u _printf_float", "-u _scanf_float"])
- elif target.name in ["RZ_A1H", "ARCH_MAX", "DISCO_F407VG", "DISCO_F429ZI", "DISCO_F469NI", "NUCLEO_F401RE", "NUCLEO_F410RB", "NUCLEO_F411RE", "NUCLEO_F446RE", "ELMO_F411RE", "MTS_MDOT_F411RE", "MTS_DRAGONFLY_F411RE", "DISCO_F746NG"]:
+ self.flags['ld'].extend(["-u _printf_float", "-u _scanf_float"])
+ elif target.name in ["RZ_A1H", "VK_RZ_A1H", "ARCH_MAX", "DISCO_F407VG", "DISCO_F429ZI", "DISCO_F469NI", "NUCLEO_F401RE", "NUCLEO_F410RB", "NUCLEO_F411RE", "NUCLEO_F429ZI", "NUCLEO_F446RE", "NUCLEO_F446ZE", "ELMO_F411RE", "MTS_MDOT_F411RE", "MTS_DRAGONFLY_F411RE", "DISCO_F746NG"]:
self.ld.extend(["-u_printf_float", "-u_scanf_float"])
+ self.flags['ld'].extend(["-u_printf_float", "-u_scanf_float"])
self.sys_libs.append("nosys")
class GCC_CR(GCC):
- def __init__(self, target, options=None, notify=None, macros=None, silent=False, extra_verbose=False, profile=None):
- GCC.__init__(self, target, options, notify, macros, silent, GCC_CR_PATH, extra_verbose=extra_verbose, profile=profile)
+ def __init__(self, target, options=None, notify=None, macros=None, silent=False, extra_verbose=False):
+ GCC.__init__(self, target, options, notify, macros, silent, GCC_CR_PATH, extra_verbose=extra_verbose)
additional_compiler_flags = [
"-D__NEWLIB__", "-D__CODE_RED", "-D__USE_CMSIS", "-DCPP_USE_HEAP",
@@ -292,4 +322,3 @@
if target.name in ["LPC1768", "LPC4088", "LPC4088_DM", "LPC4330", "UBLOX_C027", "LPC2368"]:
self.ld.extend(["-u _printf_float", "-u _scanf_float"])
self.ld += ["-nostdlib"]
-
