-
-
Notifications
You must be signed in to change notification settings - Fork 14.6k
add tests for thumb interworking #153153
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
+183
−0
Merged
add tests for thumb interworking #153153
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ENTRY(entry); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| #![feature(no_core)] | ||
| #![no_core] | ||
| #![no_main] | ||
|
|
||
| extern crate minicore; | ||
| use minicore::*; | ||
|
|
||
| #[unsafe(no_mangle)] | ||
| fn entry() { | ||
| arm(); | ||
| thumb(); | ||
| } | ||
|
|
||
| #[unsafe(no_mangle)] | ||
| pub fn arm() { | ||
| // thumbv5te-LABEL: <arm>: | ||
| // thumbv5te: blx {{0x[0-9a-f]+}} <main::arm_normalfn> | ||
| // thumbv5te: blx {{0x[0-9a-f]+}} <arm_globalfn> | ||
| // thumbv5te: blx {{0x[0-9a-f]+}} <main::arm_nakedfn> | ||
|
|
||
| // thumbv4t-LABEL: <arm>: | ||
| // thumbv4t: bl {{0x[0-9a-f]+}} <__Thumbv4ABSLongBXThunk__{{.*}}arm_normalfn> | ||
| // thumbv4t: bl {{0x[0-9a-f]+}} <__Thumbv4ABSLongBXThunk_arm_globalfn> | ||
| // thumbv4t: bl {{0x[0-9a-f]+}} <__Thumbv4ABSLongBXThunk__{{.*}}arm_nakedfn> | ||
|
|
||
| // armv5te-LABEL: <arm>: | ||
| // armv5te: bl {{0x[0-9a-f]+}} <main::arm_normalfn> | ||
| // armv5te: bl {{0x[0-9a-f]+}} <arm_globalfn> | ||
| // armv5te: bl {{0x[0-9a-f]+}} <main::arm_nakedfn> | ||
|
|
||
| // armv4t-LABEL: <arm>: | ||
| // armv4t: bl {{0x[0-9a-f]+}} <main::arm_normalfn> | ||
| // armv4t: bl {{0x[0-9a-f]+}} <arm_globalfn> | ||
| // armv4t: bl {{0x[0-9a-f]+}} <main::arm_nakedfn> | ||
| arm_normalfn(); | ||
| arm_globalfn(); | ||
| arm_nakedfn(); | ||
| } | ||
|
|
||
| #[unsafe(no_mangle)] | ||
| pub fn thumb() { | ||
| // thumbv5te-LABEL: <thumb>: | ||
| // thumbv5te: bl {{0x[0-9a-f]+}} <main::thumb_normalfn> | ||
| // thumbv5te: bl {{0x[0-9a-f]+}} <thumb_globalfn> | ||
| // thumbv5te: bl {{0x[0-9a-f]+}} <main::thumb_nakedfn> | ||
|
|
||
| // thumbv4t-LABEL: <thumb>: | ||
| // thumbv4t: bl {{0x[0-9a-f]+}} <main::thumb_normalfn> | ||
| // thumbv4t: bl {{0x[0-9a-f]+}} <thumb_globalfn> | ||
| // thumbv4t: bl {{0x[0-9a-f]+}} <main::thumb_nakedfn> | ||
|
|
||
| // armv5te-LABEL: <thumb>: | ||
| // armv5te: blx {{0x[0-9a-f]+}} <main::thumb_normalfn> | ||
| // armv5te: blx {{0x[0-9a-f]+}} <thumb_globalfn> | ||
| // armv5te: blx {{0x[0-9a-f]+}} <main::thumb_nakedfn> | ||
|
|
||
| // armv4t-LABEL: <thumb>: | ||
| // armv4t: bl {{0x[0-9a-f]+}} <__ARMv4ABSLongBXThunk__{{.*}}thumb_normalfn> | ||
| // armv4t: bl {{0x[0-9a-f]+}} <__ARMv4ABSLongBXThunk_thumb_globalfn> | ||
| // armv4t: bl {{0x[0-9a-f]+}} <__ARMv4ABSLongBXThunk__{{.*}}thumb_nakedfn> | ||
| thumb_normalfn(); | ||
| thumb_globalfn(); | ||
| thumb_nakedfn(); | ||
| } | ||
|
|
||
| #[instruction_set(arm::t32)] | ||
| extern "C" fn thumb_normalfn() { | ||
| unsafe { asm!("nop") } | ||
| } | ||
|
|
||
| unsafe extern "C" { | ||
| safe fn thumb_globalfn(); | ||
| } | ||
|
|
||
| global_asm!( | ||
| r#" | ||
| .thumb | ||
| .global thumb_globalfn | ||
| .type thumb_globalfn, %function | ||
| thumb_globalfn: | ||
| nop | ||
| bx lr | ||
| .size thumb_globalfn, . - thumb_globalfn | ||
| "# | ||
| ); | ||
|
|
||
| #[unsafe(naked)] | ||
| #[instruction_set(arm::t32)] | ||
| extern "C" fn thumb_nakedfn() { | ||
| naked_asm!("nop", "bx lr",); | ||
| } | ||
|
|
||
| #[instruction_set(arm::a32)] | ||
| extern "C" fn arm_normalfn() { | ||
| unsafe { asm!("nop") } | ||
| } | ||
|
|
||
| unsafe extern "C" { | ||
| safe fn arm_globalfn(); | ||
| } | ||
|
|
||
| global_asm!( | ||
| r#" | ||
| .arm | ||
| .global arm_globalfn | ||
| .type arm_globalfn, %function | ||
| arm_globalfn: | ||
| nop | ||
| bx lr | ||
| .size arm_globalfn, . - arm_globalfn | ||
| "# | ||
| ); | ||
|
|
||
| #[unsafe(naked)] | ||
| #[instruction_set(arm::a32)] | ||
| extern "C" fn arm_nakedfn() { | ||
| naked_asm!("nop", "bx lr",); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| //@ needs-llvm-components: arm | ||
| //@ needs-rust-lld | ||
| use run_make_support::{llvm_filecheck, llvm_objdump, path, rfs, run, rustc, source_root}; | ||
|
|
||
| // Test a thumb target calling arm functions. Doing so requires switching from thumb mode to arm | ||
| // mode, calling the arm code, then switching back to thumb mode. Depending on the thumb version, | ||
| // this happens using a special calling instruction, or by calling a generated thunk that performs | ||
| // the mode switching. | ||
| // | ||
| // In particular this tests that naked functions behave like normal functions. Before LLVM 22, a | ||
| // bug in LLVM caused thumb mode to be used unconditonally when symbols were .hidden, miscompiling | ||
| // calls to arm functions. | ||
| // | ||
| // - https://github.com/llvm/llvm-project/pull/181156 | ||
| // - https://github.com/rust-lang/rust/issues/151946 | ||
|
|
||
| fn main() { | ||
| // Thumb calling thumb and arm. | ||
| helper("thumbv5te", "thumbv5te-none-eabi"); | ||
| helper("thumbv4t", "thumbv4t-none-eabi"); | ||
|
|
||
| // Arm calling thumb and arm. | ||
| helper("armv5te", "armv5te-none-eabi"); | ||
| helper("armv4t", "armv4t-none-eabi"); | ||
| } | ||
|
|
||
| fn helper(prefix: &str, target: &str) { | ||
| rustc() | ||
| .input(source_root().join("tests/auxiliary/minicore.rs")) | ||
| .crate_name("minicore") | ||
| .crate_type("rlib") | ||
| .target(target) | ||
| .output("libminicore.rlib") | ||
| .run(); | ||
| let minicore = path("libminicore.rlib"); | ||
|
|
||
| rustc() | ||
| .input("main.rs") | ||
| .panic("abort") | ||
| .link_arg("-Tlink.ld") | ||
| .arg("--extern") | ||
| .arg(format!("minicore={}", minicore.display())) | ||
| .target(target) | ||
| .output(prefix) | ||
| .run(); | ||
|
|
||
| let dump = llvm_objdump().disassemble().demangle().input(path(prefix)).run(); | ||
|
|
||
| eprintln!("{}", str::from_utf8(&dump.stdout()).unwrap()); | ||
|
|
||
| llvm_filecheck().patterns("main.rs").check_prefix(prefix).stdin_buf(dump.stdout()).run(); | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.