Skip to content

Commit 61cc334

Browse files
rupprechtMichael137
authored andcommitted
[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 (cherry picked from commit cb0eb9d) (cherry picked from commit a9b4595baca074fa8dd6c9f3a2cd6edd6c5e2ffc)
1 parent 9a8dda9 commit 61cc334

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
@@ -135,8 +135,12 @@ def getModuleCacheSpec(self):
135135

136136
def getLibCxxArgs(self):
137137
if configuration.libcxx_include_dir and configuration.libcxx_library_dir:
138-
return ["LIBCPP_INCLUDE_DIR={}".format(configuration.libcxx_include_dir),
139-
"LIBCPP_LIBRARY_DIR={}".format(configuration.libcxx_library_dir)]
138+
libcpp_args = ["LIBCPP_INCLUDE_DIR={}".format(configuration.libcxx_include_dir),
139+
"LIBCPP_LIBRARY_DIR={}".format(configuration.libcxx_library_dir)]
140+
if configuration.libcxx_include_target_dir:
141+
libcpp_args.append("LIBCPP_INCLUDE_TARGET_DIR={}".format(
142+
configuration.libcxx_include_target_dir))
143+
return libcpp_args
140144
return []
141145

142146
def getLLDBSwiftLibs(self):

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@
131131
lldb_libs_dir = None
132132

133133
libcxx_include_dir = None
134+
libcxx_include_target_dir = None
134135
libcxx_library_dir = None
135136

136137
# 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
@@ -47,8 +47,12 @@ def create_parser():
4747
if sys.platform == 'darwin':
4848
group.add_argument('--apple-sdk', metavar='apple_sdk', dest='apple_sdk', default="", help=textwrap.dedent(
4949
'''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.'''))
50-
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.'))
51-
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.'))
50+
group.add_argument('--libcxx-include-dir', help=textwrap.dedent(
51+
'Specify the path to a custom libc++ include directory. Must be used in conjunction with --libcxx-library-dir.'))
52+
group.add_argument('--libcxx-include-target-dir', help=textwrap.dedent(
53+
'Specify the path to a custom libc++ include target directory to use in addition to --libcxx-include-dir. Optional.'))
54+
group.add_argument('--libcxx-library-dir', help=textwrap.dedent(
55+
'Specify the path to a custom libc++ library directory. Must be used in conjunction with --libcxx-include-dir.'))
5256
# FIXME? This won't work for different extra flags according to each arch.
5357
group.add_argument(
5458
'-E',

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,10 @@ endif
482482
ifeq (1,$(USE_LIBCPP))
483483
ifneq ($(and $(LIBCPP_INCLUDE_DIR), $(LIBCPP_LIBRARY_DIR)),)
484484
CXXFLAGS += -nostdlib++ -nostdinc++ -cxx-isystem $(LIBCPP_INCLUDE_DIR)
485-
LDFLAGS += -L$(LLVM_LIBS_DIR) -Wl,-rpath,$(LIBCPP_LIBRARY_DIR) -lc++
485+
ifneq "$(LIBCPP_INCLUDE_TARGET_DIR)" ""
486+
CXXFLAGS += -cxx-isystem $(LIBCPP_INCLUDE_TARGET_DIR)
487+
endif
488+
LDFLAGS += -L$(LIBCPP_LIBRARY_DIR) -Wl,-rpath,$(LIBCPP_LIBRARY_DIR) -lc++
486489
else
487490
ifeq "$(OS)" "Android"
488491
# Nothing to do, this is already handled in
@@ -504,7 +507,10 @@ endif
504507
ifeq ($(or $(USE_LIBSTDCPP), $(USE_LIBCPP), $(USE_SYSTEM_STDLIB)),)
505508
ifneq ($(and $(LIBCPP_INCLUDE_DIR), $(LIBCPP_LIBRARY_DIR)),)
506509
CXXFLAGS += -nostdlib++ -nostdinc++ -cxx-isystem $(LIBCPP_INCLUDE_DIR)
507-
LDFLAGS += -L$(LLVM_LIBS_DIR) -Wl,-rpath,$(LIBCPP_LIBRARY_DIR) -lc++
510+
ifneq "$(LIBCPP_INCLUDE_TARGET_DIR)" ""
511+
CXXFLAGS += -cxx-isystem $(LIBCPP_INCLUDE_TARGET_DIR)
512+
endif
513+
LDFLAGS += -L$(LIBCPP_LIBRARY_DIR) -Wl,-rpath,$(LIBCPP_LIBRARY_DIR) -lc++
508514
endif
509515
endif
510516

lldb/test/API/lit.cfg.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,11 @@ def delete_module_cache(path):
181181
# If we have a just-built libcxx, prefer it over the system one.
182182
if is_configured('has_libcxx') and config.has_libcxx:
183183
if platform.system() != 'Windows':
184-
if is_configured('llvm_include_dir') and is_configured('llvm_libs_dir'):
185-
dotest_cmd += ['--libcxx-include-dir', os.path.join(config.llvm_include_dir, 'c++', 'v1')]
186-
dotest_cmd += ['--libcxx-library-dir', config.llvm_libs_dir]
184+
if is_configured('libcxx_include_dir') and is_configured('libcxx_libs_dir'):
185+
dotest_cmd += ['--libcxx-include-dir', config.libcxx_include_dir]
186+
if is_configured('libcxx_include_target_dir'):
187+
dotest_cmd += ['--libcxx-include-target-dir', config.libcxx_include_target_dir]
188+
dotest_cmd += ['--libcxx-library-dir', config.libcxx_libs_dir]
187189

188190
# Forward ASan-specific environment variables to tests, as a test may load an
189191
# 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
@@ -33,6 +33,9 @@ config.test_compiler = lit_config.substitute('@LLDB_TEST_COMPILER@')
3333
config.test_swift_compiler = lit_config.substitute('@LLDB_SWIFTC@')
3434
config.dsymutil = lit_config.substitute('@LLDB_TEST_DSYMUTIL@')
3535
config.has_libcxx = @LLDB_HAS_LIBCXX@
36+
config.libcxx_libs_dir = "@LIBCXX_LIBRARY_DIR@"
37+
config.libcxx_include_dir = "@LIBCXX_GENERATED_INCLUDE_DIR@"
38+
config.libcxx_include_target_dir = "@LIBCXX_GENERATED_INCLUDE_TARGET_DIR@"
3639
# The API tests use their own module caches.
3740
config.lldb_module_cache = os.path.join("@LLDB_TEST_MODULE_CACHE_LLDB@", "lldb-api")
3841
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
@@ -122,6 +122,14 @@ if(TARGET clang)
122122

123123
if (TARGET libcxx OR ("libcxx" IN_LIST LLVM_ENABLE_RUNTIMES))
124124
set(LLDB_HAS_LIBCXX ON)
125+
if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
126+
set(LIBCXX_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${LLVM_DEFAULT_TARGET_TRIPLE})
127+
set(LIBCXX_GENERATED_INCLUDE_DIR "${LLVM_BINARY_DIR}/include/c++/v1")
128+
set(LIBCXX_GENERATED_INCLUDE_TARGET_DIR "${LLVM_BINARY_DIR}/include/${LLVM_DEFAULT_TARGET_TRIPLE}/c++/v1")
129+
else()
130+
set(LIBCXX_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBCXX_LIBDIR_SUFFIX})
131+
set(LIBCXX_GENERATED_INCLUDE_DIR "${CMAKE_BINARY_DIR}/include/c++/v1")
132+
endif()
125133
add_lldb_test_dependency(cxx)
126134
endif()
127135

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
@@ -24,8 +37,13 @@ set(vars
2437
LLDB_LIBS_DIR
2538
LLVM_TOOLS_DIR
2639
LLDB_SWIFTC
40+
LIBCXX_LIBRARY_DIR
41+
LIBCXX_GENERATED_INCLUDE_DIR
42+
LIBCXX_GENERATED_INCLUDE_TARGET_DIR
2743
)
2844

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

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ lldb_framework_dir = "@LLDB_FRAMEWORK_DIR_CONFIGURED@"
1515
lldb_libs_dir = "@LLDB_LIBS_DIR_CONFIGURED@"
1616
llvm_tools_dir = "@LLVM_TOOLS_DIR_CONFIGURED@"
1717
swift_libs_dir = '@LLDB_SWIFT_LIBS@'
18+
has_libcxx = @LLDB_HAS_LIBCXX@
19+
libcxx_libs_dir = "@LIBCXX_LIBRARY_DIR@"
20+
libcxx_include_dir = "@LIBCXX_GENERATED_INCLUDE_DIR@"
21+
libcxx_include_target_dir = "@LIBCXX_GENERATED_INCLUDE_TARGET_DIR@"
1822

1923
if __name__ == '__main__':
2024
wrapper_args = sys.argv[1:]
@@ -35,6 +39,11 @@ if __name__ == '__main__':
3539
cmd.extend(['--llvm-tools-dir', llvm_tools_dir])
3640
if swift_compiler:
3741
cmd.extend(['--swift-compiler', swift_compiler])
42+
if has_libcxx:
43+
cmd.extend(['--libcxx-include-dir', libcxx_include_dir])
44+
if libcxx_include_target_dir:
45+
cmd.extend(['--libcxx-include-target-dir', libcxx_include_target_dir])
46+
cmd.extend(['--libcxx-library-dir', libcxx_libs_dir])
3847
if lldb_framework_dir:
3948
cmd.extend(['--framework', lldb_framework_dir])
4049
if lldb_build_intel_pt == "1":

0 commit comments

Comments
 (0)