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

rustc: Fix regression where jemalloc isn't used #57287

Merged
merged 1 commit into from
Jan 6, 2019

Conversation

alexcrichton
Copy link
Member

In #56986 the linkage of jemalloc to the compiler was switched from the
driver library to the rustc binary to ensure that only rustc itself uses
jemalloc. In doing so, however, it turns out jemalloc wasn't actually
linked in at all! None of the symbols were referenced so the static
library wasn't used. This means that jemalloc wasn't pulled in at all.

This commit performs a bit of a dance to reference jemalloc symbols,
attempting to pull it in despite LLVM's optimizations.

Closes #57115

@rust-highfive
Copy link
Collaborator

r? @nikomatsakis

(rust_highfive has picked a reviewer for you, use r? to override)

@alexcrichton
Copy link
Member Author

@bors: try

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 2, 2019
bors added a commit that referenced this pull request Jan 2, 2019
rustc: Fix regression where jemalloc isn't used

In #56986 the linkage of jemalloc to the compiler was switched from the
driver library to the rustc binary to ensure that only rustc itself uses
jemalloc. In doing so, however, it turns out jemalloc wasn't actually
linked in at all! None of the symbols were referenced so the static
library wasn't used. This means that jemalloc wasn't pulled in at all.

This commit performs a bit of a dance to reference jemalloc symbols,
attempting to pull it in despite LLVM's optimizations.

Closes #57115
@bors
Copy link
Contributor

bors commented Jan 2, 2019

⌛ Trying commit 5265c31 with merge 3550c27...

src/rustc/rustc.rs Outdated Show resolved Hide resolved
src/rustc/rustc.rs Outdated Show resolved Hide resolved
@bors
Copy link
Contributor

bors commented Jan 3, 2019

☀️ Test successful - status-travis
State: approved= try=True

@alexcrichton
Copy link
Member Author

@rust-timer build 3550c27

@rust-timer
Copy link
Collaborator

Success: Queued 3550c27 with parent ec19464, comparison URL.

@nikomatsakis
Copy link
Contributor

So my take on this:

  • The code itself seems "obviously" "fine" (as in, not going go to break things)
  • But oh god what a hack

It seems surprising to me that there is no more elegant way to do this.

I'm willing therefore to r+ though I might prefer if somebody else who was closer to the whole linking story did so, since maybe they will have another idea. (e.g., @petrochenkov is asking good questions here).

@nikomatsakis
Copy link
Contributor

Also, the try build is ready, not sure what use you had in mind, @alexcrichton ?

@alexcrichton
Copy link
Member Author

The most elegant way to do this without looking like a hack is probably to use linker flags directly, but actually doing that in Rust would look like more of a hack unfortunately. We don't have that level of control over how things are built to know what's where on the command line, so I've found symbol references to be much more flexible.

Also sorry should have mentioned, but I'd like to do a perf run to confirm that this actually fixes the regression this claims to fix.

@alexcrichton
Copy link
Member Author

(I'd also like to add more comments in the code about the hacks here code-wise, was just waiting on perf)

@rust-timer
Copy link
Collaborator

Finished benchmarking try commit 3550c27

@alexcrichton
Copy link
Member Author

Yay regression is indeed fixed!

I've added some comments, and perhaps in addition to @petrochenkov @michaelwoerister may want to take a look?

In rust-lang#56986 the linkage of jemalloc to the compiler was switched from the
driver library to the rustc binary to ensure that only rustc itself uses
jemalloc. In doing so, however, it turns out jemalloc wasn't actually
linked in at all! None of the symbols were referenced so the static
library wasn't used. This means that jemalloc wasn't pulled in at all.

This commit performs a bit of a dance to reference jemalloc symbols,
attempting to pull it in despite LLVM's optimizations.

Closes rust-lang#57115
@petrochenkov
Copy link
Contributor

Other crates that want to use static jemalloc will have to do something like this as well?

@alexcrichton
Copy link
Member Author

alexcrichton commented Jan 3, 2019

In theory, yes, but in practice it isn't much of a problem. Almost all Rust code that isn't rustc is built with all Rust code statically linked, so the references to the jemalloc symbols will come through things like libstd or just bland Vec::push

@petrochenkov
Copy link
Contributor

@alexcrichton

I think the --whole-archive with -l vs #[link] is probably a bug actually?

Some update: apparently I misremembered the details, command line and attribute behave identically (that's good).

The difference was that static uses whole-archive, but static-nobundle doesn't.
That's also not entirely correct since bundling and whole-archive-ness are somewhat independent.
For example, for linking jemalloc in this case we'd want exactly nobundle + whole-archive.

@alexcrichton
Copy link
Member Author

From my experience at least creating a composable system where libraires can specify linkage and whatnot is insanely hard to say the least and likely downright impossible. We do our best when we can and otherwise just try to fix things when a bug comes up. We're definitely not consistent though :(

@nikomatsakis
Copy link
Contributor

@bors r+

Since it seems like @petrochenkov doesn't have any blocking objections, I'm going to r+ here for now. Feel free to r- or r? someone else though.

@bors
Copy link
Contributor

bors commented Jan 4, 2019

📌 Commit ccbf28e has been approved by nikomatsakis

@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 Jan 4, 2019
@bors
Copy link
Contributor

bors commented Jan 6, 2019

⌛ Testing commit ccbf28e with merge af2c159...

bors added a commit that referenced this pull request Jan 6, 2019
rustc: Fix regression where jemalloc isn't used

In #56986 the linkage of jemalloc to the compiler was switched from the
driver library to the rustc binary to ensure that only rustc itself uses
jemalloc. In doing so, however, it turns out jemalloc wasn't actually
linked in at all! None of the symbols were referenced so the static
library wasn't used. This means that jemalloc wasn't pulled in at all.

This commit performs a bit of a dance to reference jemalloc symbols,
attempting to pull it in despite LLVM's optimizations.

Closes #57115
@bors
Copy link
Contributor

bors commented Jan 6, 2019

☀️ Test successful - status-appveyor, status-travis
Approved by: nikomatsakis
Pushing af2c159 to master...

@bors bors merged commit ccbf28e into rust-lang:master Jan 6, 2019
@alexcrichton alexcrichton deleted the fix-jemalloc branch March 12, 2019 20:26
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants