Skip to content

Commit 02b23fd

Browse files
authored
Unrolled build for rust-lang#124280
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 20aa2d8 + c2fd6ed commit 02b23fd

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
@@ -3318,6 +3318,7 @@ dependencies = [
33183318
name = "run_make_support"
33193319
version = "0.0.0"
33203320
dependencies = [
3321+
"gimli",
33213322
"object 0.34.0",
33223323
"regex",
33233324
"similar",

src/tools/compiletest/src/runtest.rs

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

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

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

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

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

18+
pub use gimli;
1819
pub use object;
1920
pub use regex;
2021
pub use wasmparser;

src/tools/tidy/src/allowed_run_make_makefiles.txt

-1
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,6 @@ run-make/relocation-model/Makefile
235235
run-make/relro-levels/Makefile
236236
run-make/remap-path-prefix-dwarf/Makefile
237237
run-make/remap-path-prefix/Makefile
238-
run-make/repr128-dwarf/Makefile
239238
run-make/reproducible-build-2/Makefile
240239
run-make/reproducible-build/Makefile
241240
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)