From d3073fdad402b81ee831fe845928166b495a88c3 Mon Sep 17 00:00:00 2001 From: Anhad Singh Date: Sun, 19 Jan 2025 00:11:51 +1100 Subject: [PATCH] feat(ld.so): more debug info for scopes When scopes is set for `LD_DEBUG`, more debug information is displayed now, Signed-off-by: Anhad Singh --- src/ld_so/linker.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/ld_so/linker.rs b/src/ld_so/linker.rs index f57caf101f..96eb0263b3 100644 --- a/src/ld_so/linker.rs +++ b/src/ld_so/linker.rs @@ -453,7 +453,7 @@ impl Linker { match name { Some(name) => { if let Some(id) = self.name_to_object_id_map.get(name) { - let obj = self.objects.get_mut(id).unwrap(); + let obj = self.objects.get(id).unwrap(); // We may be upgrading the object from a local scope to the // global scope. @@ -464,6 +464,7 @@ impl Linker { let mut global_scope = GLOBAL_SCOPE.write(); obj.scope().copy_into(&mut global_scope); + self.scope_debug(); } Ok(ObjectHandle::new(obj.clone())) @@ -923,6 +924,17 @@ impl Linker { obj.run_init(); } + + fn scope_debug(&self) { + if self.config.debug_flags.contains(DebugFlags::SCOPES) { + println!("[ld.so]: =========== SCOPES =========="); + GLOBAL_SCOPE.read().debug(); + for obj in self.objects.values() { + obj.scope().debug(); + } + println!("[ld.so]: =============================="); + } + } } // GOT[1] = object_id