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

Compiling static lib (relic-toolkit) to TA #1691

Closed
sthomsen1 opened this issue Jul 14, 2017 · 10 comments
Closed

Compiling static lib (relic-toolkit) to TA #1691

sthomsen1 opened this issue Jul 14, 2017 · 10 comments

Comments

@sthomsen1
Copy link

Hi
i have some trouble compiling a static lib (the crypto relic-toolkit library) to my TA.
when i try to compile my TA i got some errors like:

/home/sascha/work/hikey/optee_os/out/arm/export-ta_arm32/lib/librelic_s.a(relic_core.c.o): In Funktion `core_init':
relic_core.c:(.text+0xcc): Nicht definierter Verweis auf `_setjmp'
/home/sascha/work/hikey/optee_os/out/arm/export-ta_arm32/lib/librelic_s.a(relic_rand_hash.c.o): In Funktion `rand_bytes':
relic_rand_hash.c:(.text+0x6c4): Nicht definierter Verweis auf `exit'
/home/sascha/work/hikey/optee_os/out/arm/export-ta_arm32/lib/librelic_s.a(relic_rand_hash.c.o): In Funktion `rand_seed':
relic_rand_hash.c:(.text+0x84e): Nicht definierter Verweis auf `exit'
/home/sascha/work/hikey/optee_os/out/arm/export-ta_arm32/lib/librelic_s.a(relic_fp_prime.c.o): In Funktion `fp2_calc':
relic_fp_prime.c:(.text+0xca): Nicht definierter Verweis auf `_setjmp'
relic_fp_prime.c:(.text+0x420): Nicht definierter Verweis auf `exit'

relic itself is static and (i think) is included right in my code. at least i can include it and call the functions.
Searching the include libraries for TA got me thinking the functions exit() and setjmp() are not supported. is this right ?

thanks for your help
ps: i know that optee offers its own crypt lib.

@jenswi-linaro
Copy link
Contributor

I don't think you've compiled the static lib with our headers or you'd get a compile error for exit.
setjmp() is supported, but not exit().

#define exit(x) TEE_Panic((x))

At some good place should take care of the exit problem as well.

@sthomsen1
Copy link
Author

ah okay i think this is the error and i need to recompile the library. maybe you can help me with the right parameters, i keep getting errors and i think i don't know exactly if I'm missing something.
Or is it to "library specific" ?

SET(CMAKE_SYSTEM_NAME Linux)
SET(CMAKE_SYSTEM_VERSION 1)

# specify the cross compiler
SET(CMAKE_C_COMPILER   	/home/sascha/work/hikey/toolchains/aarch32/bin/arm-linux-gnueabihf-gcc)
SET(CMAKE_CXX_COMPILER 	/home/sascha/work/hikey/toolchains/aarch32/bin/arm-linux-gnueabihf-g++)
SET(CMAKE_STRIP 	/home/sascha/work/hikey/toolchains/aarch32/bin/arm-linux-gnueabihf-strip)

# where is the target environment 
SET(CMAKE_FIND_ROOT_PATH  /home/sascha/work/hikey/toolchains/aarch32)

# search for programs in the build host directories
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY)

# for libraries and headers in the target directories
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY /home/sascha/work/hikey/toolchains/aarch32/lib)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE /home/sascha/work/hikey/toolchains/aarch32/include)
SET(CMAKE_POSITION_INDEPENDENT_CODE ON)

SET(CMAKE_C_FLAGS "-mno-unaligned-access")
SET(CMAKE_STATIC_LINKER_FLAGS "-static")

@jenswi-linaro
Copy link
Contributor

Which options needed depends on how OP-TEE was compiled. Compiling for instance libutee with V=1 as an argument to make will give you a clue which flags are needed.

@sthomsen1
Copy link
Author

okay thanks for your help i will figure it out

@sthomsen1
Copy link
Author

sorry i have to reopen this issue but i still have an error with the compiled library.

I build my library with the compiler flags found in $(TA_DEV_KIT_DIR)/mk/config.mk and linked all my libs like:

-LINKER_FILE=" -L/home/sascha/work/hikey/toolchains/aarch32/arm-linux-gnueabihf/libc/lib/ -L/home/sascha/work/hikey/toolchains/aarch32/arm-linux-gnueabihf/libc/usr/lib/" 

-COMPILER="-static -mcpu=cortex-a53 -Os -g3 -fpie -mthumb -mthumb-interwork -fno-short-enums -fno-common -mno-unaligned-access -mfloat-abi=hard -funsafe-math-optimizations -funwind-tables -I/home/sascha/work/hikey/toolchains/aarch32/arm-linux-gnueabihf/libc/usr/include" \

when i try to compile the hello_world (using my new lib) i get this error.

home/sascha/work/hikey/build/../toolchains/aarch32/bin/arm-linux-gnueabihf-ld  -pie -T ./ta.lds -Map=./8aaaf200-2450-11e4-abe2-0002a5d5c51b.map --sort-section=alignment  ./hello_world_ta.o ./user_ta_header.o  -L/home/sascha/work/hikey/optee_os/out/arm/export-ta_arm32/lib -lrelic_s -lutee -lpng -lzlib -lutils -lmpa -lutee -lutils -o 8aaaf200-2450-11e4-abe2-0002a5d5c51b.elf
/home/sascha/work/hikey/optee_os/out/arm/export-ta_arm32/lib/librelic_s.a(relic_ed_util.c.o): In Funktion `ed_is_infty':
/home/sascha/work/relic-ref/src/ed/relic_ed_util.c:193: Not defined `__assert_fail'

I try to check why this is happend. __assert_fail seems to be in libc.a but i dont have it in the TA right ?
Is there a way to get this working ? I already try to copy the libc.a file from cross-compiler to my ta/lib folder. But even though the compiler include it i get this error.

@sthomsen1 sthomsen1 reopened this Jul 19, 2017
@jenswi-linaro
Copy link
Contributor

The libc (and header files) shipped together with the compiler is targeting Linux user space, that will not work in a TA.

@igoropaniuk
Copy link
Contributor

igoropaniuk commented Jul 19, 2017

Hi @sthomsen1
Here is a pretty good explanation here about pitfalls of porting linux usermode libs (why it's a complex task) and linking/using them with TAs
#1303 (comment)
#1496 (comment)
#988

@sthomsen1
Copy link
Author

I managed it by rewriting the source of the library. Now i need some test to see if everything is working thanks for your help.

@igoropaniuk very useful link! Thanks

@stefan2904
Copy link

@sthomsen1 did you succeed with porting relic to OPTEE? and is your result open source by any chance? ;-) thanks!

@sthomsen1
Copy link
Author

Sorry for the late response, didn’t see your comment. Unfortunately I don’t have the source code anymore :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants