-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
test #[naked] with #[link_section = "..."] on windows
#154598
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -141,8 +141,14 @@ fn prefix_and_suffix<'tcx>( | |
| let attrs = tcx.codegen_instance_attrs(instance.def); | ||
| let link_section = attrs.link_section.map(|symbol| symbol.as_str().to_string()); | ||
|
|
||
| // If no alignment is specified, an alignment of 4 bytes is used. | ||
| let align_bytes = attrs.alignment.map(|a| a.bytes()).unwrap_or(4); | ||
| // Pick a default alignment when the alignment is not explicitly specified. | ||
| let align_bytes = match attrs.alignment { | ||
| Some(align) => align.bytes(), | ||
| None => match asm_binary_format { | ||
| BinaryFormat::Coff => 16, | ||
| _ => 4, | ||
| }, | ||
| }; | ||
|
|
||
| // In particular, `.arm` can also be written `.code 32` and `.thumb` as `.code 16`. | ||
| let (arch_prefix, arch_suffix) = if is_arm { | ||
|
|
@@ -267,19 +273,18 @@ fn prefix_and_suffix<'tcx>( | |
| } | ||
| } | ||
| BinaryFormat::Coff => { | ||
| let section = link_section.unwrap_or_else(|| format!(".text.{asm_name}")); | ||
| writeln!(begin, ".pushsection {},\"xr\"", section).unwrap(); | ||
| writeln!(begin, ".balign {align_bytes}").unwrap(); | ||
| write_linkage(&mut begin).unwrap(); | ||
| writeln!(begin, ".def {asm_name}").unwrap(); | ||
| writeln!(begin, ".scl 2").unwrap(); | ||
| writeln!(begin, ".type 32").unwrap(); | ||
| writeln!(begin, ".endef").unwrap(); | ||
|
|
||
| let section = link_section.unwrap_or_else(|| format!(".text.{asm_name}")); | ||
| writeln!(begin, ".pushsection {},\"xr\"", section).unwrap(); | ||
| write_linkage(&mut begin).unwrap(); | ||
| writeln!(begin, ".balign {align_bytes}").unwrap(); | ||
|
Comment on lines
-270
to
+284
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This just got moved up so that |
||
| writeln!(begin, "{asm_name}:").unwrap(); | ||
|
|
||
| writeln!(end).unwrap(); | ||
| writeln!(end, ".Lfunc_end_{asm_name}:").unwrap(); | ||
| writeln!(end, ".popsection").unwrap(); | ||
|
Comment on lines
-281
to
-282
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. LLVM does not emit these, so then we should not need to either |
||
| if !arch_suffix.is_empty() { | ||
| writeln!(end, "{}", arch_suffix).unwrap(); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| //@ revisions: windows-x86-gnu windows-x86-msvc | ||
| //@ add-minicore | ||
| //@ assembly-output: emit-asm | ||
| // | ||
| //@[windows-x86-gnu] compile-flags: --target x86_64-pc-windows-gnu | ||
| //@[windows-x86-gnu] needs-llvm-components: x86 | ||
| // | ||
| //@[windows-x86-msvc] compile-flags: --target x86_64-pc-windows-msvc | ||
| //@[windows-x86-msvc] needs-llvm-components: x86 | ||
|
|
||
| #![crate_type = "lib"] | ||
| #![feature(no_core)] | ||
| #![no_core] | ||
|
|
||
| // Tests that naked and non-naked functions emit the same directives when the function uses | ||
| // `#[link_section = "..."]`. | ||
|
|
||
| extern crate minicore; | ||
| use minicore::*; | ||
|
|
||
| #[unsafe(naked)] | ||
| #[unsafe(no_mangle)] | ||
| #[unsafe(link_section = "naked")] | ||
| extern "C" fn naked_ret() { | ||
| // CHECK: .def naked_ret; | ||
| // CHECK-NEXT: .scl 2; | ||
| // CHECK-NEXT: .type 32; | ||
| // CHECK-NEXT: .endef | ||
| // CHECK-NEXT: .section naked,"xr" | ||
| // CHECK-NEXT: .globl naked_ret | ||
| // CHECK-NEXT: .p2align 4 | ||
| // CHECK-NEXT: naked_ret: | ||
| // CHECK-NEXT: retq | ||
| naked_asm!("ret") | ||
| } | ||
|
|
||
| #[unsafe(no_mangle)] | ||
| #[unsafe(link_section = "regular")] | ||
| extern "C" fn regular_ret() { | ||
| // CHECK: .def regular_ret; | ||
| // CHECK-NEXT: .scl 2; | ||
| // CHECK-NEXT: .type 32; | ||
| // CHECK-NEXT: .endef | ||
| // CHECK-NEXT: .section regular,"xr" | ||
| // CHECK-NEXT: .globl regular_ret | ||
| // CHECK-NEXT: .p2align 4 | ||
| // CHECK-NEXT: regular_ret: | ||
| // CHECK-NEXT: retq | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,13 +23,11 @@ use minicore::*; | |
| // | ||
| // linux: .pushsection .text.naked_empty,\22ax\22, @progbits | ||
| // macos: .pushsection __TEXT,__text,regular,pure_instructions | ||
| // win_x86: .pushsection .text.naked_empty,\22xr\22 | ||
| // win_i686: .pushsection .text._naked_empty,\22xr\22 | ||
| // thumb: .pushsection .text.naked_empty,\22ax\22, %progbits | ||
| // | ||
| // CHECK: .balign 4 | ||
| // linux, macos, thumb: .balign 4 | ||
| // | ||
| // linux,win,thumb: .globl naked_empty | ||
| // linux,thumb: .globl naked_empty | ||
| // macos: .globl _naked_empty | ||
| // | ||
| // CHECK-NOT: .private_extern | ||
|
|
@@ -44,16 +42,24 @@ use minicore::*; | |
| // win_x86,win_i686: .type 32 | ||
| // win_x86,win_i686: .endef | ||
| // | ||
| // win_x86: .pushsection .text.naked_empty,\22xr\22 | ||
| // win_i686: .pushsection .text._naked_empty,\22xr\22 | ||
| // | ||
| // win_x86: .globl naked_empty | ||
| // win_i686: .globl _naked_empty | ||
| // | ||
| // win_x86,win_i686: .balign 16 | ||
| // | ||
| // thumb: .type naked_empty, %function | ||
| // thumb: .thumb | ||
| // thumb: .thumb_func | ||
| // | ||
| // CHECK-LABEL: naked_empty: | ||
| // | ||
| // linux,macos,win: ret | ||
| // linux,macos,win_x86,win_x86: ret | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You probably meant i686 and x86 here. |
||
| // thumb: bx lr | ||
| // | ||
| // CHECK: .popsection | ||
| // linux,macos,thumb: .popsection | ||
| // | ||
| // thumb: .thumb | ||
| // | ||
|
|
@@ -76,13 +82,11 @@ pub extern "C" fn naked_empty() { | |
| // | ||
| // linux: .pushsection .text.naked_with_args_and_return,\22ax\22, @progbits | ||
| // macos: .pushsection __TEXT,__text,regular,pure_instructions | ||
| // win_x86: .pushsection .text.naked_with_args_and_return,\22xr\22 | ||
| // win_i686: .pushsection .text._naked_with_args_and_return,\22xr\22 | ||
| // thumb: .pushsection .text.naked_with_args_and_return,\22ax\22, %progbits | ||
| // | ||
| // CHECK: .balign 4 | ||
| // linux, macos, thumb: .balign 4 | ||
| // | ||
| // linux,win,thumb: .globl naked_with_args_and_return | ||
| // linux,thumb: .globl naked_with_args_and_return | ||
| // macos: .globl _naked_with_args_and_return | ||
| // | ||
| // CHECK-NOT: .private_extern | ||
|
|
@@ -97,6 +101,14 @@ pub extern "C" fn naked_empty() { | |
| // win_x86,win_i686: .type 32 | ||
| // win_x86,win_i686: .endef | ||
| // | ||
| // win_x86: .pushsection .text.naked_with_args_and_return,\22xr\22 | ||
| // win_i686: .pushsection .text._naked_with_args_and_return,\22xr\22 | ||
| // | ||
| // win_x86: .globl naked_with_args_and_return | ||
| // win_i686: .globl _naked_with_args_and_return | ||
| // | ||
| // win_x86,win_i686: .balign 16 | ||
| // | ||
| // thumb: .type naked_with_args_and_return, %function | ||
| // thumb: .thumb | ||
| // thumb: .thumb_func | ||
|
|
@@ -110,7 +122,7 @@ pub extern "C" fn naked_empty() { | |
| // linux,macos,win: ret | ||
| // thumb: bx lr | ||
| // | ||
| // CHECK: .popsection | ||
| // linux,macos,thumb: .popsection | ||
| // | ||
| // thumb: .thumb | ||
| // | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this really matters but we may as well match LLVM