mirror of
https://github.com/ARM-software/arm-trusted-firmware.git
synced 2025-04-16 01:24:27 +00:00
Merge changes from topic "romlib-fixes" into integration
* changes: fix(romlib): wrap indirectly included functions fix(arm): remove duplicate jumptable entry
This commit is contained in:
commit
2d4f264ba5
7 changed files with 55 additions and 22 deletions
|
@ -71,6 +71,15 @@ image(s) is replaced with the wrapper function.
|
||||||
The "library at ROM" contains a necessary init function that initialises the
|
The "library at ROM" contains a necessary init function that initialises the
|
||||||
global variables defined by the functions inside "library at ROM".
|
global variables defined by the functions inside "library at ROM".
|
||||||
|
|
||||||
|
Wrapper functions are specified at the link stage of compilation and cannot
|
||||||
|
interpose uppon functions within the same translation unit. For example, if
|
||||||
|
function ``fn_a`` calls ``fn_b`` within translation unit ``functions.c`` and
|
||||||
|
the romlib jump table includes an entry for ``fn_b``, ``fn_a`` will include
|
||||||
|
a reference to ``fn_b``'s original program text instead of the wrapper. Thus
|
||||||
|
the jumptable author must take care to include public entry points into
|
||||||
|
translation units to avoid paying the program text cost twice, once in the
|
||||||
|
original executable and once in romlib.
|
||||||
|
|
||||||
Script
|
Script
|
||||||
~~~~~~
|
~~~~~~
|
||||||
|
|
||||||
|
@ -86,7 +95,7 @@ files for the "library at ROM" to work. It implements multiple functions:
|
||||||
|
|
||||||
3. ``romlib_generator.py genwrappers [args]`` - Generates a wrapper function for
|
3. ``romlib_generator.py genwrappers [args]`` - Generates a wrapper function for
|
||||||
each entry in the index file except for the ones that contain the keyword
|
each entry in the index file except for the ones that contain the keyword
|
||||||
``patch``. The generated wrapper file is called ``<fn_name>.s``.
|
``patch``. The generated wrapper file is called ``wrappers.s``.
|
||||||
|
|
||||||
4. ``romlib_generator.py pre [args]`` - Preprocesses the index file which means
|
4. ``romlib_generator.py pre [args]`` - Preprocesses the index file which means
|
||||||
it resolves all the include commands in the file recursively. It can also
|
it resolves all the include commands in the file recursively. It can also
|
||||||
|
|
|
@ -45,7 +45,7 @@ endif
|
||||||
|
|
||||||
.PHONY: all clean distclean
|
.PHONY: all clean distclean
|
||||||
|
|
||||||
all: $(BUILD_DIR)/romlib.bin $(LIB_DIR)/libwrappers.a
|
all: $(BUILD_DIR)/romlib.bin $(BUILD_DIR)/romlib.ldflags $(LIB_DIR)/libwrappers.a
|
||||||
|
|
||||||
%.o: %.s | $$(@D)/
|
%.o: %.s | $$(@D)/
|
||||||
$(s)echo " AS $@"
|
$(s)echo " AS $@"
|
||||||
|
@ -89,6 +89,10 @@ $(BUILD_DIR)/jmptbl.s: $(BUILD_DIR)/jmptbl.i | $$(@D)/
|
||||||
$(s)echo " TBL $@"
|
$(s)echo " TBL $@"
|
||||||
$(q)$(ROMLIB_GEN) gentbl --output $@ --bti=$(ENABLE_BTI) $<
|
$(q)$(ROMLIB_GEN) gentbl --output $@ --bti=$(ENABLE_BTI) $<
|
||||||
|
|
||||||
|
$(BUILD_DIR)/romlib.ldflags: ../../$(PLAT_DIR)/jmptbl.i
|
||||||
|
$(s)echo " LDFLAGS $@"
|
||||||
|
$(q)$(ROMLIB_GEN) link-flags $< > $@
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
$(q)rm -f $(BUILD_DIR)/*
|
$(q)rm -f $(BUILD_DIR)/*
|
||||||
|
|
||||||
|
|
|
@ -182,6 +182,22 @@ class TableGenerator(RomlibApplication):
|
||||||
template_name = "jmptbl_entry_" + item["type"] + bti + ".S"
|
template_name = "jmptbl_entry_" + item["type"] + bti + ".S"
|
||||||
output_file.write(self.build_template(template_name, item, True))
|
output_file.write(self.build_template(template_name, item, True))
|
||||||
|
|
||||||
|
class LinkArgs(RomlibApplication):
|
||||||
|
""" Generates the link arguments to wrap functions. """
|
||||||
|
|
||||||
|
def __init__(self, prog):
|
||||||
|
RomlibApplication.__init__(self, prog)
|
||||||
|
self.args.add_argument("file", help="Input file")
|
||||||
|
|
||||||
|
def main(self):
|
||||||
|
index_file_parser = IndexFileParser()
|
||||||
|
index_file_parser.parse(self.config.file)
|
||||||
|
|
||||||
|
fns = [item["function_name"] for item in index_file_parser.items
|
||||||
|
if not item["patch"] and item["type"] != "reserved"]
|
||||||
|
|
||||||
|
print(" ".join("-Wl,--wrap " + f for f in fns))
|
||||||
|
|
||||||
class WrapperGenerator(RomlibApplication):
|
class WrapperGenerator(RomlibApplication):
|
||||||
"""
|
"""
|
||||||
Generates a wrapper function for each entry in the index file except for the ones that contain
|
Generates a wrapper function for each entry in the index file except for the ones that contain
|
||||||
|
@ -214,21 +230,19 @@ class WrapperGenerator(RomlibApplication):
|
||||||
if item["type"] == "reserved" or item["patch"]:
|
if item["type"] == "reserved" or item["patch"]:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
asm = self.config.b + "/" + item["function_name"] + ".s"
|
if not self.config.list:
|
||||||
if self.config.list:
|
# The jump instruction is 4 bytes but BTI requires and extra instruction so
|
||||||
# Only listing files
|
# this makes it 8 bytes per entry.
|
||||||
files.append(asm)
|
function_offset = item_index * (8 if self.config.bti else 4)
|
||||||
else:
|
|
||||||
with open(asm, "w") as asm_file:
|
|
||||||
# The jump instruction is 4 bytes but BTI requires and extra instruction so
|
|
||||||
# this makes it 8 bytes per entry.
|
|
||||||
function_offset = item_index * (8 if self.config.bti else 4)
|
|
||||||
|
|
||||||
item["function_offset"] = function_offset
|
item["function_offset"] = function_offset
|
||||||
asm_file.write(self.build_template("wrapper" + bti + ".S", item))
|
files.append(self.build_template("wrapper" + bti + ".S", item))
|
||||||
|
|
||||||
if self.config.list:
|
if self.config.list:
|
||||||
print(" ".join(files))
|
print(self.config.b + "/wrappers.s")
|
||||||
|
else:
|
||||||
|
with open(self.config.b + "/wrappers.s", "w") as asm_file:
|
||||||
|
asm_file.write("\n".join(files))
|
||||||
|
|
||||||
class VariableGenerator(RomlibApplication):
|
class VariableGenerator(RomlibApplication):
|
||||||
""" Generates the jump table global variable with the absolute address in ROM. """
|
""" Generates the jump table global variable with the absolute address in ROM. """
|
||||||
|
@ -258,7 +272,8 @@ class VariableGenerator(RomlibApplication):
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
APPS = {"genvar": VariableGenerator, "pre": IndexPreprocessor,
|
APPS = {"genvar": VariableGenerator, "pre": IndexPreprocessor,
|
||||||
"gentbl": TableGenerator, "genwrappers": WrapperGenerator}
|
"gentbl": TableGenerator, "genwrappers": WrapperGenerator,
|
||||||
|
"link-flags": LinkArgs}
|
||||||
|
|
||||||
if len(sys.argv) < 2 or sys.argv[1] not in APPS:
|
if len(sys.argv) < 2 or sys.argv[1] not in APPS:
|
||||||
print("usage: romlib_generator.py [%s] [args]" % "|".join(APPS.keys()), file=sys.stderr)
|
print("usage: romlib_generator.py [%s] [args]" % "|".join(APPS.keys()), file=sys.stderr)
|
||||||
|
|
|
@ -3,8 +3,9 @@
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: BSD-3-Clause
|
* SPDX-License-Identifier: BSD-3-Clause
|
||||||
*/
|
*/
|
||||||
.globl ${function_name}
|
.section .text.__wrap_${function_name}
|
||||||
${function_name}:
|
.globl __wrap_${function_name}
|
||||||
|
__wrap_${function_name}:
|
||||||
ldr x17, =jmptbl
|
ldr x17, =jmptbl
|
||||||
mov x16, #${function_offset}
|
mov x16, #${function_offset}
|
||||||
ldr x17, [x17]
|
ldr x17, [x17]
|
||||||
|
|
|
@ -3,8 +3,9 @@
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: BSD-3-Clause
|
* SPDX-License-Identifier: BSD-3-Clause
|
||||||
*/
|
*/
|
||||||
.globl ${function_name}
|
.section .text.__wrap_${function_name}
|
||||||
${function_name}:
|
.globl __wrap_${function_name}
|
||||||
|
__wrap_${function_name}:
|
||||||
bti jc
|
bti jc
|
||||||
ldr x17, =jmptbl
|
ldr x17, =jmptbl
|
||||||
mov x16, #${function_offset}
|
mov x16, #${function_offset}
|
||||||
|
|
|
@ -465,6 +465,10 @@ define linker_script_path
|
||||||
$(patsubst %.S,$(BUILD_DIR)/%,$(1))
|
$(patsubst %.S,$(BUILD_DIR)/%,$(1))
|
||||||
endef
|
endef
|
||||||
|
|
||||||
|
ifeq ($(USE_ROMLIB),1)
|
||||||
|
WRAPPER_FLAGS := @${BUILD_PLAT}/romlib/romlib.ldflags
|
||||||
|
endif
|
||||||
|
|
||||||
# MAKE_BL macro defines the targets and options to build each BL image.
|
# MAKE_BL macro defines the targets and options to build each BL image.
|
||||||
# Arguments:
|
# Arguments:
|
||||||
# $(1) = BL stage
|
# $(1) = BL stage
|
||||||
|
@ -514,11 +518,11 @@ ifeq ($($(ARCH)-ld-id),arm-link)
|
||||||
--map --list="$(MAPFILE)" --scatter=${PLAT_DIR}/scat/${1}.scat \
|
--map --list="$(MAPFILE)" --scatter=${PLAT_DIR}/scat/${1}.scat \
|
||||||
$(LDPATHS) $(LIBWRAPPER) $(LDLIBS) $(BL_LIBS) $(OBJS)
|
$(LDPATHS) $(LIBWRAPPER) $(LDLIBS) $(BL_LIBS) $(OBJS)
|
||||||
else ifeq ($($(ARCH)-ld-id),gnu-gcc)
|
else ifeq ($($(ARCH)-ld-id),gnu-gcc)
|
||||||
$$(q)$($(ARCH)-ld) -o $$@ $$(TF_LDFLAGS) $$(LDFLAGS) $(BL_LDFLAGS) -Wl,-Map=$(MAPFILE) \
|
$$(q)$($(ARCH)-ld) -o $$@ $$(TF_LDFLAGS) $$(LDFLAGS) $$(WRAPPER_FLAGS) $(BL_LDFLAGS) -Wl,-Map=$(MAPFILE) \
|
||||||
$(addprefix -Wl$(comma)--script$(comma),$(LINKER_SCRIPTS)) -Wl,--script,$(DEFAULT_LINKER_SCRIPT) \
|
$(addprefix -Wl$(comma)--script$(comma),$(LINKER_SCRIPTS)) -Wl,--script,$(DEFAULT_LINKER_SCRIPT) \
|
||||||
$(OBJS) $(LDPATHS) $(LIBWRAPPER) $(LDLIBS) $(BL_LIBS)
|
$(OBJS) $(LDPATHS) $(LIBWRAPPER) $(LDLIBS) $(BL_LIBS)
|
||||||
else
|
else
|
||||||
$$(q)$($(ARCH)-ld) -o $$@ $$(TF_LDFLAGS) $$(LDFLAGS) $(BL_LDFLAGS) -Map=$(MAPFILE) \
|
$$(q)$($(ARCH)-ld) -o $$@ $$(TF_LDFLAGS) $$(LDFLAGS) $$(WRAPPER_FLAGS) $(BL_LDFLAGS) -Map=$(MAPFILE) \
|
||||||
$(addprefix -T ,$(LINKER_SCRIPTS)) --script $(DEFAULT_LINKER_SCRIPT) \
|
$(addprefix -T ,$(LINKER_SCRIPTS)) --script $(DEFAULT_LINKER_SCRIPT) \
|
||||||
$(OBJS) $(LDPATHS) $(LIBWRAPPER) $(LDLIBS) $(BL_LIBS)
|
$(OBJS) $(LDPATHS) $(LIBWRAPPER) $(LDLIBS) $(BL_LIBS)
|
||||||
endif
|
endif
|
||||||
|
|
|
@ -36,7 +36,6 @@ fdt fdt_get_alias_namelen
|
||||||
fdt fdt_get_name
|
fdt fdt_get_name
|
||||||
fdt fdt_get_alias
|
fdt fdt_get_alias
|
||||||
fdt fdt_node_offset_by_phandle
|
fdt fdt_node_offset_by_phandle
|
||||||
fdt fdt_subnode_offset
|
|
||||||
fdt fdt_add_subnode
|
fdt fdt_add_subnode
|
||||||
mbedtls mbedtls_asn1_get_alg
|
mbedtls mbedtls_asn1_get_alg
|
||||||
mbedtls mbedtls_asn1_get_alg_null
|
mbedtls mbedtls_asn1_get_alg_null
|
||||||
|
|
Loading…
Add table
Reference in a new issue