From b5642b361f4cd4352892c32172b1ed839d46328f Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 31 Mar 2024 10:08:56 +0200 Subject: [PATCH 1/2] extern-so: give the version script a better name; show errors from failing to build the C lib --- .../{libcode.version => libtest.map} | 2 ++ src/tools/miri/tests/ui.rs | 20 +++++++++++-------- 2 files changed, 14 insertions(+), 8 deletions(-) rename src/tools/miri/tests/extern-so/{libcode.version => libtest.map} (72%) diff --git a/src/tools/miri/tests/extern-so/libcode.version b/src/tools/miri/tests/extern-so/libtest.map similarity index 72% rename from src/tools/miri/tests/extern-so/libcode.version rename to src/tools/miri/tests/extern-so/libtest.map index 0f04b9aaebb3..a9887a79a798 100644 --- a/src/tools/miri/tests/extern-so/libcode.version +++ b/src/tools/miri/tests/extern-so/libtest.map @@ -1,9 +1,11 @@ CODEABI_1.0 { + # Define which symbols to export. global: *add_one_int*; *printer*; *test_stack_spill*; *get_unsigned_int*; *add_int16*; *add_short_to_long*; + # The rest remains private. local: *; }; diff --git a/src/tools/miri/tests/ui.rs b/src/tools/miri/tests/ui.rs index a75fa4cf986d..7e8d1401183b 100644 --- a/src/tools/miri/tests/ui.rs +++ b/src/tools/miri/tests/ui.rs @@ -1,9 +1,10 @@ -use colored::*; -use regex::bytes::Regex; use std::ffi::OsString; use std::num::NonZeroUsize; use std::path::{Path, PathBuf}; use std::{env, process::Command}; + +use colored::*; +use regex::bytes::Regex; use ui_test::color_eyre::eyre::{Context, Result}; use ui_test::{ status_emitter, CommandBuilder, Config, Format, Match, Mode, OutputConflictHandling, @@ -44,12 +45,15 @@ fn build_so_for_c_ffi_tests() -> PathBuf { // This is to avoid automatically adding `malloc`, etc. // Source: https://anadoxin.org/blog/control-over-symbol-exports-in-gcc.html/ "-fPIC", - "-Wl,--version-script=tests/extern-so/libcode.version", + "-Wl,--version-script=tests/extern-so/libtest.map", ]) .output() .expect("failed to generate shared object file for testing external C function calls"); if !cc_output.status.success() { - panic!("error in generating shared object file for testing external C function calls"); + panic!( + "error in generating shared object file for testing external C function calls:\n{}", + String::from_utf8_lossy(&cc_output.stderr), + ); } so_file_path } @@ -120,10 +124,10 @@ fn run_tests( config.program.args.push("--target".into()); config.program.args.push(target.into()); - // If we're on linux, and we're testing the extern-so functionality, - // then build the shared object file for testing external C function calls - // and push the relevant compiler flag. - if cfg!(target_os = "linux") && path.starts_with("tests/extern-so/") { + // If we're testing the extern-so functionality, then build the shared object file for testing + // external C function calls and push the relevant compiler flag. + if path.starts_with("tests/extern-so/") { + assert!(cfg!(target_os = "linux")); let so_file_path = build_so_for_c_ffi_tests(); let mut flag = std::ffi::OsString::from("-Zmiri-extern-so-file="); flag.push(so_file_path.into_os_string()); From 38780aa5a420c301b94345cfc372d8463ce46711 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 31 Mar 2024 10:10:35 +0200 Subject: [PATCH 2/2] there is no need for these wildcards --- src/tools/miri/tests/extern-so/libtest.map | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/tools/miri/tests/extern-so/libtest.map b/src/tools/miri/tests/extern-so/libtest.map index a9887a79a798..a57a4dc149fe 100644 --- a/src/tools/miri/tests/extern-so/libtest.map +++ b/src/tools/miri/tests/extern-so/libtest.map @@ -1,11 +1,12 @@ CODEABI_1.0 { # Define which symbols to export. - global: *add_one_int*; - *printer*; - *test_stack_spill*; - *get_unsigned_int*; - *add_int16*; - *add_short_to_long*; + global: + add_one_int; + printer; + test_stack_spill; + get_unsigned_int; + add_int16; + add_short_to_long; # The rest remains private. local: *; };