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

bootstrap: don't apply -Ztls-model=initial-exec to proc macros #100536

Merged
merged 1 commit into from
Aug 21, 2022

Conversation

Alexendoo
Copy link
Member

Potentially fixes #100530

r? @bjorn3

@rustbot rustbot added the T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) label Aug 14, 2022
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 14, 2022
@bjorn3
Copy link
Member

bjorn3 commented Aug 14, 2022

@bors try

@bors
Copy link
Contributor

bors commented Aug 14, 2022

⌛ Trying commit 7ecc8c0e6b3cbebb9568e373def599e8932280d5 with merge b8faa934fa7fcac224925252dcd9884abf34a688...

src/bootstrap/bin/rustc.rs Outdated Show resolved Hide resolved
@bjorn3
Copy link
Member

bjorn3 commented Aug 14, 2022

If you have rustup-toolchain-install-master installed (cargo install rustup-toolchain-install-master) you can use rustup-toolchain-install-master -c rustc-dev b8faa934fa7fcac224925252dcd9884abf34a688 to install it once the try build is complete and then cargo +b8faa934fa7fcac224925252dcd9884abf34a688 build to build your test project.

@bors
Copy link
Contributor

bors commented Aug 14, 2022

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

@rustbot rustbot added the T-infra Relevant to the infrastructure team, which will review and decide on the PR/issue. label Aug 14, 2022
@Alexendoo
Copy link
Member Author

Alexendoo commented Aug 14, 2022

Ah the try build produced x86 linux assets 😅

Pushed a commit that I believe should make it use aarch64 temporarily

@bjorn3
Copy link
Member

bjorn3 commented Aug 14, 2022

@bors try

@bors
Copy link
Contributor

bors commented Aug 14, 2022

⌛ Trying commit 7b941bb9f11cc75b463d5255528b1d9b179890a0 with merge ad757cfdaf165871015454fd840ff1400125fd79...

@bors
Copy link
Contributor

bors commented Aug 14, 2022

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

@Alexendoo
Copy link
Member Author

No such luck:

error: /home/alex/.rustup/toolchains/ad757cfdaf165871015454fd840ff1400125fd79/lib/rustlib/aarch64-unknown-linux-gnu/lib/libserde_derive-6dc9fea9ed4dba80.so: cannot allocate memory in static TLS block
 --> src/lib.rs:3:1
  |
3 | extern crate rustc_attr;
  | ^^^^^^^^^^^^^^^^^^^^^^^^

@bjorn3
Copy link
Member

bjorn3 commented Aug 14, 2022

Right, -Zdual-proc-macro means that the proc macro is compiled a second time for the target. This time -Ztls-model=initial-exec is passed. Could you add a check that the crate type is not proc-macro before adding the argument? This doesn't catch proc macro dependencies, so at least also the proc-macro2 crate needs to have -Ztls-model=initial-exec disabled. For which you need another conditional.

@Alexendoo
Copy link
Member Author

Is that what you meant?

My comment is lacking, I don't know enough about proc macros to explain why it's in target.is_some()

@bjorn3
Copy link
Member

bjorn3 commented Aug 16, 2022

Is that what you meant?

Yes

@bors try

@bors
Copy link
Contributor

bors commented Aug 16, 2022

⌛ Trying commit de81d0661c0278a95fde22aa0a5b9f0eac1bb3e9 with merge 5618bbd2f9cff002b70877eb50368991de5e4ab7...

@bors
Copy link
Contributor

bors commented Aug 16, 2022

☀️ Try build successful - checks-actions
Build commit: 5618bbd2f9cff002b70877eb50368991de5e4ab7 (5618bbd2f9cff002b70877eb50368991de5e4ab7)

@Alexendoo
Copy link
Member Author

There's progress, before the following crates would give the error:

rustc_ast_lowering
rustc_ast_passes
rustc_attr
rustc_borrowck
rustc_builtin_macros
rustc_codegen_llvm
rustc_codegen_ssa
rustc_const_eval
rustc_driver
rustc_errors
rustc_expand
rustc_hir_pretty
rustc_hir
rustc_incremental
rustc_infer
rustc_interface
rustc_lint_defs
rustc_lint
rustc_metadata
rustc_middle
rustc_mir_build
rustc_mir_dataflow
rustc_mir_transform
rustc_monomorphize
rustc_parse
rustc_passes
rustc_plugin_impl
rustc_privacy
rustc_query_impl
rustc_query_system
rustc_resolve
rustc_save_analysis
rustc_session
rustc_smir
rustc_symbol_mangling
rustc_target
rustc_trait_selection
rustc_traits
rustc_transmute
rustc_ty_utils
rustc_typeck

On 5618bbd2f9cff002b70877eb50368991de5e4ab7 there are fewer:

rustc_ast_lowering
rustc_borrowck
rustc_codegen_llvm
rustc_codegen_ssa
rustc_const_eval
rustc_driver
rustc_incremental
rustc_infer
rustc_interface
rustc_lint
rustc_metadata
rustc_middle
rustc_mir_build
rustc_mir_dataflow
rustc_mir_transform
rustc_monomorphize
rustc_passes
rustc_plugin_impl
rustc_privacy
rustc_query_impl
rustc_resolve
rustc_save_analysis
rustc_smir
rustc_symbol_mangling
rustc_trait_selection
rustc_traits
rustc_transmute
rustc_ty_utils
rustc_typeck

@bjorn3
Copy link
Member

bjorn3 commented Aug 16, 2022

What is the exact error in those cases?

@Alexendoo
Copy link
Member Author

Alexendoo commented Aug 16, 2022

error: /home/alex/.rustup/toolchains/5618bbd2f9cff002b70877eb50368991de5e4ab7/lib/rustlib/aarch64-unknown-linux-gnu/lib/libchalk_derive-8ea0a51673aa1739.so: cannot allocate memory in static TLS block
 --> src/lib.rs:3:1
  |
3 | extern crate rustc_ast_lowering;
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

(same error for all of them)

@bjorn3
Copy link
Member

bjorn3 commented Aug 16, 2022

chalk_derive depends on quote, syn and synstructure. I don't know which one is responsible, but adding all of them as exceptions just like proc-macro2 would work I think.

@bjorn3
Copy link
Member

bjorn3 commented Aug 16, 2022

@bors try

@bors
Copy link
Contributor

bors commented Aug 16, 2022

⌛ Trying commit fd0327d0194cb9a6150f814ea84ec9973faee050 with merge d65f8b66932795e8cc8e3f099902dc2ad9813af5...

@bors
Copy link
Contributor

bors commented Aug 16, 2022

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

@Alexendoo Alexendoo changed the title bootstrap: limit -Ztls-model=initial-exec to non-host crates bootstrap: don't apply -Ztls-model=initial-exec to proc macros Aug 16, 2022
@Alexendoo
Copy link
Member Author

Nice, that one compiled successfully! Thanks for walking me through it

rebased + removed the ci try change

@workingjubilee workingjubilee added the O-AArch64 Armv8-A or later processors in AArch64 mode label Aug 17, 2022
@bjorn3
Copy link
Member

bjorn3 commented Aug 17, 2022

LGTM, but given that I suggested this fix, I'm going to defer final review to someone else.

r? @Mark-Simulacrum You also reviewed #78201. Would you mind taking a look?

// issue https://github.com/rust-lang/rust/issues/100530
if env::var("RUSTC_TLS_MODEL_INITIAL_EXEC").is_ok()
&& arg("--crate-type") != Some("proc-macro")
&& !matches!(crate_name, Some("proc_macro2" | "quote" | "syn" | "synstructure"))
Copy link
Member

Choose a reason for hiding this comment

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

Is there a test or something else we can add that validates this list is enough? For example, I'm thinking that maybe our invocations of cargo metadata can help here?

I don't think this is something we should do in rustc.rs, probably too much overhead, but some kind of out of band check seems like a good idea to me.

Copy link
Member

Choose a reason for hiding this comment

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

I guess the actual set is something like proc macros dep and contains TLS symbols, or so?

For example, rustc_macros depends on multiple other crates:

https://github.com/rust-lang/rust/blob/master/compiler/rustc_macros/Cargo.toml#L10

Copy link
Member

Choose a reason for hiding this comment

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

I guess the actual set is something like proc macros dep and contains TLS symbols, or so?

Yes, although a blanket include of all proc macro deps would be correct though. It may just cause a perf regression.

Copy link
Member

Choose a reason for hiding this comment

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

I think we should try it; my guess is that TLS access for these crates isn't hot (even at runtime if they're pulled in there).

Or we can go a different direction and try to test this, but it sounds like doing that isn't trivial?

Copy link
Member

Choose a reason for hiding this comment

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

I think checking all proc macro dylibs shipped with rustc-dev for the R_X86_64_TPOFF64 relocation kind (on x86_64, aarch64 has a different relocation name) would suffice. R_X86_64_DTPOFF64 is the only TLS relocation kind that is used for the global dynamic tls model (the most general tls model) I think.

Copy link
Member Author

Choose a reason for hiding this comment

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

The difference before/after appears to be R_AARCH64_TLS_TPREL64

Is there a nice way to get a list of the proc macro dylibs in a run-make-fulldeps test? (or a better way to test for that)

Copy link
Member

Choose a reason for hiding this comment

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

Not sure.

@Mark-Simulacrum
Copy link
Member

@bors r+ rollup=never

I think let's land this for now, we'll keep #92976 open (I'll leave a comment there) that we should add testing for this since the current solution is easy to regress on in the future.

@bors
Copy link
Contributor

bors commented Aug 20, 2022

📌 Commit 23abd59 has been approved by Mark-Simulacrum

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 Aug 20, 2022
@bors
Copy link
Contributor

bors commented Aug 21, 2022

⌛ Testing commit 23abd59 with merge f2858b5...

@bors
Copy link
Contributor

bors commented Aug 21, 2022

☀️ Test successful - checks-actions
Approved by: Mark-Simulacrum
Pushing f2858b5 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Aug 21, 2022
@bors bors merged commit f2858b5 into rust-lang:master Aug 21, 2022
@rustbot rustbot added this to the 1.65.0 milestone Aug 21, 2022
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (f2858b5): comparison url.

Instruction count

  • Primary benchmarks: no relevant changes found
  • Secondary benchmarks: ✅ relevant improvements found
mean1 max count2
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.3% -0.3% 2
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results
  • Primary benchmarks: no relevant changes found
  • Secondary benchmarks: mixed results
mean1 max count2
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
1.8% 1.8% 3
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.7% -2.7% 1
All ❌✅ (primary) - - 0

Cycles

Results
  • Primary benchmarks: mixed results
  • Secondary benchmarks: no relevant changes found
mean1 max count2
Regressions ❌
(primary)
2.9% 3.2% 2
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-1.8% -1.8% 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 1.3% 3.2% 3

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

@rustbot label: -perf-regression

Footnotes

  1. the arithmetic mean of the percent change 2 3

  2. number of relevant changes 2 3

@Alexendoo Alexendoo deleted the bootstrap-tls-model branch August 21, 2022 10:24
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. O-AArch64 Armv8-A or later processors in AArch64 mode 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) T-infra Relevant to the infrastructure team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Build failure with rustc_private crates on aarch64-unknown-linux-gnu
8 participants