Handle GOT sections gracefully #3064
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 assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gh-raspberrypi/pico-sdk#3064
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?
If any of the libraries linked against is built as position independent code, weak undefined symbols and comdat symbols may have GOT relocations in ARM targets. We observed this in the LLVM runtime libraries (libc.a/libm.a) but this behavior is not specific to Clang/LLVM toolchains. Handle GOT sections gracefully to prevent possible broken behavior.
ok, so what is the upshot - does it fail linking, or what? I'm not keen to include the
.gotsections in the linker script - we could discard them, or assert they are empty (are they?)does adding
-fno-picorfno-pieto compile/link help?Even if the final link of the binary has no PIC flags set, there might be valid GOT sections coming from libraries that are linked if they were built as PIC. In this scenario, we will not see a compile/link failure but we will end up dropping valid GOT sections leading to runtime failures.
Having said that, the push back against this patch is fair. We currently build our LLVM libc distributions in PIC mode by default. A recent change upstream https://github.com/llvm/llvm-project/pull/198577 caused GOT sections being introduced in our libm.a which prompted the proposed change. We are working with upstream to resolve this particular case through this patch https://github.com/llvm/llvm-project/pull/209660 which should make our current change here to place GOT sections in linker script irrelevant.
I am still in favor of having the GOT sections handled in one way or the other given it is not illegal for them to be present in the final binary. Assuming we will get the GOT sections removed in our toolchain distribution, the other approach is to actually assert from linker script that no GOT sections exist in the input sections list. I'd prefer that GOT sections are not quietly ignored, if present, causing runtime crashes.
Yup - I was leaning towards an assertion but that doesn’t help obviously if we have toolchain versions that produce them
I wonder even if present if they actually work as intended - can u point me at something that produces them
The current version of the clang toolchain in pico-sdk does not produce GOT sections. I can make sure that we dont update the toolchain version to one which emits GOT sections.
"I wonder even if present if they actually work as intended - can u point me at something that produces them" -- In the problematic toolchain revisions used in our ecosystem, accessing this symbol became a GOT relocation: https://github.com/llvm/llvm-project/blob/main/libc/src/__support/FPUtil/rounding_mode.h#L30-L89 from many of our math library functions. This crashed some our products which we fixed by placing the GOT sections in linker scripts. We did not hit this sort of failure in pipico as we have not used a toolchain version which has this issue. My aim here is to proactively handle GOT sections correctly. I can hold off on placing the GOT sections and instead directly emit assertions for pico-sdk.
To answer your question directly, using this revision for clang toolchain will be able to help reproduce the failure mode: b8e34c5adc38b5406d175e7e94c95f6399da096a
I may not have time this week to get through this experiment to produce an example for pico-sdk.
fix merged into develop