[llvm-dev] Thumb frame pointer register

Peter Smith via llvm-dev llvm-dev at lists.llvm.org
Wed Aug 21 04:14:19 PDT 2019


On Wed, 21 Aug 2019 at 11:29, Son Tuan VU <sontuan.vu119 at gmail.com> wrote:
>
> Thanks Tim & Peter,
>
> I am referring to mpi_montmul function from library/bignum.c, and this problem only occurs at clang -O3, so for the moment I am compiling the library with clang -02.
>
> As for GCC, if -fno-omit-frame-pointer is NOT used, it doesn't use r7 as frame register, while clang uses r7 by default (even without -fno-omit-frame-pointer).
>
> So my question is how to turn the use of frame pointer off for clang/llc?
>

I think you may be referring to
https://bugs.llvm.org/show_bug.cgi?id=34165 this is when compiling for
Thumb with a frame-pointer is enabled (default and with
-fno-omit-frame-pointer) and there is an inline assembly block with r7
in the clobber list.
The option -fomit-frame-pointer will disable the frame pointer in
clang and should work around this problem.

I'm a bit confused by "I tried passing -fomit-frame-pointer but this
is just a hacky workaround and does not work in this case, since the
function here does indeed need frame pointer."
Unless you are planning on unwinding the stack at run time through the
function it shouldn't need a frame-pointer. If you do require a frame
pointer then I think you are out of luck until pr34165 is fixed. If
you can alter the code locally, one possibility is to remove the
inline assembly to use a C implementation.

> Son Tuan Vu
>
>
> On Wed, Aug 21, 2019 at 11:18 AM Peter Smith <peter.smith at linaro.org> wrote:
>>
>> On Wed, 21 Aug 2019 at 06:05, Son Tuan VU via llvm-dev
>> <llvm-dev at lists.llvm.org> wrote:
>> >
>> > Hello all,
>> >
>> > I noticed that for ARM Thumb target, llc uses r7 as frame pointer (gcc does not do this AFAIK), and this register should therefore not be used as a general-purpose register.
>> >
>> > However, when compiling mbedTLS, which contains some code that is highly optimized for ARM platform and uses r7 to efficiently perform an operation. This raises an exception since r7 is now the frame pointer.
>> >
>> > I tried passing -fomit-frame-pointer but this is just a hacky workaround and does not work in this case, since the function here does indeed need frame pointer.
>> > ```
>> > The -fomit-frame-pointer option instructs the compiler to not store stack frame pointers if the function does not need it. You can use this option to reduce the code image size.
>> > ```
>>
>> Can you let us know which function in mbedTLS you are referring to. I
>> found https://tls.mbed.org/kb/development/arm-thumb-error-r7-cannot-be-used-in-asm-here
>> on the mbedTLS website which implies that you should use
>> -fomit-frame-pointer. I would be very surprised for code in mbedTLS to
>> simultaneously require a frame pointer and reserve r7 in Thumb state.
>> There may be some confusion about what GCC does as arm-none-eabi-gcc
>> uses -fomit-frame-pointer by default. As Tim points out, I think
>> you'll find that gcc will use r7 as the frame pointer if
>> -fno-omit-frame-pointer is used.
>>
>> Peter
>>
>> >
>> > My question is, how can I instruct the register allocator to use another register as frame pointer, or at least turn off the use of frame pointer? I tried changing the ABI with -mabi and -meabi but nothing works so far.
>> >
>> > Thanks a lot for your help,
>> >
>> > Cheers,
>> >
>> > Son Tuan Vu
>> > _______________________________________________
>> > LLVM Developers mailing list
>> > llvm-dev at lists.llvm.org
>> > https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev


More information about the llvm-dev mailing list