Skip to content

Make sure fmt-write-bloat doesn't vacuously pass on no symbols #143669

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

jieyouxu
Copy link
Member

@jieyouxu jieyouxu commented Jul 9, 2025

This PR fixes the tests/run-make/fmt-write-float/ run-make test to both (1) not vacuously pass on no symbols at all, and (2) actually check aginst the platform-specific decorated panic symbols.

  • Commit 1 introduces a new dependency on getsentry/pdb in the run-make-support library to allow us to programmatically inspect PDB files, instead of trying to perform textual output matching on llvm-pdbutil whose textual output is not necessarily guaranteed to remain the same between versions.
  • Commit 2 both adds a smoke check to make sure that the executable (or PDB file) we're inspecting actually has a main symbol and isn't completely devoid of symbols, and also fixes the negative check against panic machinery symbols to account for platform differences.

Context

Previously, the test only checks for the absence of certain panic symbols, but having no symbols was also a possible albeit vacuous way to satisfy this assertion.

Fix this by checking we at least observe the main symbol which is always expected to be present.

Noticed in #142841 (comment).

r? @ChrisDenton

try-job: aarch64-apple
try-job: x86_64-apple-1
try-job: x86_64-msvc-1
try-job: i686-msvc-1
try-job: x86_64-mingw-1

@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 Jul 9, 2025
@ChrisDenton

This comment has been minimized.

@rust-bors

This comment has been minimized.

@ChrisDenton
Copy link
Member

@bors2 try jobs=x86_64-msvc-*

@rust-bors
Copy link

rust-bors bot commented Jul 9, 2025

⌛ Trying commit 5cef54f with merge 9306675

To cancel the try build, run the command @bors2 try cancel.

rust-bors bot added a commit that referenced this pull request Jul 9, 2025
Make sure `fmt-write-bloat` doesn't vacuously pass on no symbols

Previously, the test only checks for the absence of certain panic symbols, but having no symbols was also a possible albeit vacuous way to satisfy this assertion.

Fix this by checking we at least observe the `main` symbol which is always expected to be present.

Noticed in #142841 (comment).

r? `@ChrisDenton`
try-job: x86_64-msvc-*
@rust-bors
Copy link

rust-bors bot commented Jul 9, 2025

💔 Test failed

@jieyouxu
Copy link
Member Author

jieyouxu commented Jul 9, 2025

Hm. Let me try this locally on windows.

@jieyouxu jieyouxu added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 9, 2025
@ChrisDenton
Copy link
Member

The failure is not surprising to me. On Windows, symbols are not contained in the binary itself and are instead in a separate file (the .pdb). So the object crate would not be able to find them.

@jieyouxu
Copy link
Member Author

jieyouxu commented Jul 9, 2025

Oh of course... D'oh. Let me see if I can cook something up.

@rustbot
Copy link
Collaborator

rustbot commented Jul 9, 2025

These commits modify the Cargo.lock file. Unintentional changes to Cargo.lock can be introduced when switching branches and rebasing PRs.

If this was unintentional then you should revert the changes before this PR is merged.
Otherwise, you can ignore this comment.

@jieyouxu jieyouxu changed the title Make sure fmt-write-bloat doesn't vacuously pass on no symbols [WIP] Make sure fmt-write-bloat doesn't vacuously pass on no symbols Jul 9, 2025
@jieyouxu
Copy link
Member Author

jieyouxu commented Jul 9, 2025

@bors2 try

@rust-bors
Copy link

rust-bors bot commented Jul 9, 2025

⌛ Trying commit 63b9636 with merge a1b33a4

To cancel the try build, run the command @bors2 try cancel.

rust-bors bot added a commit that referenced this pull request Jul 9, 2025
[WIP] Make sure `fmt-write-bloat` doesn't vacuously pass on no symbols

Previously, the test only checks for the absence of certain panic symbols, but having no symbols was also a possible albeit vacuous way to satisfy this assertion.

Fix this by checking we at least observe the `main` symbol which is always expected to be present.

Noticed in #142841 (comment).

r? `@ChrisDenton`

try-job: aarch64-apple
try-job: x86_64-apple-1
try-job: x86_64-msvc-1
try-job: i686-msvc-1
try-job: x86_64-mingw-1
@jieyouxu
Copy link
Member Author

jieyouxu commented Jul 9, 2025

llvm-pdbutil is an fallback approach, trying pdb crate to see if that works under CI conditions.

@jieyouxu
Copy link
Member Author

jieyouxu commented Jul 9, 2025

I bet this will also fail on apple because _ prefix to symbol names.

@jieyouxu
Copy link
Member Author

jieyouxu commented Jul 9, 2025

I forgor to run this locally, it's is_windows_msvc not is_msvc.
@bors2 try cancel

@rust-bors
Copy link

rust-bors bot commented Jul 9, 2025

Try build cancelled. Cancelled workflows:

@jieyouxu
Copy link
Member Author

jieyouxu commented Jul 9, 2025

Oh. Apparently we have both is_msvc and is_windows_msvc. I'll fix that separately.

@bors2 try

@rust-bors
Copy link

rust-bors bot commented Jul 9, 2025

⌛ Trying commit 63b9636 with merge 1d2e78e

To cancel the try build, run the command @bors2 try cancel.

rust-bors bot added a commit that referenced this pull request Jul 9, 2025
[WIP] Make sure `fmt-write-bloat` doesn't vacuously pass on no symbols

Previously, the test only checks for the absence of certain panic symbols, but having no symbols was also a possible albeit vacuous way to satisfy this assertion.

Fix this by checking we at least observe the `main` symbol which is always expected to be present.

Noticed in #142841 (comment).

r? `@ChrisDenton`

try-job: aarch64-apple
try-job: x86_64-apple-1
try-job: x86_64-msvc-1
try-job: i686-msvc-1
try-job: x86_64-mingw-1
@rust-bors
Copy link

rust-bors bot commented Jul 10, 2025

💔 Test failed

@jieyouxu
Copy link
Member Author

jieyouxu commented Jul 10, 2025

Huh, does i686 msvc prefix main with an underscore unlike x86_64 msvc...?

Symbols found on i686-pc-windows-msvc
found_symbols = [
    "__register_thread_local_exe_atexit_callback",
    "___report_gsfailure",
    "___isa_available",
    "___scrt_is_nonwritable_in_current_image",
    "__onexit",
    "___scrt_initialize_onexit_tables",
    "__c_exit",
    "___xi_a",
    "___enclave_config",
    "___isa_inverted",
    "___AbsoluteZero",
    "__initialize_default_precision",
    "_memset",
    "___security_init_cookie",
    "__IMPORT_DESCRIPTOR_api-ms-win-crt-runtime-l1-1-0",
    "___guard_longjmp_table",
    "?__scrt_initialize_type_info@@YAXXZ",
    "__imp____p___argv",
    "___favor",
    "___vcrt_uninitialize",
    "__RTC_Terminate",
    "__imp__GetCurrentProcessId@0",
    "__crt_atexit",
    "___scrt_initialize_crt",
    "__imp__terminate",
    "___guard_fids_count",
    "?_OptionsStorage@?1??__local_stdio_scanf_options@@9@4_KA",
    "___isa_enabled",
    "__initialize_onexit_table",
    "__NULL_IMPORT_DESCRIPTOR",
    "__imp___controlfp_s",
    "__set_new_mode",
    "___xi_z",
    "__imp____setusermatherr",
    "__imp__IsProcessorFeaturePresent@4",
    "__imp___configure_narrow_argv",
    "_exit",
    "___raise_securityfailure",
    "___acrt_uninitialize",
    "__imp__GetSystemTimeAsFileTime@4",
    "___scrt_current_native_startup_state",
    "__imp____current_exception",
    "\u{7f}api-ms-win-crt-math-l1-1-0_NULL_THUNK_DATA",
    "__should_initialize_environment",
    "__imp___set_app_type",
    "__IMPORT_DESCRIPTOR_VCRUNTIME140",
    "__imp___initialize_onexit_table",
    "__imp___get_initial_narrow_environment",
    "__imp____p__commode",
    "__get_initial_narrow_environment",
    "___current_exception_context",
    "__imp__memset",
    "__IMPORT_DESCRIPTOR_api-ms-win-crt-heap-l1-1-0",
    "___p___argv",
    "___scrt_fastfail",
    "__imp__UnhandledExceptionFilter@4",
    "___scrt_ucrt_dll_is_in_use",
    "___xp_z",
    "___p__commode",
    "___scrt_exe_initialize_mta",
    "__set_fmode",
    "__initterm_e",
    "__imp___except_handler4_common",
    "___guard_check_icall_fptr",
    "__IMPORT_DESCRIPTOR_api-ms-win-crt-stdio-l1-1-0",
    "__imp__exit",
    "__initialize_invalid_parameter_handler",
    "__imp__GetCurrentThreadId@0",
    "___local_stdio_scanf_options",
    "__imp___initterm_e",
    "___rtc_taa",
    "__imp__GetModuleHandleW@4",
    "__imp___register_onexit_function",
    "__imp___initialize_narrow_environment",
    "___guard_eh_cont_count",
    "__imp__InitializeSListHead@4",
    "__configure_narrow_argv",
    "__imp__QueryPerformanceCounter@4",
    "__crt_debugger_hook",
    "___scrt_initialize_default_local_stdio_options",
    "___xp_a",
    "__configthreadlocale",
    "___xc_z",
    "__get_startup_new_mode",
    "___security_cookie",
    "__imp__IsDebuggerPresent@0",
    "__imp___configthreadlocale",
    "___safe_se_handler_count",
    "___guard_flags",
    "___volatile_metadata",
    "___dyn_tls_dtor_callback",
    "__imp__SetUnhandledExceptionFilter@4",
    "__IMPORT_DESCRIPTOR_api-ms-win-crt-math-l1-1-0",
    "__exit",
    "__register_onexit_function",
    "___scrt_get_dyn_tls_dtor_callback",
    "___scrt_unhandled_exception_filter@4",
    "___guard_fids_table",
    "@__security_check_cookie@4",
    "__filter_x86_sse2_floating_point_exception",
    "__initialize_denormal_control",
    "__imp___set_fmode",
    "__imp___initterm",
    "__except_handler4_common",
    "___guard_eh_cont_table",
    "__get_startup_file_mode",
    "___safe_se_handler_table",
    "___castguard_check_failure_os_handled_fptr",
    "__IMPORT_DESCRIPTOR_KERNEL32",
    "___scrt_stub_for_initialize_mta",
    "___security_cookie_complement",
    "___guard_longjmp_count",
    "?_OptionsStorage@?1??__local_stdio_printf_options@@9@4_KA",
    "___rtc_iaa",
    "__set_app_type",
    "___acrt_initialize",
    "___scrt_is_ucrt_dll_in_use",
    "__imp____current_exception_context",
    "___scrt_get_dyn_tls_init_callback",
    "__imp___exit",
    "__imp___cexit",
    "___scrt_default_matherr",
    "___scrt_uninitialize_crt",
    "___setusermatherr",
    "\u{7f}api-ms-win-crt-stdio-l1-1-0_NULL_THUNK_DATA",
    "__IMPORT_DESCRIPTOR_api-ms-win-crt-locale-l1-1-0",
    "__except_handler4",
    "__imp____p___argc",
    "___scrt_debugger_hook_flag",
    "__imp__TerminateProcess@8",
    "___scrt_stub_for_acrt_initialize",
    "___current_exception",
    "__controlfp_s",
    "___scrt_native_dllmain_reason",
    "___isa_available_init",
    "__initterm",
    "__imp__GetCurrentProcess@0",
    "___guard_iat_count",
    "__initialize_narrow_environment",
    "___vcrt_initialize",
    "__cexit",
    "_atexit",
    "\u{7f}api-ms-win-crt-runtime-l1-1-0_NULL_THUNK_DATA",
    "___rtc_tzz",
    "__get_startup_commit_mode",
    "__imp___crt_atexit",
    "___xt_a",
    "___scrt_is_user_matherr_present",
    "___xc_a",
    "__imp___set_new_mode",
    "___p___argc",
    "\u{7f}api-ms-win-crt-locale-l1-1-0_NULL_THUNK_DATA",
    "\u{7f}VCRUNTIME140_NULL_THUNK_DATA",
    "___xt_z",
    "__imp___c_exit",
    "___scrt_set_unhandled_exception_filter",
    "___scrt_acquire_startup_lock",
    "___scrt_native_startup_lock",
    "___rtc_izz",
    "__imp___register_thread_local_exe_atexit_callback",
    "___local_stdio_printf_options",
    "___guard_iat_table",
    "\u{7f}KERNEL32_NULL_THUNK_DATA",
    "__get_startup_thread_locale_mode",
    "__imp___seh_filter_exe",
    "_mainCRTStartup",
    "__seh_filter_exe",
    "___dyn_tls_init_callback",
    "_terminate",
    "__filter_x86_sse2_floating_point_exception_default",
    "__RTC_Initialize",
    "___scrt_is_managed_app",
    "__SEH_prolog4",
    "@_guard_check_icall_nop@4",
    "___scrt_initialize_winrt",
    "___avx10_version",
    "\u{7f}api-ms-win-crt-heap-l1-1-0_NULL_THUNK_DATA",
    "_main",
    "__get_startup_argv_mode",
    "?__type_info_root_node@@3U__type_info_node@@A",
    "___scrt_release_startup_lock",
    "___scrt_stub_for_acrt_uninitialize",
    "___scrt_initialize_mta",
    "__load_config_used",
    "__matherr",
]

@ChrisDenton
Copy link
Member

See https://learn.microsoft.com/en-us/cpp/build/reference/decorated-names?view=msvc-170#FormatC

On i686-msvc extern "C" functions (aka cdecl) will indeed be prefixed with an underscore.

jieyouxu added 2 commits July 10, 2025 18:54
Previously, the test only checks for the absence of certain panic
symbols, but having no symbols was also a possible albeit vacuous way to
satisfy this assertion.

Fix this by checking we at least observe the `main` symbol which is
always expected to be present.
@jieyouxu
Copy link
Member Author

@bors2 try

@rust-bors
Copy link

rust-bors bot commented Jul 10, 2025

⌛ Trying commit 24830de with merge f734e9c

To cancel the try build, run the command @bors2 try cancel.

rust-bors bot added a commit that referenced this pull request Jul 10, 2025
[WIP] Make sure `fmt-write-bloat` doesn't vacuously pass on no symbols

Previously, the test only checks for the absence of certain panic symbols, but having no symbols was also a possible albeit vacuous way to satisfy this assertion.

Fix this by checking we at least observe the `main` symbol which is always expected to be present.

Noticed in #142841 (comment).

r? `@ChrisDenton`

try-job: aarch64-apple
try-job: x86_64-apple-1
try-job: x86_64-msvc-1
try-job: i686-msvc-1
try-job: x86_64-mingw-1
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jul 10, 2025
Assorted `run-make-support` maintenance

This PR should contain no functional changes.

- Commit 1: Removes the support library's CHANGELOG. In the very beginning, I thought maybe we would try to version this library. But this is a purely internal test support library, and it's just extra busywork trying to maintain changelog/versions. It's also hopelessly outdated.
- Commit 2: Resets version number to `0.0.0`. Ditto on busywork.
- Commit 3: Bump `run-make-support` to Edition 2024. The support library was already "compliant" with Edition 2024.
- Commit 4: Slightly organizes the support library dependencies.
- Commit 5: Previously, I tried hopelessly to maintain some manual formatting, but that was annoying because it required skipping rustfmt (so export ordering etc. could not be extra formatted). Give up, and do some rearrangements / module prefix tricks to get the `lib.rs` looking at least *reasonable*. IMO this is not a strict improvement, but I rather regain the ability to auto-format it with rustfmt.
- Commit {6,7}: Noticed in rust-lang#143669 that we apparently had *both* {`is_msvc`, `is_windows_msvc`}. This PR removes `is_msvc` in favor of `is_windows_msvc` to make it unambiguous (and only retain one way of gating) as there are some UEFI targets which are MSVC but not Windows.

Best reviewed commit-by-commit.

r? `@Kobzol`
@rust-bors
Copy link

rust-bors bot commented Jul 10, 2025

☀️ Try build successful (CI)
Build commit: f734e9c (f734e9c362b13118d196e6a5f983e9c8cf7f4a32, parent: cf3fb768db439825e3c8d327f6d9f46e02965668)

@jieyouxu jieyouxu changed the title [WIP] Make sure fmt-write-bloat doesn't vacuously pass on no symbols Make sure fmt-write-bloat doesn't vacuously pass on no symbols Jul 10, 2025
@jieyouxu
Copy link
Member Author

Try jobs are green.
@rustbot review

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jul 10, 2025
@jieyouxu
Copy link
Member Author

jieyouxu commented Jul 10, 2025

Re. the pdb crate dependency, other run-make tests use llvm-pdbutil currently, but matching against its textual output is IMO quite fragile. It's probably possible to migrate them over to also use pdb programmatically, but beyond the scope of this PR.

@ChrisDenton
Copy link
Member

My only concern with the pdb crate is it doesn't look like it's been updated in awhile. It's probably fine (it has few dependencies by the looks of it) but it makes me slightly wary.

I'm not going to insist on it on this PR but I think long term it would be good to use official debugging APIs on Windows hosts and only fallback to the pdb crate on other platforms (or maybe if they're unavailable for some reason).

Copy link
Member

@ChrisDenton ChrisDenton left a comment

Choose a reason for hiding this comment

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

Thinking about this some more, maybe a more robust way to do this test is to compile two programs: one with the symbols and one without. That would guard against, e.g. changing symbol names or different kinds of naming conventions.

Comment on lines +100 to +101
assert!(any_symbol_contains(bin_name("main"), &["main"]));
assert!(!any_symbol_contains(bin_name("main"), &panic_syms));
Copy link
Member

Choose a reason for hiding this comment

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

wait, I know this is pre-existing but why is this bin_name? That should be a no-op on unix targets but main.exe on Windows, which sounds weird.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it's just because the underlying helper uses fs::read, which doesn't try to account for .exe or not.

@jieyouxu
Copy link
Member Author

My only concern with the pdb crate is it doesn't look like it's been updated in awhile. It's probably fine (it has few dependencies by the looks of it) but it makes me slightly wary.

I'm not going to insist on it on this PR but I think long term it would be good to use official debugging APIs on Windows hosts and only fallback to the pdb crate on other platforms (or maybe if they're unavailable for some reason).

Ah, did you mean the Debug Interface Access SDK?

@ChrisDenton
Copy link
Member

Yeah. But I mean, figuring out how to use it is perhaps more work then you signed up for 😉.

@jieyouxu
Copy link
Member Author

jieyouxu commented Jul 10, 2025

Hm yeah. I think in the long-term, we should probably be using DIA wrappers (but that's quite a bit of Windows-specific work). In the short-term, I could also fallback to just using llvm-pdbutil for now, since if the long-term plan is to use DIA, then it seems better to not introduce a dependency on pdb.

EDIT: #143737

@jieyouxu
Copy link
Member Author

Let me try the

compile two programs: one with the symbols and one without. That would guard against, e.g. changing symbol names or different kinds of naming conventions.

approach.

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 10, 2025
rust-timer added a commit that referenced this pull request Jul 10, 2025
Rollup merge of #143683 - jieyouxu:rms-cleanup, r=Kobzol

Assorted `run-make-support` maintenance

This PR should contain no functional changes.

- Commit 1: Removes the support library's CHANGELOG. In the very beginning, I thought maybe we would try to version this library. But this is a purely internal test support library, and it's just extra busywork trying to maintain changelog/versions. It's also hopelessly outdated.
- Commit 2: Resets version number to `0.0.0`. Ditto on busywork.
- Commit 3: Bump `run-make-support` to Edition 2024. The support library was already "compliant" with Edition 2024.
- Commit 4: Slightly organizes the support library dependencies.
- Commit 5: Previously, I tried hopelessly to maintain some manual formatting, but that was annoying because it required skipping rustfmt (so export ordering etc. could not be extra formatted). Give up, and do some rearrangements / module prefix tricks to get the `lib.rs` looking at least *reasonable*. IMO this is not a strict improvement, but I rather regain the ability to auto-format it with rustfmt.
- Commit {6,7}: Noticed in #143669 that we apparently had *both* {`is_msvc`, `is_windows_msvc`}. This PR removes `is_msvc` in favor of `is_windows_msvc` to make it unambiguous (and only retain one way of gating) as there are some UEFI targets which are MSVC but not Windows.

Best reviewed commit-by-commit.

r? `@Kobzol`
@bors
Copy link
Collaborator

bors commented Jul 10, 2025

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


fn main() {
rustc().input("main.rs").opt().run();
// panic machinery identifiers, these should not appear in the final binary
let mut panic_syms = vec!["panic_bounds_check", "Debug"];
let mut panic_syms = vec![sym("panic_bounds_check"), sym("Debug")];
if no_debug_assertions() {
Copy link
Member Author

@jieyouxu jieyouxu Jul 11, 2025

Choose a reason for hiding this comment

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

Remark: while investigating this test, I realized this is actually incorrect (even in the original Makefile version), and the port preserved the incorrect gating

# Allow for debug_assert!() in debug builds of std.
ifdef NO_DEBUG_ASSERTIONS
PANIC_SYMS += panicking panic_fmt pad_integral Display Debug
endif

I believe NO_DEBUG_ASSERTIONS corresponds (confusingly) only to whether rustc has debug assertions enabled, not std.

I have a separate PR that I'll send first.

Copy link
Member Author

Choose a reason for hiding this comment

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

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-author Status: This is awaiting some action (such as code changes or more information) from the author. 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