gcc, arm, and thumbs mode

Thomas Stüfe thomas.stuefe at gmail.com
Mon May 30 05:57:01 UTC 2022


Hi Anton,

thanks for looking into this.

For my specific problem, I can and probably should use .function. But my
question was more general, should we leave the decision whether to use
thumb or arm up to the toolchain. For two reasons, one is executable size -
I assume using thumb has certain advantages, executables are smaller and
you can fit more into the instruction cache, and second, because errors
like mine are probably not that uncommon and it makes me nervous that we
only caught it because someone happened to build on his Raspi.

Cheers, Thomas

On Fri, May 27, 2022 at 3:28 PM Anton Kozlov <akozlov at azul.com> wrote:

> Hi Thomas,
>
> On 5/27/22 16:12, Thomas Stüfe wrote:
> > P.S. I found one possible solution for my particular problem was to add
> > `.type function` to the static assembler routine. That caused gcc to use
> > the correct jump instruction (blx instead of bl). But I am not sure this
> is
> > the best solution, maybe best would be to just use the same mode for all
> > hotspot compilation units.
>
> AFAIR, that .type %function directive is a correct way to write asm
> code. At least this is what gcc generates for the C code [1]. I'm not
> sure how the annotation in the assembly code affects the caller code,
> may be link time optimization? But if adding the directive resolves the
> issue, I vote for it.
>
> (I expect arm-none crosscompiler to produce similar results compared to
> arm-linux target)
>
> Thanks,
> Anton
>
> $ echo "int main() { return 0; }" | arm-none-eabi-gcc -mthumb -S -x c - -o
> -
>         .cpu arm7tdmi
>         .arch armv4t
>         .fpu softvfp
>         .eabi_attribute 20, 1
>         .eabi_attribute 21, 1
>         .eabi_attribute 23, 3
>         .eabi_attribute 24, 1
>         .eabi_attribute 25, 1
>         .eabi_attribute 26, 1
>         .eabi_attribute 30, 6
>         .eabi_attribute 34, 0
>         .eabi_attribute 18, 4
>         .file   "<stdin>"
>         .text
>         .align  1
>         .global main
>         .syntax unified
>         .code   16
>         .thumb_func
>         .type   main, %function
> main:
>         @ Function supports interworking.
>         @ args = 0, pretend = 0, frame = 0
>         @ frame_needed = 1, uses_anonymous_args = 0
>         push    {r7, lr}
>         add     r7, sp, #0
>         movs    r3, #0
>         movs    r0, r3
>         mov     sp, r7
>         @ sp needed
>         pop     {r7}
>         pop     {r1}
>         bx      r1
>         .size   main, .-main
>         .ident  "GCC: (Arch Repository) 12.1.0"
>
>



More information about the build-dev mailing list