|
| 1 | +//@ add-minicore |
| 2 | +//@ assembly-output: emit-asm |
| 3 | +// |
| 4 | +//@ revisions: linux-x86-gnu-fs-true linux-x86-gnu-fs-false |
| 5 | +//@[linux-x86-gnu-fs-true] compile-flags: --target x86_64-unknown-linux-gnu -Zfunction-sections=true |
| 6 | +//@[linux-x86-gnu-fs-true] needs-llvm-components: x86 |
| 7 | +//@[linux-x86-gnu-fs-false] compile-flags: --target x86_64-unknown-linux-gnu -Zfunction-sections=false |
| 8 | +//@[linux-x86-gnu-fs-false] needs-llvm-components: x86 |
| 9 | +// |
| 10 | +//@ revisions: macos-aarch64-fs-true macos-aarch64-fs-false |
| 11 | +//@[macos-aarch64-fs-true] compile-flags: --target aarch64-apple-darwin -Zfunction-sections=true |
| 12 | +//@[macos-aarch64-fs-true] needs-llvm-components: aarch64 |
| 13 | +//@[macos-aarch64-fs-false] compile-flags: --target aarch64-apple-darwin -Zfunction-sections=false |
| 14 | +//@[macos-aarch64-fs-false] needs-llvm-components: aarch64 |
| 15 | +// |
| 16 | +//@ revisions: windows-x86-gnu-fs-true windows-x86-gnu-fs-false |
| 17 | +//@[windows-x86-gnu-fs-true] compile-flags: --target x86_64-pc-windows-gnu -Zfunction-sections=true |
| 18 | +//@[windows-x86-gnu-fs-true] needs-llvm-components: x86 |
| 19 | +//@[windows-x86-gnu-fs-false] compile-flags: --target x86_64-pc-windows-gnu -Zfunction-sections=false |
| 20 | +//@[windows-x86-gnu-fs-false] needs-llvm-components: x86 |
| 21 | +// |
| 22 | +//@ revisions: windows-x86-msvc-fs-true windows-x86-msvc-fs-false |
| 23 | +//@[windows-x86-msvc-fs-true] compile-flags: --target x86_64-pc-windows-msvc -Zfunction-sections=true |
| 24 | +//@[windows-x86-msvc-fs-true] needs-llvm-components: x86 |
| 25 | +//@[windows-x86-msvc-fs-false] compile-flags: --target x86_64-pc-windows-msvc -Zfunction-sections=false |
| 26 | +//@[windows-x86-msvc-fs-false] needs-llvm-components: x86 |
| 27 | +// |
| 28 | +//@ revisions: x86-uefi-fs-true x86-uefi-fs-false |
| 29 | +//@[x86-uefi-fs-true] compile-flags: --target x86_64-unknown-uefi -Zfunction-sections=true |
| 30 | +//@[x86-uefi-fs-true] needs-llvm-components: x86 |
| 31 | +//@[x86-uefi-fs-false] compile-flags: --target x86_64-unknown-uefi -Zfunction-sections=false |
| 32 | +//@[x86-uefi-fs-false] needs-llvm-components: x86 |
| 33 | + |
| 34 | +#![crate_type = "lib"] |
| 35 | +#![feature(no_core)] |
| 36 | +#![no_core] |
| 37 | + |
| 38 | +// Tests that naked and non-naked functions emit the same directives when (not) using |
| 39 | +// -Zfunction-sections. This setting is ignored on macos, off by default on windows gnu, |
| 40 | +// and on by default in the remaining revisions tested here. |
| 41 | + |
| 42 | +extern crate minicore; |
| 43 | +use minicore::*; |
| 44 | + |
| 45 | +#[unsafe(naked)] |
| 46 | +#[unsafe(no_mangle)] |
| 47 | +extern "C" fn naked_ret() { |
| 48 | + // linux-x86-gnu-fs-true: .section .text.naked_ret,"ax",@progbits |
| 49 | + // linux-x86-gnu-fs-false: .text |
| 50 | + // |
| 51 | + // macos-aarch64-fs-true: .section __TEXT,__text,regular,pure_instructions |
| 52 | + // macos-aarch64-fs-false: .section __TEXT,__text,regular,pure_instructions |
| 53 | + // |
| 54 | + // NOTE: the regular function below adds `unique,0` at the end, but we have no way of generating |
| 55 | + // the unique ID to use there, so don't emit that part. |
| 56 | + // |
| 57 | + // windows-x86-gnu-fs-true: .section .text$naked_ret,"xr",one_only,naked_ret |
| 58 | + // windows-x86-msvc-fs-true: .section .text,"xr",one_only,naked_ret |
| 59 | + // x86-uefi-fs-true: .section .text,"xr",one_only,naked_ret |
| 60 | + // |
| 61 | + // windows-x86-gnu-fs-false: .text |
| 62 | + // windows-x86-msvc-fs-false: .text |
| 63 | + // x86-uefi-fs-false: .text |
| 64 | + // |
| 65 | + // CHECK-LABEL: naked_ret: |
| 66 | + naked_asm!("ret") |
| 67 | +} |
| 68 | + |
| 69 | +// Use a different section here so that `regular_ret` has to explicitly specify the section. |
| 70 | +#[link_section = cfg_select!( |
| 71 | + target_os = "macos" => "__FOO,bar", |
| 72 | + _ => ".bar", |
| 73 | +)] |
| 74 | +#[unsafe(no_mangle)] |
| 75 | +extern "C" fn omarker() -> i32 { |
| 76 | + // CHECK-LABEL: omarker: |
| 77 | + 32 |
| 78 | +} |
| 79 | + |
| 80 | +#[unsafe(no_mangle)] |
| 81 | +extern "C" fn regular_ret() { |
| 82 | + // linux-x86-gnu-fs-true: .section .text.regular_ret,"ax",@progbits |
| 83 | + // linux-x86-gnu-fs-false: .text |
| 84 | + // |
| 85 | + // macos-aarch64-fs-true: .section __TEXT,__text,regular,pure_instructions |
| 86 | + // macos-aarch64-fs-false: .section __TEXT,__text,regular,pure_instructions |
| 87 | + // |
| 88 | + // windows-x86-gnu-fs-true: .section .text$regular_ret,"xr",one_only,regular_ret,unique,0 |
| 89 | + // windows-x86-msvc-fs-true: .section .text,"xr",one_only,regular_ret,unique,0 |
| 90 | + // x86-uefi-fs-true: .section .text,"xr",one_only,regular_ret,unique,0 |
| 91 | + // |
| 92 | + // windows-x86-gnu-fs-false: .text |
| 93 | + // windows-x86-msvc-fs-false: .text |
| 94 | + // x86-uefi-fs-false: .text |
| 95 | + // |
| 96 | + // CHECK-LABEL: regular_ret: |
| 97 | +} |
0 commit comments