about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOneirical <manchot@videotron.ca>2024-05-30 16:20:49 -0400
committerOneirical <manchot@videotron.ca>2024-06-18 14:38:33 -0400
commit83cb760e2c2b9fa3f0bb90ad2941f4cbceba2255 (patch)
tree3f9976697abc11cfabe309e7017567c585e5a388
parent8814b926f49bc5780753ed9533853679a1181357 (diff)
downloadrust-83cb760e2c2b9fa3f0bb90ad2941f4cbceba2255.tar.gz
rust-83cb760e2c2b9fa3f0bb90ad2941f4cbceba2255.zip
run_make_support nm implementation + bin-emit-no-symbols rmake rewrite
m---------library/backtrace0
m---------src/doc/book0
m---------src/doc/edition-guide0
m---------src/doc/reference0
m---------src/doc/rust-by-example0
m---------src/doc/rustc-dev-guide0
m---------src/tools/cargo0
-rw-r--r--src/tools/run-make-support/src/nm/mod.rs48
-rw-r--r--src/tools/tidy/src/allowed_run_make_makefiles.txt1
-rw-r--r--tests/run-make/bin-emit-no-symbols/app.rs (renamed from tests/run-make/issue-51671/app.rs)0
-rw-r--r--tests/run-make/bin-emit-no-symbols/rmake.rs19
-rw-r--r--tests/run-make/issue-51671/Makefile9
12 files changed, 67 insertions, 10 deletions
diff --git a/library/backtrace b/library/backtrace
-Subproject 72265bea210891ae47bbe6d4f17b493ef060661
+Subproject 5e05efa87905fb5b351a2bc5644d60c57d6d932
diff --git a/src/doc/book b/src/doc/book
-Subproject 45c1a6d69edfd1fc91fb7504cb73958dbd09441
+Subproject 5e9051f71638aa941cd5dda465e25c61cde9594
diff --git a/src/doc/edition-guide b/src/doc/edition-guide
-Subproject cb58c430b4e8054c2cb81d2d4434092c482a93d
+Subproject bbaabbe088e21a81a0d9ae6757705020d5d7b41
diff --git a/src/doc/reference b/src/doc/reference
-Subproject 0b805c65804019b0ac8f2fe3117afad82a6069b
+Subproject 6019b76f5b28938565b251bbba0bf5cc5c43d86
diff --git a/src/doc/rust-by-example b/src/doc/rust-by-example
-Subproject b1d97bd6113aba732b2091ce093c76f2d05bb8a
+Subproject 4840dca06cadf48b305d3ce0aeafde7f80933f8
diff --git a/src/doc/rustc-dev-guide b/src/doc/rustc-dev-guide
-Subproject aec82168dd3121289a194b381f56076fc789a4d
+Subproject 6a7374bd87cbac0f8be4fd4877d8186d9c31398
diff --git a/src/tools/cargo b/src/tools/cargo
-Subproject a1f47ec3f7cd076986f1bfcd7061f2e8cb1a726
+Subproject 431db31d0dbeda320caf8ef8535ea48eb309340
diff --git a/src/tools/run-make-support/src/nm/mod.rs b/src/tools/run-make-support/src/nm/mod.rs
new file mode 100644
index 00000000000..c304877eba1
--- /dev/null
+++ b/src/tools/run-make-support/src/nm/mod.rs
@@ -0,0 +1,48 @@
+use crate::{fs_wrapper, object};
+use object::{Object, ObjectSection};
+use std::path::Path;
+
+#[derive(Debug)]
+pub struct Nm {
+    file: Option<object::File>,
+}
+
+pub fn nm() -> Nm {
+    Nm::new()
+}
+
+impl Nm {
+    /// Construct a bare `nm` invocation.
+    pub fn new() -> Self {
+        Self { file: None }
+    }
+
+    /// Specify the file to analyze the symbols of.
+    pub fn input<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
+        &mut Self {
+            file: Some(
+                object::File::parse(fs_wrapper::read(path))
+                    .expect(format!("Failed to parse ELF file at {:?}", path.as_ref().display())),
+            ),
+        }
+    }
+
+    /// Collect all symbols of an object file into a String.
+    pub fn collect_symbols(&self) -> String {
+        let object_file = self.file;
+        let mut symbols_str = String::new();
+        for section in object_file.sections() {
+            if let Ok(ObjectSection::SymbolTable(st)) = section.parse::<object::SymbolTable>() {
+                for symbol in st.symbols() {
+                    symbols_str.push_str(&format!(
+                        "{:016x} {:?} {}\n",
+                        symbol.address(),
+                        symbol.kind(),
+                        symbol.name()
+                    ));
+                }
+            }
+        }
+        symbols_str
+    }
+}
diff --git a/src/tools/tidy/src/allowed_run_make_makefiles.txt b/src/tools/tidy/src/allowed_run_make_makefiles.txt
index 1596257747f..98438e8004d 100644
--- a/src/tools/tidy/src/allowed_run_make_makefiles.txt
+++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt
@@ -84,7 +84,6 @@ run-make/issue-37839/Makefile
 run-make/issue-40535/Makefile
 run-make/issue-47384/Makefile
 run-make/issue-47551/Makefile
-run-make/issue-51671/Makefile
 run-make/issue-68794-textrel-on-minimal-lib/Makefile
 run-make/issue-69368/Makefile
 run-make/issue-83045/Makefile
diff --git a/tests/run-make/issue-51671/app.rs b/tests/run-make/bin-emit-no-symbols/app.rs
index e9dc1e9744f..e9dc1e9744f 100644
--- a/tests/run-make/issue-51671/app.rs
+++ b/tests/run-make/bin-emit-no-symbols/app.rs
diff --git a/tests/run-make/bin-emit-no-symbols/rmake.rs b/tests/run-make/bin-emit-no-symbols/rmake.rs
new file mode 100644
index 00000000000..6d6d6b32967
--- /dev/null
+++ b/tests/run-make/bin-emit-no-symbols/rmake.rs
@@ -0,0 +1,19 @@
+// When setting the crate type as a "bin" (in app.rs),
+// this could cause a bug where some symbols would not be
+// emitted in the object files. This has been fixed, and
+// this test checks that the correct symbols have been successfully
+// emitted inside the object files.
+// See https://github.com/rust-lang/rust/issues/51671
+
+use run_make_support::{nm, rustc, tmp_dir};
+
+fn main() {
+    rustc().emit("obj").input("app.rs").run();
+    //FIXME(Oneirical): This should eventually be rmake_out_path
+    let nm = nm(tmp_dir().join("app.o"));
+    assert!(
+        nm.contains("rust_begin_unwind")
+            && nm.contains("rust_eh_personality")
+            && nm.contains("__rg_oom")
+    );
+}
diff --git a/tests/run-make/issue-51671/Makefile b/tests/run-make/issue-51671/Makefile
deleted file mode 100644
index c9364536992..00000000000
--- a/tests/run-make/issue-51671/Makefile
+++ /dev/null
@@ -1,9 +0,0 @@
-include ../tools.mk
-
-# ignore-windows-msvc
-
-all:
-	$(RUSTC) --emit=obj app.rs
-	nm $(TMPDIR)/app.o | $(CGREP) rust_begin_unwind
-	nm $(TMPDIR)/app.o | $(CGREP) rust_eh_personality
-	nm $(TMPDIR)/app.o | $(CGREP) __rg_oom