Merge pull request #3730 from c1728p9/redirect_support

Add redirect support to toolchains
pull/3734/head
Sam Grove 2017-02-09 09:51:32 -06:00 committed by GitHub
commit 9ae6f7aa49
4 changed files with 88 additions and 1 deletions

View File

@ -1345,6 +1345,51 @@ class mbedToolchain:
"""
raise NotImplemented
@staticmethod
@abstractmethod
def name_mangle(name):
"""Mangle a name based on the conventional name mangling of this toolchain
Positional arguments:
name -- the name to mangle
Return:
the mangled name as a string
"""
raise NotImplemented
@staticmethod
@abstractmethod
def make_ld_define(name, value):
"""Create an argument to the linker that would define a symbol
Positional arguments:
name -- the symbol to define
value -- the value to give the symbol
Return:
The linker flag as a string
"""
raise NotImplemented
@staticmethod
@abstractmethod
def redirect_symbol(source, sync, build_dir):
"""Redirect a symbol at link time to point at somewhere else
Positional arguments:
source -- the symbol doing the pointing
sync -- the symbol being pointed to
build_dir -- the directory to put "response files" if needed by the toolchain
Side Effects:
Possibly create a file in the build directory
Return:
The linker flag to redirect the symbol, as a string
"""
raise NotImplemented
# Return the list of macros geenrated by the build system
def get_config_macros(self):
return Config.config_to_macros(self.config_data) if self.config_data else []

View File

@ -15,7 +15,9 @@ See the License for the specific language governing permissions and
limitations under the License.
"""
import re
from os.path import join, dirname, splitext, basename
from os.path import join, dirname, splitext, basename, exists
from os import makedirs, write
from tempfile import mkstemp
from tools.toolchains import mbedToolchain, TOOLCHAIN_PATHS
from tools.hooks import hook_tool
@ -222,6 +224,22 @@ class ARM(mbedToolchain):
self.cc_verbose("FromELF: %s" % ' '.join(cmd))
self.default_cmd(cmd)
@staticmethod
def name_mangle(name):
return "_Z%i%sv" % (len(name), name)
@staticmethod
def make_ld_define(name, value):
return "--predefine=\"-D%s=0x%x\"" % (name, value)
@staticmethod
def redirect_symbol(source, sync, build_dir):
if not exists(build_dir):
makedirs(build_dir)
handle, filename = mkstemp(prefix=".redirect-symbol.", dir=build_dir)
write(handle, "RESOLVE %s AS %s\n" % (source, sync))
return "--edit=%s" % filename
class ARM_STD(ARM):
pass

View File

@ -268,6 +268,18 @@ class GCC(mbedToolchain):
self.cc_verbose("FromELF: %s" % ' '.join(cmd))
self.default_cmd(cmd)
@staticmethod
def name_mangle(name):
return "_Z%i%sv" % (len(name), name)
@staticmethod
def make_ld_define(name, value):
return "-D%s=0x%x" % (name, value)
@staticmethod
def redirect_symbol(source, sync, build_dir):
return "-Wl,--defsym=%s=%s" % (source, sync)
class GCC_ARM(GCC):
@staticmethod

View File

@ -231,3 +231,15 @@ class IAR(mbedToolchain):
# Exec command
self.cc_verbose("FromELF: %s" % ' '.join(cmd))
self.default_cmd(cmd)
@staticmethod
def name_mangle(name):
return "_Z%i%sv" % (len(name), name)
@staticmethod
def make_ld_define(name, value):
return "--config_def %s=0x%x" % (name, value)
@staticmethod
def redirect_symbol(source, sync, build_dir):
return "--redirect %s=%s" % (source, sync)