[PATCH] D110580: [THUMB2] default .text alignment to 2B

Nick Desaulniers via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 28 11:10:39 PDT 2021


nickdesaulniers added a comment.

In D110580#3027025 <https://reviews.llvm.org/D110580#3027025>, @peter.smith wrote:

> One thing that may cause problems is an immediate inline change of state to Arm something like the following with a thumb target.
>
>   .text
>   .arm
>   nop

I think I can extend this patch (preferably a child patch on top); it seems that GAS will:

1. use 4B alignment for .text if .arm and .thumb are encountered, regardless of -mthumb.
2. use 4B alignment if only .arm is encountered regardless of -mthumb, or 2B alignment if only .thumb is encountered regardless of -marm.
3. use 2B alignment for -mthumb, 4B otherwise (if neither .arm or .thumb are encountered).

I'll bet this happens with other TEXT sections, too, not just .text. (unverified)

though for pr/51929, there are no .arm or .thumb directives, so pr/51929 is the third case above.

  @ $ arm-linux-gnueabi-as -march=armv7-a x.s -o x.o
  @ $ llvm-readelf -S x.o
  @ [ 1] .text             PROGBITS        00000000 000034 000004 00  AX  0   0  4
  .text
  nop

  @ $ arm-linux-gnueabi-as -mthumb -march=armv7-a x.s -o x.o
  @ $ llvm-readelf -S x.o
  @ [ 1] .text             PROGBITS        00000000 000034 000002 00  AX  0   0  2
  .text
  nop

  @ $ arm-linux-gnueabi-as -mthumb -march=armv7-a x.s -o x.o
  @ $ llvm-readelf -S x.o
  @ [ 1] .text             PROGBITS        00000000 000034 000004 00  AX  0   0  4
  .text
  .arm
  nop

  @ $ arm-linux-gnueabi-as -march=armv7-a x.s -o x.o
  @ $ llvm-readelf -S x.o
  @ [ 1] .text             PROGBITS        00000000 000034 000002 00  AX  0   0  2
  .text
  .thumb
  nop

  @ $ arm-linux-gnueabi-as -march=armv7-a x.s -o x.o
  @ $ llvm-readelf -S x.o
  @ [ 1] .text             PROGBITS        00000000 000034 000008 00  AX  0   0  4
  .text
  .thumb
  nop
  .arm
  nop

  @ $ arm-linux-gnueabi-as -march=armv7-a -mthumb x.s -o x.o
  @ $ llvm-readelf -S x.o
  @ [ 1] .text             PROGBITS        00000000 000034 000008 00  AX  0   0  4
  .text
  .thumb
  nop
  .arm
  nop

That said, looking at the case from pr/51929, it still doesn't have a 2B alignment for .text. Trying my best with `cvise`, it seems the presence of a `.align 0` directive also forces GAS to emit .text with 4B alignment.  So that's yet a fourth case...(but also what's occurring for pr/51929, so I suspect I'll need this plus handling `.align 0` better in llvm).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D110580/new/

https://reviews.llvm.org/D110580



More information about the llvm-commits mailing list