Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .typos.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ aranges = "aranges"

[files]
extend-exclude = ["external_test_suites", "wild/tests/bins"]

[type.external-test-list]
extend-glob = ["*_skip_tests.toml"]
extend-ignore-re = ['(?m)^\s*tests\s*=\s*\[[^\]]*\]\s*$']
104 changes: 104 additions & 0 deletions wild/tests/external_tests/lld_skip_tests.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
[skipped_groups.lld_specific]
reason = "Test exercises an lld-specific flag or behavior not applicable to Wild"
tests = ["x86-64-branch-to-branch.s"]

[skipped_groups.requires_newer_lld]
reason = "Test requires a newer lld/relocation type than our local llvm-mc supports"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If that's so - we can introduce a llvm-mc detection and require a specific version.

tests = [
"x86-64-gotpc-no-relax-err.s",
"x86-64-gotpc-relax.s",
"x86-64-gotpc-relax-nopic.s",
"x86-64-plt-high-addr.s",
"x86-64-tlsdesc-gd.s",
"x86-64-tls-ie-err.s",
"x86-64-tls-ie-local.s",
]

[skipped_groups.design_differences]
reason = "Wild intentionally differs from lld's PLT/GOT layout and relocation binding strategy (immediate binding vs lazy binding)"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we by default pass -z now to the reference linker (lld) and achieve a parity?

tests = [
"x86-64-tlsdesc-ld.s",
"x86-64-tlsdesc-gd-mixed.s",
"x86-64-reloc-gotoff64.s",
"x86-64-reloc-gotpc64.s",
"x86-64-reloc-pltoff64.s",
"x86-64-static-tls-model.s",
"x86-64-combined-dynrel.s",
"x86-64-got-plt-header.s",
"x86-64-plt.s",
"x86-64-rela.s",
"x86-64-tls-gd-local.s",
"x86-64-tls-ld-local.s",
"x86-64-zrel-zrela.s",
]

[skipped_groups.error_message_wording]
reason = "Wild correctly errors but with different message wording than lld"
tests = [
"x86-64-reloc-tpoff32-error.s",
"x86-64-pc32-overflow-large.s",
"x86-64-reloc-error2.s",
"x86-64-reloc-debug-overflow.s",
"x86-64-reloc-range-debug-loc.s",
"x86-64-tls-ie-opt-local.s",
]

[skipped_groups.gc_sections_behavior]
reason = "Test relies on lld's default --gc-sections behavior differing from Wild's"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly here.

tests = ["x86-64-reloc-error.s"]

[skipped_groups.noinhibit_exec_unsupported]
reason = "Test relies on --noinhibit-exec, which Wild does not support"
tests = ["x86-64-reloc-range.s", "x86-64-tls-le-undef.s"]

[skipped_groups.unsupported_features]
reason = "Feature not yet implemented in Wild"
tests = [
"x86-64-feature-cet.s",
"x86-64-dyn-rel-error.s",
"x86-64-dyn-rel-error3.s",
"x86-64-dyn-rel-error5.s",
"x86-64-relax-got-abs.s",
"x86-64-reloc-size.s",
"x86-64-retpoline.s",
"x86-64-retpoline-linkerscript.s",
"x86-64-retpoline-znow.s",
"x86-64-retpoline-znow-linkerscript.s",
"x86-64-retpoline-znow-static-iplt.s",
"x86-64-section-layout.s",
"x86-64-split-stack-prologue-adjust-fail.s",
"x86-64-split-stack-prologue-adjust-shared.s",
"x86-64-split-stack-prologue-adjust-silent.s",
"x86-64-tls-gd-got.s",
"x86-64-tls-opt-noplt.s",
"x86-64-tls-pie.s",
]

[skipped_groups.missing_flag_support]
reason = "Wild does not yet recognize the --image-base flag used by this test"
tests = ["x86-64-reloc-32.s"]

[skipped_groups.previously_believed_working]
reason = "Manual testing previously suggested Wild handles this correctly, but it fails under this harness's exact FileCheck comparison. Needs investigation to reconcile: possible regression, an imprecise manual check, or a local tooling gap (e.g. objdump missing x86_64 target support)."

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, the generated LLM wording for all the reasons is too long - please reduce it.

tests = [
"x86-64-tls-le-align.s",
"x86-64-tls-ie.s",
"x86-64-tls-gdie.s",
"x86-64-reloc-8-16.s",
"x86-64-tls-ld-preemptable.s",
"x86-64-relax-offset.s",
"x86-64-gotpc-relax-too-far.s",
"x86-64-gotpc-relax-und-dso.s",
"x86-64-tls-dynamic.s",
"x86-64-reloc-pc32.s",
"x86-64-split-stack-prologue-adjust-success.s",
]

[skipped_groups.untriaged]
reason = "Not yet manually triaged against Wild"
tests = [
"x86-64-gotpc-offset.s",
"x86-64-gotpc-relax-too-far-relr.s",
"x86-64-relax-jump-tables.s",
"x86-64-reloc-size-shared.s",
]
101 changes: 96 additions & 5 deletions wild/tests/external_tests/lld_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,37 @@
use crate::Result;
use libtest_mimic::Failed;
use libtest_mimic::Trial;
use serde::Deserialize;
use std::collections::HashMap;
use std::fs;
use std::path::Path;
use std::process::Command;
use std::sync::OnceLock;

#[derive(Deserialize)]
struct Config {
skipped_groups: HashMap<String, SkippedGroup>,
}

#[derive(Deserialize)]
struct SkippedGroup {
tests: Vec<String>,
}

static SKIP_TESTS_NAME: OnceLock<Option<Vec<String>>> = OnceLock::new();

const PREFIX: &str = "external_test_suites/lld";

/// Architecture prefixes used by LLD's test file naming convention
/// (e.g. `x86-64-pcrel.s`, `aarch64-abs16.s`).
const SUPPORTED_ARCH_PREFIXES: &[&str] = &["x86-64-"];

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would call it SUPPORTED_ARCHS and put there x86-64, then I would use it directly without the extra is_supported_arch_test.


fn is_supported_arch_test(file_name: &str) -> bool {
SUPPORTED_ARCH_PREFIXES
.iter()
.any(|prefix| file_name.starts_with(prefix))
}

pub(crate) fn collect_tests(tests: &mut Vec<Trial>, filter: &crate::Filter) -> Result {
if filter.excludes(PREFIX) {
return Ok(());
Expand All @@ -21,23 +47,48 @@ pub(crate) fn collect_tests(tests: &mut Vec<Trial>, filter: &crate::Filter) -> R
if !test_dir.exists() {
return Ok(());
}

let dir = std::fs::read_dir(&test_dir)?;
for ent in dir {
let ent = ent?;
let path = ent.path();
if path.extension().is_some_and(|ext| ext == "s") {
let file_name =
String::from_utf8_lossy(path.file_name().unwrap().as_encoded_bytes()).to_string();

// Other architectures (aarch64, riscv64, ...) are left for a
// TODO.
if !is_supported_arch_test(&file_name) {
continue;
}

let name = format!("{PREFIX}/test/ELF/{file_name}");
tests.push(Trial::test(name, move || {
run_lld_test(&path).map_err(|e| Failed::from(e.to_string()))
}));

if !should_skip_lld_test(&path) {
tests.push(Trial::test(name, move || {
run_lld_test(&path).map_err(|e| Failed::from(e.to_string()))
}));
} else {
tests.push(Trial::test(format!("{name}/expect_failure"), move || {
verify_skipped_lld_test_still_fails(&path)
.map_err(|e| Failed::from(e.to_string()))
}));
}
}
}
Ok(())
}

fn verify_skipped_lld_test_still_fails(test_file: &Path) -> Result {
if run_lld_test(test_file).is_ok() {
return Err(format!(
"Test `{}` is in the skip list but now passes. Should be removed from skip list.",
test_file.display()
)
.into());
}
Ok(())
}

fn run_lld_test(test_file: &Path) -> Result {
let llvm_mc = find_tool("llvm-mc")?;
let filecheck = find_tool("FileCheck")?;
Expand Down Expand Up @@ -97,9 +148,11 @@ fn extract_run_lines(content: &str) -> Vec<String> {
}

fn substitute_vars(cmd: &str, test_file: &Path, tmpdir: &Path) -> String {
let dir = test_file.parent().unwrap().display().to_string();
cmd.replace("%s", &test_file.display().to_string())
.replace("%t", &tmpdir.join("test").display().to_string())
.replace("%p", &test_file.parent().unwrap().display().to_string())
.replace("%S", &dir)
.replace("%p", &dir)
}

fn substitute_tools(cmd: &str, llvm_mc: &str, filecheck: &str) -> String {
Expand Down Expand Up @@ -128,3 +181,41 @@ fn execute_command(cmd: &str) -> Result {
}
Ok(())
}

fn load_skip_tests_config() -> &'static Option<Vec<String>> {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly here, it's a code that is not actually run.

SKIP_TESTS_NAME.get_or_init(|| {
let skip_tests_path = std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
.join("tests")
.join("external_tests")
.join("lld_skip_tests.toml");

fs::read_to_string(&skip_tests_path)
.map(|content| {
let config: Config =
toml::from_str(&content).expect("Failed to parse lld_skip_tests.toml");

config
.skipped_groups
.into_values()
.flat_map(|group| group.tests)
.collect()
})
.ok()
})
}

fn should_skip_lld_test(path: &Path) -> bool {
let file_name = path
.file_name()
.expect("Must be a valid filename")
.to_str()
.expect("Expected valid string name");

if crate::external_tests::should_not_ignore_tests("lld") {
return false;
}

load_skip_tests_config()
.as_ref()
.is_some_and(|skip_list| skip_list.contains(&file_name.to_string()))
}
Loading