Skip to content

Commit cb0eb9d

Browse files
committed
[test] Fix LLDB tests with just-built libcxx when using a target directory.
In certain configurations, libc++ headers all exist in the same directory, and libc++ binaries exist in the same directory as lldb libs. When `LLVM_ENABLE_PER_TARGET_RUNTIME_DIR` is enabled (*and* the host is not Apple, which is why I assume this wasn't caught by others?), this is not the case: most headers will exist in the usual `include/c++/v1` directory, but `__config_site` exists in `include/$TRIPLE/c++/v1`. Likewise, the libc++.so binary exists in `lib/$TRIPLE/`, not `lib/` (where LLDB libraries reside). This also adds the just-built-libcxx functionality to the lldb-dotest tool. The `LIBCXX_` cmake config is borrowed from `libcxx/CMakeLists.txt`. I could not figure out a way to share the cmake config; ideally we would reuse the same config instead of copy/paste. Reviewed By: JDevlieghere, fdeazeve Differential Revision: https://reviews.llvm.org/D133973
1 parent b56e65d commit cb0eb9d

File tree

10 files changed

+68
-15
lines changed

10 files changed

+68
-15
lines changed

lldb/packages/Python/lldbsuite/test/builders/builder.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,12 @@ def getModuleCacheSpec(self):
122122

123123
def getLibCxxArgs(self):
124124
if configuration.libcxx_include_dir and configuration.libcxx_library_dir:
125-
return ["LIBCPP_INCLUDE_DIR={}".format(configuration.libcxx_include_dir),
126-
"LIBCPP_LIBRARY_DIR={}".format(configuration.libcxx_library_dir)]
125+
libcpp_args = ["LIBCPP_INCLUDE_DIR={}".format(configuration.libcxx_include_dir),
126+
"LIBCPP_LIBRARY_DIR={}".format(configuration.libcxx_library_dir)]
127+
if configuration.libcxx_include_target_dir:
128+
libcpp_args.append("LIBCPP_INCLUDE_TARGET_DIR={}".format(
129+
configuration.libcxx_include_target_dir))
130+
return libcpp_args
127131
return []
128132

129133
def _getDebugInfoArgs(self, debug_info):

lldb/packages/Python/lldbsuite/test/configuration.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@
124124
lldb_libs_dir = None
125125

126126
libcxx_include_dir = None
127+
libcxx_include_target_dir = None
127128
libcxx_library_dir = None
128129

129130
# A plugin whose tests will be enabled, like intel-pt.

lldb/packages/Python/lldbsuite/test/dotest.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -280,17 +280,15 @@ def parseOptionsAndInitTestdirs():
280280
logging.warning('No valid FileCheck executable; some tests may fail...')
281281
logging.warning('(Double-check the --llvm-tools-dir argument to dotest.py)')
282282

283-
configuration.libcxx_include_dir = args.libcxx_include_dir
284-
configuration.libcxx_library_dir = args.libcxx_library_dir
285283
if args.libcxx_include_dir or args.libcxx_library_dir:
286284
if args.lldb_platform_name:
287285
logging.warning('Custom libc++ is not supported for remote runs: ignoring --libcxx arguments')
288-
elif args.libcxx_include_dir and args.libcxx_library_dir:
289-
configuration.libcxx_include_dir = args.libcxx_include_dir
290-
configuration.libcxx_library_dir = args.libcxx_library_dir
291-
else:
286+
elif not (args.libcxx_include_dir and args.libcxx_library_dir):
292287
logging.error('Custom libc++ requires both --libcxx-include-dir and --libcxx-library-dir')
293288
sys.exit(-1)
289+
configuration.libcxx_include_dir = args.libcxx_include_dir
290+
configuration.libcxx_include_target_dir = args.libcxx_include_target_dir
291+
configuration.libcxx_library_dir = args.libcxx_library_dir
294292

295293
if args.channels:
296294
lldbtest_config.channels = args.channels

lldb/packages/Python/lldbsuite/test/dotest_args.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,12 @@ def create_parser():
4343
if sys.platform == 'darwin':
4444
group.add_argument('--apple-sdk', metavar='apple_sdk', dest='apple_sdk', default="", help=textwrap.dedent(
4545
'''Specify the name of the Apple SDK (macosx, macosx.internal, iphoneos, iphoneos.internal, or path to SDK) and use the appropriate tools from that SDK's toolchain.'''))
46-
group.add_argument('--libcxx-include-dir', help=textwrap.dedent('Specify the path to a custom libc++ include directory. Must be used in conjunction with --libcxx-library-dir.'))
47-
group.add_argument('--libcxx-library-dir', help=textwrap.dedent('Specify the path to a custom libc++ library directory. Must be used in conjunction with --libcxx-include-dir.'))
46+
group.add_argument('--libcxx-include-dir', help=textwrap.dedent(
47+
'Specify the path to a custom libc++ include directory. Must be used in conjunction with --libcxx-library-dir.'))
48+
group.add_argument('--libcxx-include-target-dir', help=textwrap.dedent(
49+
'Specify the path to a custom libc++ include target directory to use in addition to --libcxx-include-dir. Optional.'))
50+
group.add_argument('--libcxx-library-dir', help=textwrap.dedent(
51+
'Specify the path to a custom libc++ library directory. Must be used in conjunction with --libcxx-include-dir.'))
4852
# FIXME? This won't work for different extra flags according to each arch.
4953
group.add_argument(
5054
'-E',

lldb/packages/Python/lldbsuite/test/make/Makefile.rules

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,10 @@ endif
408408
ifeq (1,$(USE_LIBCPP))
409409
ifneq ($(and $(LIBCPP_INCLUDE_DIR), $(LIBCPP_LIBRARY_DIR)),)
410410
CXXFLAGS += -nostdlib++ -nostdinc++ -cxx-isystem $(LIBCPP_INCLUDE_DIR)
411-
LDFLAGS += -L$(LLVM_LIBS_DIR) -Wl,-rpath,$(LIBCPP_LIBRARY_DIR) -lc++
411+
ifneq "$(LIBCPP_INCLUDE_TARGET_DIR)" ""
412+
CXXFLAGS += -cxx-isystem $(LIBCPP_INCLUDE_TARGET_DIR)
413+
endif
414+
LDFLAGS += -L$(LIBCPP_LIBRARY_DIR) -Wl,-rpath,$(LIBCPP_LIBRARY_DIR) -lc++
412415
else
413416
ifeq "$(OS)" "Android"
414417
# Nothing to do, this is already handled in
@@ -430,7 +433,10 @@ endif
430433
ifeq ($(or $(USE_LIBSTDCPP), $(USE_LIBCPP), $(USE_SYSTEM_STDLIB)),)
431434
ifneq ($(and $(LIBCPP_INCLUDE_DIR), $(LIBCPP_LIBRARY_DIR)),)
432435
CXXFLAGS += -nostdlib++ -nostdinc++ -cxx-isystem $(LIBCPP_INCLUDE_DIR)
433-
LDFLAGS += -L$(LLVM_LIBS_DIR) -Wl,-rpath,$(LIBCPP_LIBRARY_DIR) -lc++
436+
ifneq "$(LIBCPP_INCLUDE_TARGET_DIR)" ""
437+
CXXFLAGS += -cxx-isystem $(LIBCPP_INCLUDE_TARGET_DIR)
438+
endif
439+
LDFLAGS += -L$(LIBCPP_LIBRARY_DIR) -Wl,-rpath,$(LIBCPP_LIBRARY_DIR) -lc++
434440
endif
435441
endif
436442

lldb/test/API/lit.cfg.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,11 @@ def delete_module_cache(path):
173173
# If we have a just-built libcxx, prefer it over the system one.
174174
if is_configured('has_libcxx') and config.has_libcxx:
175175
if platform.system() != 'Windows':
176-
if is_configured('llvm_include_dir') and is_configured('llvm_libs_dir'):
177-
dotest_cmd += ['--libcxx-include-dir', os.path.join(config.llvm_include_dir, 'c++', 'v1')]
178-
dotest_cmd += ['--libcxx-library-dir', config.llvm_libs_dir]
176+
if is_configured('libcxx_include_dir') and is_configured('libcxx_libs_dir'):
177+
dotest_cmd += ['--libcxx-include-dir', config.libcxx_include_dir]
178+
if is_configured('libcxx_include_target_dir'):
179+
dotest_cmd += ['--libcxx-include-target-dir', config.libcxx_include_target_dir]
180+
dotest_cmd += ['--libcxx-library-dir', config.libcxx_libs_dir]
179181

180182
# Forward ASan-specific environment variables to tests, as a test may load an
181183
# ASan-ified dylib.

lldb/test/API/lit.site.cfg.py.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ config.test_arch = '@LLDB_TEST_ARCH@'
3232
config.test_compiler = lit_config.substitute('@LLDB_TEST_COMPILER@')
3333
config.dsymutil = lit_config.substitute('@LLDB_TEST_DSYMUTIL@')
3434
config.has_libcxx = @LLDB_HAS_LIBCXX@
35+
config.libcxx_libs_dir = "@LIBCXX_LIBRARY_DIR@"
36+
config.libcxx_include_dir = "@LIBCXX_GENERATED_INCLUDE_DIR@"
37+
config.libcxx_include_target_dir = "@LIBCXX_GENERATED_INCLUDE_TARGET_DIR@"
3538
# The API tests use their own module caches.
3639
config.lldb_module_cache = os.path.join("@LLDB_TEST_MODULE_CACHE_LLDB@", "lldb-api")
3740
config.clang_module_cache = os.path.join("@LLDB_TEST_MODULE_CACHE_CLANG@", "lldb-api")

lldb/test/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,14 @@ if(TARGET clang)
9797

9898
if (TARGET libcxx OR ("libcxx" IN_LIST LLVM_ENABLE_RUNTIMES))
9999
set(LLDB_HAS_LIBCXX ON)
100+
if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
101+
set(LIBCXX_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${LLVM_DEFAULT_TARGET_TRIPLE})
102+
set(LIBCXX_GENERATED_INCLUDE_DIR "${LLVM_BINARY_DIR}/include/c++/v1")
103+
set(LIBCXX_GENERATED_INCLUDE_TARGET_DIR "${LLVM_BINARY_DIR}/include/${LLVM_DEFAULT_TARGET_TRIPLE}/c++/v1")
104+
else()
105+
set(LIBCXX_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBCXX_LIBDIR_SUFFIX})
106+
set(LIBCXX_GENERATED_INCLUDE_DIR "${CMAKE_BINARY_DIR}/include/c++/v1")
107+
endif()
100108
add_lldb_test_dependency(cxx)
101109
endif()
102110

lldb/utils/lldb-dotest/CMakeLists.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,21 @@ set(LLDB_LIBS_DIR "${LLVM_LIBRARY_OUTPUT_INTDIR}")
99

1010
llvm_canonicalize_cmake_booleans(
1111
LLDB_BUILD_INTEL_PT
12+
LLDB_HAS_LIBCXX
1213
)
1314

15+
if ("libcxx" IN_LIST LLVM_ENABLE_RUNTIMES)
16+
set(LLDB_HAS_LIBCXX ON)
17+
if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
18+
set(LIBCXX_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${LLVM_DEFAULT_TARGET_TRIPLE})
19+
set(LIBCXX_GENERATED_INCLUDE_DIR "${LLVM_BINARY_DIR}/include/c++/v1")
20+
set(LIBCXX_GENERATED_INCLUDE_TARGET_DIR "${LLVM_BINARY_DIR}/include/${LLVM_DEFAULT_TARGET_TRIPLE}/c++/v1")
21+
else()
22+
set(LIBCXX_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBCXX_LIBDIR_SUFFIX})
23+
set(LIBCXX_GENERATED_INCLUDE_DIR "${CMAKE_BINARY_DIR}/include/c++/v1")
24+
endif()
25+
endif()
26+
1427
set(LLVM_TOOLS_DIR "${LLVM_TOOLS_BINARY_DIR}")
1528
set(vars
1629
LLDB_TEST_COMMON_ARGS
@@ -23,8 +36,13 @@ set(vars
2336
LLDB_TEST_DSYMUTIL
2437
LLDB_LIBS_DIR
2538
LLVM_TOOLS_DIR
39+
LIBCXX_LIBRARY_DIR
40+
LIBCXX_GENERATED_INCLUDE_DIR
41+
LIBCXX_GENERATED_INCLUDE_TARGET_DIR
2642
)
2743

44+
llvm_canonicalize_cmake_booleans(LLDB_HAS_LIBCXX)
45+
2846
# Generate lldb-dotest Python driver script for each build mode.
2947
if(LLDB_BUILT_STANDALONE)
3048
set(config_types ".")

lldb/utils/lldb-dotest/lldb-dotest.in

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ lldb_build_intel_pt = "@LLDB_BUILD_INTEL_PT@"
1313
lldb_framework_dir = "@LLDB_FRAMEWORK_DIR_CONFIGURED@"
1414
lldb_libs_dir = "@LLDB_LIBS_DIR_CONFIGURED@"
1515
llvm_tools_dir = "@LLVM_TOOLS_DIR_CONFIGURED@"
16+
has_libcxx = @LLDB_HAS_LIBCXX@
17+
libcxx_libs_dir = "@LIBCXX_LIBRARY_DIR@"
18+
libcxx_include_dir = "@LIBCXX_GENERATED_INCLUDE_DIR@"
19+
libcxx_include_target_dir = "@LIBCXX_GENERATED_INCLUDE_TARGET_DIR@"
1620

1721
if __name__ == '__main__':
1822
wrapper_args = sys.argv[1:]
@@ -31,6 +35,11 @@ if __name__ == '__main__':
3135
cmd.extend(['--dsymutil', dsymutil])
3236
cmd.extend(['--lldb-libs-dir', lldb_libs_dir])
3337
cmd.extend(['--llvm-tools-dir', llvm_tools_dir])
38+
if has_libcxx:
39+
cmd.extend(['--libcxx-include-dir', libcxx_include_dir])
40+
if libcxx_include_target_dir:
41+
cmd.extend(['--libcxx-include-target-dir', libcxx_include_target_dir])
42+
cmd.extend(['--libcxx-library-dir', libcxx_libs_dir])
3443
if lldb_framework_dir:
3544
cmd.extend(['--framework', lldb_framework_dir])
3645
if lldb_build_intel_pt == "1":

0 commit comments

Comments
 (0)