mirror of https://github.com/ARMmbed/mbed-os.git
Add redirect support to toolchains
We create an API for generating the linker flags needed to redirect functions in an applicationpull/3730/head
parent
cd55625faf
commit
c0f27597ec
|
|
@ -1345,6 +1345,51 @@ class mbedToolchain:
|
||||||
"""
|
"""
|
||||||
raise NotImplemented
|
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
|
# Return the list of macros geenrated by the build system
|
||||||
def get_config_macros(self):
|
def get_config_macros(self):
|
||||||
return Config.config_to_macros(self.config_data) if self.config_data else []
|
return Config.config_to_macros(self.config_data) if self.config_data else []
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,9 @@ 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, 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.toolchains import mbedToolchain, TOOLCHAIN_PATHS
|
||||||
from tools.hooks import hook_tool
|
from tools.hooks import hook_tool
|
||||||
|
|
@ -222,6 +224,22 @@ class ARM(mbedToolchain):
|
||||||
self.cc_verbose("FromELF: %s" % ' '.join(cmd))
|
self.cc_verbose("FromELF: %s" % ' '.join(cmd))
|
||||||
self.default_cmd(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):
|
class ARM_STD(ARM):
|
||||||
pass
|
pass
|
||||||
|
|
|
||||||
|
|
@ -258,6 +258,18 @@ class GCC(mbedToolchain):
|
||||||
self.cc_verbose("FromELF: %s" % ' '.join(cmd))
|
self.cc_verbose("FromELF: %s" % ' '.join(cmd))
|
||||||
self.default_cmd(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):
|
class GCC_ARM(GCC):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|
|
||||||
|
|
@ -231,3 +231,15 @@ class IAR(mbedToolchain):
|
||||||
# Exec command
|
# Exec command
|
||||||
self.cc_verbose("FromELF: %s" % ' '.join(cmd))
|
self.cc_verbose("FromELF: %s" % ' '.join(cmd))
|
||||||
self.default_cmd(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)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue