Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#122790 - Zoxc:dllimp-rev, r=<try>
Browse files Browse the repository at this point in the history
Apply dllimport in ThinLTO for -Z dylib-lto

This partially reverts rust-lang#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`
bors committed Mar 21, 2024

Verified

This commit was signed with the committer’s verified signature.
Byron Sebastian Thiel
2 parents 6e1f7b5 + ea72d12 commit af61c39
Showing 3 changed files with 27 additions and 14 deletions.
11 changes: 6 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -438,7 +438,7 @@ jobs:
os: windows-2019-8core-32gb
- name: dist-x86_64-msvc
env:
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"
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"
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
DIST_REQUIRE_ALL_TOOLS: 1
os: windows-2019-8core-32gb
@@ -592,7 +592,6 @@ jobs:
try:
name: "try - ${{ matrix.name }}"
env:
DIST_TRY_BUILD: 1
CI_JOB_NAME: "${{ matrix.name }}"
CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse
HEAD_SHA: "${{ github.event.pull_request.head.sha || github.sha }}"
@@ -610,10 +609,12 @@ jobs:
strategy:
matrix:
include:
- name: dist-x86_64-linux
- name: dist-x86_64-msvc
env:
CODEGEN_BACKENDS: "llvm,cranelift"
os: ubuntu-20.04-16core-64gb
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"
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
DIST_REQUIRE_ALL_TOOLS: 1
os: windows-2019-8core-32gb
defaults:
run:
shell: "${{ contains(matrix.os, 'windows') && 'msys2 {0}' || 'bash' }}"
9 changes: 7 additions & 2 deletions compiler/rustc_codegen_llvm/src/consts.rs
Original file line number Diff line number Diff line change
@@ -302,15 +302,20 @@ impl<'ll> CodegenCx<'ll, '_> {
}

if !def_id.is_local() {
// Workaround an LLD bug (https://github.com/rust-lang/rust/issues/81408) with importing
// static symbols triggered by ThinLTO if we're not using -Z dylib-lto. Note this
// workaround may not be sound for crate graphs with dylibs.
let workaround_lld_bug =
self.tcx.sess.lto() == Lto::Thin && !self.tcx.sess.opts.unstable_opts.dylib_lto;

let needs_dll_storage_attr = self.use_dll_storage_attrs && !self.tcx.is_foreign_item(def_id) &&
// Local definitions can never be imported, so we must not apply
// the DLLImport annotation.
!dso_local &&
// ThinLTO can't handle this workaround in all cases, so we don't
// emit the attrs. Instead we make them unnecessary by disallowing
// dynamic linking when linker plugin based LTO is enabled.
!self.tcx.sess.opts.cg.linker_plugin_lto.enabled() &&
self.tcx.sess.lto() != Lto::Thin;
!self.tcx.sess.opts.cg.linker_plugin_lto.enabled() && !workaround_lld_bug;

// If this assertion triggers, there's something wrong with commandline
// argument validation.
21 changes: 14 additions & 7 deletions src/ci/github-actions/ci.yml
Original file line number Diff line number Diff line change
@@ -688,6 +688,7 @@ jobs:
--enable-full-tools
--enable-profiler
--set rust.codegen-units=1
--set rust.lto=thin
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
DIST_REQUIRE_ALL_TOOLS: 1
<<: *job-windows-8c
@@ -753,19 +754,25 @@ jobs:
<<: *base-ci-job
name: try - ${{ matrix.name }}
env:
DIST_TRY_BUILD: 1
# DIST_TRY_BUILD: 1
<<: [*shared-ci-variables, *prod-variables]
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'))
strategy:
matrix:
include:
- &dist-x86_64-linux
name: dist-x86_64-linux
- name: dist-x86_64-msvc
env:
CODEGEN_BACKENDS: llvm,cranelift
<<: *job-linux-16c


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
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
DIST_REQUIRE_ALL_TOOLS: 1
<<: *job-windows-8c
master:
name: master
runs-on: ubuntu-latest

0 comments on commit af61c39

Please sign in to comment.