Skip to content

Commit d6092d0

Browse files
committed
Auto merge of rust-lang#128785 - matthiaskrgr:rollup-13chr4m, r=matthiaskrgr
Rollup of 5 pull requests Successful merges: - rust-lang#128384 (Add tests to ensure MTE tags are preserved across FFI boundaries) - rust-lang#128407 (Migrate `min-global-align` and `no-alloc-shim` `run-make` tests to rmake) - rust-lang#128584 (Add a set of tests for LLVM 19) - rust-lang#128636 (migrate `thumb-none-cortex-m` to rmake) - rust-lang#128696 (Migrate `staticlib-dylib-linkage` `run-make` test to rmake) Failed merges: - rust-lang#128639 (migrate `thumb-none-qemu` to rmake) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 8d00669 + acef3a1 commit d6092d0

File tree

25 files changed

+583
-110
lines changed

25 files changed

+583
-110
lines changed

src/tools/compiletest/src/command-list.rs

+1
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ const KNOWN_DIRECTIVE_NAMES: &[&str] = &[
170170
"only-32bit",
171171
"only-64bit",
172172
"only-aarch64",
173+
"only-aarch64-unknown-linux-gnu",
173174
"only-apple",
174175
"only-arm",
175176
"only-avr",

src/tools/run-make-support/src/assertion_helpers.rs

+14
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,20 @@ pub fn assert_not_contains_regex<H: AsRef<str>, N: AsRef<str>>(haystack: H, need
7777
}
7878
}
7979

80+
/// Assert that `haystack` contains `needle` a `count` number of times.
81+
#[track_caller]
82+
pub fn assert_count_is<H: AsRef<str>, N: AsRef<str>>(count: usize, haystack: H, needle: N) {
83+
let haystack = haystack.as_ref();
84+
let needle = needle.as_ref();
85+
if count != haystack.matches(needle).count() {
86+
eprintln!("=== HAYSTACK ===");
87+
eprintln!("{}", haystack);
88+
eprintln!("=== NEEDLE ===");
89+
eprintln!("{}", needle);
90+
panic!("needle did not appear {count} times in haystack");
91+
}
92+
}
93+
8094
/// Assert that all files in `dir1` exist and have the same content in `dir2`
8195
pub fn assert_dirs_are_equal(dir1: impl AsRef<Path>, dir2: impl AsRef<Path>) {
8296
let dir2 = dir2.as_ref();

src/tools/run-make-support/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ pub use path_helpers::{
8686
pub use scoped_run::{run_in_tmpdir, test_while_readonly};
8787

8888
pub use assertion_helpers::{
89-
assert_contains, assert_contains_regex, assert_dirs_are_equal, assert_equals,
89+
assert_contains, assert_contains_regex, assert_count_is, assert_dirs_are_equal, assert_equals,
9090
assert_not_contains, assert_not_contains_regex,
9191
};
9292

src/tools/tidy/src/allowed_run_make_makefiles.txt

-4
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,15 @@ run-make/libtest-json/Makefile
1313
run-make/libtest-junit/Makefile
1414
run-make/libtest-thread-limit/Makefile
1515
run-make/macos-deployment-target/Makefile
16-
run-make/min-global-align/Makefile
1716
run-make/native-link-modifier-bundle/Makefile
18-
run-make/no-alloc-shim/Makefile
1917
run-make/pdb-buildinfo-cl-cmd/Makefile
2018
run-make/pgo-indirect-call-promotion/Makefile
2119
run-make/remap-path-prefix-dwarf/Makefile
2220
run-make/reproducible-build/Makefile
2321
run-make/rlib-format-packed-bundled-libs/Makefile
2422
run-make/split-debuginfo/Makefile
25-
run-make/staticlib-dylib-linkage/Makefile
2623
run-make/symbol-mangling-hashed/Makefile
2724
run-make/sysroot-crates-are-unstable/Makefile
28-
run-make/thumb-none-cortex-m/Makefile
2925
run-make/thumb-none-qemu/Makefile
3026
run-make/translation/Makefile
3127
run-make/x86_64-fortanix-unknown-sgx-lvi/Makefile
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//@ compile-flags: -O
2+
//@ min-llvm-version: 19
3+
4+
// Test for #107681.
5+
// Make sure we don't create `br` or `select` instructions.
6+
7+
#![crate_type = "lib"]
8+
9+
use std::iter::Copied;
10+
use std::slice::Iter;
11+
12+
#[no_mangle]
13+
pub unsafe fn foo(x: &mut Copied<Iter<'_, u32>>) -> u32 {
14+
// CHECK-LABEL: @foo(
15+
// CHECK-NOT: br
16+
// CHECK-NOT: select
17+
// CHECK: [[RET:%.*]] = load i32, ptr
18+
// CHECK-NEXT: ret i32 [[RET]]
19+
x.next().unwrap_unchecked()
20+
}

tests/codegen/issues/issue-118306.rs

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//@ compile-flags: -O -Zno-jump-tables
2+
//@ min-llvm-version: 19
3+
4+
// Test for #118306.
5+
// Ensure that the default branch is optimized to be unreachable.
6+
7+
#![crate_type = "lib"]
8+
9+
#[no_mangle]
10+
pub fn foo(input: u64) -> u64 {
11+
// CHECK-LABEL: @foo(
12+
// CHECK: switch {{.*}}, label %[[UNREACHABLE:.*]] [
13+
// CHECK: [[UNREACHABLE]]:
14+
// CHECK-NEXT: unreachable
15+
match input % 4 {
16+
1 | 2 => 1,
17+
3 => 2,
18+
_ => 0,
19+
}
20+
}

tests/codegen/issues/issue-126585.rs

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//@ compile-flags: -Copt-level=s
2+
//@ min-llvm-version: 19
3+
4+
// Test for #126585.
5+
// Ensure that this IR doesn't have extra undef phi input, which also guarantees that this asm
6+
// doesn't have subsequent labels and unnecessary `jmp` instructions.
7+
8+
#![crate_type = "lib"]
9+
10+
#[no_mangle]
11+
fn checked_div_round(a: u64, b: u64) -> Option<u64> {
12+
// CHECK-LABEL: @checked_div_round
13+
// CHECK: phi
14+
// CHECK-NOT: undef
15+
// CHECK: phi
16+
// CHECK-NOT: undef
17+
match b {
18+
0 => None,
19+
1 => Some(a),
20+
// `a / b` is computable and `(a % b) * 2` can not overflow since `b >= 2`.
21+
b => Some(a / b + if (a % b) * 2 >= b { 1 } else { 0 }),
22+
}
23+
}

tests/run-make/min-global-align/Makefile

-22
This file was deleted.
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// This test checks that global variables respect the target minimum alignment.
2+
// The three bools `STATIC_BOOL`, `STATIC_MUT_BOOL`, and `CONST_BOOL` all have
3+
// type-alignment of 1, but some targets require greater global alignment.
4+
// See https://github.com/rust-lang/rust/pull/44440
5+
6+
//@ only-linux
7+
// Reason: this test is target-independent, considering compilation is targeted
8+
// towards linux architectures only.
9+
10+
use run_make_support::{assert_count_is, llvm_components_contain, rfs, rustc};
11+
12+
fn main() {
13+
// Most targets are happy with default alignment -- take i686 for example.
14+
if llvm_components_contain("x86") {
15+
rustc().target("i686-unknown-linux-gnu").emit("llvm-ir").input("min_global_align.rs").run();
16+
assert_count_is(3, rfs::read_to_string("min_global_align.ll"), "align 1");
17+
}
18+
// SystemZ requires even alignment for PC-relative addressing.
19+
if llvm_components_contain("systemz") {
20+
rustc()
21+
.target("s390x-unknown-linux-gnu")
22+
.emit("llvm-ir")
23+
.input("min_global_align.rs")
24+
.run();
25+
assert_count_is(3, rfs::read_to_string("min_global_align.ll"), "align 2");
26+
}
27+
}

tests/run-make/mte-ffi/bar.h

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#ifndef __BAR_H
2+
#define __BAR_H
3+
4+
#include <sys/mman.h>
5+
#include <sys/auxv.h>
6+
#include <sys/prctl.h>
7+
#include <unistd.h>
8+
#include <stdio.h>
9+
10+
// Set the allocation tag on the destination address using the STG instruction.
11+
#define set_tag(tagged_addr) do { \
12+
asm volatile("stg %0, [%0]" : : "r" (tagged_addr) : "memory"); \
13+
} while (0)
14+
15+
int mte_enabled() {
16+
return (getauxval(AT_HWCAP2)) & HWCAP2_MTE;
17+
}
18+
19+
void *alloc_page() {
20+
// Enable MTE with synchronous checking
21+
if (prctl(PR_SET_TAGGED_ADDR_CTRL,
22+
PR_TAGGED_ADDR_ENABLE | PR_MTE_TCF_SYNC | (0xfffe << PR_MTE_TAG_SHIFT),
23+
0, 0, 0))
24+
{
25+
perror("prctl() failed");
26+
}
27+
28+
// Using `mmap` allows us to ensure that, on systems which support MTE, the allocated
29+
// memory is 16-byte aligned for MTE.
30+
// This also allows us to explicitly specify whether the region should be protected by
31+
// MTE or not.
32+
if (mte_enabled()) {
33+
void *ptr = mmap(NULL, sysconf(_SC_PAGESIZE),
34+
PROT_READ | PROT_WRITE | PROT_MTE, MAP_PRIVATE | MAP_ANONYMOUS,
35+
-1, 0);
36+
} else {
37+
void *ptr = mmap(NULL, sysconf(_SC_PAGESIZE),
38+
PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS,
39+
-1, 0);
40+
}
41+
}
42+
43+
#endif // __BAR_H

tests/run-make/mte-ffi/bar_float.c

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
#include <stdint.h>
4+
#include "bar.h"
5+
6+
extern void foo(char*);
7+
8+
void bar(char *ptr) {
9+
if (((uintptr_t)ptr >> 56) != 0x1f) {
10+
fprintf(stderr, "Top byte corrupted on Rust -> C FFI boundary!\n");
11+
exit(1);
12+
}
13+
}
14+
15+
int main(void)
16+
{
17+
float *ptr = alloc_page();
18+
if (ptr == MAP_FAILED)
19+
{
20+
perror("mmap() failed");
21+
return EXIT_FAILURE;
22+
}
23+
24+
// Store an arbitrary tag in bits 56-59 of the pointer (where an MTE tag may be),
25+
// and a different value in the ignored top 4 bits.
26+
ptr = (float *)((uintptr_t)ptr | 0x1fl << 56);
27+
28+
if (mte_enabled()) {
29+
set_tag(ptr);
30+
}
31+
32+
ptr[0] = 2.0f;
33+
ptr[1] = 1.5f;
34+
35+
foo(ptr); // should change the contents of the page and call `bar`
36+
37+
if (ptr[0] != 0.5f || ptr[1] != 0.2f) {
38+
fprintf(stderr, "invalid data in memory; expected '0.5 0.2', got '%f %f'\n",
39+
ptr[0], ptr[1]);
40+
return EXIT_FAILURE;
41+
}
42+
43+
return 0;
44+
}

tests/run-make/mte-ffi/bar_function.c

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
#include <stdint.h>
4+
#include "bar.h"
5+
6+
typedef void (*fp)(int (*)());
7+
8+
extern void foo(fp);
9+
10+
void bar(int (*ptr)()) {
11+
if (((uintptr_t)ptr >> 56) != 0x2f) {
12+
fprintf(stderr, "Top byte corrupted on Rust -> C FFI boundary!\n");
13+
exit(1);
14+
}
15+
16+
int r = (*ptr)();
17+
if (r != 32) {
18+
fprintf(stderr, "invalid return value; expected 32, got '%d'\n", r);
19+
exit(1);
20+
}
21+
}
22+
23+
int main(void)
24+
{
25+
fp ptr = alloc_page();
26+
if (ptr == MAP_FAILED)
27+
{
28+
perror("mmap() failed");
29+
return EXIT_FAILURE;
30+
}
31+
32+
// Store an arbitrary tag in bits 56-59 of the pointer (where an MTE tag may be),
33+
// and a different value in the ignored top 4 bits.
34+
ptr = (fp)((uintptr_t)&bar | 0x1fl << 56);
35+
36+
foo(ptr);
37+
38+
return 0;
39+
}

tests/run-make/mte-ffi/bar_int.c

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
#include <stdint.h>
4+
#include "bar.h"
5+
6+
extern void foo(unsigned int *);
7+
8+
void bar(char *ptr) {
9+
if (((uintptr_t)ptr >> 56) != 0x1f) {
10+
fprintf(stderr, "Top byte corrupted on Rust -> C FFI boundary!\n");
11+
exit(1);
12+
}
13+
}
14+
15+
int main(void)
16+
{
17+
// Construct a pointer with an arbitrary tag in bits 56-59, simulating an MTE tag.
18+
// It's only necessary that the tag is preserved across FFI bounds for this test.
19+
unsigned int *ptr;
20+
21+
ptr = alloc_page();
22+
if (ptr == MAP_FAILED)
23+
{
24+
perror("mmap() failed");
25+
return EXIT_FAILURE;
26+
}
27+
28+
// Store an arbitrary tag in bits 56-59 of the pointer (where an MTE tag may be),
29+
// and a different value in the ignored top 4 bits.
30+
ptr = (unsigned int *)((uintptr_t)ptr | 0x1fl << 56);
31+
32+
if (mte_enabled()) {
33+
set_tag(ptr);
34+
}
35+
36+
ptr[0] = 61;
37+
ptr[1] = 62;
38+
39+
foo(ptr); // should change the contents of the page to start with 0x63 0x64 and call `bar`
40+
41+
if (ptr[0] != 0x63 || ptr[1] != 0x64) {
42+
fprintf(stderr, "invalid data in memory; expected '63 64', got '%d %d'\n", ptr[0], ptr[1]);
43+
return EXIT_FAILURE;
44+
}
45+
46+
return 0;
47+
}

0 commit comments

Comments
 (0)