Skip to content

enable PIC for multi-versioned objects when targeting shared libraries#1

Merged
ATTron merged 2 commits intoATTron:mainfrom
0xroko:fix/enable-pic-option
Apr 15, 2026
Merged

enable PIC for multi-versioned objects when targeting shared libraries#1
ATTron merged 2 commits intoATTron:mainfrom
0xroko:fix/enable-pic-option

Conversation

@0xroko
Copy link
Copy Markdown
Contributor

@0xroko 0xroko commented Apr 7, 2026

addMultiVersion objects don't inherit PIC from the parent compile step. When linking into a dynamic library, the linker fails with R_X86_64_32S relocation cannot be used against local symbol. This auto-detects compile.linkage == .dynamic and sets .pic = true on both the user and wrapper modules, with an explicit override option.

Copy link
Copy Markdown
Owner

@ATTron ATTron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, thanks for this :) great catch and clean fix!

Tested locally on macOS aarch64 (Zig 0.16.0). Build and tests pass. The example hits a PIC error, but that's already broken on main so not from your PR :)

One thing — compile.linkage == .dynamic misses platforms like macOS/aarch64 where PIC is required for everything. Swapping to compile.root_module.pic inherits what Zig already decided for the parent, covering both cases. Tested and the example runs clean after that ( i should probably make it CI tbh but another task for another day )

I'll push the tweak onto your branch. Thanks for helping out!

Comment thread build.zig Outdated
@ATTron ATTron merged commit fa6ec1f into ATTron:main Apr 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants