[Lldb-commits] [lldb] 203b477 - [lldb][ObjectFile] Relocate sections for in-memory objects (e.g. received via JITLoaderGDB)

Stefan Gränitz via lldb-commits lldb-commits at lists.llvm.org
Tue Nov 10 02:39:23 PST 2020


Author: Stefan Gränitz
Date: 2020-11-10T11:37:53+01:00
New Revision: 203b4774b88322de22c99881a3e1e4c78a9d5a0e

URL: https://github.com/llvm/llvm-project/commit/203b4774b88322de22c99881a3e1e4c78a9d5a0e
DIFF: https://github.com/llvm/llvm-project/commit/203b4774b88322de22c99881a3e1e4c78a9d5a0e.diff

LOG: [lldb][ObjectFile] Relocate sections for in-memory objects (e.g. received via JITLoaderGDB)

Part 2 of a fix for JITed code debugging. This has been a regression from 5.0 to 6.0 and it's still reproducible on current master: https://bugs.llvm.org/show_bug.cgi?id=36209 Part 1 was D61611 a while ago.

The in-memory object files we obtain from JITLoaderGDB are not yet relocated. It looks like this used to happen on the LLDB side and my guess is that it broke with D38142. (However, it's hard to tell because the whole thing was broken already due to the bug in part 1.) The patch moved relocation resolution to a later point in time and didn't apply it to in-memory objects. I am not aware of any reason why we wouldn't resolve relocations per-se, so I made it unconditional here. On Debian, it fixes the bug for me and all tests in `check-lldb` are still fine.

Reviewed By: labath

Differential Revision: https://reviews.llvm.org/D90769

Added: 
    

Modified: 
    lldb/source/Symbol/ObjectFile.cpp
    lldb/test/Shell/Breakpoint/jitbp_elf.test

Removed: 
    


################################################################################
diff  --git a/lldb/source/Symbol/ObjectFile.cpp b/lldb/source/Symbol/ObjectFile.cpp
index 6b552dd0c19e..79683284f36a 100644
--- a/lldb/source/Symbol/ObjectFile.cpp
+++ b/lldb/source/Symbol/ObjectFile.cpp
@@ -503,6 +503,9 @@ size_t ObjectFile::ReadSectionData(Section *section,
     return section->GetObjectFile()->ReadSectionData(section, section_offset,
                                                      dst, dst_len);
 
+  if (!section->IsRelocated())
+    RelocateSection(section);
+
   if (IsInMemory()) {
     ProcessSP process_sp(m_process_wp.lock());
     if (process_sp) {
@@ -514,9 +517,6 @@ size_t ObjectFile::ReadSectionData(Section *section,
                                       dst_len, error);
     }
   } else {
-    if (!section->IsRelocated())
-      RelocateSection(section);
-
     const lldb::offset_t section_file_size = section->GetFileSize();
     if (section_offset < section_file_size) {
       const size_t section_bytes_left = section_file_size - section_offset;
@@ -547,6 +547,9 @@ size_t ObjectFile::ReadSectionData(Section *section,
   if (section->GetObjectFile() != this)
     return section->GetObjectFile()->ReadSectionData(section, section_data);
 
+  if (!section->IsRelocated())
+    RelocateSection(section);
+
   if (IsInMemory()) {
     ProcessSP process_sp(m_process_wp.lock());
     if (process_sp) {
@@ -563,17 +566,12 @@ size_t ObjectFile::ReadSectionData(Section *section,
         }
       }
     }
-    return GetData(section->GetFileOffset(), section->GetFileSize(),
-                   section_data);
-  } else {
-    // The object file now contains a full mmap'ed copy of the object file
-    // data, so just use this
-    if (!section->IsRelocated())
-      RelocateSection(section);
-
-    return GetData(section->GetFileOffset(), section->GetFileSize(),
-                   section_data);
   }
+
+  // The object file now contains a full mmap'ed copy of the object file
+  // data, so just use this
+  return GetData(section->GetFileOffset(), section->GetFileSize(),
+                  section_data);
 }
 
 bool ObjectFile::SplitArchivePathWithObject(llvm::StringRef path_with_object,

diff  --git a/lldb/test/Shell/Breakpoint/jitbp_elf.test b/lldb/test/Shell/Breakpoint/jitbp_elf.test
index 1dc5fa97005e..c637dba75b05 100644
--- a/lldb/test/Shell/Breakpoint/jitbp_elf.test
+++ b/lldb/test/Shell/Breakpoint/jitbp_elf.test
@@ -7,5 +7,8 @@
 # CHECK: Breakpoint 1: no locations (pending).
 # CHECK: (lldb) run -jit-kind=mcjit {{.*}}/jitbp_elf.test.tmp.ll
 # CHECK: Process {{.*}} stopped
-# CHECK: JIT(0x{{.*}})`jitbp:
+# CHECK: JIT(0x{{.*}})`jitbp() at jitbp.cpp:1:15
+# CHECK: -> 1    int jitbp() { return 0; }
+# CHECK:                       ^
+# CHECK:    2    int main() { return jitbp(); }
 # CHECK: Process {{.*}} launched: {{.*}}


        


More information about the lldb-commits mailing list