zig icon indicating copy to clipboard operation
zig copied to clipboard

`--version-script` should be applicable for `--export-dynamic` binaries

Open MasterAwesome opened this issue 1 year ago • 0 comments

Zig Version

0.13.0-dev.46+3648d7df1

Steps to Reproduce and Observed Behavior

I'm trying to export a symbol from my binary (kinda similar to https://github.com/ziglang/zig/issues/6804).

For the following code:

export const FOO linksection(".custom") = "Zig".*;

pub fn main() !void {}

Using zig build-exe -O ReleaseSmall --force_undefined FOO -rdynamic src/main.zig exports the symbol FOO but also export a bunch of symbols that I don't need to export:

000000000101bebe W fmodq
000000000101bcbc W __fmodx
0000000001008168 R FOO        // The symbol I actually care about
0000000001012e0f W __gedf2
0000000001012d7d W __gehf2

-rdynamic documentation mentions Add all symbols to the dynamic symbol table.

I tried using --version-script <version_script> --no-undefined-version but --version-script doesn't seem to change the linker command at all (at least for build-exe). --version-script behavior is exactly what I need here although I cannot use this for build-exe due to version script only used for dyn_libs here. I think --version-script behavior shouldn't be restricted only to is_dyn_libs but also executables with -rdynamic.

Rust does this as well to ensure certain symbols are maintained in the executable here

Expected Behavior

--version-script and related must apply for executables when -rdynamic flag is applied.

MasterAwesome avatar May 05 '24 23:05 MasterAwesome