Skip to content

Commit 66bfb1f

Browse files
committed
[lldb][test] Link certain libc++ tests with the whole library
Some tests from 'import-std-module' used to fail on the builder https://lab.llvm.org/staging/#/builders/195/builds/4470, since libcxx is set up to be linked statically with test binaries on it. Thus, they were temporarily disabled in llvm#112530. Here, this commit is reverted. When libcxx is linked with a program as an archive of static libraries, functions that aren't used in the program are omitted. Then, jitted expressions from the tests try calling several functions that aren't present in the process image, which causes the failure. Here, --whole-archive linker flags are added to tests' Makefiles to ensure that the whole libc++ is included during static linking. It's applied only to -lc++ and -lc++abi (via --push-state/--pop-state), since for some reason clang Gnu toolchain driver on certain Linux configurations adds -libclang_rt.builtins twice, so we can't just apply --whole-archive to all static libraries. Flags in Makefile.rules and tests' Makefiles are changed to supported the configuration when libc++, libc++abi and libunwind are linked separately (this configuration will be enabled on lldb remote buildbots to be able to control what we link with and avoid duplicate symbols errors). '-nostdlib++ -nostdinc' are added to LDFLAGS in Makefile.rules to avoid duplicate symbols error. Applying them only to CXXFLAGS is not enough since thus they are not passed to the linker call. '--libcxx-include-dir' flag passing has been fixed on Windows host for remote platform in lldb/test/API/lit.cfg.py.
1 parent a43b2e1 commit 66bfb1f

File tree

8 files changed

+30
-3
lines changed

8 files changed

+30
-3
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ ifeq (,$(filter 1, $(USE_LIBSTDCPP) $(USE_LIBCPP) $(USE_SYSTEM_STDLIB)))
368368
ifneq "$(LIBCPP_INCLUDE_TARGET_DIR)" ""
369369
CXXFLAGS += -cxx-isystem $(LIBCPP_INCLUDE_TARGET_DIR)
370370
endif
371-
LDFLAGS += -L$(LIBCPP_LIBRARY_DIR) -Wl,-rpath,$(LIBCPP_LIBRARY_DIR) -lc++
371+
LDFLAGS += -L$(LIBCPP_LIBRARY_DIR) -Wl,-rpath,$(LIBCPP_LIBRARY_DIR) -lc++ -lc++abi
372372
else
373373
USE_SYSTEM_STDLIB := 1
374374
endif
@@ -389,7 +389,7 @@ ifeq (1,$(USE_LIBCPP))
389389
ifneq "$(LIBCPP_INCLUDE_TARGET_DIR)" ""
390390
CXXFLAGS += -cxx-isystem $(LIBCPP_INCLUDE_TARGET_DIR)
391391
endif
392-
LDFLAGS += -L$(LIBCPP_LIBRARY_DIR) -Wl,-rpath,$(LIBCPP_LIBRARY_DIR) -lc++
392+
LDFLAGS += -nostdlib++ -nostdinc -L$(LIBCPP_LIBRARY_DIR) -Wl,-rpath,$(LIBCPP_LIBRARY_DIR) -lc++ -lc++abi
393393
else
394394
ifeq "$(OS)" "Android"
395395
# Nothing to do, this is already handled in
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
USE_LIBCPP := 1
22
CXX_SOURCES := main.cpp
3+
4+
ifneq ($(OS),Darwin)
5+
LDFLAGS := -Xlinker --push-state -Xlinker --whole-archive -lc++ -lc++abi -Xlinker --pop-state
6+
endif
7+
38
include Makefile.rules
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
USE_LIBCPP := 1
22
CXX_SOURCES := main.cpp
3+
4+
ifneq ($(OS),Darwin)
5+
LDFLAGS := -Xlinker --push-state -Xlinker --whole-archive -lc++ -lc++abi -Xlinker --pop-state
6+
endif
7+
38
include Makefile.rules
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
USE_LIBCPP := 1
22
CXX_SOURCES := main.cpp
3+
4+
ifneq ($(OS),Darwin)
5+
LDFLAGS := -Xlinker --push-state -Xlinker --whole-archive -lc++ -lc++abi -Xlinker --pop-state
6+
endif
7+
38
include Makefile.rules
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
USE_LIBCPP := 1
22
CXX_SOURCES := main.cpp
3+
4+
ifneq ($(OS),Darwin)
5+
LDFLAGS := -Xlinker --push-state -Xlinker --whole-archive -lc++ -lc++abi -Xlinker --pop-state
6+
endif
7+
38
include Makefile.rules
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
USE_LIBCPP := 1
22
CXX_SOURCES := main.cpp
3+
4+
ifneq ($(OS),Darwin)
5+
LDFLAGS := -Xlinker --push-state -Xlinker --whole-archive -lc++ -lc++abi -Xlinker --pop-state
6+
endif
7+
38
include Makefile.rules

lldb/test/API/lit.cfg.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import os
66
import platform
7+
import re
78
import shlex
89
import shutil
910
import subprocess
@@ -211,7 +212,7 @@ def delete_module_cache(path):
211212

212213
# If we have a just-built libcxx, prefer it over the system one.
213214
if is_configured("has_libcxx") and config.has_libcxx:
214-
if platform.system() != "Windows":
215+
if platform.system() != "Windows" or re.match(r".*-linux.*", config.target_triple):
215216
if is_configured("libcxx_include_dir") and is_configured("libcxx_libs_dir"):
216217
dotest_cmd += ["--libcxx-include-dir", config.libcxx_include_dir]
217218
if is_configured("libcxx_include_target_dir"):

lldb/test/Shell/helper/toolchain.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ def use_support_substitutions(config):
239239
host_flags += [
240240
"-L{}".format(config.libcxx_libs_dir),
241241
"-lc++",
242+
"-lc++abi",
242243
]
243244

244245
host_flags = " ".join(host_flags)

0 commit comments

Comments
 (0)