Searched hist:"7 f761274bdee764b074451ade98cbdd2dd3e225d" (Results 1 – 1 of 1) sorted by relevance
| /optee_os/core/arch/arm/ |
| H A D | arm.mk | 7f761274bdee764b074451ade98cbdd2dd3e225d Wed Feb 27 15:54:22 UTC 2019 Jerome Forissier <jerome.forissier@linaro.org> Compile user TAs with -fpic rather than -fpie
TA source files are compiled with the -fpie GCC flag in order to generate a Position Independent Executable. This is not suitable to produce a shared library as introduced by commit f8896d1301fc ("TA dev kit: add support for creating shared libraries"). -fpic should be used instead. Here is what the GCC man page has to say on these flags:
-fpic Generate position-independent code (PIC) suitable for use in a shared library [...]
-fpie -fPIE These options are similar to -fpic and -fPIC, but generated position independent code can be only linked into executables.
So, it is quite clear that -fpie is wrong for a shared library. It is not very clear however if -fpic can be used when generating code for an executable. I think it can, and there is a bug report against the GCC documentation that would confirm this [1]. Therefore we can simply use -fpic in all cases. This is quite convenient because we currently make no difference in the compile flags when we are building an executable, a static library or a shared library.
The difference between -fpie and -fpic has to do with the kinds of relocations that the compiler is allowed to emit. I stumbled upon this issue when experimenting with shared libraries and the code proposed by Jens to share read-only pages between TAs [2]. In my test case, a shared library already loaded by one TA, is used by another TA. During the load phase of the second TA, the TEE core crashed with a data-abort (write permission fault) when trying to apply an R_ARM_REL32 relocation to some literal pool data in the .text section of the library. The whole .text being mapped read-only, there should be no relocation to do here. And indeed the cause was the wrong flag (-fpie) used when compiling the shared library.
Link: [1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70419 Link: [2] https://github.com/OP-TEE/optee_os/pull/2801 Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org> CC: Jens Wiklander <jens.wiklander@linaro.org> Tested-by: Jerome Forissier <jerome.forissier@linaro.org> (QEMU) Tested-by: Jerome Forissier <jerome.forissier@linaro.org> (HiKey960 32 & 64-bit TA) Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org> Tested-by: Etienne Carriere <etienne.carriere@linaro.org> (stm32mp1 Armv7)
|