Skip to content

Commit 1827ffd

Browse files
authored
Rollup merge of #138346 - folkertdev:naked-asm-windows-endef, r=ChrisDenton
naked functions: on windows emit `.endef` without the symbol name tracking issue: #90957 fixes #138320 The `.endef` directive does not take the name as an argument. Apparently the LLVM x86_64 parser does accept this, but on i686 it's rejected. In general `i686` does some special name mangling stuff, so it's good to include it in the naked function tests. r? ````@ChrisDenton```` (because windows)
2 parents 5ae93cf + c0957ef commit 1827ffd

File tree

2 files changed

+49
-25
lines changed

2 files changed

+49
-25
lines changed

compiler/rustc_codegen_ssa/src/mir/naked_asm.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ fn prefix_and_suffix<'tcx>(
245245
writeln!(begin, ".def {asm_name}").unwrap();
246246
writeln!(begin, ".scl 2").unwrap();
247247
writeln!(begin, ".type 32").unwrap();
248-
writeln!(begin, ".endef {asm_name}").unwrap();
248+
writeln!(begin, ".endef").unwrap();
249249
writeln!(begin, "{asm_name}:").unwrap();
250250

251251
writeln!(end).unwrap();

tests/codegen/naked-fn/naked-functions.rs

+48-24
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
//@ add-core-stubs
2-
//@ revisions: linux win macos thumb
2+
//@ revisions: linux win_x86 win_i686 macos thumb
33
//
44
//@[linux] compile-flags: --target x86_64-unknown-linux-gnu
55
//@[linux] needs-llvm-components: x86
6-
//@[win] compile-flags: --target x86_64-pc-windows-gnu
7-
//@[win] needs-llvm-components: x86
6+
//@[win_x86] compile-flags: --target x86_64-pc-windows-gnu
7+
//@[win_x86] needs-llvm-components: x86
8+
//@[win_i686] compile-flags: --target i686-pc-windows-gnu
9+
//@[win_i686] needs-llvm-components: x86
810
//@[macos] compile-flags: --target aarch64-apple-darwin
911
//@[macos] needs-llvm-components: arm
1012
//@[thumb] compile-flags: --target thumbv7em-none-eabi
@@ -19,10 +21,11 @@ use minicore::*;
1921

2022
// linux,win: .intel_syntax
2123
//
22-
// linux: .pushsection .text.naked_empty,\22ax\22, @progbits
23-
// macos: .pushsection __TEXT,__text,regular,pure_instructions
24-
// win: .pushsection .text.naked_empty,\22xr\22
25-
// thumb: .pushsection .text.naked_empty,\22ax\22, %progbits
24+
// linux: .pushsection .text.naked_empty,\22ax\22, @progbits
25+
// macos: .pushsection __TEXT,__text,regular,pure_instructions
26+
// win_x86: .pushsection .text.naked_empty,\22xr\22
27+
// win_i686: .pushsection .text._naked_empty,\22xr\22
28+
// thumb: .pushsection .text.naked_empty,\22ax\22, %progbits
2629
//
2730
// CHECK: .balign 4
2831
//
@@ -34,10 +37,12 @@ use minicore::*;
3437
//
3538
// linux: .type naked_empty, @function
3639
//
37-
// win: .def naked_empty
38-
// win: .scl 2
39-
// win: .type 32
40-
// win: .endef naked_empty
40+
// win_x86: .def naked_empty
41+
// win_i686: .def _naked_empty
42+
//
43+
// win_x86,win_i686: .scl 2
44+
// win_x86,win_i686: .type 32
45+
// win_x86,win_i686: .endef
4146
//
4247
// thumb: .type naked_empty, %function
4348
// thumb: .thumb
@@ -66,10 +71,11 @@ pub unsafe extern "C" fn naked_empty() {
6671

6772
// linux,win: .intel_syntax
6873
//
69-
// linux: .pushsection .text.naked_with_args_and_return,\22ax\22, @progbits
70-
// macos: .pushsection __TEXT,__text,regular,pure_instructions
71-
// win: .pushsection .text.naked_with_args_and_return,\22xr\22
72-
// thumb: .pushsection .text.naked_with_args_and_return,\22ax\22, %progbits
74+
// linux: .pushsection .text.naked_with_args_and_return,\22ax\22, @progbits
75+
// macos: .pushsection __TEXT,__text,regular,pure_instructions
76+
// win_x86: .pushsection .text.naked_with_args_and_return,\22xr\22
77+
// win_i686: .pushsection .text._naked_with_args_and_return,\22xr\22
78+
// thumb: .pushsection .text.naked_with_args_and_return,\22ax\22, %progbits
7379
//
7480
// CHECK: .balign 4
7581
//
@@ -81,18 +87,20 @@ pub unsafe extern "C" fn naked_empty() {
8187
//
8288
// linux: .type naked_with_args_and_return, @function
8389
//
84-
// win: .def naked_with_args_and_return
85-
// win: .scl 2
86-
// win: .type 32
87-
// win: .endef naked_with_args_and_return
90+
// win_x86: .def naked_with_args_and_return
91+
// win_i686: .def _naked_with_args_and_return
92+
//
93+
// win_x86,win_i686: .scl 2
94+
// win_x86,win_i686: .type 32
95+
// win_x86,win_i686: .endef
8896
//
8997
// thumb: .type naked_with_args_and_return, %function
9098
// thumb: .thumb
9199
// thumb: .thumb_func
92100
//
93101
// CHECK-LABEL: naked_with_args_and_return:
94102
//
95-
// linux, win: lea rax, [rdi + rsi]
103+
// linux, win_x86,win_i686: lea rax, [rdi + rsi]
96104
// macos: add x0, x0, x1
97105
// thumb: adds r0, r0, r1
98106
//
@@ -124,10 +132,10 @@ pub unsafe extern "C" fn naked_with_args_and_return(a: isize, b: isize) -> isize
124132
}
125133
}
126134

127-
// linux: .pushsection .text.some_different_name,\22ax\22, @progbits
128-
// macos: .pushsection .text.some_different_name,regular,pure_instructions
129-
// win: .pushsection .text.some_different_name,\22xr\22
130-
// thumb: .pushsection .text.some_different_name,\22ax\22, %progbits
135+
// linux: .pushsection .text.some_different_name,\22ax\22, @progbits
136+
// macos: .pushsection .text.some_different_name,regular,pure_instructions
137+
// win_x86,win_i686: .pushsection .text.some_different_name,\22xr\22
138+
// thumb: .pushsection .text.some_different_name,\22ax\22, %progbits
131139
// CHECK-LABEL: test_link_section:
132140
#[no_mangle]
133141
#[naked]
@@ -139,3 +147,19 @@ pub unsafe extern "C" fn test_link_section() {
139147
#[cfg(all(target_arch = "arm", target_feature = "thumb-mode"))]
140148
naked_asm!("bx lr");
141149
}
150+
151+
// win_x86: .def fastcall_cc
152+
// win_i686: .def @fastcall_cc@4
153+
//
154+
// win_x86,win_i686: .scl 2
155+
// win_x86,win_i686: .type 32
156+
// win_x86,win_i686: .endef
157+
//
158+
// win_x86-LABEL: fastcall_cc:
159+
// win_i686-LABEL: @fastcall_cc@4:
160+
#[cfg(target_os = "windows")]
161+
#[no_mangle]
162+
#[naked]
163+
pub unsafe extern "fastcall" fn fastcall_cc(x: i32) -> i32 {
164+
naked_asm!("ret");
165+
}

0 commit comments

Comments
 (0)