Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

linker: Pass fewer search directories to the linker #128370

Merged
merged 2 commits into from
Aug 3, 2024

Conversation

petrochenkov
Copy link
Contributor

@petrochenkov petrochenkov commented Jul 29, 2024

  • The logic for passing -L directories to the linker is consolidated in a single function, so the search priorities are immediately clear.
  • Only -Lnative=, -Lframework= -Lall= directories are passed to linker, but not -Lcrate= and others. That's because only native libraries are looked up by name by linker, all Rust crates are passed using full paths, and their directories should not interfere with linker search paths.
  • The main sysroot library directory shouldn't generally be passed because it shouldn't contain native libraries, except for one case which is now marked with a FIXME.
  • This also helps with linker: Allow MSVC to use import libraries following the Meson/MinGW convention #123436, in which we need to walk the same list of directories manually.

The next step is to migrate find_native_static_library to exactly the same set and order of search directories (which may be a bit annoying for the iOSSupport directories #121430 (comment)).

@rustbot
Copy link
Collaborator

rustbot commented Jul 29, 2024

r? @BoxyUwU

rustbot has assigned @BoxyUwU.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 29, 2024
@petrochenkov petrochenkov added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 29, 2024
@petrochenkov
Copy link
Contributor Author

@bors try

bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 29, 2024
linker: Pass fewer search directories to the linker

Work in progress.

try-job: dist-x86_64-musl
try-job: dist-x86_64-mingw
try-job: dist-x86_64-msvc
try-job: dist-x86_64-apple
try-job: dist-various-1
try-job: dist-various-2
@bors
Copy link
Contributor

bors commented Jul 29, 2024

⌛ Trying commit 79ac35b with merge aad9548...

@rust-log-analyzer

This comment has been minimized.

@bors

This comment was marked as resolved.

@petrochenkov
Copy link
Contributor Author

@bors try

@bors
Copy link
Contributor

bors commented Jul 30, 2024

⌛ Trying commit 66a962e with merge b44ca11...

bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 30, 2024
linker: Pass fewer search directories to the linker

Work in progress.

try-job: dist-x86_64-musl
try-job: dist-x86_64-mingw
try-job: dist-x86_64-msvc
try-job: dist-x86_64-apple
try-job: dist-various-1
try-job: dist-various-2
@BoxyUwU
Copy link
Member

BoxyUwU commented Jul 30, 2024

r? @bjorn3

@rustbot rustbot assigned bjorn3 and unassigned BoxyUwU Jul 30, 2024
@bors
Copy link
Contributor

bors commented Jul 30, 2024

☀️ Try build successful - checks-actions
Build commit: b44ca11 (b44ca11ed1037aa434552547921b20bd82077d14)

@petrochenkov
Copy link
Contributor Author

@bors rollup=never
@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jul 30, 2024
@bjorn3
Copy link
Member

bjorn3 commented Jul 31, 2024

Makes sense.

@bors r+

@bors
Copy link
Contributor

bors commented Jul 31, 2024

📌 Commit a83783a has been approved by bjorn3

It is now in the queue for this repository.

@bors bors 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 Jul 31, 2024
@bors
Copy link
Contributor

bors commented Aug 2, 2024

⌛ Testing commit a83783a with merge 83cf265...

bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 2, 2024
linker: Pass fewer search directories to the linker

- The logic for passing `-L` directories to the linker is consolidated in a single function, so the search priorities are immediately clear.
- Only `-Lnative=`, `-Lframework=` `-Lall=` directories are passed to linker, but not `-Lcrate=` and others. That's because only native libraries are looked up by name by linker, all Rust crates are passed using full paths, and their directories should not interfere with linker search paths.
- The main sysroot library directory shouldn't generally be passed because it shouldn't contain native libraries, except for one case which is now marked with a FIXME.
- This also helps with rust-lang#123436, in which we need to walk the same list of directories manually.

The next step is to migrate `find_native_static_library` to exactly the same set and order of search directories (which may be a bit annoying for the `iOSSupport` directories rust-lang#121430 (comment)).
@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Aug 2, 2024

💔 Test failed - checks-actions

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Aug 2, 2024
@petrochenkov petrochenkov added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 3, 2024
@petrochenkov
Copy link
Contributor Author

Sanitizers are also shipped in the sysroot library directory and linked by name on some targets.
@bors r=bjorn3

@bors
Copy link
Contributor

bors commented Aug 3, 2024

📌 Commit 1f873f9 has been approved by bjorn3

It is now in the queue for this repository.

@bors bors 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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Aug 3, 2024
@bors
Copy link
Contributor

bors commented Aug 3, 2024

⌛ Testing commit 1f873f9 with merge edc4dc3...

@bors
Copy link
Contributor

bors commented Aug 3, 2024

☀️ Test successful - checks-actions
Approved by: bjorn3
Pushing edc4dc3 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Aug 3, 2024
@bors bors merged commit edc4dc3 into rust-lang:master Aug 3, 2024
7 checks passed
@rustbot rustbot added this to the 1.82.0 milestone Aug 3, 2024
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (edc4dc3): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

Results (primary -3.4%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-3.4% [-4.7%, -2.0%] 2
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -3.4% [-4.7%, -2.0%] 2

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 758.691s -> 760.453s (0.23%)
Artifact size: 336.82 MiB -> 336.89 MiB (0.02%)

bors added a commit to rust-lang-ci/rust that referenced this pull request Sep 15, 2024
…-mingw-import-libraries, r=petrochenkov

linker: Allow MSVC to use import libraries following the Meson/MinGW convention

Hi all,

This PR implements support for `MsvcLinker` to use import libraries following Meson and the MinGW toolchain's naming convention. Meson [follows the `libfoo.dll.a` naming convention](https://mesonbuild.com/FAQ.html#why-does-building-my-project-with-msvc-output-static-libraries-called-libfooa) to disambiguate between static and import libraries.

This support already existed for static libraries (see rust-lang#100101), but not for dynamic libraries. The latter case was added by duplicating the logic in `native_libs::find_native_static_library`, but a separate case was added in `link_dylib_by_name` for the Windows CRT libraries which must be handled by the linker itself.

See for prerequisites rust-lang#129366, rust-lang#126094, and rust-lang#128370.

All feedback is appreciated!

Fixes rust-lang#122455

cc `@sdroege` `@nirbheek`
bors added a commit to rust-lang-ci/rust that referenced this pull request Sep 16, 2024
…-mingw-import-libraries, r=petrochenkov

linker: Allow MSVC to use import libraries following the Meson/MinGW convention

Hi all,

This PR implements support for `MsvcLinker` to use import libraries following Meson and the MinGW toolchain's naming convention. Meson [follows the `libfoo.dll.a` naming convention](https://mesonbuild.com/FAQ.html#why-does-building-my-project-with-msvc-output-static-libraries-called-libfooa) to disambiguate between static and import libraries.

This support already existed for static libraries (see rust-lang#100101), but not for dynamic libraries. The latter case was added by duplicating the logic in `native_libs::find_native_static_library`, but a separate case was added in `link_dylib_by_name` for the Windows CRT libraries which must be handled by the linker itself.

See for prerequisites rust-lang#129366, rust-lang#126094, and rust-lang#128370.

All feedback is appreciated!

Fixes rust-lang#122455

cc `@sdroege` `@nirbheek`
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Sep 16, 2024
…nd-mingw-import-libraries, r=petrochenkov

linker: Allow MSVC to use import libraries following the Meson/MinGW convention

Hi all,

This PR implements support for `MsvcLinker` to use import libraries following Meson and the MinGW toolchain's naming convention. Meson [follows the `libfoo.dll.a` naming convention](https://mesonbuild.com/FAQ.html#why-does-building-my-project-with-msvc-output-static-libraries-called-libfooa) to disambiguate between static and import libraries.

This support already existed for static libraries (see rust-lang#100101), but not for dynamic libraries. The latter case was added by duplicating the logic in `native_libs::find_native_static_library`, but a separate case was added in `link_dylib_by_name` for the Windows CRT libraries which must be handled by the linker itself.

See for prerequisites rust-lang#129366, rust-lang#126094, and rust-lang#128370.

All feedback is appreciated!

Fixes rust-lang#122455

cc `@sdroege` `@nirbheek`
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Sep 16, 2024
Rollup merge of rust-lang#123436 - amyspark:allow-msvc-to-use-meson-and-mingw-import-libraries, r=petrochenkov

linker: Allow MSVC to use import libraries following the Meson/MinGW convention

Hi all,

This PR implements support for `MsvcLinker` to use import libraries following Meson and the MinGW toolchain's naming convention. Meson [follows the `libfoo.dll.a` naming convention](https://mesonbuild.com/FAQ.html#why-does-building-my-project-with-msvc-output-static-libraries-called-libfooa) to disambiguate between static and import libraries.

This support already existed for static libraries (see rust-lang#100101), but not for dynamic libraries. The latter case was added by duplicating the logic in `native_libs::find_native_static_library`, but a separate case was added in `link_dylib_by_name` for the Windows CRT libraries which must be handled by the linker itself.

See for prerequisites rust-lang#129366, rust-lang#126094, and rust-lang#128370.

All feedback is appreciated!

Fixes rust-lang#122455

cc `@sdroege` `@nirbheek`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants