Skip to content

Conversation

@folkertdev
Copy link
Member

fixes #419

A tried to use a .cargo/config.toml instead, e.g.

[target.x86_64-unknown-linux-gnu]  # your real target triple
rustflags = [
  "-C", "link-arg=-Wl,--version-script=include/zlib.map"
]

but I just can't get that path to work. So here we are with a build.rs, something I've been wanting to avoid.

There is another alternative in manually adding assembly directives, but that seems even more problematic.

@folkertdev folkertdev force-pushed the version-symbols branch 2 times, most recently from 49969a5 to eff48c9 Compare October 31, 2025 22:08
@codecov
Copy link

codecov bot commented Oct 31, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

Flag Coverage Δ
fuzz-compress 40.49% <ø> (-0.14%) ⬇️
fuzz-decompress 30.43% <ø> (-0.27%) ⬇️
test-aarch64-apple-darwin 92.24% <ø> (-1.45%) ⬇️
test-aarch64-unknown-linux-gnu 89.73% <ø> (-0.03%) ⬇️
test-i686-unknown-linux-gnu 89.51% <ø> (+0.02%) ⬆️
test-x86_64-apple-darwin 90.18% <ø> (-1.91%) ⬇️
test-x86_64-unknown-linux-gnu 91.98% <ø> (-1.23%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.
see 5 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@folkertdev folkertdev force-pushed the version-symbols branch 8 times, most recently from 234c03f to 9e7f85a Compare October 31, 2025 23:18
@folkertdev
Copy link
Member Author

the failing test (checking that the symbols are actually versioned) succeeds with mold, but clearly fails on CI. Great...

@folkertdev folkertdev force-pushed the version-symbols branch 8 times, most recently from 4ad10be to 735b380 Compare November 1, 2025 13:17
working-directory: libz-rs-sys-cdylib
run: |
cargo build --release --target ${{matrix.target}} --features=gz
cc -shared -Wl,--whole-archive target/${{matrix.target}}/release/libz_rs.a -Wl,--no-whole-archive -Wl,--version-script=include/zlib.map -Wl,--undefined-version -Wl,-soname,libz_rs.so.1 -lc -o target/${{matrix.target}}/release/libz_rs.versioned.so
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you try to just set package.metadata.capi.library.rustflags with the linker line above in Cargo.toml and use cargo-cbuild?

Copy link
Contributor

Choose a reason for hiding this comment

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

I added a target-specific section with just rustflags for now. It will hit the release matching current cargo

Copy link
Collaborator

Choose a reason for hiding this comment

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

The linker has to be invoked separately. If we let rustc invoke the linker, it will pass a version script that conflicts with the version script this PR applies.

Copy link
Contributor

Choose a reason for hiding this comment

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

wouldn't the last one win?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

it seems working with the current lld

     Running `rustc --crate-name z_rs --edition=2021 src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=252 --crate-type staticlib --crate-type cdylib --emit=dep-info,link -C panic=abort -C embed-bitcode=no -C debuginfo=2 --deny=unsafe_op_in_unsafe_fn --cfg 'feature="c-allocator"' --cfg 'feature="capi"' --cfg 'feature="default"' --check-cfg 'cfg(docsrs,test)' --check-cfg 'cfg(feature, values("__internal-test", "c-allocator", "capi", "custom-prefix", "default", "gz", "gzprintf", "rust-allocator", "semver-prefix"))' -C metadata=e06a1d63542bbf68 --out-dir /root/zlib-rs/libz-rs-sys-cdylib/target/aarch64-unknown-linux-gnu/debug/deps --target aarch64-unknown-linux-gnu -C linker=clang -C incremental=/root/zlib-rs/libz-rs-sys-cdylib/target/aarch64-unknown-linux-gnu/debug/incremental -L dependency=/root/zlib-rs/libz-rs-sys-cdylib/target/aarch64-unknown-linux-gnu/debug/deps -L dependency=/root/zlib-rs/libz-rs-sys-cdylib/target/debug/deps --extern libz_rs_sys=/root/zlib-rs/libz-rs-sys-cdylib/target/aarch64-unknown-linux-gnu/debug/deps/liblibz_rs_sys-f92c9d585058d057.rlib --extern zlib_rs=/root/zlib-rs/libz-rs-sys-cdylib/target/aarch64-unknown-linux-gnu/debug/deps/libzlib_rs-ac94033f0625444d.rlib -C link-arg=-Wl,-soname,libz_rs.so.1 -Clink-arg=-Wl,--no-whole-archive -Clink-arg=-Wl,--version-script=include/zlib.map -Clink-arg=-Wl,--undefined-version --cfg cargo_c --print native-static-libs -C link-arg=-fuse-ld=lld`
LLD 21.1.4 (compatible with GNU linkers)

Copy link
Member Author

Choose a reason for hiding this comment

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

that invocation has only one version script, so I'm not sure what you are actually running here?

Copy link
Contributor

Choose a reason for hiding this comment

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

the other version script is injected by rustc.

Copy link
Contributor

@lu-zero lu-zero Nov 2, 2025

Choose a reason for hiding this comment

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

I test it using the following configuration:

[target.aarch64-unknown-linux-gnu]
linker = "clang"
# rustflags = [ "-C", "link-arg=-fuse-ld=ld" ]
# rustflags = [ "-C", "link-arg=-fuse-ld=lld" ]
# rustflags = [ "-C", "link-arg=-fuse-ld=mold" ]

uncommenting one at time.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm seeing that now lld and ld seem to favour the first linker script so only using mold we get what is expected according to objdump.

gz_error;
gz_intmax;
rust_eh_personality;
_*;
Copy link
Member Author

Choose a reason for hiding this comment

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

re #419 (comment), _* is already excluded, so that should cover _R* right?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Right

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.

zlib-rs as a system libz.so replacement?

4 participants