Skip to content

test using multiple c-variadic ABIs in the same program #144379

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

Conversation

folkertdev
Copy link
Contributor

@folkertdev folkertdev commented Jul 23, 2025

tracking issue: #100189

Check that multiple c-variadic calling conventions can be used in the same program.

Clang and gcc reject defining functions with a non-default calling convention and a variable
argument list, so C programs that use multiple c-variadic calling conventions are unlikely
to come up. Here we validate that our codegen backends do in fact generate correct code.

(CI will not run this test because it runs on aarch64, I would like to at least test that this runs on windows)

try-job: x86_64-gnu
try-job: x86_64-msvc-*
try-job: x86_64-apple-2

@rustbot
Copy link
Collaborator

rustbot commented Jul 23, 2025

r? @oli-obk

rustbot has assigned @oli-obk.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@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 Jul 23, 2025
@folkertdev
Copy link
Contributor Author

@bors2 try

rust-bors bot added a commit that referenced this pull request Jul 23, 2025
…bis, r=<try>

test using multiple c-variadic ABIs in the same program

try-job: `x86_64-*`
@rust-bors
Copy link

rust-bors bot commented Jul 23, 2025

⌛ Trying commit 596d8e8 with merge 94c4410

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

@rust-bors
Copy link

rust-bors bot commented Jul 23, 2025

💔 Test failed (CI). Failed job:

@rust-log-analyzer

This comment has been minimized.

@folkertdev
Copy link
Contributor Author

@bors2 try

@rust-bors
Copy link

rust-bors bot commented Jul 23, 2025

⌛ Trying commit 596d8e8 with merge 27b661f

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

rust-bors bot added a commit that referenced this pull request Jul 23, 2025
…bis, r=<try>

test using multiple c-variadic ABIs in the same program

try-job: `x86_64-gnu`
try-job: `x86_64-msvc-*`
@rust-bors
Copy link

rust-bors bot commented Jul 24, 2025

☀️ Try build successful (CI)
Build commit: 27b661f (27b661fc99a51243cb90353daf6f7f111102b969, parent: 29a58723b05d004c2e19ddcf2be80d514401f22e)

@RalfJung
Copy link
Member

Ah, that's a fun way of testing this.

Could you add the C source code for that assembly in the test file, so we have it checked in to git?

@folkertdev folkertdev force-pushed the c-variadic-same-program-multiple-abis branch from 596d8e8 to aea74c4 Compare July 24, 2025 09:37
@folkertdev folkertdev force-pushed the c-variadic-same-program-multiple-abis branch from aea74c4 to 963cd8a Compare July 24, 2025 09:47
@oli-obk
Copy link
Contributor

oli-obk commented Jul 24, 2025

I know nothing about these ABIs or issues with it, @workingjubilee do you want to take this one?

@RalfJung
Copy link
Member

I was about to approve -- I don't know how the ABIs are implemented, but the way this is being tested looks sound to me.

@oli-obk oli-obk assigned RalfJung and unassigned oli-obk Jul 24, 2025
@oli-obk
Copy link
Contributor

oli-obk commented Jul 24, 2025

Ah cool, that wfm

@RalfJung
Copy link
Member

Let's land this then, we can always adjust later if @workingjubilee has more comments. It's just a test after all.

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented Jul 24, 2025

📌 Commit 963cd8a has been approved by RalfJung

It is now in the queue for this repository.

@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 Jul 24, 2025
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Jul 25, 2025
…-multiple-abis, r=RalfJung

test using multiple c-variadic ABIs in the same program

tracking issue: rust-lang#100189

Check that multiple c-variadic calling conventions can be used in the same program.

Clang and gcc reject defining functions with a non-default calling convention and a variable
argument list, so C programs that use multiple c-variadic calling conventions are unlikely
to come up. Here we validate that our codegen backends do in fact generate correct code.

(CI will not run this test because it runs on aarch64, I would like to at least test that this runs on windows)

try-job: `x86_64-gnu`
try-job: `x86_64-msvc-*`
bors added a commit that referenced this pull request Jul 25, 2025
Rollup of 13 pull requests

Successful merges:

 - #144356 (Add `ignore-backends` annotations in failing GCC backend ui tests)
 - #144359 (add codegen test for variadics)
 - #144376 (Suggest unwrapping when private method name is available in inner type)
 - #144379 (test using multiple c-variadic ABIs in the same program)
 - #144383 (disable cfg.has_reliable_f128 on amdgcn)
 - #144409 (Stop compilation early if macro expansion failed)
 - #144412 (Small cleanup: Use LocalKey<Cell> methods more)
 - #144421 (Call `is_parsed_attribute` rather than keeping track of a list of parsed attributes manually)
 - #144422 (library/windows_targets: Fix macro expansion error in 'link' macro)
 - #144424 (Allow setting `release-blog-post` label with rustbot)
 - #144430 (tests: aarch64-outline-atomics: Remove hardcoded target)
 - #144435 (rustc-dev-guide subtree update)
 - #144445 (Fix `./x check bootstrap` (again))

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit that referenced this pull request Jul 25, 2025
Rollup of 13 pull requests

Successful merges:

 - #144356 (Add `ignore-backends` annotations in failing GCC backend ui tests)
 - #144359 (add codegen test for variadics)
 - #144376 (Suggest unwrapping when private method name is available in inner type)
 - #144379 (test using multiple c-variadic ABIs in the same program)
 - #144383 (disable cfg.has_reliable_f128 on amdgcn)
 - #144409 (Stop compilation early if macro expansion failed)
 - #144412 (Small cleanup: Use LocalKey<Cell> methods more)
 - #144421 (Call `is_parsed_attribute` rather than keeping track of a list of parsed attributes manually)
 - #144422 (library/windows_targets: Fix macro expansion error in 'link' macro)
 - #144424 (Allow setting `release-blog-post` label with rustbot)
 - #144430 (tests: aarch64-outline-atomics: Remove hardcoded target)
 - #144435 (rustc-dev-guide subtree update)
 - #144445 (Fix `./x check bootstrap` (again))

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit that referenced this pull request Jul 25, 2025
Rollup of 13 pull requests

Successful merges:

 - #144356 (Add `ignore-backends` annotations in failing GCC backend ui tests)
 - #144359 (add codegen test for variadics)
 - #144376 (Suggest unwrapping when private method name is available in inner type)
 - #144379 (test using multiple c-variadic ABIs in the same program)
 - #144383 (disable cfg.has_reliable_f128 on amdgcn)
 - #144409 (Stop compilation early if macro expansion failed)
 - #144412 (Small cleanup: Use LocalKey<Cell> methods more)
 - #144421 (Call `is_parsed_attribute` rather than keeping track of a list of parsed attributes manually)
 - #144422 (library/windows_targets: Fix macro expansion error in 'link' macro)
 - #144424 (Allow setting `release-blog-post` label with rustbot)
 - #144430 (tests: aarch64-outline-atomics: Remove hardcoded target)
 - #144435 (rustc-dev-guide subtree update)
 - #144445 (Fix `./x check bootstrap` (again))

r? `@ghost`
`@rustbot` modify labels: rollup
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Jul 25, 2025
…-multiple-abis, r=RalfJung

test using multiple c-variadic ABIs in the same program

tracking issue: rust-lang#100189

Check that multiple c-variadic calling conventions can be used in the same program.

Clang and gcc reject defining functions with a non-default calling convention and a variable
argument list, so C programs that use multiple c-variadic calling conventions are unlikely
to come up. Here we validate that our codegen backends do in fact generate correct code.

(CI will not run this test because it runs on aarch64, I would like to at least test that this runs on windows)

try-job: `x86_64-gnu`
try-job: `x86_64-msvc-*`
bors added a commit that referenced this pull request Jul 25, 2025
Rollup of 14 pull requests

Successful merges:

 - #144316 (bootstrap: Move musl-root fallback out of sanity check)
 - #144352 (RustWrapper: Suppress getNextNonDebugInfoInstruction)
 - #144356 (Add `ignore-backends` annotations in failing GCC backend ui tests)
 - #144359 (add codegen test for variadics)
 - #144376 (Suggest unwrapping when private method name is available in inner type)
 - #144379 (test using multiple c-variadic ABIs in the same program)
 - #144383 (disable cfg.has_reliable_f128 on amdgcn)
 - #144412 (Small cleanup: Use LocalKey<Cell> methods more)
 - #144421 (Call `is_parsed_attribute` rather than keeping track of a list of parsed attributes manually)
 - #144422 (library/windows_targets: Fix macro expansion error in 'link' macro)
 - #144424 (Allow setting `release-blog-post` label with rustbot)
 - #144430 (tests: aarch64-outline-atomics: Remove hardcoded target)
 - #144435 (rustc-dev-guide subtree update)
 - #144445 (Fix `./x check bootstrap` (again))

r? `@ghost`
`@rustbot` modify labels: rollup
@jieyouxu
Copy link
Member

Failed in rollup: #144466 (comment)

---- [ui] tests/ui/c-variadic/same-program-multiple-abis.rs stdout ----

error: test compilation failed although it shouldn't!
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/Users/runner/work/rust/rust/build/x86_64-apple-darwin/stage2/bin/rustc" "/Users/runner/work/rust/rust/tests/ui/c-variadic/same-program-multiple-abis.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/Users/runner/.cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/Users/runner/work/rust/rust/vendor" "--sysroot" "/Users/runner/work/rust/rust/build/x86_64-apple-darwin/stage2" "--target=x86_64-apple-darwin" "--check-cfg" "cfg(test,FALSE)" "-O" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "-C" "prefer-dynamic" "-o" "/Users/runner/work/rust/rust/build/x86_64-apple-darwin/test/ui/c-variadic/same-program-multiple-abis/a" "-A" "internal_features" "-A" "unused_parens" "-A" "unused_braces" "-Crpath" "-Cdebuginfo=0" "-Lnative=/Users/runner/work/rust/rust/build/x86_64-apple-darwin/native/rust-test-helpers"
stdout: none
--- stderr -------------------------------
error: linking with `cc` failed: exit status: 1
   |
   = note:  "cc" "/var/folders/vk/nx37ffx50hv5djclhltc26vw0000gn/T/rustcOb3uu5/symbols.o" "<1 object files omitted>" "<sysroot>/lib/rustlib/x86_64-apple-darwin/lib/libstd-9498668422812724.dylib" "<sysroot>/lib/rustlib/x86_64-apple-darwin/lib/libcompiler_builtins-*.rlib" "-lSystem" "-lc" "-lm" "-arch" "x86_64" "-mmacosx-version-min=10.12.0" "-L" "/Users/runner/work/rust/rust/build/x86_64-apple-darwin/native/rust-test-helpers" "-o" "/Users/runner/work/rust/rust/build/x86_64-apple-darwin/test/ui/c-variadic/same-program-multiple-abis/a" "-Wl,-dead_strip" "-nodefaultlibs" "-Wl,-rpath,@loader_path/../../../../stage2/lib/rustlib/x86_64-apple-darwin/lib"
   = note: some arguments are omitted. use `--verbose` to show all linker arguments
   = note: ld: Undefined symbols:
             _variadic_sysv64, referenced from:
                 same_program_multiple_abis::main::h19382578e34d292b in a.same_program_multiple_abis.180f9a3e337e18ef-cgu.0.rcgu.o
             _variadic_win64, referenced from:
                 same_program_multiple_abis::main::h19382578e34d292b in a.same_program_multiple_abis.180f9a3e337e18ef-cgu.0.rcgu.o
           clang: error: linker command failed with exit code 1 (use -v to see **invocation)**

@bors r-

@bors bors 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-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jul 26, 2025
@folkertdev folkertdev force-pushed the c-variadic-same-program-multiple-abis branch from 963cd8a to 69ebf70 Compare July 26, 2025 10:30
@folkertdev
Copy link
Contributor Author

folkertdev commented Jul 26, 2025

Of course it's macos symbol mangling

Usually the way to resolve this sort of problem is to use a naked function, but those can't yet use ... with non-default ABIs. Casting function pointers is also just kind of fraught, so instead we're using a cool trick where the extern block defines the symbol, and the assembly uses that via a sym operand.

@bors2 try

rust-bors bot added a commit that referenced this pull request Jul 26, 2025
…bis, r=<try>

test using multiple c-variadic ABIs in the same program

try-job: `x86_64-gnu`
try-job: `x86_64-msvc-*`
try-job: `x86_64-apple-2`
@rust-bors
Copy link

rust-bors bot commented Jul 26, 2025

⌛ Trying commit 69ebf70 with merge a6a0deb

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

@rust-bors
Copy link

rust-bors bot commented Jul 26, 2025

☀️ Try build successful (CI)
Build commit: a6a0deb (a6a0deb8c7c83d00e666502bb897f5b3fdb65b4b, parent: 051d0e8a957c98f87ddaf6295c3a3ecd88742ff9)

@folkertdev
Copy link
Contributor Author

@bors r=RalfJung

@bors
Copy link
Collaborator

bors commented Jul 26, 2025

📌 Commit 69ebf70 has been approved by RalfJung

It is now in the queue for this repository.

@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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jul 26, 2025
jhpratt added a commit to jhpratt/rust that referenced this pull request Jul 26, 2025
…-multiple-abis, r=RalfJung

test using multiple c-variadic ABIs in the same program

tracking issue: rust-lang#100189

Check that multiple c-variadic calling conventions can be used in the same program.

Clang and gcc reject defining functions with a non-default calling convention and a variable
argument list, so C programs that use multiple c-variadic calling conventions are unlikely
to come up. Here we validate that our codegen backends do in fact generate correct code.

(CI will not run this test because it runs on aarch64, I would like to at least test that this runs on windows)

try-job: `x86_64-gnu`
try-job: `x86_64-msvc-*`
try-job: `x86_64-apple-2`
bors added a commit that referenced this pull request Jul 27, 2025
Rollup of 13 pull requests

Successful merges:

 - #144359 (add codegen test for variadics)
 - #144379 (test using multiple c-variadic ABIs in the same program)
 - #144383 (disable cfg.has_reliable_f128 on amdgcn)
 - #144409 (Stop compilation early if macro expansion failed)
 - #144422 (library/windows_targets: Fix macro expansion error in 'link' macro)
 - #144429 (Enable outline-atomics for aarch64-unknown-linux-musl)
 - #144430 (tests: aarch64-outline-atomics: Remove hardcoded target)
 - #144445 (Fix `./x check bootstrap` (again))
 - #144453 (canonicalize build root in `tests/run-make/linker-warning`)
 - #144464 (Only run bootstrap tests in `x test` on CI)
 - #144470 (clif: Don't set the `compiler-builtins-no-f16-f128` feature)
 - #144480 (Revert "coverage: Enlarge empty spans during MIR instrumentation, not codegen")
 - #144495 (bump cargo_metadata)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit that referenced this pull request Jul 27, 2025
Rollup of 13 pull requests

Successful merges:

 - #141840 (If `HOME` is empty, use the fallback instead)
 - #144359 (add codegen test for variadics)
 - #144379 (test using multiple c-variadic ABIs in the same program)
 - #144383 (disable cfg.has_reliable_f128 on amdgcn)
 - #144409 (Stop compilation early if macro expansion failed)
 - #144422 (library/windows_targets: Fix macro expansion error in 'link' macro)
 - #144429 (Enable outline-atomics for aarch64-unknown-linux-musl)
 - #144430 (tests: aarch64-outline-atomics: Remove hardcoded target)
 - #144445 (Fix `./x check bootstrap` (again))
 - #144453 (canonicalize build root in `tests/run-make/linker-warning`)
 - #144464 (Only run bootstrap tests in `x test` on CI)
 - #144470 (clif: Don't set the `compiler-builtins-no-f16-f128` feature)
 - #144480 (Revert "coverage: Enlarge empty spans during MIR instrumentation, not codegen")

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit c96c802 into rust-lang:master Jul 27, 2025
11 checks passed
@rustbot rustbot added this to the 1.90.0 milestone Jul 27, 2025
rust-timer added a commit that referenced this pull request Jul 27, 2025
Rollup merge of #144379 - folkertdev:c-variadic-same-program-multiple-abis, r=RalfJung

test using multiple c-variadic ABIs in the same program

tracking issue: #100189

Check that multiple c-variadic calling conventions can be used in the same program.

Clang and gcc reject defining functions with a non-default calling convention and a variable
argument list, so C programs that use multiple c-variadic calling conventions are unlikely
to come up. Here we validate that our codegen backends do in fact generate correct code.

(CI will not run this test because it runs on aarch64, I would like to at least test that this runs on windows)

try-job: `x86_64-gnu`
try-job: `x86_64-msvc-*`
try-job: `x86_64-apple-2`
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. 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.

7 participants