[Lldb-commits] [PATCH] D65826: Add support for deterministically linked binaries to lldb.

Erik Chen via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Tue Aug 6 13:40:31 PDT 2019


erikchen created this revision.
erikchen added a reviewer: rnk.
Herald added a reviewer: JDevlieghere.
Herald added subscribers: lldb-commits, abidh, mgrang.
Herald added a reviewer: jdoerfert.
Herald added a project: LLDB.

When ld64 links a binary deterministically using the flag ZERO_AR_DATE, it sets

  a timestamp of 0 for N_OSO members in the symtab section, rather than the usual
  last modified date of the object file. Prior to this patch, lldb would compare
  the timestamp from the N_OSO member against the last modified date of the object
  file, and skip loading the object file if there was a mismatch. This patch
  updates the logic to ignore the timestamp check if the N_OSO member has
  timestamp 0.
  
  The original logic was added in https://reviews.llvm.org/rL181631 as a safety
  check to avoid problems when debugging if the object file was out of date. This
  was prior to the introduction of deterministic build in ld64. lld still doesn't
  support deterministic build.
  
  Other code in llvm already relies on and uses the assumption that a timestamp of
  0 means deterministic build. For example, commit
  9ccfddc39d4d27f9b16fcc72ab30d483151d6d08 adds similar timestamp checking logic
  to dsymutil, but special cases timestamp 0. Likewise, commit
  0d1bb79a0413f221432a7b1d0d2d10c84c4bbb99 adds a long comment describing
  deterministic archive, which mostly uses timestamp 0 for determinism.
  
  To test this code, run:
  ```
  // example.cc
  int main() { return 0; }
  
  clang -c -g example.cc -o example.o
  ZERO_AR_DATE=1 clang -g example.o -o example
  lldb example
  break main
  run
  ```
  
  This should correctly load the object file symbols.


Repository:
  rLLDB LLDB

https://reviews.llvm.org/D65826

Files:
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp


Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
===================================================================
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
@@ -420,7 +420,11 @@
         // than the one from the CU.
         auto oso_mod_time = std::chrono::time_point_cast<std::chrono::seconds>(
             FileSystem::Instance().GetModificationTime(oso_file));
-        if (oso_mod_time != comp_unit_info->oso_mod_time) {
+        // A timestamp of 0 means that the linker was in deterministic mode. In
+        // that case, we should skip the check against the filesystem last
+        // modification timestamp, since it will never match.
+        if (comp_unit_info->oso_mod_time != llvm::sys::TimePoint<>() &&
+            oso_mod_time != comp_unit_info->oso_mod_time) {
           obj_file->GetModule()->ReportError(
               "debug map object file '%s' has changed (actual time is "
               "%s, debug map time is %s"


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D65826.213701.patch
Type: text/x-patch
Size: 1063 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20190806/9fba3b0c/attachment.bin>


More information about the lldb-commits mailing list