Skip to content

Implement -Z function-sections=yes|no #78414

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

Merged
merged 2 commits into from
Oct 28, 2020
Merged

Conversation

nox
Copy link
Contributor

@nox nox commented Oct 26, 2020

This lets rustc users tweak whether all functions should be put in their own TEXT section, using whatever default value the target defines if the flag is missing.

I'm having fun experimenting with musl libc and trying to implement the start symbol in Rust, that means avoiding code that requires relocations, and AFAIK putting everything in its own section makes the toolchain generate GOTPCREL relocations for symbols that could use plain old PC-relative addressing (at least on x86_64) if they were all in the same section.

@rust-highfive
Copy link
Contributor

r? @varkor

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

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 26, 2020
@nox
Copy link
Contributor Author

nox commented Oct 26, 2020

I implemented it as a flag because AFAIK that particular setting doesn't require libstd etc to be built the same thing, thus it is a bit unfortunate that it requires building a whole new target currently to change the value. Plus, it would make it easier to check on Windows if we can turn back function-sections on by default there if the bugs are gone.

@nox nox force-pushed the function-sections branch from a46eea0 to b8934ee Compare October 26, 2020 21:41
@eddyb
Copy link
Member

eddyb commented Oct 26, 2020

r? @bjorn3 cc @nagisa

@jyn514
Copy link
Member

jyn514 commented Oct 26, 2020

@bors delegate=bjorn3

@bors
Copy link
Collaborator

bors commented Oct 26, 2020

✌️ @bjorn3 can now approve this pull request

@@ -904,6 +904,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
"force all crates to be `rustc_private` unstable (default: no)"),
fuel: Option<(String, u64)> = (None, parse_optimization_fuel, [TRACKED],
"set the optimization fuel quota for a crate"),
function_sections: Option<bool> = (None, parse_opt_bool, [TRACKED],
"whether each function should go in its own .text section"),
Copy link
Member

Choose a reason for hiding this comment

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

.text is not exactly the most portable name (e.g. machO uses __text AFAIR). I suggest dropping the . or perhaps the whole .text.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a good point, I removed it.

This lets rustc users tweak whether all functions should be put in their own
TEXT section, using whatever default value the target defines if the flag
is missing.
@nox nox force-pushed the function-sections branch from b8934ee to 0569422 Compare October 26, 2020 22:26
@nagisa
Copy link
Member

nagisa commented Oct 26, 2020

@bors r=nagisa,bjorn3

@bors
Copy link
Collaborator

bors commented Oct 26, 2020

📌 Commit 0569422 has been approved by nagisa,bjorn3

@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 Oct 26, 2020
@nox
Copy link
Contributor Author

nox commented Oct 28, 2020

Any chance I could get a p=1 here? I can't wait to play around with that and confirm my understanding of that stuff, but as I'm switching jobs and computers and whatnot all I'm doing is building stuff for Linux on my macOS computer and I don't understand how to do that with a custom rustc. 😅

@nagisa
Copy link
Member

nagisa commented Oct 28, 2020

Its the next PR in the bors queue.

@bors
Copy link
Collaborator

bors commented Oct 28, 2020

⌛ Testing commit 0569422 with merge 3dddf6a...

@bors
Copy link
Collaborator

bors commented Oct 28, 2020

☀️ Test successful - checks-actions
Approved by: nagisa,bjorn3
Pushing 3dddf6a to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Oct 28, 2020
@bors bors merged commit 3dddf6a into rust-lang:master Oct 28, 2020
@rustbot rustbot added this to the 1.49.0 milestone Oct 28, 2020
@jyn514 jyn514 added A-linkage Area: linking into static, shared libraries and binaries T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-linkage Area: linking into static, shared libraries and binaries 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.

9 participants