Skip to content

[bootstrap] Don't reverse the order of dylib search path entries - #161377

Open
jnkel wants to merge 1 commit into
rust-lang:mainfrom
jnkel:fix-dylib-search-order
Open

[bootstrap] Don't reverse the order of dylib search path entries#161377
jnkel wants to merge 1 commit into
rust-lang:mainfrom
jnkel:fix-dylib-search-order

Conversation

@jnkel

@jnkel jnkel commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

The add_dylib_path helper function prepends paths to the beginning of the dynamic linker search path, but it reverses their order while doing so. This is surprising and undocumented, and seems to be unexpected by several callers of this function.

Particularly, rustc_lib_paths appends the ci-llvm path to the list it returns; reversing the order puts ci-llvm at a higher priority than the compiler's lib directory. On my system, this currently causes ./x test to fail (when building the unstable book), because the stage0 compiler is run using CI LLVM instead of stage0 LLVM (which are currently different because stage0 is on LLVM 22 while main is on LLVM 23).

Might be worth a try build as this change could potentially cause issues if there is somewhere we depend on this ordering reversal. I checked all the call-sites (and ran ./x test locally) and I don't think anyone intentionally relied on the ordering being reversed. I did find one snippet that concerned me (from #144303, cc @Kobzol):

// The `cargo` command configured above has dylib dir path set to the `build_compiler`'s
// libdir. That causes issues in cargo test, because the programs that cargo compiles are
// incorrectly picking that libdir, even though they should be picking the
// `tested_compiler`'s libdir. We thus have to override the precedence here.
let mut existing_dylib_paths = cargo
.get_envs()
.find(|(k, _)| *k == OsStr::new(dylib_path_var()))
.and_then(|(_, v)| v)
.map(|value| split_paths(value).collect::<Vec<PathBuf>>())
.unwrap_or_default();
existing_dylib_paths.insert(0, builder.rustc_libdir(tested_compiler));
add_dylib_path(existing_dylib_paths, &mut cargo);

The comment states we're inserting builder.rustc_libdir(tested_compiler) at the highest priority in the search path, but because add_dylib_path reversed the ordering, it's actually inserted at the lowest priority. I don't know how to reproduce the issue this was supposed to fix, so I can't be sure that this PR doesn't cause a regression.

Follow-up to #161335. r? @jieyouxu

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 19, 2026
@rustbot rustbot added the T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) label Aug 19, 2026
@rust-log-analyzer

This comment has been minimized.

@jnkel
jnkel force-pushed the fix-dylib-search-order branch from 02b6017 to 67e8a19 Compare August 19, 2026 23:44
Comment thread src/bootstrap/src/utils/helpers.rs
@Kobzol

Kobzol commented Aug 20, 2026

Copy link
Copy Markdown
Member

The code in add_dylib is 11 years old and comes from bootstrap's first Rust commit. I agree that what you describe makes more sense.

Also, this is such a mess.. the ci-llvm directory really shouldn't be added in this function, that's super ad-hoc.

@jieyouxu

Copy link
Copy Markdown
Member

(I'll look at this on Friday)

@jieyouxu jieyouxu left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks. I did some history digging and could not find why this needed to be reversed. This order looks more correct to me.

@bors r+ rollup

View changes since this review

@rust-bors

rust-bors Bot commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 67e8a19 has been approved by jieyouxu

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 28, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Aug 28, 2026
…eyouxu

[bootstrap] Don't reverse the order of dylib search path entries

The `add_dylib_path` helper function prepends paths to the beginning of the dynamic linker search path, but it reverses their order while doing so. This is surprising and undocumented, and seems to be unexpected by several callers of this function.

Particularly, [`rustc_lib_paths`](https://github.com/rust-lang/rust/blob/f7d782a3be46d6bb4b9792fe69a61db389ba1769/src/bootstrap/src/core/builder/mod.rs#L1375) appends the `ci-llvm` path to the list it returns; reversing the order puts `ci-llvm` at a higher priority than the compiler's lib directory. On my system, this currently causes `./x test` to fail (when building the unstable book), because the stage0 compiler is run using CI LLVM instead of stage0 LLVM (which are currently different because stage0 is on LLVM 22 while main is on LLVM 23).

Might be worth a try build as this change could potentially cause issues if there is somewhere we depend on this ordering reversal. I checked all the call-sites (and ran `./x test` locally) and I don't think anyone *intentionally* relied on the ordering being reversed. I did find one snippet that concerned me (from rust-lang#144303, cc @Kobzol):

https://github.com/rust-lang/rust/blob/f7d782a3be46d6bb4b9792fe69a61db389ba1769/src/bootstrap/src/core/build_steps/test.rs#L437-L448

The comment states we're inserting `builder.rustc_libdir(tested_compiler)` at the highest priority in the search path, but because `add_dylib_path` reversed the ordering, it's actually inserted at the *lowest* priority. I don't know how to reproduce the issue this was supposed to fix, so I can't be sure that this PR doesn't cause a regression.

Follow-up to rust-lang#161335. r? @jieyouxu
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Aug 28, 2026
…eyouxu

[bootstrap] Don't reverse the order of dylib search path entries

The `add_dylib_path` helper function prepends paths to the beginning of the dynamic linker search path, but it reverses their order while doing so. This is surprising and undocumented, and seems to be unexpected by several callers of this function.

Particularly, [`rustc_lib_paths`](https://github.com/rust-lang/rust/blob/f7d782a3be46d6bb4b9792fe69a61db389ba1769/src/bootstrap/src/core/builder/mod.rs#L1375) appends the `ci-llvm` path to the list it returns; reversing the order puts `ci-llvm` at a higher priority than the compiler's lib directory. On my system, this currently causes `./x test` to fail (when building the unstable book), because the stage0 compiler is run using CI LLVM instead of stage0 LLVM (which are currently different because stage0 is on LLVM 22 while main is on LLVM 23).

Might be worth a try build as this change could potentially cause issues if there is somewhere we depend on this ordering reversal. I checked all the call-sites (and ran `./x test` locally) and I don't think anyone *intentionally* relied on the ordering being reversed. I did find one snippet that concerned me (from rust-lang#144303, cc @Kobzol):

https://github.com/rust-lang/rust/blob/f7d782a3be46d6bb4b9792fe69a61db389ba1769/src/bootstrap/src/core/build_steps/test.rs#L437-L448

The comment states we're inserting `builder.rustc_libdir(tested_compiler)` at the highest priority in the search path, but because `add_dylib_path` reversed the ordering, it's actually inserted at the *lowest* priority. I don't know how to reproduce the issue this was supposed to fix, so I can't be sure that this PR doesn't cause a regression.

Follow-up to rust-lang#161335. r? @jieyouxu
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Aug 28, 2026
…eyouxu

[bootstrap] Don't reverse the order of dylib search path entries

The `add_dylib_path` helper function prepends paths to the beginning of the dynamic linker search path, but it reverses their order while doing so. This is surprising and undocumented, and seems to be unexpected by several callers of this function.

Particularly, [`rustc_lib_paths`](https://github.com/rust-lang/rust/blob/f7d782a3be46d6bb4b9792fe69a61db389ba1769/src/bootstrap/src/core/builder/mod.rs#L1375) appends the `ci-llvm` path to the list it returns; reversing the order puts `ci-llvm` at a higher priority than the compiler's lib directory. On my system, this currently causes `./x test` to fail (when building the unstable book), because the stage0 compiler is run using CI LLVM instead of stage0 LLVM (which are currently different because stage0 is on LLVM 22 while main is on LLVM 23).

Might be worth a try build as this change could potentially cause issues if there is somewhere we depend on this ordering reversal. I checked all the call-sites (and ran `./x test` locally) and I don't think anyone *intentionally* relied on the ordering being reversed. I did find one snippet that concerned me (from rust-lang#144303, cc @Kobzol):

https://github.com/rust-lang/rust/blob/f7d782a3be46d6bb4b9792fe69a61db389ba1769/src/bootstrap/src/core/build_steps/test.rs#L437-L448

The comment states we're inserting `builder.rustc_libdir(tested_compiler)` at the highest priority in the search path, but because `add_dylib_path` reversed the ordering, it's actually inserted at the *lowest* priority. I don't know how to reproduce the issue this was supposed to fix, so I can't be sure that this PR doesn't cause a regression.

Follow-up to rust-lang#161335. r? @jieyouxu
rust-bors Bot pushed a commit that referenced this pull request Aug 28, 2026
…uwer

Rollup of 15 pull requests

Successful merges:

 - #160170 (Refactored docs for `std::fs::set_permissions_nofollow` + fix BSD-based systems to use fchmodat with AT_SYMLINK_NOFOLLOW flag)
 - #160594 (attach global target features to module-level assembly)
 - #161858 (fix ICE in generic_const_parameter_types with inherents)
 - #161353 (Add test for parallel compiler reproducible build)
 - #161377 ([bootstrap] Don't reverse the order of dylib search path entries)
 - #161804 (Document PartialOrd behavior for Option<T> where T: PartialOrd)
 - #161865 (loongarch: support passing `u128`/`i128` to inline assembly)
 - #161877 (Do not load macro metadata for local definitions in rustdoc)
 - #161880 (fix rustc_lint_defs doctest issues)
 - #161883 (better deal with internal features being injected into doctests)
 - #161887 (std: uefi: fix File::seek returning the EOF sentinel)
 - #161897 (Reject contract attributes without arguments)
 - #161909 (Report the configured Polonius default in -Z help)
 - #161910 (Add rustdoc-html regression test for generated macro)
 - #161914 (Retroactively add relnotes for `bool::{ok_or,ok_or_else}` (1.98.0))
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Aug 28, 2026
…eyouxu

[bootstrap] Don't reverse the order of dylib search path entries

The `add_dylib_path` helper function prepends paths to the beginning of the dynamic linker search path, but it reverses their order while doing so. This is surprising and undocumented, and seems to be unexpected by several callers of this function.

Particularly, [`rustc_lib_paths`](https://github.com/rust-lang/rust/blob/f7d782a3be46d6bb4b9792fe69a61db389ba1769/src/bootstrap/src/core/builder/mod.rs#L1375) appends the `ci-llvm` path to the list it returns; reversing the order puts `ci-llvm` at a higher priority than the compiler's lib directory. On my system, this currently causes `./x test` to fail (when building the unstable book), because the stage0 compiler is run using CI LLVM instead of stage0 LLVM (which are currently different because stage0 is on LLVM 22 while main is on LLVM 23).

Might be worth a try build as this change could potentially cause issues if there is somewhere we depend on this ordering reversal. I checked all the call-sites (and ran `./x test` locally) and I don't think anyone *intentionally* relied on the ordering being reversed. I did find one snippet that concerned me (from rust-lang#144303, cc @Kobzol):

https://github.com/rust-lang/rust/blob/f7d782a3be46d6bb4b9792fe69a61db389ba1769/src/bootstrap/src/core/build_steps/test.rs#L437-L448

The comment states we're inserting `builder.rustc_libdir(tested_compiler)` at the highest priority in the search path, but because `add_dylib_path` reversed the ordering, it's actually inserted at the *lowest* priority. I don't know how to reproduce the issue this was supposed to fix, so I can't be sure that this PR doesn't cause a regression.

Follow-up to rust-lang#161335. r? @jieyouxu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants