Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

__clzsi2_thumb1() fails to link due to R_ARM_ABS32 relocation error with PIC #22050

Closed
ikskuh opened this issue Nov 23, 2024 · 4 comments · Fixed by #22051
Closed

__clzsi2_thumb1() fails to link due to R_ARM_ABS32 relocation error with PIC #22050

ikskuh opened this issue Nov 23, 2024 · 4 comments · Fixed by #22051
Labels
arch-arm 32-bit ARM bug Observed behavior contradicts documented or intended behavior compiler-rt
Milestone

Comments

@ikskuh
Copy link
Contributor

ikskuh commented Nov 23, 2024

Zig Version

0.14.0-dev.2271+f845fa04a

Steps to Reproduce and Observed Behavior

Compile any file with

[user@host ~]$ zig build-exe -target thumb-freestanding-eabi -mcpu cortex_m0plus -fPIE stub.zig 

which results in

[user@host ~]$ zig build-exe -target thumb-freestanding-eabi -mcpu cortex_m0plus -fPIE src/main.zig 
error: ld.lld: relocation R_ARM_ABS32 cannot be used against local symbol; recompile with -fPIC
    note: defined in /home/user/.cache/zig/o/…/libcompiler_rt.a(/home/user/.cache/zig/o/…/libcompiler_rt.a.o)
    note: referenced by compiler_rt
    note:               /home/user/.cache/zig/o/…/libcompiler_rt.a.o:(__clzsi2) in archive /home/user/.cache/zig/o/…/libcompiler_rt.a
[user@host ~]$ 

stub.zig may look like this:

export fn _start() void {}

Expected Behavior

compiler_rt should be compiled with -fPIC if the build artifact is built as position independent code (-fPIC, -fPIE)

Related Issues

@ikskuh ikskuh added the bug Observed behavior contradicts documented or intended behavior label Nov 23, 2024
@ikskuh
Copy link
Contributor Author

ikskuh commented Nov 23, 2024

Ashet OS is currently kinda blocking on this as i want to add support for ARM systems and i need PIE executables to be able to load applications without virtual memory

@alexrp
Copy link
Member

alexrp commented Nov 23, 2024

To clarify, is this a regression or does it also happen with 0.13.0?

@alexrp
Copy link
Member

alexrp commented Nov 23, 2024

I can find no evidence that PIC isn't being enabled for compiler-rt. This looks like a problem specific to __clzsi2 which has special-casing for Thumb. LLD is just giving an unhelpful error message.

@alexrp alexrp added this to the 0.14.0 milestone Nov 23, 2024
@alexrp alexrp changed the title compiler_rt does not respect -fPIC __clzsi2_thumb1() fails to link due to R_ARM_ABS32 relocation error with PIC Nov 23, 2024
@ikskuh
Copy link
Contributor Author

ikskuh commented Nov 23, 2024

To clarify, is this a regression or does it also happen with 0.13.0?

Also happens in 0.13.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arch-arm 32-bit ARM bug Observed behavior contradicts documented or intended behavior compiler-rt
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants