Skip to content

Conversation

@folkertdev
Copy link
Contributor

fixes #147789

r? @Amanieu

@rustbot
Copy link
Collaborator

rustbot commented Oct 17, 2025

Some changes occurred in compiler/rustc_codegen_ssa

cc @WaffleLapkin

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 17, 2025
@folkertdev folkertdev changed the title Naked function sections naked functions: respect function-sections Oct 17, 2025
@folkertdev folkertdev force-pushed the naked-function-sections branch from 2ebd197 to ac4b179 Compare October 17, 2025 14:39
@rustbot rustbot added the A-run-make Area: port run-make Makefiles to rmake.rs label Oct 17, 2025
@folkertdev folkertdev force-pushed the naked-function-sections branch from ac4b179 to 6580a5f Compare October 17, 2025 14:51
if let Some(section) = &link_section {
writeln!(begin, ".pushsection {section},\"xr\"").unwrap()
} else if function_sections {
writeln!(begin, ".pushsection .text${asm_name},\"xr\"").unwrap()
Copy link
Member

Choose a reason for hiding this comment

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

On -msvc targets, function_sections is ignored. .text$sym is only used on -gnu targets.

Copy link
Member

Choose a reason for hiding this comment

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

Also LLVM currently generates the following line on COFF targets:

.section        {section},"xr",one_only,{sym},unique,0`

Should we be doing the same here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

On -msvc targets, function_sections is ignored.

Meaning that it's just always assumed to be on? https://godbolt.org/z/a6ofW49YK

.text$sym is only used on -gnu targets.

It should still work for msvc, no?

Should we be doing the same here?

I don't think we can reliably emit the unique,id bit of that line because how do we make that ID?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually using -Zfunction-sections=no on msvc does have an effect. So I'm not really sure what it being ignored means then. Maybe this is a more recent LLVM change?

Copy link
Member

Choose a reason for hiding this comment

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

No, it's always assumed to be off on msvc. You can see it always uses .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.

It does always use .text but normally it emits the line you quoted:

  .section .text,"xr",one_only,foo,unique,0

i.e. it uses a subsection which, as far as I understand, does allow DCE, with -Zfunction-sections=no it emits just

  .text

So then DCE is impossible

@bors
Copy link
Collaborator

bors commented Nov 3, 2025

☔ The latest upstream changes (presumably #148305) made this pull request unmergeable. Please resolve the merge conflicts.

@folkertdev folkertdev force-pushed the naked-function-sections branch from 6580a5f to b12830c Compare November 7, 2025 17:00
@rustbot
Copy link
Collaborator

rustbot commented Nov 7, 2025

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@rust-log-analyzer
Copy link
Collaborator

The job tidy failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
spellchecking files
building external tool typos from package typos-cli@1.38.1
finished building tool typos
npm WARN deprecated puppeteer@22.15.0: < 24.10.2 is no longer supported
npm ERR! code 127
npm ERR! git dep preparation failed
npm ERR! command /node/bin/node /node/lib/node_modules/npm/bin/npm-cli.js install --force --cache=/home/user/.npm --prefer-offline=false --prefer-online=false --offline=false --no-progress --no-save --no-audit --include=dev --include=peer --include=optional --no-package-lock-only --no-dry-run
npm ERR! npm WARN using --force Recommended protections disabled.
npm ERR! npm WARN deprecated inflight@1.0.6: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
npm ERR! npm WARN deprecated glob@7.2.3: Glob versions prior to v9 are no longer supported
npm ERR! npm WARN deprecated glob@7.2.3: Glob versions prior to v9 are no longer supported
npm ERR! npm WARN deprecated readdir-scoped-modules@1.1.0: This functionality has been moved to @npmcli/fs
npm ERR! npm WARN deprecated debuglog@1.0.1: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
npm ERR! npm WARN deprecated read-package-json@2.1.2: This package is no longer supported. Please use @npmcli/package-json instead.
npm ERR! npm WARN deprecated read-installed@4.0.3: This package is no longer supported.
npm ERR! npm ERR! code 127
npm ERR! npm ERR! path /home/user/.npm/_cacache/tmp/git-cloneXXXXXXFFqMuu/node_modules/rollup
npm ERR! npm ERR! command failed
npm ERR! npm ERR! command sh -c patch-package
npm ERR! npm ERR! sh: 1: patch-package: not found
npm ERR! 
npm ERR! npm ERR! A complete log of this run can be found in: /home/user/.npm/_logs/2025-11-07T17_06_48_002Z-debug-0.log

npm ERR! A complete log of this run can be found in: /home/user/.npm/_logs/2025-11-07T17_06_40_599Z-debug-0.log
npm install did not exit successfully
tidy [extra_checks]: IO error: npm install returned exit code exit status: 127
tidy [extra_checks]: FAIL
tidy: The following check failed: extra_checks
Command `/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-tools-bin/rust-tidy /checkout /checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo /checkout/obj/build 4 /node/bin/npm --extra-checks=py,cpp,js,spellcheck` failed with exit code 1
Created at: src/bootstrap/src/core/build_steps/tool.rs:1549:23
Executed at: src/bootstrap/src/core/build_steps/test.rs:1279:29

Command has failed. Rerun with -v to see more details.
Bootstrap failed while executing `test src/tools/tidy tidyselftest --extra-checks=py,cpp,js,spellcheck`
Build completed unsuccessfully in 0:02:59
  local time: Fri Nov  7 17:07:06 UTC 2025
  network time: Fri, 07 Nov 2025 17:07:06 GMT
##[error]Process completed with exit code 1.

@folkertdev
Copy link
Contributor Author

folkertdev commented Nov 8, 2025

Looks like windows will also be using function sections by default soon #148669

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-run-make Area: port run-make Makefiles to rmake.rs S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. 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.

Each naked function creates separate PE code section

6 participants