[Lldb-commits] [PATCH] D58630: [lldb] [test] Pass appropriate -L for just-built libc++

Michał Górny via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Mon Feb 25 09:12:06 PST 2019


mgorny created this revision.
mgorny added reviewers: krytarowski, labath, zturner.
mgorny added a project: LLDB.
Herald added a reviewer: EricWF.
Herald added a subscriber: teemperor.
Herald added a reviewer: serge-sans-paille.

Pass appropriate -L flags pointing out to the LLVM library directory
when linking tests.  This is necessary on platforms that default to
libc++ but don't ship with one, e.g. on NetBSD buildbot.

This patch includes -L passing for tests using clang via toolchain
substitutions, via build.py and via Makefiles.  This is not pretty.
I'm open to better solutions.


Repository:
  rLLDB LLDB

https://reviews.llvm.org/D58630

Files:
  lldb/lit/BuildScript/toolchain-clang.test
  lldb/lit/Suite/lit.cfg
  lldb/lit/helper/build.py
  lldb/lit/helper/toolchain.py
  lldb/packages/Python/lldbsuite/test/make/Makefile.rules


Index: lldb/packages/Python/lldbsuite/test/make/Makefile.rules
===================================================================
--- lldb/packages/Python/lldbsuite/test/make/Makefile.rules
+++ lldb/packages/Python/lldbsuite/test/make/Makefile.rules
@@ -297,6 +297,9 @@
 LD = $(CC)
 LDFLAGS ?= $(CFLAGS)
 LDFLAGS += $(LD_EXTRAS) $(ARCH_LDFLAGS)
+ifneq (,$(LLVM_LIBS_DIR))
+	LDFLAGS += -L$(LLVM_LIBS_DIR)
+endif
 ifeq (,$(filter $(OS), Windows_NT Android Darwin))
 	ifneq (,$(filter YES,$(ENABLE_THREADS)))
 		LDFLAGS += -pthread
Index: lldb/lit/helper/toolchain.py
===================================================================
--- lldb/lit/helper/toolchain.py
+++ lldb/lit/helper/toolchain.py
@@ -31,6 +31,8 @@
         build_script_args.append('--tools-dir={0}'.format(config.lldb_lit_tools_dir))
     if config.lldb_tools_dir:
         build_script_args.append('--tools-dir={0}'.format(config.lldb_tools_dir))
+    if config.llvm_libs_dir:
+        build_script_args.append('--libs-dir={0}'.format(config.llvm_libs_dir))
 
     primary_tools = [
         ToolSubst('%lldb',
@@ -99,6 +101,8 @@
     elif platform.system() in ['OpenBSD', 'Linux']:
         flags = ['-pthread']
 
+    # needed e.g. to use freshly built libc++
+    flags.append('-L' + config.llvm_libs_dir)
 
     additional_tool_dirs=[]
     if config.lldb_lit_tools_dir:
Index: lldb/lit/helper/build.py
===================================================================
--- lldb/lit/helper/build.py
+++ lldb/lit/helper/build.py
@@ -35,6 +35,13 @@
                     required=True,
                     help='Path to a compiler executable, or one of the values [any, msvc, clang-cl, gcc, clang]')
 
+parser.add_argument('--libs-dir',
+                    metavar='directory',
+                    dest='libs_dir',
+                    required=False,
+                    action='append',
+                    help='If specified, a path to linked libraries to be passed via -L')
+
 parser.add_argument('--tools-dir',
                     metavar='directory',
                     dest='tools_dir',
@@ -225,6 +232,7 @@
         self.nodefaultlib = args.nodefaultlib
         self.verbose = args.verbose
         self.obj_ext = obj_ext
+        self.lib_paths = args.libs_dir
 
     def _exe_file_name(self):
         assert self.mode != 'compile'
@@ -648,6 +656,7 @@
             if sys.platform == 'darwin':
                 main_symbol = '_main'
             args.append('-Wl,-e,' + main_symbol)
+        args.extend(['-L' + x for x in self.lib_paths])
         args.extend(['-o', self._exe_file_name()])
         args.extend(self._obj_file_names())
 
Index: lldb/lit/Suite/lit.cfg
===================================================================
--- lldb/lit/Suite/lit.cfg
+++ lldb/lit/Suite/lit.cfg
@@ -32,6 +32,9 @@
     'detect_stack_use_after_return=1'
   config.environment['DYLD_INSERT_LIBRARIES'] = runtime
 
+# Library path may be needed to locate just-built clang.
+config.environment['LLVM_LIBS_DIR'] = config.llvm_libs_dir
+
 # Build dotest command.
 dotest_cmd = [config.dotest_path, '-q']
 dotest_cmd.extend(config.dotest_args_str.split(';'))
Index: lldb/lit/BuildScript/toolchain-clang.test
===================================================================
--- lldb/lit/BuildScript/toolchain-clang.test
+++ lldb/lit/BuildScript/toolchain-clang.test
@@ -10,5 +10,5 @@
 CHECK-32: {{.*}}clang++{{(.exe)?}} -m32 -g -O0 -c -o {{.*}}foo.exe-foobar.o {{.*}}foobar.c
 CHECK-64: {{.*}}clang++{{(.exe)?}} -m64 -g -O0 -c -o {{.*}}foo.exe-foobar.o {{.*}}foobar.c
 CHECK: linking foo.exe-foobar.o -> foo.exe
-CHECK-32: {{.*}}clang++{{(.exe)?}} -m32 -o {{.*}}foo.exe {{.*}}foo.exe-foobar.o
-CHECK-64: {{.*}}clang++{{(.exe)?}} -m64 -o {{.*}}foo.exe {{.*}}foo.exe-foobar.o
+CHECK-32: {{.*}}clang++{{(.exe)?}} -m32 {{(-L.*)?}} -o {{.*}}foo.exe {{.*}}foo.exe-foobar.o
+CHECK-64: {{.*}}clang++{{(.exe)?}} -m64 {{(-L.*)?}} -o {{.*}}foo.exe {{.*}}foo.exe-foobar.o


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D58630.188195.patch
Type: text/x-patch
Size: 3942 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20190225/3890e00f/attachment-0001.bin>


More information about the lldb-commits mailing list