Skip to content

Commit af61c39

Browse files
committed
Auto merge of #122790 - Zoxc:dllimp-rev, r=<try>
Apply dllimport in ThinLTO for -Z dylib-lto This partially reverts #103353 by properly applying `dllimport` if `-Z dylib-lto` is passed. That PR should probably fully be reverted as it looks quite sketchy. We don't know locally if the entire crate graph would be statically linked. This should hopefully be sufficient to make ThinLTO work for rustc on Windows. r? `@wesleywiser`
2 parents 6e1f7b5 + ea72d12 commit af61c39

File tree

3 files changed

+27
-14
lines changed

3 files changed

+27
-14
lines changed

.github/workflows/ci.yml

+6-5
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ jobs:
438438
os: windows-2019-8core-32gb
439439
- name: dist-x86_64-msvc
440440
env:
441-
RUST_CONFIGURE_ARGS: "--build=x86_64-pc-windows-msvc --host=x86_64-pc-windows-msvc --target=x86_64-pc-windows-msvc --enable-full-tools --enable-profiler --set rust.codegen-units=1"
441+
RUST_CONFIGURE_ARGS: "--build=x86_64-pc-windows-msvc --host=x86_64-pc-windows-msvc --target=x86_64-pc-windows-msvc --enable-full-tools --enable-profiler --set rust.codegen-units=1 --set rust.lto=thin"
442442
SCRIPT: python x.py build --set rust.debug=true opt-dist && PGO_HOST=x86_64-pc-windows-msvc ./build/x86_64-pc-windows-msvc/stage0-tools-bin/opt-dist windows-ci -- python x.py dist bootstrap --include-default-paths
443443
DIST_REQUIRE_ALL_TOOLS: 1
444444
os: windows-2019-8core-32gb
@@ -592,7 +592,6 @@ jobs:
592592
try:
593593
name: "try - ${{ matrix.name }}"
594594
env:
595-
DIST_TRY_BUILD: 1
596595
CI_JOB_NAME: "${{ matrix.name }}"
597596
CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse
598597
HEAD_SHA: "${{ github.event.pull_request.head.sha || github.sha }}"
@@ -610,10 +609,12 @@ jobs:
610609
strategy:
611610
matrix:
612611
include:
613-
- name: dist-x86_64-linux
612+
- name: dist-x86_64-msvc
614613
env:
615-
CODEGEN_BACKENDS: "llvm,cranelift"
616-
os: ubuntu-20.04-16core-64gb
614+
RUST_CONFIGURE_ARGS: "--build=x86_64-pc-windows-msvc --host=x86_64-pc-windows-msvc --target=x86_64-pc-windows-msvc --enable-full-tools --enable-profiler --set rust.codegen-units=1 --set rust.lto=thin"
615+
SCRIPT: python x.py build --set rust.debug=true opt-dist && PGO_HOST=x86_64-pc-windows-msvc ./build/x86_64-pc-windows-msvc/stage0-tools-bin/opt-dist windows-ci -- python x.py dist bootstrap --include-default-paths
616+
DIST_REQUIRE_ALL_TOOLS: 1
617+
os: windows-2019-8core-32gb
617618
defaults:
618619
run:
619620
shell: "${{ contains(matrix.os, 'windows') && 'msys2 {0}' || 'bash' }}"

compiler/rustc_codegen_llvm/src/consts.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -302,15 +302,20 @@ impl<'ll> CodegenCx<'ll, '_> {
302302
}
303303

304304
if !def_id.is_local() {
305+
// Workaround an LLD bug (https://github.com/rust-lang/rust/issues/81408) with importing
306+
// static symbols triggered by ThinLTO if we're not using -Z dylib-lto. Note this
307+
// workaround may not be sound for crate graphs with dylibs.
308+
let workaround_lld_bug =
309+
self.tcx.sess.lto() == Lto::Thin && !self.tcx.sess.opts.unstable_opts.dylib_lto;
310+
305311
let needs_dll_storage_attr = self.use_dll_storage_attrs && !self.tcx.is_foreign_item(def_id) &&
306312
// Local definitions can never be imported, so we must not apply
307313
// the DLLImport annotation.
308314
!dso_local &&
309315
// ThinLTO can't handle this workaround in all cases, so we don't
310316
// emit the attrs. Instead we make them unnecessary by disallowing
311317
// dynamic linking when linker plugin based LTO is enabled.
312-
!self.tcx.sess.opts.cg.linker_plugin_lto.enabled() &&
313-
self.tcx.sess.lto() != Lto::Thin;
318+
!self.tcx.sess.opts.cg.linker_plugin_lto.enabled() && !workaround_lld_bug;
314319

315320
// If this assertion triggers, there's something wrong with commandline
316321
// argument validation.

src/ci/github-actions/ci.yml

+14-7
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,7 @@ jobs:
688688
--enable-full-tools
689689
--enable-profiler
690690
--set rust.codegen-units=1
691+
--set rust.lto=thin
691692
SCRIPT: python x.py build --set rust.debug=true opt-dist && PGO_HOST=x86_64-pc-windows-msvc ./build/x86_64-pc-windows-msvc/stage0-tools-bin/opt-dist windows-ci -- python x.py dist bootstrap --include-default-paths
692693
DIST_REQUIRE_ALL_TOOLS: 1
693694
<<: *job-windows-8c
@@ -753,19 +754,25 @@ jobs:
753754
<<: *base-ci-job
754755
name: try - ${{ matrix.name }}
755756
env:
756-
DIST_TRY_BUILD: 1
757+
# DIST_TRY_BUILD: 1
757758
<<: [*shared-ci-variables, *prod-variables]
758759
if: github.event_name == 'push' && (((github.ref == 'refs/heads/try' || github.ref == 'refs/heads/try-perf') && github.repository == 'rust-lang-ci/rust') || ((github.ref == 'refs/heads/automation/bors/try') && github.repository == 'rust-lang/rust'))
759760
strategy:
760761
matrix:
761762
include:
762-
- &dist-x86_64-linux
763-
name: dist-x86_64-linux
763+
- name: dist-x86_64-msvc
764764
env:
765-
CODEGEN_BACKENDS: llvm,cranelift
766-
<<: *job-linux-16c
767-
768-
765+
RUST_CONFIGURE_ARGS: >-
766+
--build=x86_64-pc-windows-msvc
767+
--host=x86_64-pc-windows-msvc
768+
--target=x86_64-pc-windows-msvc
769+
--enable-full-tools
770+
--enable-profiler
771+
--set rust.codegen-units=1
772+
--set rust.lto=thin
773+
SCRIPT: python x.py build --set rust.debug=true opt-dist && PGO_HOST=x86_64-pc-windows-msvc ./build/x86_64-pc-windows-msvc/stage0-tools-bin/opt-dist windows-ci -- python x.py dist bootstrap --include-default-paths
774+
DIST_REQUIRE_ALL_TOOLS: 1
775+
<<: *job-windows-8c
769776
master:
770777
name: master
771778
runs-on: ubuntu-latest

0 commit comments

Comments
 (0)