Skip to content

Support for whole-archive - #185

Open
piguycs wants to merge 6 commits into
rust-lang:masterfrom
piguycs:dpdk-whole-archive
Open

piguycs wants to merge 6 commits into
rust-lang:masterfrom
piguycs:dpdk-whole-archive

Conversation

@piguycs

@piguycs piguycs commented Feb 25, 2026

Copy link
Copy Markdown

This should fix #179.

Tested locally by statically linking DPDK, which would lead to runtime errors without this patch. Open to any feedback, thanks!

@piguycs
piguycs force-pushed the dpdk-whole-archive branch from ee96d73 to 74b1731 Compare August 1, 2026 13:18

@sdroege sdroege left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks, this looks correct but can you add some tests for this?

Comment thread src/lib.rs Outdated
Comment on lines +933 to +934
// this would be cleaner with an if-let chain of strip_prefix and
// strip_suffix, and would be "safer" without random slicing

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please update that accordingly. MSRV was updated :) Then clippy is also more happy.

Comment thread src/lib.rs
Comment on lines +940 to +942
// adding a library multiple times with different modifiers is not allowed by
// rustc, but can be allowed by c compilers
if added_libs.contains(&val) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This de-dup should probably go into a separate commit with explanation (can be in the same PR).

Duplicated libraries are now skipped before emitting linker arguments.

When testing the new changes with DPDK, the flags generated from the
pkg-config file had some duplicated libraries. Passing same values to
rustc-link-arg multiple times results in:
"error: overriding linking modifiers from command line is not supported".

The cause of this issue is that DPDK provides two files: libdpdk.pc and
libdpdk-libs.pc. libdpdk.pc requires libdpdk-libs.pc, so contents of
both files get merged and returned by the pkt-config command. However,
some objects appear in both files, which causes the error.
@piguycs
piguycs force-pushed the dpdk-whole-archive branch from 74b1731 to 3bd7004 Compare August 14, 2026 09:46
@piguycs

piguycs commented Aug 14, 2026 •

Copy link
Copy Markdown
Author

can you add some tests for this

So I added a field whole_archive_libs: Vec<String> to the Library struct. The issue with this one is that in the test environment, there needs to be an archive available so that is_static_available does not fail (eg: librte_eal.a). I could make a temp file which resolves correctly during the tests, but I am not sure if it will be a good approach. Do you have any suggestions for this?

There are no other tests which require .statik(true), so I do not know what is the acceptable approach for this would be.

@piguycs

piguycs commented Aug 14, 2026

Copy link
Copy Markdown
Author

For now, the approach I am going with is to ignore is_static_available, when using --whole-archive.

--whole-archive
For each archive mentioned on the command line after the --whole-archive option, include every object file in the archive in the link, rather than searching the archive for the required object files. This is normally used to turn an archive file into a shared library, forcing every object to be included in the resulting shared library. This option may be used more than once.

Based on this snippet from GNU LD docs, it might be safe to assume that making this change should be functionally correct, and that the whole archive being used while the archive being unavailable should result in an error (which it would after this change)

This branch has not been deployed

No deployments
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.

Whole archive is not working when we do static linking

2 participants