summaryrefslogtreecommitdiff
path: root/ldelf
AgeCommit message (Collapse)Author
2020-09-04ldelf: use libunwJerome Forissier
Drop ldelf/unwind_arm32,64}.c and use common code from libunw instead. Signed-off-by: Jerome Forissier <jerome@forissier.org> Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org> Reviewed-by: Etienne Carriere <etienne.carriere@linaro.org>
2020-09-02ldelf: arm64: support R_AARCH64_NONE relocationsEtienne Carriere
Add support for relocation type R_AARCH64_NONE indicating no relocation is needed. No issue have been currently reported on 64bit machines but the issue was found with 32bit TAs that were built with GCC 9 and were illegitimately refused to be loaded. Linker that generates the TA executable usually does not add such relocation type entries in the relocation table as it adds no real value at run or debug time. This change ensures that if such entries remain in a TA, it is still loadable. Signed-off-by: Etienne Carriere <etienne.carriere@linaro.org> Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org> Reviewed-by: Jerome Forissier <jerome@forissier.org>
2020-09-02ldelf: arm32: support R_ARM_NONE relocationsEtienne Carriere
Fixes an issue when the toolchain used to build a TA creates R_ARM_NONE entries in the relocation table. Such relocation type means that no relocation is expected but the relocation table parser did not handle this type prior this change and TAs with such entries failed to be loaded with an error message like: E/LD: e32_relocate:378 Unknown relocation type 0 It appears that GCC 9 (at least GCC-9.2 and GCC-9.3) creates such entries while prior version of the GCC toolchain did not. Linker that generates the TA executable usually does not add such relocation type entries in the relocation table as it adds no real value at run or debug time. This change ensures that if such entries remain in a TA, it is still loadable. Fixes: https://github.com/OP-TEE/optee_os/issues/4064 Tested-by: Etienne Carriere <etienne.carriere@linaro.org> (stm32mp1, qemu) Signed-off-by: Etienne Carriere <etienne.carriere@linaro.org> Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org> Reviewed-by: Jerome Forissier <jerome@forissier.org>
2020-08-25ldelf: arm64: support R_AARCH64_TLSDESC relocationsJerome Forissier
When compiling the __thread test in optee_test (xtest 1029), GCC 8.3 emits R_AARCH64_TLS_TPREL relocations while GCC 6 and 7 generate R_AARCH64_TLSDESC instead. The latter are quite easy to implement once the former are done so add the required code to ldelf. This also enables the C++ tests (xtest 1031) to pass with the older compilers. Signed-off-by: Jerome Forissier <jerome@forissier.org> Tested-by: Jerome Forissier <jerome@forissier.org> (QEMUv8, GCC 6.2/7.2) Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
2020-08-06ldelf: increase heap size from 12 to 16 KiBJerome Forissier
Preparing for C++ support in TAs. The current ldelf heap is barely sufficient to run some tests such as xtest 1022 (dlopen()) when CFG_ULIBS_SHARED=y. If slightly larger section headers are present (such as when introducing Thread Local Storage tests, needed for C++), the heap becomes too small and the TA fails to load. Signed-off-by: Jerome Forissier <jerome@forissier.org> Acked-by: Etienne Carriere <etienne.carriere@linaro.org> Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
2020-08-06ldelf, libutee: rework support of DT_INIT_ARRAY/DT_FINI_ARRAYJerome Forissier
Now that we have the standard function dl_iterate_phdr() in libutee, we can use it to process the initialization and finalization arrays in the ELF files and deprecate the ad-hoc structure __init_fini_info introduced in commit dd655cb9906c ("ldelf, ta: add support for DT_INIT_ARRAY and DT_FINI_ARRAY") [1]. Unfortunately, removing __init_fini_info is not an option if we want to ensure backward compatibility. This concerns only TAs which use ELF initialization and/or finalization functions. [1] Released in version 3.9.0. Signed-off-by: Jerome Forissier <jerome@forissier.org> Acked-by: Etienne Carriere <etienne.carriere@linaro.org> Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
2020-08-06ldelf, libutee: add minimal Thread Local Storage supportJerome Forissier
Preparing for C++ support in TAs. Adds enough runtime Thread Local Storage (TLS) support for the GNU C++ compilers (arm-linux-gnueabihf-g++, aarch64-linux-gnu-g++) to work with OP-TEE. That is: - A Thread Control Block, - The __tls_get_addr() and dl_iterate_phdr() functions. Note that __tls_get_addr() is an ABI helper so it has no prototype in a user-accessible header file. dl_iterate_phdr() however is defined in <link.h> and may be used in a TA. The file lib/libutee/include/link.h is borrowed from Android's Bionic [1] with minor changes (added the required #include statement and named the function parameters). A similar <link.h> header is provided by other C libraries such as GNU libc, musl and FreeBSD/NetBSD/OpenBSD. Link: [1] https://android.googlesource.com/platform/bionic/+/master/libc/include/link.h Signed-off-by: Jerome Forissier <jerome@forissier.org> Acked-by: Etienne Carriere <etienne.carriere@linaro.org> Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
2020-08-06Move ELF headers from ldelf/ to lib/libutee/Jerome Forissier
Preparing for C++ support in TAs. Moves the ELF headers (elf32.h, elf64.h, elf_common.h) from ldelf/include to lib/libutee/include so that they may be used by libutee to implement the dl_iterate_phdr() function. This will be done in a later commit. Signed-off-by: Jerome Forissier <jerome@forissier.org> Acked-by: Etienne Carriere <etienne.carriere@linaro.org> Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
2020-08-06ldelf: arm64: support R_AARCH64_TLS_TPREL relocationsJerome Forissier
Preparing for C++ support in TAs. This commit adds support for relocation type R_AARCH64_TLS_TPREL. Although OP-TEE does not support multi-threaded TAs, introducing basic support for multi-threading will allow binaries generated by the aarch64-linux-gnueabihf-g++ compiler to work properly. Indeed, this compiler is configured for a multi-threadded environment by default. The way R_AARCH64_TLS_TPREL works is simple: the runtime library needs to keep a per-thread copy of all the TLS segments in the application. When the compiler needs to access a thread-specific symbol, it emits this relocation. The loader will then replace the value by the offset of the desired symbol in the Thread Control Block of the current thread (the address of the TCB is obtained via the TPIDR_EL0 register). The runtime code that sets up the TCB from the TLS segments will come in a later commit. Signed-off-by: Jerome Forissier <jerome@forissier.org> Acked-by: Etienne Carriere <etienne.carriere@linaro.org> Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
2020-08-06ldelf: arm: support R_ARM_TLS_DTPMOD32 and R_ARM_TLS_DTPOFF32 relocationsJerome Forissier
Preparing for C++ support in TAs. This commit adds support for Thread Local Storage (TLS) relocation types R_ARM_TLS_DTPMOD32 and R_ARM_TLS_DTPOFF32. OP-TEE does not support multi-threaded TAs so in principle there is no need to handle the TLS relocations. However, this commit will allow to run C++ TAs built with the "official" arm-linux-gnueabihf compiler (which is built with threading support enabled), as long as no multi-thread feature is explicitly used by the TA. In other words, it avoids the need to re-build a toolchain with --disable-threads. Signed-off-by: Jerome Forissier <jerome@forissier.org> Acked-by: Etienne Carriere <etienne.carriere@linaro.org> Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
2020-08-06ldelf: add support for weak symbolsJerome Forissier
Preparing for C++ support in TAs. When ldelf performs a symbol lookup in a TA, it currently considers only global symbols that are not undefined. It turns out that g++ can generates dynamic relocations referencing symbols that are weak and undefined [1], in other words: weak declarations. Those should end up resolving to zero. This commit updates the symbol resolution to first look for global defined symbols, then weak defined, then weak undefined. [1] __pthread_key_create, pthread_mutex_lock, pthread_mutex_unlock, __gnu_Unwind_Find_exidx. Signed-off-by: Jerome Forissier <jerome@forissier.org> Acked-by: Etienne Carriere <etienne.carriere@linaro.org> Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
2020-08-03ldelf: __resolve_sym(): support STT_NOTYPEJerome Forissier
Symbols defined in a linker script are assigned type STT_NOTYPE, but the __resolve_sym() function in ldelf only supports STT_OBJECT and STT_FUNCTION. As a result, it is impossible to resolve STT_NOTYPE symbols at runtime. This causes an error in shared libraries when ftrace is enabled: # Platform: QEMU $ make CFG_FTRACE_SUPPORT=y CFLAGS_ta_arm32=-pg run $ xtest 1019 D/LD: ldelf:134 Loading TA 5b9e0e40-2636-11e1-ad9e-0002a5d5c51b E/LD: __resolve_sym:61 Symbol type not supported E/TC:? 0 init_with_ldelf:232 ldelf failed with res: 0xffff000a * regression_1019 Test dynamically linked TA regression_1000.c:1502: [...] TEEC_ERROR_NOT_SUPPORTED This commit adds STT_NOTYPE to the supported types, handled the same way as STT_OBJECT and STT_FUNCTION. Fixes: 97c5ac19427b ("ldelf: check ranges in __resolve_sym()") Signed-off-by: Jerome Forissier <jerome@forissier.org> Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
2020-08-03ldelf: arm: fix the unwind stack failure with __no_return functionJerome Forissier
Similar fix to commit 19b3fe6c5a72 ("core: arm: fix the unwind stack failure with __no_return function") for user space. Signed-off-by: Jerome Forissier <jerome@forissier.org> Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
2020-06-24libutee, ldelf: add leading underscore to syscall wrappersJerome Forissier
libutee defines assembler wrapper functions for each OP-TEE system call. These wrappers have a utee_ prefix. This commit adds a leading underscore so that the names cannot clash with user-defined symbols. Doing so is common practice for "system" libraries, as defined by the C standard in a set of requirements that can be summarized as follows (excerpt from the GNU libc documentation [1]): [R]eserved names include all external identifiers (global functions and variables) that begin with an underscore (‘_’) and all identifiers regardless of use that begin with either two underscores or an underscore followed by a capital letter are reserved names. This is so that the library and header files can define functions, variables, and macros for internal purposes without risk of conflict with names in user programs. The utee_*() wrappers are internal to OP-TEE and are not supposed to be called directly by TAs so this should not have any user-visible impact. Link: [1] https://www.gnu.org/software/libc/manual/html_node/Reserved-Names.html Signed-off-by: Jerome Forissier <jerome@forissier.org> Acked-by: Jens Wiklander <jens.wiklander@linaro.org> Reviewed-by: Etienne Carriere <etienne.carriere@linaro.org>
2020-06-22ldelf: arm64: do not unwind past end of stackJerome Forissier
unwind_arm64() currently does not check the value of the frame pointer after it has done its job unwinding one frame. A NULL value indicates the end of the call stack, and therefore the function should return false to stop the caller from unwinding further (a do .. while loop is used in print_stack_arm64()). Instead invalid values for FP and PC are returned which causes an erroneous display and the unwind stops one step too late, when the FP is found to be outside the stack. Fixes the invalid last line in call stacks such as xtest 1019: E/TC:? 0 TA panicked with code 0x0 E/LD: Status of TA 5b9e0e40-2636-11e1-ad9e-0002a5d5c51b E/LD: arch: aarch64 [...] E/LD: Call stack: E/LD: 0x0000000080062a50 E/LD: 0x00000000801df848 E/LD: 0x00000000800631a8 E/LD: 0xfffffffffffffffc Signed-off-by: Jerome Forissier <jerome@forissier.org> Acked-by: Jens Wiklander <jens.wiklander@linaro.org>
2020-05-26link.mk: add missing $libgcc to ldargsVictor Chong
Add missing $libgcc arg to ldargs for ldelf, ta link.mk and ta link_shlib.mk. This is required for the AOSP clang build to fix compile errors like below: ld.lld: error: undefined symbol: __aeabi_mem* Signed-off-by: Victor Chong <victor.chong@linaro.org> Reviewed-by: Jerome Forissier <jerome@forissier.org>
2020-04-06ldelf: ldelf.ld.S: make sure _ldelf_start() is firstJens Wiklander
Makes sure that _ldelf_start() which is the entry point of ldelf is first in the binary. _ldelf_start() depends on this to perform relocation. Acked-by: Etienne Carriere <etienne.carriere@linaro.org> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
2020-03-09ldelf: prints consistent with readelfJens Wiklander
Prints names of sections consistent with names used in the readelf utility. Reviewed-by: Jerome Forissier <jerome@forissier.org> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
2020-03-09ldelf: consistent error codesJens Wiklander
Changes error codes related to bad format or values in ELF to TEE_ERROR_BAD_FORMAT. This includes overflowing multiplications and addresses outside the range of the current ELF being parsed. Reviewed-by: Jerome Forissier <jerome@forissier.org> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
2020-03-09ldelf: use confine_array_index() to cap speculationJens Wiklander
Uses confine_array_index() to limit speculation on different indexes into the ELF. Reviewed-by: Etienne Carriere <etienne.carriere@linaro.org> Acked-by: Jerome Forissier <jerome@forissier.org> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
2020-03-09ldelf: check ranges in __resolve_sym()Jens Wiklander
Adds checks in __resolve_sym() to see that the offset of the name and location of a symbol is in range. Reviewed-by: Jerome Forissier <jerome@forissier.org> Acked-by: Etienne Carriere <etienne.carriere@linaro.org> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
2020-03-09ldelf: calculate correct elf->max_addrJens Wiklander
Prior to this patch when the different load sections are mapped elf->max_addr is inceased as appropriate, except in one case, when memsz is larger than filesz. With this patch use memsz instead to calculate elf->max_addr in order to also cover .bss and friends. Reviewed-by: Jerome Forissier <jerome@forissier.org> Reviewed-by: Etienne Carriere <etienne.carriere@linaro.org> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
2020-03-06ldelf: strict checks during relocationJens Wiklander
Adds strict check of symbol index, string table index and destination location when relocating an ELF. This fixes an error where a malformed ELF may cause the loader to read/write data from/in other ELF or from the loader itself. Reviewed-by: Etienne Carriere <etienne.carriere@linaro.org> Reported-by: Martijn Bogaard <martijn@riscure.com> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
2020-03-06ldelf: check dynsym index is in rangeJens Wiklander
Checks that a dynsym index found in hashtab is in the valid range of dynsyms before indexing into the dynsym table. This fixes an error where a malformed ELF may cause the loader to read data from other ELF or from the loader itself. Acked-by: Etienne Carriere <etienne.carriere@linaro.org> Reported-by: Martijn Bogaard <martijn@riscure.com> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
2020-03-06ldelf: check string table rangesJens Wiklander
Checks that the string table is in the range of the ELF and also checks that offsets into the string table are indeed inside the string table. This fixes an error where a malformed ELF may cause the loader to read data from other ELF or from the loader itself. Acked-by: Etienne Carriere <etienne.carriere@linaro.org> Reported-by: Martijn Bogaard <martijn@riscure.com> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
2020-03-06ldelf: fix possible integer overflow in init_elf()Jens Wiklander
The size of the program headers is calculated as: e_phoff + e_phnum * e_phentsize This can overflow for large values leading to the 4k size check to fail. Fix this by using MUL_OVERFLOW() and ADD_OVERFLOW() instead. Reviewed-by: Etienne Carriere <etienne.carriere@linaro.org> Reported-by: Martijn Bogaard <martijn@riscure.com> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
2020-03-06ldelf: check dynsymtab and dynstr rangesJens Wiklander
Checks the ranges of dynsymtab and dynstr. Also checks that the dynstr index in section headers isn't out of range. This fixes an error where a malformed ELF may cause the loader to read data from other ELF or from the loader itself. Reviewed-by: Etienne Carriere <etienne.carriere@linaro.org> Reported-by: Martijn Bogaard <martijn@riscure.com> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
2020-03-06ldelf: check against section headers size overflowJens Wiklander
Adds a check in copy_section_headers() to guard against overflow in the e_shnum * e_shentsize multiplication. Reviewed-by: Etienne Carriere <etienne.carriere@linaro.org> Reviewed-by: Rouven Czerwinski <r.czerwinski@pengutronix.de> Reported-by: Martijn Bogaard <martijn@riscure.com> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
2020-03-06ldelf: check that hashtab entries are in rangeJens Wiklander
Adds checks that each looked up entry in the hashtab is in the range of the hashtab. This fixes an error where a malformed ELF may cause the loader to read data from other ELF or from the loader itself. Reviewed-by: Etienne Carriere <etienne.carriere@linaro.org> Reviewed-by: Rouven Czerwinski <r.czerwinski@pengutronix.de> Reported-by: Martijn Bogaard <martijn@riscure.com> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
2020-03-06ldelf: check that hashtab is in range before useJens Wiklander
Adds checks that the hashtab found via the dynamic section is in range of the loaded ELF before they are used. This fixes an error where a malformed ELF may cause the loader to read data from other ELF or from the loader itself. Acked-by: Etienne Carriere <etienne.carriere@linaro.org> Reported-by: Martijn Bogaard <martijn@riscure.com> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
2020-03-06ldelf: check that PT_DYNAMIC is in range before useJens Wiklander
Adds checks that the ELF program header PT_DYNAMIC is in range of the loaded ELF before they are used. This fixes an error where a malformed ELF may cause the loader to read data from other ELF or from the loader itself. Acked-by: Etienne Carriere <etienne.carriere@linaro.org> Reported-by: Martijn Bogaard <martijn@riscure.com> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
2020-02-25ldelf, ta: add support for DT_INIT_ARRAY and DT_FINI_ARRAYJerome Forissier
Adds support for running initialization and finalization functions in TA ELF files. Such functions are used, for instance, by C++ compilers to construct and destruct global objects. They can also be used in C thanks to __attribute__((constructor)) and __attribute__((destructor)). A global structure is added to libutee. ldelf is responsible for filling it with the addresses of the functions pointer arrays present in the ELF files whenever such a file is loaded. Since the number of arrays is unknown at compile time (it depends on how many ELF files are loaded, and whether they have constructors or destructors), memory is allocated on the TA heap. Two helper functions are introduced: __utee_call_elf_init_fn() and __utee_call_elf_fini_fn(). They are used when the TA instance is created and torn down, as well as by dlopen(). Signed-off-by: Jerome Forissier <jerome@forissier.org> Tested-by: Jerome Forissier <jerome@forissier.org> (QEMU, QEMUv8, HiKey960 32/64) Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
2019-11-14elf_common.h: Add relocation type R_AARCH64_NONEJens Wiklander
Adds the relocation type R_AARCH64_NONE. Reviewed-by: Jerome Forissier <jerome@forissier.org> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
2019-10-24ldelf: link.mk: add generated ldelf.map to $(cleanfiles)Jerome Forissier
Commit 7509ff7ce5e5 ("Add user mode ELF loader") omitted to add the generated file $(O)/ldelf/ldelf.map to $(cleanfiles) and therefore 'make clean' leaves it intact. Fix that. Signed-off-by: Jerome Forissier <jerome@forissier.org> Acked-by: Jens Wiklander <jens.wiklander@linaro.org>
2019-10-21ftrace: Add support for syscall function tracerSumit Garg
This patch adds support for syscall tracing in TEE core. It complements existing ftrace support for user TAs via adding trace for syscalls that are invoked by user TAs into the TEE core. And after this patch ftrace will cover both TA and TEE core code. So lets rename config option from CFG_TA_FTRACE_SUPPORT to CFG_FTRACE_SUPPORT. It is optional to enable syscall trace via CFG_SYSCALL_FTRACE=y config option in addition to CFG_FTRACE_SUPPORT=y config option. Signed-off-by: Sumit Garg <sumit.garg@linaro.org> Reviewed-by: Jerome Forissier <jerome@forissier.org>
2019-10-07ldelf: increase heap size from 8 to 12 KiBJerome Forissier
The ldelf heap is not big enough to load some 64-bit TAs with several shared libraries such as xtest 1006 when CFG_ULIBS_SHARED=y: * regression_1006 Test Basic OS features E/LD: copy_section_headers:766 malloc E/TC:? 0 init_with_ldelf:229 ldelf failed with res: 0xffff000c E/TC:? 0 tee_ta_open_session:727 Failed. Return error 0xffff000c regression_1006 FAILED Signed-off-by: Jerome Forissier <jerome@forissier.org> Acked-by: Joakim Bech <joakim.bech@linaro.org> Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
2019-09-10ldelf: add __noreturnJerome Forissier
The 32-bit variant of e64_relocate() deserves a __noreturn attribute because it calls utee_return() unconditionally. Fixes a Clang warning. Signed-off-by: Jerome Forissier <jerome@forissier.org> Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
2019-09-09ta: ldelf.ld.S: align __reloc_begin on 8 bytesJerome Forissier
__reloc_begin is currently defined as "__reloc_begin = ." just before the various .rel.* output sections. The problem is, there is no guarantee that the symbol will actually point to the first relocation entry due to the alignment constraints on relocation sections. For instance for Aarch64 relocations, alignment is 8 bytes, but __reloc_begin has no alignment constraint, so it might end before the first relocation (this issue was observed with the Clang linker, ld.lld). The patch forces the alignment of __reloc_begin on 8 bytes so that there can be no unwanted padding. Signed-off-by: Jerome Forissier <jerome@forissier.org> Acked-by: Rouven Czerwinski <r.czerwinski@pengutronix.de> Acked-by: Jens Wiklander <jens.wiklander@linaro.org>
2019-09-02build: do not use -Wp with the preprocessor and use -o instead of a redirectionJerome Forissier
This patch cleans up the command line where we use the C preprocessor to better reflect the documented usage in the GCC man page, thus preparing for Clang support. 1. When invoking the C preprocessor, there is no need for -Wp to pass arguments, so remove it. 2. -MD is not supposed to take a file name when passed to cpp. The dependency output file name is overridden with -MF. 3. Lastly, it is better to use -o to specify the output file instead of redirecting standard output, because if an error occurs during preprocessing we don't want the output file to be created. Signed-off-by: Jerome Forissier <jerome@forissier.org> Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
2019-08-23core, ldelf: add support for runtime loading of shared librariesJerome Forissier
This commit prepares the introduction of libdl, a dynamic linking library which will allow TAs to load shared libraries at run time, and resolve symbols on demand. It adds the following function to the system PTA, inspired from the POSIX dlopen() and dlsym(): - system_dlopen(): takes a UUID and flags. Performs an upcall into ldelf which then uses the usual system PTA functions to load an map the requested library into the address space of the calling TA. - system_dlsym(): takes a UUID and a symbol name. The symbol is looked up in the library specified by UUID by calling into ldelf. If UUID is all zeros, all the mapped binaries are searched. Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org> Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org> Acked-by: Etienne Carriere <etienne.carriere@linaro.org>
2019-08-23libutee: add tee_uuid_from_str()Jerome Forissier
Moves internal function parse_uuid() from ldelf/ta_elf.c to libutee so that it may be used by TAs or other user-space libraries such as the upcoming libdl. The function is renamed to tee_uuid_from_str() and declared in tee_internal_api_extensions.h. Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org> Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org> Reviewed-by: Etienne Carriere <etienne.carriere@linaro.org>
2019-08-23ldelf: fix commentJerome Forissier
ldelf_dump() does not exist, the comment about struct dump_entry_arg should refer to ldelf_arg::dump_entry() instead. Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org> Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org> Reviewed-by: Etienne Carriere <etienne.carriere@linaro.org>
2019-08-21Remove ASM define for assembly filesJens Wiklander
Removes the ASM define for assembly files now that they rely on the predefined macro __ASSEMBLER__ instead. Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
2019-08-21Replace ASM with compiler-builtin __ASSEMBLER__Jens Wiklander
The C preprocessor predefines __ASSEMBLER__ with value 1 when when preprocessing assembly language, see [1]. Instead of using a special defines, let's use the define already provided. Link: [1] https://gcc.gnu.org/onlinedocs/cpp/Standard-Predefined-Macros.html Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
2019-08-20ftrace: enable trace for utee_* assembly APIsSumit Garg
Enable function trace for utee_* syscall assembly APIs for better view of user-space to kernel switching. Suggested-by: Jerome Forissier <jerome.forissier@linaro.org> Signed-off-by: Sumit Garg <sumit.garg@linaro.org> Acked-by: Jerome Forissier <jerome.forissier@linaro.org>
2019-08-13ftrace: Add function execution time supportSumit Garg
Add support to dump function execution time at corresponding function exit points in output ftrace buffer. To achieve proper function execution time we need to exclude TA suspend time from timestamps, so add corresponding support in TEE core. Also user mapping must be active to access ftrace buffer, so do that during TA resume. Signed-off-by: Sumit Garg <sumit.garg@linaro.org> Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org> Tested-by: Jerome Forissier <jerome.forissier@linaro.org> (QEMU) Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
2019-08-13ldelf: ftrace: pass ftrace buffer address to kernelSumit Garg
Enable support to pass ftrace buffer address to kernel during loading of particular TA. It is required to support function execution time feature since kernel needs to update timestamps in ftrace buffer during TA suspends for proper execution time. Signed-off-by: Sumit Garg <sumit.garg@linaro.org> Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org> Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
2019-07-30ldelf: accurate non-legacy TA checkJens Wiklander
Prior to this patch ldelf relied on e_entry in the ELF header to point anywhere but at the lowest possible executable address to tell that it's not a legacy TA. This isn't enough since all TAs can use this entry address depending on compiler and linker. The only reliable indicator that the TA is not a legacy TA is that the depr_entry field of the TA header is UINT64_MAX. Unfortunately this means assuming that the ELF is not a legacy TA at load time and that the process needs to be restarted in case it turns out that it was a legacy TA. With this patch we have reliable detection of non-legacy TAs, but with increased load time for legacy TAs since the main ELF needs to be loaded and verified twice due to the TA store interface. Acked-by: Jerome Forissier <jerome.forissier@linaro.org> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
2019-07-19ldelf: fix warning in ftrace_init()Jens Wiklander
Fixes warning in ftrace_init(): ldelf/ftrace.c: In function ‘ftrace_init’: ldelf/ftrace.c:47:9: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast] fbuf = (struct ftrace_buf *)finfo->buf_start.ptr64; ^ Fixes: c96d7091b566 ("ftrace: Enable support for 32 bit apps") Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
2019-07-10ta: ldelf.ld.S: move .dynamic section next to .gotJerome Forissier
Updates the ldelf linker script in the same way the TA linker script was updated in commit "ta: arm: ta.ld.S: move .dynamic section next to .got". Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org> Acked-by: Jens Wiklander <jens.wiklander@linaro.org>