double_sci_m33.S: rtwopi/trigtab tables have no alignment directive; Clang leaves them byte-aligned and ldmia faults (UNALIGNED) on RP2350 #3183
Labels
No labels
bazel
bluetooth
board settings
boot_stage2
bug
build
c++
can't reproduce
clang
clib-interface
cmsis
code cleanliness
code size
compiler version issues
cyw43_driver
debug
discussion
documentation
duplicate
dynamic_clock
elf2uf2
enhancement
errata
filesystem
flash layout
floating point
FreeRTOS
hardware_adc
hardware_claim
hardware_clocks
hardware_dma
hardware_exception
hardware_flash
hardware_gpio
hardware_i2c
hardware_irq
hardware_pio
hardware_pwm
hardware_rcp
hardware_rtc
hardware_spi
hardware_sync
hardware_uart
hardware_vreg
hardware_watchdog
hardware_xosc
help wanted
host
IAR
installation
invalid
linker scripts
lto
lwip
mbedtls
missing API
needs reporter detail
networking
newlib
newlib-multicore
non-c
non-cmake
non-gcc
openocd
orphan PR
OS integration
pico_async_context
pico_base
pico_binary_info
pico_flash
picolibc
pico_lwip
pico_malloc
pico_multicore
pico_printf
pico_runtime
pico_stdio
pico_stdio_usb
pico_sync
pico_time
pico_util
pioasm
port
question
review
review2
rtos interop
runtime init
static library
svd
test
tinyusb
vscode
wifi integration
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gh-raspberrypi/pico-sdk#3183
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
src/rp2_common/pico_double/double_sci_m33.Sdefines its two data tables,rtwopiandtrigtab, withdouble_section(a fresh"ax"section each) and no alignment directive. When the file is assembled by Clang's integrated assembler (LLVM Embedded Toolchain for Arm 19.1.5,PICO_COMPILER=pico_arm_cortex_m33_clang), those sections getsh_addralign = 1, so the linker may place a table at a 2-byte-aligned address behind Thumb code. The code then reads them with word-aligned-only instructions (ldmia r3,{r2-r5}in the sin/cos range reduction and inatan2_entry), which raises a UsageFault (UNALIGNED, escalated to HardFault when UsageFault is disabled) on the Cortex-M33.Observed on pico-sdk 2.3.0 (
98a542c1a62fb549ffb5d66a3e5892b06276b670); the file is unchanged onmasteranddevelopas of today.Evidence
llvm-readelf -Son the object built forrp2350-arm-s:exptabis preceded by.align 2and gets alignment 4; the other two are not and get 1. In one linktrigtablanded at0x10001066, and a program callingatan2()faulted at the first table read:Whether a given build faults depends on the size of the code the linker places before the table, so it is easy to miss: a build that happens to land the table on a word boundary runs fine.
GCC builds are unaffected in practice because GNU as gives these sections word alignment.
Fix
Two lines:
float_sci_m33_vfp.Salready carries.p2alignbefore its tables, so this brings the double file in line with it. Happy to open a PR if that is preferred.Configuration
PICO_PLATFORM=rp2350-arm-s,PICO_BOARD=pico2PICO_COMPILER=pico_arm_cortex_m33_clang,PICO_CLIB=llvm_libc,PICO_HARD_FLOAT_ABI=1(the section alignment does not depend on the ABI)pico_double_pico_dcp(the defaultpicodouble implementation on RP2350 Arm)