[Lldb-commits] [PATCH] D54747: Discard debuginfo for object files empty after GC

2018-11-20 Thread Robert O'Callahan via Phabricator via lldb-commits
rocallahan created this revision.
rocallahan added a reviewer: ruiu.
rocallahan added a project: lld.
Herald added subscribers: llvm-commits, MaskRay, JDevlieghere, arichardson, 
emaste.
Herald added a reviewer: espindola.

Rust projects tend to link in all object files from all dependent libraries and 
rely on --gc-sections to strip unused code and data. Unfortunately 
--gc-sections doesn't currently strip any debuginfo associated with GC'ed 
sections, so lld links in the full debuginfo from all dependencies even if 
almost all that code has been discarded. See 
https://github.com/rust-lang/rust/issues/56068 for some details.

Properly stripping debuginfo for discarded sections would be difficult, but a 
simple approach that helps significantly is to mark debuginfo sections as live 
only if their associated object file has at least one live code/data section. 
This patch does that. In a (contrived but not totally artificial) Rust testcase 
linked above, it reduces the final binary size from 41MB to 6.1MB.


Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D54747

Files:
  lld/ELF/Driver.cpp
  lld/ELF/InputFiles.h
  lld/ELF/InputSection.cpp
  lld/ELF/InputSection.h
  lld/ELF/MarkLive.cpp
  lld/test/ELF/linkerscript/comdat-gc.s
  lld/test/ELF/linkerscript/debuginfo-gc.s

Index: lld/test/ELF/linkerscript/debuginfo-gc.s
===
--- /dev/null
+++ lld/test/ELF/linkerscript/debuginfo-gc.s
@@ -0,0 +1,14 @@
+# REQUIRES: x86
+
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/comdat-gc.s -o %t1
+# RUN: echo "SECTIONS { .text : { *(.text*) } }" > %t.script
+# RUN: ld.lld --gc-sections --script %t.script %t %t1 -o %t2
+# RUN: llvm-readobj -sections -symbols %t2 | FileCheck %s
+
+# CHECK-NOT: Name: .debug_line
+
+.file 1 "test/ELF/linkerscript/comdat_gc.s"
+.section  .text._Z3fooIiEvv,"axG",@progbits,_Z3fooIiEvv,comdat
+.loc 1 14
+  ret
Index: lld/test/ELF/linkerscript/comdat-gc.s
===
--- lld/test/ELF/linkerscript/comdat-gc.s
+++ lld/test/ELF/linkerscript/comdat-gc.s
@@ -8,6 +8,9 @@
 
 # GC1: Name: .debug_line
 
+# Add .ctors section so all debuginfo isn't GCed
+.section  .ctors,"ax",@progbits
+
 .file 1 "test/ELF/linkerscript/comdat_gc.s"
 .section  .text._Z3fooIiEvv,"axG",@progbits,_Z3fooIiEvv,comdat
 .loc 1 14
Index: lld/ELF/MarkLive.cpp
===
--- lld/ELF/MarkLive.cpp
+++ lld/ELF/MarkLive.cpp
@@ -119,9 +119,9 @@
 // the gc pass. With that we would be able to also gc some sections holding
 // LSDAs and personality functions if we found that they were unused.
 template 
-static void
-scanEhFrameSection(EhInputSection &EH, ArrayRef Rels,
-   llvm::function_ref Fn) {
+static void scanEhFrameSection(
+EhInputSection &EH, ArrayRef Rels,
+llvm::function_ref Fn) {
   const endianness E = ELFT::TargetEndianness;
 
   for (unsigned I = 0, N = EH.Pieces.size(); I < N; ++I) {
@@ -132,7 +132,10 @@
 if (read32(Piece.data().data() + 4) == 0) {
   // This is a CIE, we only need to worry about the first relocation. It is
   // known to point to the personality function.
-  resolveReloc(EH, Rels[FirstRelI], Fn);
+  resolveReloc(EH, Rels[FirstRelI],
+ [&](InputSectionBase *Sec, uint64_t Offset) {
+   Fn(Sec, Offset, false);
+ });
   continue;
 }
 // This is a FDE. The relocations point to the described function or to
@@ -147,16 +150,16 @@
  [&](InputSectionBase *Sec, uint64_t Offset) {
if (Sec && Sec != &InputSection::Discarded &&
!(Sec->Flags & SHF_EXECINSTR))
- Fn(Sec, 0);
+ Fn(Sec, 0, true);
  });
 }
   }
 }
 
 template 
-static void
-scanEhFrameSection(EhInputSection &EH,
-   llvm::function_ref Fn) {
+static void scanEhFrameSection(
+EhInputSection &EH,
+llvm::function_ref Fn) {
   if (!EH.NumRelocations)
 return;
 
@@ -184,41 +187,60 @@
   }
 }
 
+template  static void setSectionLive(InputSectionBase *Sec) {
+  Sec->Live = true;
+  if (Sec->kind() != SectionBase::Kind::Regular &&
+  Sec->kind() != SectionBase::Kind::Merge)
+return;
+  if (!Sec->File || !ObjFile::classof(Sec->File))
+return;
+  if (auto *IS = dyn_cast(Sec)) {
+Sec->getFile()->HasLiveCodeOrData = true;
+  }
+}
+
 // This is the main function of the garbage collector.
 // Starting from GC-root sections, this function visits all reachable
 // sections to set their "Live" bits.
 template  static void doGcSections() {
   SmallVector Q;
   CNamedSections.clear();
 
-  auto Enqueue = [&](InputSectionBase *Sec, uint64_t Offset) {
+  auto EnqueueMaybeLDSA = [

[Lldb-commits] [PATCH] D54751: [LLDB] - Fix setting the breakpoints when -gsplit-dwarf and DWARF 5 owere used for executable.

2018-11-20 Thread George Rimar via Phabricator via lldb-commits
grimar created this revision.
grimar added reviewers: LLDB, clayborg.
Herald added subscribers: JDevlieghere, aprantl.

Imagine the following code:

  void baz() {
  }
  
  int main() {
baz();
return 0;
  }

When compiling with with `-gdwarf-4 -gsplit-dwarf` LLDB is able to set the 
breakpoint correctly:

  clang test.cc -g -fno-rtti -c -gdwarf-4 -gsplit-dwarf
  clang test.o -g -fno-rtti -gdwarf-4 -o test -gsplit-dwarf
  lldb test
  (lldb) target create "test"
  Current executable set to 'test' (x86_64).
  (lldb) b baz
  Breakpoint 1: where = test`baz() + 4 at test.cc:4:1, address = 
0x00400524

But not when -dwarf-5 is used. It thinks there are 2 locations:

  clang test.cc -g -fno-rtti -c -gdwarf-5 -gsplit-dwarf
  clang test.o -g -fno-rtti -gdwarf-5 -o test -gsplit-dwarf
  lldb test
  (lldb) target create "test"
  Current executable set to 'test' (x86_64).
  (lldb) b baz
  Breakpoint 1: 2 locations.

The issue happens because starting from DWARF v5 `DW_AT_addr_base` attribute 
should be used
instead of `DW_AT_GNU_addr_base`. LLDB does not do that and we end up reading 
the
`.debug_addr` header as section content (as addresses) instead of skipping it 
and reading the real addresses.
Then LLDB is unable to match 2 similar locations and thinks they are different.


https://reviews.llvm.org/D54751

Files:
  source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp


Index: source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
===
--- source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
+++ source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
@@ -306,9 +306,11 @@
 }
 
 // m_die_array_mutex must be already held as read/write.
-void DWARFUnit::AddUnitDIE(const DWARFDebugInfoEntry &cu_die) {
-  SetAddrBase(
-  cu_die.GetAttributeValueAsUnsigned(m_dwarf, this, DW_AT_addr_base, 0));
+void DWARFUnit::AddUnitDIE(const DWARFDebugInfoEntry &cu_die) {  
+  dw_addr_t addr_base =
+  cu_die.GetAttributeValueAsUnsigned(m_dwarf, this, DW_AT_addr_base, 
0);
+  SetAddrBase(addr_base);
+
   SetRangesBase(cu_die.GetAttributeValueAsUnsigned(m_dwarf, this,
DW_AT_rnglists_base, 0));
 
@@ -342,8 +344,12 @@
 
   m_dwo_symbol_file = std::move(dwo_symbol_file);
 
-  dw_addr_t addr_base =
-  cu_die.GetAttributeValueAsUnsigned(m_dwarf, this, DW_AT_GNU_addr_base, 
0);
+  // Here we make DWO CU use address base set in the skeleton unit.
+  // DWO files in pre-DWARF v5 could use DW_AT_GNU_addr_base.
+  // Starting from DWARF v5, the DW_AT_addr_base is used instead.
+  if (!addr_base)
+addr_base =
+   cu_die.GetAttributeValueAsUnsigned(m_dwarf, this, DW_AT_GNU_addr_base, 
0);
   dwo_cu->SetAddrBase(addr_base);
 
   dw_addr_t ranges_base = cu_die.GetAttributeValueAsUnsigned(


Index: source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
===
--- source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
+++ source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
@@ -306,9 +306,11 @@
 }
 
 // m_die_array_mutex must be already held as read/write.
-void DWARFUnit::AddUnitDIE(const DWARFDebugInfoEntry &cu_die) {
-  SetAddrBase(
-  cu_die.GetAttributeValueAsUnsigned(m_dwarf, this, DW_AT_addr_base, 0));
+void DWARFUnit::AddUnitDIE(const DWARFDebugInfoEntry &cu_die) {  
+  dw_addr_t addr_base =
+  cu_die.GetAttributeValueAsUnsigned(m_dwarf, this, DW_AT_addr_base, 0);
+  SetAddrBase(addr_base);
+
   SetRangesBase(cu_die.GetAttributeValueAsUnsigned(m_dwarf, this,
DW_AT_rnglists_base, 0));
 
@@ -342,8 +344,12 @@
 
   m_dwo_symbol_file = std::move(dwo_symbol_file);
 
-  dw_addr_t addr_base =
-  cu_die.GetAttributeValueAsUnsigned(m_dwarf, this, DW_AT_GNU_addr_base, 0);
+  // Here we make DWO CU use address base set in the skeleton unit.
+  // DWO files in pre-DWARF v5 could use DW_AT_GNU_addr_base.
+  // Starting from DWARF v5, the DW_AT_addr_base is used instead.
+  if (!addr_base)
+addr_base =
+   cu_die.GetAttributeValueAsUnsigned(m_dwarf, this, DW_AT_GNU_addr_base, 0);
   dwo_cu->SetAddrBase(addr_base);
 
   dw_addr_t ranges_base = cu_die.GetAttributeValueAsUnsigned(
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D54751: [LLDB] - Fix setting the breakpoints when -gsplit-dwarf and DWARF 5 owere used for executable.

2018-11-20 Thread George Rimar via Phabricator via lldb-commits
grimar updated this revision to Diff 174755.
grimar added a comment.

- Added the test case forgotten.


https://reviews.llvm.org/D54751

Files:
  lit/Breakpoint/Inputs/split-dwarf-5-addrbase.dwo.yaml
  lit/Breakpoint/Inputs/split-dwarf-5-addrbase.yaml
  lit/Breakpoint/split-dwarf-5-addrbase.test
  source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp

Index: source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
===
--- source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
+++ source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
@@ -307,8 +307,10 @@
 
 // m_die_array_mutex must be already held as read/write.
 void DWARFUnit::AddUnitDIE(const DWARFDebugInfoEntry &cu_die) {
-  SetAddrBase(
-  cu_die.GetAttributeValueAsUnsigned(m_dwarf, this, DW_AT_addr_base, 0));
+  dw_addr_t addr_base =
+  cu_die.GetAttributeValueAsUnsigned(m_dwarf, this, DW_AT_addr_base, 0);
+  SetAddrBase(addr_base);
+
   SetRangesBase(cu_die.GetAttributeValueAsUnsigned(m_dwarf, this,
DW_AT_rnglists_base, 0));
 
@@ -342,8 +344,12 @@
 
   m_dwo_symbol_file = std::move(dwo_symbol_file);
 
-  dw_addr_t addr_base =
-  cu_die.GetAttributeValueAsUnsigned(m_dwarf, this, DW_AT_GNU_addr_base, 0);
+  // Here we make DWO CU use address base set in the skeleton unit.
+  // DWO files in pre-DWARF v5 could use DW_AT_GNU_addr_base.
+  // Starting from DWARF v5, the DW_AT_addr_base is used instead.
+  if (!addr_base)
+addr_base =
+   cu_die.GetAttributeValueAsUnsigned(m_dwarf, this, DW_AT_GNU_addr_base, 0);
   dwo_cu->SetAddrBase(addr_base);
 
   dw_addr_t ranges_base = cu_die.GetAttributeValueAsUnsigned(
Index: lit/Breakpoint/split-dwarf-5-addrbase.test
===
--- lit/Breakpoint/split-dwarf-5-addrbase.test
+++ lit/Breakpoint/split-dwarf-5-addrbase.test
@@ -0,0 +1,30 @@
+# RUN: rm -rf %t.dir
+# RUN: mkdir %t.dir
+# RUN: cd %t.dir
+# RUN: yaml2obj %p/Inputs/split-dwarf-5-addrbase.dwo.yaml > %t.dir/test.dwo
+# RUN: yaml2obj %p/Inputs/split-dwarf-5-addrbase.yaml > %t.dir/test
+# RUN: lldb-test breakpoints %t.dir/test %s | FileCheck %s
+
+# This test checks that source code location is shown correctly
+# when -gsplit-dwarf and DWARF 5 are used.
+#
+# split-dwarf-5-addrbase.dwo.yaml and split-dwarf-5-addrbase.yamlare
+# reduced yaml files produces from the dwo file and the corresponding executable.
+#
+# The following code was used initially:
+# void baz() {
+# }
+# 
+# int main() {
+#   baz();
+#   return 0;
+# }
+#
+# Invocation used to produce outputs was:
+# clang test.cc -g -fno-rtti -c -gdwarf-5 -gsplit-dwarf
+# clang test.o -g -fno-rtti -gdwarf-5 -o test -gsplit-dwarf
+# clang version 8.0.0 (trunk 347299)
+
+b baz
+# CHECK-LABEL: b baz
+# CHECK: Address: {{.*}}baz() + 4 at test.cc:2:1
Index: lit/Breakpoint/Inputs/split-dwarf-5-addrbase.yaml
===
--- lit/Breakpoint/Inputs/split-dwarf-5-addrbase.yaml
+++ lit/Breakpoint/Inputs/split-dwarf-5-addrbase.yaml
@@ -0,0 +1,61 @@
+--- !ELF
+FileHeader:  
+  Class:   ELFCLASS64
+  Data:ELFDATA2LSB
+  Type:ET_EXEC
+  Machine: EM_X86_64
+  Entry:   0x00400440
+Sections:
+  - Name:.text
+Type:SHT_PROGBITS
+Flags:   [ SHF_ALLOC, SHF_EXECINSTR ]
+Address: 0x00400440
+AddressAlign:0x0010
+Content: 31ED4989D15E4889E24883E4F0505449C7C0C005400048C7C15005400048C7C730054000E8B7FFF4660F1F4455B820204000483D202040004889E57417B84885C0740D5DBF20204000FFE00F1F445DC3660F1F44BE20204000554881EE202040004889E548C1FE034889F048C1E83F4801C648D1FE7415B84885C0740B5DBF20204000FFE00F1F005DC3660F1F44803D391B007517554889E5E87EFFC605271B015DC30F1F44F3C30F1F4000662E0F1F8400554889E55DEB89660F1F8400554889E55DC3662E0F1F8400554889E54883EC10C745FCE8DCFF31C04883C4105DC30F1F4000415741564189FF415541544C8D25A61855488D2DA618534989F64989D54C29E54883EC0848C1FD03E86FFE4885ED742031DB0F1F84004C89EA4C89F64489FF41FF14DC4883C3014839EB75EA4883C4085B5D415C415D415E415FC390662E0F1F8400F3C3
+  - Name:.debug_str_offsets
+Type:SHT_PROGBITS
+AddressAlign:0x0001
+Content: 0C0005000900
+  - Name:.debug_str
+Type:SHT_PROGBITS
+Flags:   [ SHF_MERGE, SHF_STRINGS ]
+AddressAlign:0x0001
+Content: 746573742E64776F002F686F6D652F756D622F74657374735F323031382F3132322F69737375652F6477617266355F73706C69740062617A005F5A3362617A76006D61696E00696E7400
+  - Name:.debug_abbrev
+Type:SHT_PROGBITS
+AddressAlign:0x0001
+Content: 01110010177217B042251B25B442197317111B120600
+  - Name:   

[Lldb-commits] [PATCH] D54476: [CMake] Streamline code signing for debugserver

2018-11-20 Thread Phabricator via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL347305: [CMake] Streamline code signing for debugserver and 
pass entitlements to… (authored by stefan.graenitz, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D54476?vs=174405&id=174761#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D54476

Files:
  lldb/trunk/CMakeLists.txt
  lldb/trunk/cmake/modules/AddLLDB.cmake
  lldb/trunk/test/CMakeLists.txt
  lldb/trunk/tools/debugserver/CMakeLists.txt
  lldb/trunk/tools/debugserver/source/CMakeLists.txt
  lldb/trunk/unittests/tools/CMakeLists.txt

Index: lldb/trunk/cmake/modules/AddLLDB.cmake
===
--- lldb/trunk/cmake/modules/AddLLDB.cmake
+++ lldb/trunk/cmake/modules/AddLLDB.cmake
@@ -100,13 +100,13 @@
 function(add_lldb_executable name)
   cmake_parse_arguments(ARG
 "INCLUDE_IN_SUITE;GENERATE_INSTALL"
-""
+"ENTITLEMENTS"
 "LINK_LIBS;LINK_COMPONENTS"
 ${ARGN}
 )
 
   list(APPEND LLVM_LINK_COMPONENTS ${ARG_LINK_COMPONENTS})
-  add_llvm_executable(${name} ${ARG_UNPARSED_ARGUMENTS})
+  add_llvm_executable(${name} ${ARG_UNPARSED_ARGUMENTS} ENTITLEMENTS ${ARG_ENTITLEMENTS})
 
   target_link_libraries(${name} PRIVATE ${ARG_LINK_LIBS})
   set_target_properties(${name} PROPERTIES
Index: lldb/trunk/test/CMakeLists.txt
===
--- lldb/trunk/test/CMakeLists.txt
+++ lldb/trunk/test/CMakeLists.txt
@@ -93,11 +93,11 @@
   endif()
 endif()
 
-if(CMAKE_HOST_APPLE)
+if(CMAKE_HOST_APPLE AND DEBUGSERVER_PATH)
   list(APPEND LLDB_TEST_COMMON_ARGS --server ${DEBUGSERVER_PATH})
 endif()
 
-if(SKIP_DEBUGSERVER)
+if(SKIP_TEST_DEBUGSERVER)
   list(APPEND LLDB_TEST_COMMON_ARGS --out-of-tree-debugserver)
 endif()
 
Index: lldb/trunk/CMakeLists.txt
===
--- lldb/trunk/CMakeLists.txt
+++ lldb/trunk/CMakeLists.txt
@@ -11,6 +11,12 @@
 include(LLDBConfig)
 include(AddLLDB)
 
+option(LLDB_USE_ENTITLEMENTS "When codesigning, use entitlements if available" ON)
+if(LLDB_CODESIGN_IDENTITY)
+  # In the future we may use LLVM_CODESIGNING_IDENTITY directly.
+  set(LLVM_CODESIGNING_IDENTITY ${LLDB_CODESIGN_IDENTITY})
+endif()
+
 # Define the LLDB_CONFIGURATION_xxx matching the build type
 if( uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" )
   add_definitions( -DLLDB_CONFIGURATION_DEBUG )
Index: lldb/trunk/unittests/tools/CMakeLists.txt
===
--- lldb/trunk/unittests/tools/CMakeLists.txt
+++ lldb/trunk/unittests/tools/CMakeLists.txt
@@ -1,5 +1,5 @@
 if(CMAKE_SYSTEM_NAME MATCHES "Android|Darwin|Linux|NetBSD")
-  if ((CMAKE_SYSTEM_NAME MATCHES "Darwin" AND SKIP_DEBUGSERVER) OR (NOT CMAKE_SYSTEM_NAME MATCHES "Darwin" AND SKIP_LLDB_SERVER_BUILD))
+  if ((CMAKE_SYSTEM_NAME MATCHES "Darwin" AND SKIP_TEST_DEBUGSERVER) OR (NOT CMAKE_SYSTEM_NAME MATCHES "Darwin" AND SKIP_LLDB_SERVER_BUILD))
 # These tests are meant to test lldb-server/debugserver in isolation, and
 # don't provide any value if run against a server copied from somewhere.
   else()
Index: lldb/trunk/tools/debugserver/source/CMakeLists.txt
===
--- lldb/trunk/tools/debugserver/source/CMakeLists.txt
+++ lldb/trunk/tools/debugserver/source/CMakeLists.txt
@@ -94,32 +94,102 @@
 
 add_library(lldbDebugserverCommon ${lldbDebugserverCommonSources})
 
+option(LLDB_NO_DEBUGSERVER "Disable the debugserver target" OFF)
+option(LLDB_USE_SYSTEM_DEBUGSERVER "Use the system's debugserver instead of building it from source (Darwin only)." OFF)
 
-set(LLDB_CODESIGN_IDENTITY "lldb_codesign"
-  CACHE STRING "Identity used for code signing. Set to empty string to skip the signing step.")
+# Incompatible options
+if(LLDB_NO_DEBUGSERVER AND LLDB_USE_SYSTEM_DEBUGSERVER)
+  message(FATAL_ERROR "Inconsistent options: LLDB_NO_DEBUGSERVER and LLDB_USE_SYSTEM_DEBUGSERVER")
+endif()
 
-if(NOT LLDB_CODESIGN_IDENTITY STREQUAL "")
-  set(DEBUGSERVER_PATH ${LLVM_RUNTIME_OUTPUT_INTDIR}/debugserver${CMAKE_EXECUTABLE_SUFFIX} CACHE PATH "Path to debugserver.")
-  set(SKIP_DEBUGSERVER OFF CACHE BOOL "Skip building the in-tree debug server")
-else()
+# Try to locate the system debugserver.
+# Subsequent feasibility checks depend on it.
+if(APPLE AND CMAKE_HOST_APPLE)
   execute_process(
 COMMAND xcode-select -p
-OUTPUT_VARIABLE XCODE_DEV_DIR)
-  string(STRIP ${XCODE_DEV_DIR} XCODE_DEV_DIR)
-  if(EXISTS "${XCODE_DEV_DIR}/../SharedFrameworks/LLDB.framework/")
-set(DEBUGSERVER_PATH
-  "${XCODE_DEV_DIR}/../SharedFrameworks/LLDB.framework/Resources/debugserver" CACHE PATH "Path to debugserver.")
-  elseif(EXISTS "${XCODE_DEV_DIR}/Library/PrivateFrameworks/LLDB.framework/")
-set(DEBUGSERVER_PATH
-  "${XCODE_DEV_DIR}/Library/PrivateFrameworks/LLDB.framework/Resources/debugserver" CACHE PATH "Path to debugserver.")
+  

[Lldb-commits] [lldb] r347305 - [CMake] Streamline code signing for debugserver and pass entitlements to extended llvm_codesign

2018-11-20 Thread Stefan Granitz via lldb-commits
Author: stefan.graenitz
Date: Tue Nov 20 06:10:33 2018
New Revision: 347305

URL: http://llvm.org/viewvc/llvm-project?rev=347305&view=rev
Log:
[CMake] Streamline code signing for debugserver and pass entitlements to 
extended llvm_codesign

Summary:
Use llvm_codesign to sign debugserver with entitlements.
Set global LLVM_CODESIGNING_IDENTITY from LLDB_CODESIGN_IDENTITY (if given).
Pass through ENTITLEMENTS from add_lldb_executable to add_llvm_executable.
Handle reconfigurations correctly.

We have a lot of cases, make them explicit:

(1) build and sign debugserver, if all conditions apply:
* LLDB_NO_DEBUGSERVER=OFF (default)
* On Darwin: LLDB_USE_SYSTEM_DEBUGSERVER=OFF (default)
* On Darwin: LLVM_CODESIGNING_IDENTITY == lldb_codesign

(2) use system debugserver, if on Darwin and any of:
* LLDB_USE_SYSTEM_DEBUGSERVER=ON and found on system (explicit case)
* LLVM_CODESIGNING_IDENTITY != lldb_codesign and found on system (fallback case)

(3) debugserver will not be available, in case of:
* LLDB_NO_DEBUGSERVER=ON
* On Darwin: LLVM_CODESIGNING_IDENTITY != lldb_codesign and not found on system

(4) error state, in case of:
* LLDB_USE_SYSTEM_DEBUGSERVER=ON and not found on system
* LLDB_USE_SYSTEM_DEBUGSERVER=ON and LLDB_NO_DEBUGSERVER=ON

Reviewers: xiaobai, beanz, vsk, JDevlieghere

Subscribers: mgorny, lldb-commits, llvm-commits

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

Modified:
lldb/trunk/CMakeLists.txt
lldb/trunk/cmake/modules/AddLLDB.cmake
lldb/trunk/test/CMakeLists.txt
lldb/trunk/tools/debugserver/CMakeLists.txt
lldb/trunk/tools/debugserver/source/CMakeLists.txt
lldb/trunk/unittests/tools/CMakeLists.txt

Modified: lldb/trunk/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/CMakeLists.txt?rev=347305&r1=347304&r2=347305&view=diff
==
--- lldb/trunk/CMakeLists.txt (original)
+++ lldb/trunk/CMakeLists.txt Tue Nov 20 06:10:33 2018
@@ -11,6 +11,12 @@ include(LLDBStandalone)
 include(LLDBConfig)
 include(AddLLDB)
 
+option(LLDB_USE_ENTITLEMENTS "When codesigning, use entitlements if available" 
ON)
+if(LLDB_CODESIGN_IDENTITY)
+  # In the future we may use LLVM_CODESIGNING_IDENTITY directly.
+  set(LLVM_CODESIGNING_IDENTITY ${LLDB_CODESIGN_IDENTITY})
+endif()
+
 # Define the LLDB_CONFIGURATION_xxx matching the build type
 if( uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" )
   add_definitions( -DLLDB_CONFIGURATION_DEBUG )

Modified: lldb/trunk/cmake/modules/AddLLDB.cmake
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/cmake/modules/AddLLDB.cmake?rev=347305&r1=347304&r2=347305&view=diff
==
--- lldb/trunk/cmake/modules/AddLLDB.cmake (original)
+++ lldb/trunk/cmake/modules/AddLLDB.cmake Tue Nov 20 06:10:33 2018
@@ -100,13 +100,13 @@ endfunction(add_lldb_library)
 function(add_lldb_executable name)
   cmake_parse_arguments(ARG
 "INCLUDE_IN_SUITE;GENERATE_INSTALL"
-""
+"ENTITLEMENTS"
 "LINK_LIBS;LINK_COMPONENTS"
 ${ARGN}
 )
 
   list(APPEND LLVM_LINK_COMPONENTS ${ARG_LINK_COMPONENTS})
-  add_llvm_executable(${name} ${ARG_UNPARSED_ARGUMENTS})
+  add_llvm_executable(${name} ${ARG_UNPARSED_ARGUMENTS} ENTITLEMENTS 
${ARG_ENTITLEMENTS})
 
   target_link_libraries(${name} PRIVATE ${ARG_LINK_LIBS})
   set_target_properties(${name} PROPERTIES

Modified: lldb/trunk/test/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/test/CMakeLists.txt?rev=347305&r1=347304&r2=347305&view=diff
==
--- lldb/trunk/test/CMakeLists.txt (original)
+++ lldb/trunk/test/CMakeLists.txt Tue Nov 20 06:10:33 2018
@@ -93,11 +93,11 @@ if (NOT "${LLDB_LIT_TOOLS_DIR}" STREQUAL
   endif()
 endif()
 
-if(CMAKE_HOST_APPLE)
+if(CMAKE_HOST_APPLE AND DEBUGSERVER_PATH)
   list(APPEND LLDB_TEST_COMMON_ARGS --server ${DEBUGSERVER_PATH})
 endif()
 
-if(SKIP_DEBUGSERVER)
+if(SKIP_TEST_DEBUGSERVER)
   list(APPEND LLDB_TEST_COMMON_ARGS --out-of-tree-debugserver)
 endif()
 

Modified: lldb/trunk/tools/debugserver/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/CMakeLists.txt?rev=347305&r1=347304&r2=347305&view=diff
==
--- lldb/trunk/tools/debugserver/CMakeLists.txt (original)
+++ lldb/trunk/tools/debugserver/CMakeLists.txt Tue Nov 20 06:10:33 2018
@@ -8,12 +8,18 @@ if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURR
 "${CMAKE_SOURCE_DIR}/../../cmake"
 "${CMAKE_SOURCE_DIR}/../../cmake/modules"
 )
-  
+
   include(LLDBStandalone)
   include(AddLLDB)
 
   set(LLDB_SOURCE_DIR "${CMAKE_SOURCE_DIR}/../../")
   include_directories(${LLDB_SOURCE_DIR}/include)
+
+  option(LLDB_USE_ENTITLEMENTS "When codesigning, use entitlements if 
available" ON)
+  if(LLDB_CODESIGN_IDENTITY)
+# In the future we may use LLVM_CODESIGNING_IDENTITY directly.
+

[Lldb-commits] [lldb] r347321 - [lit] Disable the stop hook tests on Windows

2018-11-20 Thread Stella Stamenova via lldb-commits
Author: stella.stamenova
Date: Tue Nov 20 08:24:03 2018
New Revision: 347321

URL: http://llvm.org/viewvc/llvm-project?rev=347321&view=rev
Log:
[lit] Disable the stop hook tests on Windows
These tests are not able to pass on Windows as written as they don't even build

Modified:
lldb/trunk/lit/ExecControl/StopHook/stop-hook-threads.test
lldb/trunk/lit/ExecControl/StopHook/stop-hook.test

Modified: lldb/trunk/lit/ExecControl/StopHook/stop-hook-threads.test
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/ExecControl/StopHook/stop-hook-threads.test?rev=347321&r1=347320&r2=347321&view=diff
==
--- lldb/trunk/lit/ExecControl/StopHook/stop-hook-threads.test (original)
+++ lldb/trunk/lit/ExecControl/StopHook/stop-hook-threads.test Tue Nov 20 
08:24:03 2018
@@ -3,6 +3,7 @@
 # RUN: | FileCheck --check-prefix=CHECK --check-prefix=CHECK-NO-FILTER %s
 # RUN: %lldb -b -s %p/Inputs/stop-hook-threads-2.lldbinit -s %s -f %t \
 # RUN: | FileCheck --check-prefix=CHECK --check-prefix=CHECK-FILTER %s
+# XFAIL: system-windows
 
 thread list
 break set -f stop-hook-threads.cpp -p "Set break point at this line"

Modified: lldb/trunk/lit/ExecControl/StopHook/stop-hook.test
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/ExecControl/StopHook/stop-hook.test?rev=347321&r1=347320&r2=347321&view=diff
==
--- lldb/trunk/lit/ExecControl/StopHook/stop-hook.test (original)
+++ lldb/trunk/lit/ExecControl/StopHook/stop-hook.test Tue Nov 20 08:24:03 2018
@@ -6,6 +6,7 @@
 # RUN: %lldb -b -s %p/Inputs/stop-hook-2.lldbinit -s %s -f %t | FileCheck %s
 # Test setting stop-hook with multi-line expression
 # RUN: %lldb -b -s %p/Inputs/stop-hook-3.lldbinit -s %s -f %t | FileCheck %s
+# XFAIL: system-windows
 
 break set -f stop-hook.c -p "// Set breakpoint here to test target stop-hook"
 break set -f stop-hook.c -p "// Another breakpoint which is outside of the 
stop-hook range"


___
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] r347323 - [lit] Build and link TestIRMemoryMapWindows explicitly

2018-11-20 Thread Stella Stamenova via lldb-commits
Author: stella.stamenova
Date: Tue Nov 20 08:44:06 2018
New Revision: 347323

URL: http://llvm.org/viewvc/llvm-project?rev=347323&view=rev
Log:
[lit] Build and link TestIRMemoryMapWindows explicitly

If we just invoke clang-cl without specifying the linker, the tests fail on 
Windows because they cannot find the correct linker to use, so it needs to be 
specified explicitly

Modified:
lldb/trunk/lit/Expr/TestIRMemoryMapWindows.test

Modified: lldb/trunk/lit/Expr/TestIRMemoryMapWindows.test
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/Expr/TestIRMemoryMapWindows.test?rev=347323&r1=347322&r2=347323&view=diff
==
--- lldb/trunk/lit/Expr/TestIRMemoryMapWindows.test (original)
+++ lldb/trunk/lit/Expr/TestIRMemoryMapWindows.test Tue Nov 20 08:44:06 2018
@@ -1,6 +1,7 @@
 # REQUIRES: system-windows
 
-# RUN: %clang_cl /Zi %p/Inputs/call-function.cpp -o %t
+# RUN: %clang_cl /Zi /GS- %p/Inputs/call-function.cpp /c /o %t.obj
+# RUN: %msvc_link /debug:full %t.obj /out:%t
 
 # RUN: lldb-test ir-memory-map %t %S/Inputs/ir-memory-map-basic
 # RUN: lldb-test ir-memory-map -host-only %t %S/Inputs/ir-memory-map-basic


___
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] r347365 - Update call to EvaluateAsInt() to the new syntax.

2018-11-20 Thread Bill Wendling via lldb-commits
Author: void
Date: Tue Nov 20 15:24:18 2018
New Revision: 347365

URL: http://llvm.org/viewvc/llvm-project?rev=347365&view=rev
Log:
Update call to EvaluateAsInt() to the new syntax.

Modified:
lldb/trunk/source/Symbol/ClangASTContext.cpp

Modified: lldb/trunk/source/Symbol/ClangASTContext.cpp
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/ClangASTContext.cpp?rev=347365&r1=347364&r2=347365&view=diff
==
--- lldb/trunk/source/Symbol/ClangASTContext.cpp (original)
+++ lldb/trunk/source/Symbol/ClangASTContext.cpp Tue Nov 20 15:24:18 2018
@@ -5963,10 +5963,10 @@ GetObjCFieldAtIndex(clang::ASTContext *a
 
 if (is_bitfield && ast) {
   clang::Expr *bitfield_bit_size_expr = ivar_pos->getBitWidth();
-  llvm::APSInt bitfield_apsint;
+  clang::Expr::EvalResult result;
   if (bitfield_bit_size_expr &&
-  bitfield_bit_size_expr->EvaluateAsInt(bitfield_apsint,
-*ast)) {
+  bitfield_bit_size_expr->EvaluateAsInt(result, *ast)) {
+llvm::APSInt bitfield_apsint = result.Val.getInt();
 *bitfield_bit_size_ptr = bitfield_apsint.getLimitedValue();
   }
 }
@@ -6023,10 +6023,11 @@ CompilerType ClangASTContext::GetFieldAt
 
 if (is_bitfield) {
   clang::Expr *bitfield_bit_size_expr = field->getBitWidth();
-  llvm::APSInt bitfield_apsint;
+  clang::Expr::EvalResult result;
   if (bitfield_bit_size_expr &&
-  bitfield_bit_size_expr->EvaluateAsInt(bitfield_apsint,
+  bitfield_bit_size_expr->EvaluateAsInt(result,
 *getASTContext())) {
+llvm::APSInt bitfield_apsint = result.Val.getInt();
 *bitfield_bit_size_ptr = bitfield_apsint.getLimitedValue();
   }
 }


___
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D54731: [lit] Enable the use of custom user-defined lit commands

2018-11-20 Thread Reid Kleckner via Phabricator via lldb-commits
rnk added a comment.

I think the code to implement this is fine, but before we add this complexity 
to lit, I just wanted to know if other folks who work on the LLDB test suite 
are on board and want to use this approach to abstract over building apps for 
different targets. I see @stella.stamenova is, but I wanted to hear from other 
people involved in the LLDB lit test suite stuff. The `%compile %debug %opt %s` 
 lit substitution approach is limiting, but do people feel strongly that this 
is much better?




Comment at: 
llvm/utils/lit/tests/Inputs/shtest-keyword-command/keyword_helper.py:2
+
+def customCommand(line):
+  return ('STDOUT: ' + line, 'STDERR: ' + line)

Oh, the joys of multiprocessing and pickling...


https://reviews.llvm.org/D54731



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D54731: [lit] Enable the use of custom user-defined lit commands

2018-11-20 Thread Zachary Turner via Phabricator via lldb-commits
zturner added a reviewer: vsk.
zturner added a comment.

+vsk.  One thing I need input from LLDB people on is whether this seems like a 
good "general direction" for writing lit tests.  Does wrapping compilation and 
linker commands behind a python function seem like it would address these use 
cases?

Can we think of any other use cases for custom commands like this?


https://reviews.llvm.org/D54731



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D54731: [lit] Enable the use of custom user-defined lit commands

2018-11-20 Thread Vedant Kumar via Phabricator via lldb-commits
vsk added a subscriber: filcab.
vsk added a comment.

For compiling/linking, I think we can get by using lit substitutions to fill in 
platform-specific options? iOS testing for Swift is done this way (both 
on-device and simulator), as is testing for the profiling runtime. Dan and 
@filcab are more active in the area of sanitizer runtime testing, so they may 
have more informed opinions to share about how well that model works.

I’m not sure what we’d use custom lit commands for beyond compiling tests.


https://reviews.llvm.org/D54731



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits