Skip to content

Commit 9ae6f7a

Browse files
authored
Merge pull request #3730 from c1728p9/redirect_support
Add redirect support to toolchains
2 parents cf19bb6 + c0f2759 commit 9ae6f7a

File tree

4 files changed

+88
-1
lines changed

4 files changed

+88
-1
lines changed

tools/toolchains/__init__.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1345,6 +1345,51 @@ def binary(self, resources, elf, bin):
13451345
"""
13461346
raise NotImplemented
13471347

1348+
@staticmethod
1349+
@abstractmethod
1350+
def name_mangle(name):
1351+
"""Mangle a name based on the conventional name mangling of this toolchain
1352+
1353+
Positional arguments:
1354+
name -- the name to mangle
1355+
1356+
Return:
1357+
the mangled name as a string
1358+
"""
1359+
raise NotImplemented
1360+
1361+
@staticmethod
1362+
@abstractmethod
1363+
def make_ld_define(name, value):
1364+
"""Create an argument to the linker that would define a symbol
1365+
1366+
Positional arguments:
1367+
name -- the symbol to define
1368+
value -- the value to give the symbol
1369+
1370+
Return:
1371+
The linker flag as a string
1372+
"""
1373+
raise NotImplemented
1374+
1375+
@staticmethod
1376+
@abstractmethod
1377+
def redirect_symbol(source, sync, build_dir):
1378+
"""Redirect a symbol at link time to point at somewhere else
1379+
1380+
Positional arguments:
1381+
source -- the symbol doing the pointing
1382+
sync -- the symbol being pointed to
1383+
build_dir -- the directory to put "response files" if needed by the toolchain
1384+
1385+
Side Effects:
1386+
Possibly create a file in the build directory
1387+
1388+
Return:
1389+
The linker flag to redirect the symbol, as a string
1390+
"""
1391+
raise NotImplemented
1392+
13481393
# Return the list of macros geenrated by the build system
13491394
def get_config_macros(self):
13501395
return Config.config_to_macros(self.config_data) if self.config_data else []

tools/toolchains/arm.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
limitations under the License.
1616
"""
1717
import re
18-
from os.path import join, dirname, splitext, basename
18+
from os.path import join, dirname, splitext, basename, exists
19+
from os import makedirs, write
20+
from tempfile import mkstemp
1921

2022
from tools.toolchains import mbedToolchain, TOOLCHAIN_PATHS
2123
from tools.hooks import hook_tool
@@ -222,6 +224,22 @@ def binary(self, resources, elf, bin):
222224
self.cc_verbose("FromELF: %s" % ' '.join(cmd))
223225
self.default_cmd(cmd)
224226

227+
@staticmethod
228+
def name_mangle(name):
229+
return "_Z%i%sv" % (len(name), name)
230+
231+
@staticmethod
232+
def make_ld_define(name, value):
233+
return "--predefine=\"-D%s=0x%x\"" % (name, value)
234+
235+
@staticmethod
236+
def redirect_symbol(source, sync, build_dir):
237+
if not exists(build_dir):
238+
makedirs(build_dir)
239+
handle, filename = mkstemp(prefix=".redirect-symbol.", dir=build_dir)
240+
write(handle, "RESOLVE %s AS %s\n" % (source, sync))
241+
return "--edit=%s" % filename
242+
225243

226244
class ARM_STD(ARM):
227245
pass

tools/toolchains/gcc.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,18 @@ def binary(self, resources, elf, bin):
268268
self.cc_verbose("FromELF: %s" % ' '.join(cmd))
269269
self.default_cmd(cmd)
270270

271+
@staticmethod
272+
def name_mangle(name):
273+
return "_Z%i%sv" % (len(name), name)
274+
275+
@staticmethod
276+
def make_ld_define(name, value):
277+
return "-D%s=0x%x" % (name, value)
278+
279+
@staticmethod
280+
def redirect_symbol(source, sync, build_dir):
281+
return "-Wl,--defsym=%s=%s" % (source, sync)
282+
271283

272284
class GCC_ARM(GCC):
273285
@staticmethod

tools/toolchains/iar.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,3 +231,15 @@ def binary(self, resources, elf, bin):
231231
# Exec command
232232
self.cc_verbose("FromELF: %s" % ' '.join(cmd))
233233
self.default_cmd(cmd)
234+
235+
@staticmethod
236+
def name_mangle(name):
237+
return "_Z%i%sv" % (len(name), name)
238+
239+
@staticmethod
240+
def make_ld_define(name, value):
241+
return "--config_def %s=0x%x" % (name, value)
242+
243+
@staticmethod
244+
def redirect_symbol(source, sync, build_dir):
245+
return "--redirect %s=%s" % (source, sync)

0 commit comments

Comments
 (0)