Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v4] Relax location of ta head #6316

Merged
merged 5 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ unexport MAKEFILE_LIST
# nonzero status). Useful since a few recipes use shell redirection.
.DELETE_ON_ERROR:

include mk/macros.mk
include mk/checkconf.mk

.PHONY: all
Expand Down
7 changes: 6 additions & 1 deletion ldelf/ta_elf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1195,6 +1195,8 @@ static void set_tls_offset(struct ta_elf *elf __unused) {}

static void load_main(struct ta_elf *elf)
{
vaddr_t va = 0;

init_elf(elf);
map_segments(elf);
populate_segments(elf);
Expand All @@ -1207,7 +1209,10 @@ static void load_main(struct ta_elf *elf)
if (elf->bti_enabled)
ta_elf_add_bti(elf);

elf->head = (struct ta_head *)elf->load_addr;
if (!ta_elf_resolve_sym("ta_head", &va, NULL, elf))
elf->head = (struct ta_head *)va;
else
elf->head = (struct ta_head *)elf->load_addr;
if (elf->head->depr_entry != UINT64_MAX) {
/*
* Legacy TAs sets their entry point in ta_head. For
Expand Down
10 changes: 0 additions & 10 deletions mk/checkconf.mk
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,6 @@ define check-conf-mk
$(call mv-if-changed,$@.tmp,$@)
endef

# Rename $1 to $2 only if file content differs. Otherwise just delete $1.
define mv-if-changed
if cmp -s $2 $1; then \
rm -f $1; \
else \
$(cmd-echo-silent) ' UPD $2'; \
mv $1 $2; \
fi
endef

define cfg-vars-by-prefix
$(strip $(if $(1),$(call _cfg-vars-by-prefix,$(1)),
$(call _cfg-vars-by-prefix,CFG_ _CFG_ PLATFORM_)))
Expand Down
9 changes: 9 additions & 0 deletions mk/macros.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Rename $1 to $2 only if file content differs. Otherwise just delete $1.
define mv-if-changed
if cmp -s $2 $1; then \
rm -f $1; \
else \
$(cmd-echo-silent) ' UPD $2'; \
mv $1 $2; \
fi
endef
16 changes: 16 additions & 0 deletions scripts/ts_bin_to_c.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import argparse
import array
from elftools.elf.elffile import ELFFile, ELFError
from elftools.elf.sections import SymbolTableSection
import os
import re
import struct
Expand Down Expand Up @@ -65,6 +66,21 @@ def ta_get_flags(ta_f):
with open(ta_f, 'rb') as f:
elffile = ELFFile(f)

for s in elffile.iter_sections():
if isinstance(s, SymbolTableSection):
for symbol in s.iter_symbols():
if symbol.name == 'ta_head':
# Get the section containing the symbol
s2 = elffile.get_section(symbol.entry['st_shndx'])
offs = s2.header['sh_offset'] - s2.header['sh_addr']
# ta_head offset into ELF binary
offs = offs + symbol.entry['st_value']
offs = offs + 20 # Flags offset in ta_head
f.seek(offs)
flags = struct.unpack('<I', f.read(4))[0]
return flags

# For compatibility with older TAs
for s in elffile.iter_sections():
if get_name(s) == '.ta_head':
return struct.unpack('<16x4xI', s.data()[:24])[0]
Expand Down
1 change: 0 additions & 1 deletion ta/arch/arm/ta.ld.S
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ OUTPUT_ARCH(aarch64)
#endif

SECTIONS {
.ta_head : {*(.ta_head)}
.text : {
__text_start = .;
*(.text .text.*)
Expand Down
16 changes: 9 additions & 7 deletions ta/link.mk
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,19 @@ endif
link-ldflags += --as-needed # Do not add dependency on unused shlib
link-ldflags += $(link-ldflags$(sm))

$(link-out-dir$(sm))/dyn_list:
$(link-out-dir$(sm))/dyn_list: FORCE
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of FORCE, could there be a dependancy on $(conf-file)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure that is set in the TA dev-kit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I don't think it's set in the TA dev-kit, but that's also why we're using mv-if-changed() below so that we don't trigger unnecessary rebuilds.

@$(cmd-echo-silent) ' GEN $@'
$(q)mkdir -p $(dir $@)
$(q)echo "{" >$@
$(q)echo "__elf_phdr_info;" >>$@
$(q)echo "{" >$@.tmp
$(q)echo "__elf_phdr_info;" >>$@.tmp
ifeq ($(CFG_FTRACE_SUPPORT),y)
$(q)echo "__ftrace_info;" >>$@
$(q)echo "__ftrace_info;" >>$@.tmp
endif
$(q)echo "trace_ext_prefix;" >>$@
$(q)echo "trace_level;" >>$@
$(q)echo "};" >>$@
$(q)echo "trace_ext_prefix;" >>$@.tmp
$(q)echo "trace_level;" >>$@.tmp
$(q)echo "ta_head;" >>$@.tmp
$(q)echo "};" >>$@.tmp
$(q)$(call mv-if-changed,$@.tmp,$@)
link-ldflags += --dynamic-list $(link-out-dir$(sm))/dyn_list
dynlistdep = $(link-out-dir$(sm))/dyn_list
cleanfiles += $(link-out-dir$(sm))/dyn_list
Expand Down
2 changes: 2 additions & 0 deletions ta/mk/ta_dev_kit.mk
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ all:
include $(ta-dev-kit-dir)/mk/conf.mk
ta-dev-kit-dir$(sm) := $(ta-dev-kit-dir)

include $(ta-dev-kit-dir$(sm))/mk/macros.mk

ifneq (1, $(words $(BINARY) $(LIBNAME) $(SHLIBNAME)))
$(error You must specify exactly one of BINARY, LIBNAME or SHLIBNAME)
endif
Expand Down
2 changes: 1 addition & 1 deletion ta/ta.mk
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ $(foreach f, $(libfiles), \

# Copy .mk files
ta-mkfiles = mk/compile.mk mk/subdir.mk mk/gcc.mk mk/clang.mk mk/cleandirs.mk \
mk/cc-option.mk \
mk/cc-option.mk mk/macros.mk \
ta/link.mk ta/link_shlib.mk \
ta/mk/ta_dev_kit.mk

Expand Down