This is an archive of the discontinued LLVM Phabricator instance.

[lldb] Use just-built libcxx for tests when available
ClosedPublic

Authored by fdeazeve on Aug 30 2022, 6:56 AM.

Details

Summary

This commit improves upon cc0b5ebf7fc8, which added support for
specifying which libcxx to use when testing LLDB. That patch honored
requests by tests that had USE_LIBCPP=1 defined in their makefiles.
Now, we also use a non-default libcxx if all conditions below are true:

  1. The test is not explicitly requesting the use of libstdcpp

(USE_LIBSTDCPP=1).

  1. The test is not explicitly requesting the use of the system's

library (USE_SYSTEM_STDLIB=1).

  1. A path to libcxx was either provided by the user through CMake flags

or libcxx was built together with LLDB.

Condition (2) is new and introduced in this patch in order to support
tests that are either:

  • Cross-platform (such as API/macosx/macCatalyst and

API/tools/lldb-server). The just-built libcxx is usually not built for
platforms other than the host's.

  • Cross-language (such as API/lang/objc/exceptions). In this case, the

Objective C runtime throws an exceptions that always goes through the
system's libcxx, instead of the just built libcxx. Fixing this would
require either changing the install-name of the just built libcxx in Mac
systems, or tuning the DYLD_LIBRARY_PATH variable at runtime.

Some other tests exposes limitations of LLDB when running with a debug
standard library. TestDbgInfoContentForwardLists had an assertion
removed, as it was checking for buggy LLDB behavior (which now
crashes). TestFixIts had a variable renamed, as the old name clashes
with a standard library name when debug info is present. This is a known
issue: https://github.com/llvm/llvm-project/issues/34391.

For TestSBModule, the way the "main" module is found was changed to
look for the "a.out" module, instead of relying on the index being 0. In
some systems, the index 0 is dyld when a custom standard library is
used.

Diff Detail

Event Timeline

fdeazeve created this revision.Aug 30 2022, 6:56 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 30 2022, 6:56 AM
fdeazeve requested review of this revision.Aug 30 2022, 6:56 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 30 2022, 6:56 AM
fdeazeve updated this revision to Diff 456652.Aug 30 2022, 6:57 AM

Improved error message

This patch should finally enable us to fix the LLDB bots using older versions of Clang: https://green.lab.llvm.org/green/view/LLDB/job/lldb-cmake-matrix/

This revision is now accepted and ready to land.Aug 30 2022, 10:59 AM
labath added a subscriber: labath.Aug 31 2022, 6:22 AM

Cross-platform (such as API/macosx/macCatalyst and API/tools/lldb-server).

I find this statement fairly surprising. One should be able to run ~all tests in a "cross-platform" manner (i.e. where the test architecture is different than lldb (host) arch). What makes these two tests special? Couldn't we detect that we're in the cross-platform scenario (in python or cmake) and automatically switch to the system c++ library for all tests?

Cross-platform (such as API/macosx/macCatalyst and API/tools/lldb-server).

What makes these two tests special?

These two tests are _always_ building binaries for Mac Catalyst (API/macosx/macCatalyst), and watchOS/iOS Simulator (API/tools/lldb-server/TestAppleSimulatorOSType.py). Most builds of libcxx won't have support for those, so we end up with link errors like:

building for watchOS Simulator, but linking in dylib built for macOS, file
'[...] build/./lib/libc++.dylib' for architecture arm64

Cross-platform (such as API/macosx/macCatalyst and API/tools/lldb-server).

What makes these two tests special?

These two tests are _always_ building binaries for Mac Catalyst (API/macosx/macCatalyst), and watchOS/iOS Simulator (API/tools/lldb-server/TestAppleSimulatorOSType.py).

Ok, that makes more sense. I was confused because the Makefile in lldb/test/API/tools/lldb-server is used by (a lot) more tests than just TestAppleSimulatorOSType. In that case, I would say that this argument should be passed directly from python, as a part of the self.build command (the test already passes a bunch of arguments there anyway).

lldb/packages/Python/lldbsuite/test/make/Makefile.rules
390–395

Instead of three distinct variables, it might be nicer to just have one argument (STDLIB_KIND ?) which can take three different values...

is used by (a lot) more tests than just TestAppleSimulatorOSType. In that case, I would say that this argument should be passed directly from python, as a part of the self.build command (the test already passes a bunch of arguments there anyway).

Good catch! Will change it in the next revision

lldb/packages/Python/lldbsuite/test/make/Makefile.rules
390–395

I think this could be an improvement, but since it would involve changing _all_ makefiles that define these variables, IMO it would be better to do it in a separate NFC change, if that's ok

fdeazeve updated this revision to Diff 457252.Sep 1 2022, 6:35 AM

Addressed review comments

labath accepted this revision.Sep 5 2022, 8:10 AM
labath added inline comments.
lldb/packages/Python/lldbsuite/test/make/Makefile.rules
390–395

Ok, I'm going to hold you to that. :)

fdeazeve updated this revision to Diff 458240.Sep 6 2022, 12:31 PM

Added test changes for tests known to be faulty in the presence of a standard
library containing debug symbols, so that developers using debug builds don't
see any failures.

fdeazeve added a comment.EditedSep 6 2022, 12:35 PM

I had add extra checks to some tests which are known to fail with debug builds of the standard library, disabling them while a fix is not proposed.
Didn't want devs using debug configs to suddenly start seeing test failures

labath added inline comments.Sep 6 2022, 11:18 PM
lldb/test/API/commands/expression/fixits/TestFixIts.py
54

What kind of error are you getting here? Are you sure this is not some form of https://github.com/llvm/llvm-project/issues/34391, which could be worked around by renaming some variables in the expression?

lldb/test/API/commands/expression/import-std-module/forward_list-dbg-info-content/TestDbgInfoContentForwardListFromStdModule.py
31

And here it might be better to just remove the check, as it's checking for buggy behavior anyway.

fdeazeve updated this revision to Diff 458439.Sep 7 2022, 6:46 AM

Addressed review comments

lldb/test/API/commands/expression/fixits/TestFixIts.py
54

The error is indeed about a name clash with X, where the expression evaluator also sees a definition of a type X inside a function in libcxxabi/src/private_typeinfo.cpp.

It seems like the link you described has a variant of this problem, so I'll make a comment there and rename the X in this test to something else. Thanks for the link!

lldb/test/API/commands/expression/import-std-module/forward_list-dbg-info-content/TestDbgInfoContentForwardListFromStdModule.py
31

Done!

JDevlieghere accepted this revision.Sep 7 2022, 5:21 PM

LGTM

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

s/library/standard library/

Could we land this today so we can get the bots green again? Please still make sure to respond to any post-commit feedback from @labath in case there's anything hasn't been addressed.

fdeazeve updated this revision to Diff 458793.Sep 8 2022, 10:41 AM
fdeazeve edited the summary of this revision. (Show Details)

Updated wording of error message

This revision was landed with ongoing or failed builds.Sep 8 2022, 10:43 AM
This revision was automatically updated to reflect the committed changes.

It seems that a linux bot is failing after this: https://lab.llvm.org/buildbot/#/builders/68/builds/39086

This job does _not_ build the libcxx projects, and yet the LIBCPP_INCLUDE_DIR variable is defined. I'm investigating

I've reverted this while I find an Ubuntu machine to investigate