zig
zig copied to clipboard
Dynamic library symbol lookup fails on types with higher alignment
Zig Version
0.10.0-dev.4418+99c3578f6
Steps to Reproduce
Use lookup()
with a pointer to type that has larger alignment than 1. For example: lib.lookup(*usize, "foo")
. Tested with macOS.
Expected Behavior
For it to compile.
Actual Behavior
/Users/me/zig/lib/zig/std/dynamic_library.zig:385:20: error: cast increases pointer alignment
return @ptrCast(T, symbol);
^~~~~~~~~~~~~~~~~~~
/Users/me/zig/lib/zig/std/dynamic_library.zig:385:32: note: '*anyopaque' has alignment '1'
return @ptrCast(T, symbol);
^~~~~~
/Users/me/zig/lib/zig/std/dynamic_library.zig:385:29: note: '*usize' has alignment '8'
return @ptrCast(T, symbol);
^
The workaround is to have the pointer that is the argument to lookup
be align(1)
and then optionally @alignCast
it.