Skip to content

Commit c2fd6ed

Browse files
committed
Port repr128-dwarf run-make test to rmake
1 parent aca749e commit c2fd6ed

File tree

8 files changed

+83
-18
lines changed

8 files changed

+83
-18
lines changed

Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -3341,6 +3341,7 @@ dependencies = [
33413341
name = "run_make_support"
33423342
version = "0.0.0"
33433343
dependencies = [
3344+
"gimli",
33443345
"object 0.34.0",
33453346
"regex",
33463347
"wasmparser",

src/tools/compiletest/src/runtest.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3824,6 +3824,7 @@ impl<'test> TestCx<'test> {
38243824
.arg(format!("-Ldependency={}", &support_lib_deps_deps.to_string_lossy()))
38253825
.arg("--extern")
38263826
.arg(format!("run_make_support={}", &support_lib_path.to_string_lossy()))
3827+
.arg("--edition=2021")
38273828
.arg(&self.testpaths.file.join("rmake.rs"))
38283829
.env("TARGET", &self.config.target)
38293830
.env("PYTHON", &self.config.python)

src/tools/run-make-support/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ edition = "2021"
77
object = "0.34.0"
88
wasmparser = "0.118.2"
99
regex = "1.8" # 1.8 to avoid memchr 2.6.0, as 2.5.0 is pinned in the workspace
10+
gimli = "0.28.1"

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

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use std::env;
1414
use std::path::{Path, PathBuf};
1515
use std::process::{Command, Output};
1616

17+
pub use gimli;
1718
pub use object;
1819
pub use regex;
1920
pub use wasmparser;

src/tools/tidy/src/allowed_run_make_makefiles.txt

-1
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,6 @@ run-make/relocation-model/Makefile
238238
run-make/relro-levels/Makefile
239239
run-make/remap-path-prefix-dwarf/Makefile
240240
run-make/remap-path-prefix/Makefile
241-
run-make/repr128-dwarf/Makefile
242241
run-make/reproducible-build-2/Makefile
243242
run-make/reproducible-build/Makefile
244243
run-make/resolve-rename/Makefile

tests/run-make/repr128-dwarf/Makefile

-16
This file was deleted.

tests/run-make/repr128-dwarf/lib.rs renamed to tests/run-make/repr128-dwarf/main.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#![crate_type = "lib"]
21
#![feature(repr128)]
32

43
// Use .to_le() to ensure that the bytes are in the same order on both little- and big-endian
@@ -21,3 +20,7 @@ pub enum I128Enum {
2120
}
2221

2322
pub fn f(_: U128Enum, _: I128Enum) {}
23+
24+
fn main() {
25+
f(U128Enum::U128A, I128Enum::I128A);
26+
}

tests/run-make/repr128-dwarf/rmake.rs

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
//@ ignore-windows
2+
// This test should be replaced with one in tests/debuginfo once GDB or LLDB support 128-bit enums.
3+
4+
extern crate run_make_support;
5+
6+
use gimli::{AttributeValue, Dwarf, EndianRcSlice, Reader, RunTimeEndian};
7+
use object::{Object, ObjectSection};
8+
use run_make_support::{gimli, object, rustc, tmp_dir};
9+
use std::borrow::Cow;
10+
use std::collections::HashMap;
11+
use std::rc::Rc;
12+
13+
fn main() {
14+
let output = tmp_dir().join("repr128");
15+
rustc().input("main.rs").arg("-o").arg(&output).arg("-Cdebuginfo=2").run();
16+
// Mach-O uses packed debug info
17+
let dsym_location = output
18+
.with_extension("dSYM")
19+
.join("Contents")
20+
.join("Resources")
21+
.join("DWARF")
22+
.join("repr128");
23+
let output =
24+
std::fs::read(if dsym_location.try_exists().unwrap() { dsym_location } else { output })
25+
.unwrap();
26+
let obj = object::File::parse(output.as_slice()).unwrap();
27+
let endian = if obj.is_little_endian() { RunTimeEndian::Little } else { RunTimeEndian::Big };
28+
let dwarf = gimli::Dwarf::load(|section| -> Result<_, ()> {
29+
let data = obj.section_by_name(section.name()).map(|s| s.uncompressed_data().unwrap());
30+
Ok(EndianRcSlice::new(Rc::from(data.unwrap_or_default().as_ref()), endian))
31+
})
32+
.unwrap();
33+
let mut iter = dwarf.units();
34+
let mut still_to_find = HashMap::from([
35+
("U128A", 0_u128),
36+
("U128B", 1_u128),
37+
("U128C", u64::MAX as u128 + 1),
38+
("U128D", u128::MAX),
39+
("I128A", 0_i128 as u128),
40+
("I128B", (-1_i128) as u128),
41+
("I128C", i128::MIN as u128),
42+
("I128D", i128::MAX as u128),
43+
]);
44+
while let Some(header) = iter.next().unwrap() {
45+
let unit = dwarf.unit(header).unwrap();
46+
let mut cursor = unit.entries();
47+
while let Some((_, entry)) = cursor.next_dfs().unwrap() {
48+
if entry.tag() == gimli::constants::DW_TAG_enumerator {
49+
let name = dwarf
50+
.attr_string(
51+
&unit,
52+
entry.attr(gimli::constants::DW_AT_name).unwrap().unwrap().value(),
53+
)
54+
.unwrap();
55+
let name = name.to_string().unwrap();
56+
if let Some(expected) = still_to_find.remove(name.as_ref()) {
57+
match entry.attr(gimli::constants::DW_AT_const_value).unwrap().unwrap().value()
58+
{
59+
AttributeValue::Block(value) => {
60+
assert_eq!(
61+
value.to_slice().unwrap(),
62+
expected.to_le_bytes().as_slice(),
63+
"{name}"
64+
);
65+
}
66+
value => panic!("{name}: unexpected DW_AT_const_value of {value:?}"),
67+
}
68+
}
69+
}
70+
}
71+
}
72+
if !still_to_find.is_empty() {
73+
panic!("Didn't find debug entries for {still_to_find:?}");
74+
}
75+
}

0 commit comments

Comments
 (0)