Skip to content

Quote version script symbols#158607

Open
syrel wants to merge 2 commits into
rust-lang:mainfrom
syrel:quote-version-script-symbols
Open

Quote version script symbols#158607
syrel wants to merge 2 commits into
rust-lang:mainfrom
syrel:quote-version-script-symbols

Conversation

@syrel

@syrel syrel commented Jun 30, 2026

Copy link
Copy Markdown

Hi

rustc generates an LD version script in the following format:

{
  global:
    exported_symbol;
    some$foo::bar$thing/path.rs:42;

  local:
    *;
};

However, the symbols are not quoted, which means that the following code will cause a linker failure because the gnerated LD version script has an invalid syntax.

#[unsafe(export_name = "some$foo::bar$thing/path.rs:42")]
pub extern "C" fn exported_symbol_with_version_script_special_characters() {}
error: linking with `cc` failed: exit status: 1
  |
  = note:  "cc" "-Wl,--version-script=/project/target/release/deps/rustcYQww7z/list" "-Wl,--no-undefined-version" "/project/target/release/deps/rustcYQww7z/symbols.o" ...
  = note: /project/target/release/deps/rustcYQww7z/list:349: ignoring invalid character `/' in script
          /usr/bin/ld:/project/target/release/deps/rustcYQww7z/list:349: syntax error in VERSION script
          clang: error: linker command failed with exit code 1 (use -v to see invocation)

Special characters such as $, /, ., and : are valid for a symbol name in an ELF binary. LD Script Format documentation specifies (same rules apply for symbols and file names):

If the file name contains a character such as a comma which would otherwise serve to separate file names, you may put the file name in double quotes.

This PR quotes each symbol name before adding it to the global: section. This allows exported symbols containing linker-special characters, such as $, ::, /, ., and :, to be handled correctly by the linker:

{
  global:
    "exported_symbol";
    "some$foo::bar$thing/path.rs:42";

  local:
    *;
};

The new run-make test builds a cdylib with an export_name containing those characters and verifies that the exact symbol is exported from the produced shared object.

Cheers
Alex

@rustbot rustbot added 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. labels Jun 30, 2026
@rustbot

rustbot commented Jun 30, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the pull request, and welcome! The Rust Project is excited to review your changes, and you should hear from @TaKO8Ki (or someone else) some time within the next two weeks.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue
Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 73 candidates
  • Random selection from 17 candidates

Comment thread compiler/rustc_codegen_ssa/src/back/linker.rs
@bjorn3

bjorn3 commented Jun 30, 2026

Copy link
Copy Markdown
Member

Can you check if this fixes #38238?

@syrel

syrel commented Jun 30, 2026

Copy link
Copy Markdown
Author

Can you check if this fixes #38238?

Thanks for referencing the issue! This PR does indeed fix it. Just a comment about trailing spaces in export_name: even though they will be supported on linux, macos strips whitespaces. It might be wise to extend the docs around export_name and link_name to mention platform specific quirks.

@syrel syrel requested a review from bjorn3 June 30, 2026 12:33
@rust-bors

rust-bors Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

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

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.

4 participants