https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124748

            Bug ID: 124748
           Summary: Feature request: Add -munaligned-double-access option
                    for ARM targets
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: adam.panchartek at gmail dot com
  Target Milestone: ---

Background:
On ARM Cortex-M3 and M4 cores, unaligned access is supported natively for 8-,
16-, and 32-bit types, but not for 64-bit doubles (LDRD/STRD instructions
require natural alignment). Unaligned double access therefore causes a hard
fault at runtime.

Current workaround and its limitations:
The existing -mno-unaligned-access option disables all unaligned accesses,
forcing the compiler to use byte-wise instructions (LDRB/STRB) even for 16- and
32-bit types — which Cortex-M cores handle natively. This has a significant
negative impact on both performance and code size, making it an unsuitable
solution when the goal is only to fix unaligned double access.

Requested feature:
Atollic TrueSTUDIO (based on GCC 8.1.0) implemented a private compiler option
-munaligned-double-access, which replaced all LDRD/STRD instructions with pairs
of LDR/STR word instructions (32-bit wide), without any additional runtime
checks or logic. This allowed selective compilation of specific modules with
this flag, leaving the rest of the code unaffected.
We request that a similar option be implemented in mainline GCC for ARM
targets. Unfortunately, the source code of the Atollic fork is not publicly
available, so we cannot provide a reference implementation — however, the
behavior of the option is well understood from practical use.
It is worth noting that analogous functionality already exists in GCC for the
SPARC architecture (-munaligned-doubles / -mno-unaligned-doubles), which
demonstrates that this kind of per-type unaligned access control is not
unprecedented within the GCC codebase.

Impact:
This affects embedded projects targeting Cortex-M3/M4 that work with legacy
data structures containing unaligned doubles — a situation that arises when
migrating from older toolchains or when interfacing with externally defined
binary data layouts.
Environment

Affected GCC versions: arm-none-eabi-gcc (tested with Atollic TrueSTUDIO GCC
8.1.0 fork)
Target architecture: ARM Cortex-M3, Cortex-M4

Reply via email to