Skip to content

.arm directive doesn’t align 32-bit code instructions and sections by 4 bytes #53386

@evodius96

Description

@evodius96

For Arm targets (e.g. cortex-r5), using the “.arm” directive in hand-coded assembly does not have the same behavior with the LLVM integrated assembler as for GNU as. The directive will ensure that succeeding instructions are correctly interpreted as Arm-mode instructions, but it won’t enforce a 4byte alignment on instructions (or corresponding sections). In order to do this, a user has to explicitly align sections using an alignment directive.

There is no Arm-determined specification governing the “.arm” directive alignment behavior. Further, the documentation for the .arm and .thumb directives in the GNU assembler makes no mention of alignment (https://sourceware.org/binutils/docs/as/ARM-Directives.html#ARM-Directives)

However, because the GNU assembler (GAS) implements the 4-byte alignment behavior, the LLVM integrated Arm assembler should match that behavior. This was recommended by Arm in a (now-abandoned) code review: https://reviews.llvm.org/D110580

See attached sample.s.txt
Build for GCC cross-compiler: arm-none-eabi-gcc -nostartfiles -mcpu=cortex-r5 -o sample sample.s

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions