Skip to content

Commit b51b375

Browse files
authored
Rollup merge of rust-lang#124280 - beetrees:repr128-test-rmake, r=jieyouxu
Port repr128-dwarf run-make test to rmake This PR ports the repr128-dwarf run-make test to rmake, using the `gimli` crate instead of the `llvm-dwarfdump` command. Note that this PR changes `rmake.rs` files to be compiled with the 2021 edition (previously no edition was passed to `rustc`, meaning they were compiled with the 2015 edition). This means that `panic!("{variable}")` will now work as expected in `rmake.rs` files (there's already a usage in the [wasm-symbols-not-exported test](https://github.com/rust-lang/rust/blob/aca749eefceaed0cda19a7ec5e472fce9387bc00/tests/run-make/wasm-symbols-not-exported/rmake.rs#L34) that this will fix). Tracking issue: rust-lang#121876
2 parents 0bbe193 + 8c64a56 commit b51b375

File tree

8 files changed

+75
-18
lines changed

8 files changed

+75
-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

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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+
dbg!(&output);
16+
rustc().input("main.rs").arg("-o").arg(&output).arg("-Cdebuginfo=2").run();
17+
let output = std::fs::read(output).unwrap();
18+
let obj = object::File::parse(output.as_slice()).unwrap();
19+
let endian = if obj.is_little_endian() { RunTimeEndian::Little } else { RunTimeEndian::Big };
20+
let dwarf = gimli::Dwarf::load(|section| -> Result<_, ()> {
21+
let data = obj.section_by_name(section.name()).map(|s| s.uncompressed_data().unwrap());
22+
Ok(EndianRcSlice::new(Rc::from(data.unwrap_or_default().as_ref()), endian))
23+
})
24+
.unwrap();
25+
let mut iter = dwarf.units();
26+
let mut still_to_find = HashMap::from([
27+
("U128A", 0_u128),
28+
("U128B", 1_u128),
29+
("U128C", u64::MAX as u128 + 1),
30+
("U128D", u128::MAX),
31+
("I128A", 0_i128 as u128),
32+
("I128B", (-1_i128) as u128),
33+
("I128C", i128::MIN as u128),
34+
("I128D", i128::MAX as u128),
35+
]);
36+
while let Some(header) = iter.next().unwrap() {
37+
let unit = dwarf.unit(header).unwrap();
38+
let mut cursor = unit.entries();
39+
while let Some((_, entry)) = cursor.next_dfs().unwrap() {
40+
if entry.tag() == gimli::constants::DW_TAG_enumerator {
41+
let name = dwarf
42+
.attr_string(
43+
&unit,
44+
entry.attr(gimli::constants::DW_AT_name).unwrap().unwrap().value(),
45+
)
46+
.unwrap();
47+
let name = name.to_string().unwrap();
48+
if let Some(expected) = still_to_find.remove(name.as_ref()) {
49+
match entry.attr(gimli::constants::DW_AT_const_value).unwrap().unwrap().value()
50+
{
51+
AttributeValue::Block(value) => {
52+
assert_eq!(
53+
value.to_slice().unwrap(),
54+
expected.to_le_bytes().as_slice(),
55+
"{name}"
56+
);
57+
}
58+
value => panic!("{name}: unexpected DW_AT_const_value of {value:?}"),
59+
}
60+
}
61+
}
62+
}
63+
}
64+
if !still_to_find.is_empty() {
65+
panic!("Didn't find debug entries for {still_to_find:?}");
66+
}
67+
}

0 commit comments

Comments
 (0)