relic-toolkit/relic

Relic for ARMv6

Closed this issue · 6 comments

I've been trying to compile a third-party library built on top of relic, and I'm having some issues related to how relic is built. I'm working on a Raspberry Pi Zero-W, which is ARMv6. I have configured relic so it builds for arm architecture. My parameters are: -DARITH=arm-asm-254 -DARCH="ARM" and -DWSIZE=32.

However, I get the feeling relic is building for ARMv8: despite building without errors or warnings, as soon as I use some function based on relic, I get an Illegal instruction.

Since it seemed to be a build error, I checked the relic-toolkit files. In them I saw that in relic/src/arch/relic_arch_arm.c , line 59 it can be seen defined(__ARM_ARCH_6__). Thus, I deduce that the relic-toolkit can be built for ARMv6.

Because I saw no instructions about how to do it, I searched google and found that relic can be built for arduino by changing the .s files. Inspired by this, I changed the .s files in /src/low/arm-asm-254/ from .arch armv7-a to .arch armv6. However, while building it throws:

/relic/relic-toolkit-0.5.0/src/low/arm-asm-254/relic_fp_add_low.s:566: conditional infixes are deprecated in unified syntax
/relic/relic-toolkit-0.5.0/src/low/arm-asm-254/relic_fp_add_low.s:569: conditional infixes are deprecated in unified syntax
/relic/relic-toolkit-0.5.0/src/low/arm-asm-254/relic_fp_add_low.s:572: conditional infixes are deprecated in unified syntax
/relic/relic-toolkit-0.5.0/src/low/arm-asm-254/relic_fp_add_low.s:576: conditional infixes are deprecated in unified syntax
/relic/relic-toolkit-0.5.0/src/low/arm-asm-254/relic_fp_add_low.s:579: conditional infixes are deprecated in unified syntax
/relic/relic-toolkit-0.5.0/src/low/arm-asm-254/relic_fp_add_low.s:584: conditional infixes are deprecated in unified syntax
/relic/relic-toolkit-0.5.0/src/low/arm-asm-254/relic_fp_add_low.s:587: conditional infixes are deprecated in unified syntax
/relic/relic-toolkit-0.5.0/src/low/arm-asm-254/relic_fp_add_low.s:592: conditional infixes are deprecated in unified syntax

After which, it seems to build correctly, but once again, as soon as I call a function that employs relic I get Illegal instruction. I understand that all my problems come from having ARMv6 instead of ARMv7, and that there must be a way of telling relic which one I really need, but I have run out of ideas of how to do it.

Thanks for reporting! I suspect you are having this because of the cycle counter, which is heavily customized.

Can you try configuring TIMER=POSIX or ANSI?

I tried the setting the timer but I got the same results as before:

/home/pi/libopenabe_Zero_04/deps/relic/relic-toolkit-0.5.0/src/low/arm-asm-254/relic_fp_add_low.s: Assembler messages:
/home/pi/libopenabe_Zero_04/deps/relic/relic-toolkit-0.5.0/src/low/arm-asm-254/relic_fp_add_low.s:566: conditional infixes are deprecated in unified syntax
/home/pi/libopenabe_Zero_04/deps/relic/relic-toolkit-0.5.0/src/low/arm-asm-254/relic_fp_add_low.s:569: conditional infixes are deprecated in unified syntax
/home/pi/libopenabe_Zero_04/deps/relic/relic-toolkit-0.5.0/src/low/arm-asm-254/relic_fp_add_low.s:572: conditional infixes are deprecated in unified syntax
/home/pi/libopenabe_Zero_04/deps/relic/relic-toolkit-0.5.0/src/low/arm-asm-254/relic_fp_add_low.s:576: conditional infixes are deprecated in unified syntax
/home/pi/libopenabe_Zero_04/deps/relic/relic-toolkit-0.5.0/src/low/arm-asm-254/relic_fp_add_low.s:579: conditional infixes are deprecated in unified syntax
/home/pi/libopenabe_Zero_04/deps/relic/relic-toolkit-0.5.0/src/low/arm-asm-254/relic_fp_add_low.s:584: conditional infixes are deprecated in unified syntax
/home/pi/libopenabe_Zero_04/deps/relic/relic-toolkit-0.5.0/src/low/arm-asm-254/relic_fp_add_low.s:587: conditional infixes are deprecated in unified syntax
/home/pi/libopenabe_Zero_04/deps/relic/relic-toolkit-0.5.0/src/low/arm-asm-254/relic_fp_add_low.s:592: conditional infixes are deprecated in unified syntax

And then 'Illegal instruction' again. In case it is useful, I'm building relic for OpenABE using this repo.

Can you alternately change to ARITH=easy so we verify that the illegal instruction is really in the arm-asm-254 backend?

As suggested, I have defined ARITH=easy , and I no longer get the Illegal instruction message. To make sure that it was the ARITH change what stopped the error, I have tried more configurations:

  • ARITH=easy + TIMER= "ANSI" = PASS
  • ARITH=easy + TIMER= "POSIX" = PASS
  • ARITH=easy + No defined TIMER = PASS
  • ARITH=arm-asm-254 + no defined TIMER = Illegal instruction
  • ARITH=arm-asm-254 + TIMER= "ANSI" = Illegal instruction
  • ARITH=arm-asm-254 + no defined TIMER + .c files changeg from .arch armv7-a to .arch armv6 = Illegal instruction

So far ARITH=easy seems to make my tests pass, despite it not being as efficient as needed. Thus, my issues seems to be coming from the arm-asm-254 module, which does not seem to support ARMv6.

I think this will require changing the name of instructions e.g. ADDNES -> ADDSNE, see this example. I don't know how compatible this is with existing usage, though

Good morning. I finally managed to compile the library and run my tests as needed with no more issues. Changing -DARITH=arm-asm-254 to -DARITH=easy let me compile both in armv6 (RPI0-W) and armv8 (RPI4). I consider this issue solved on my part. I did not need to define any Timer.

Thank you for all the help provided!