diff --git a/lldb/packages/Python/lldbsuite/test/make/Makefile.rules b/lldb/packages/Python/lldbsuite/test/make/Makefile.rules --- a/lldb/packages/Python/lldbsuite/test/make/Makefile.rules +++ b/lldb/packages/Python/lldbsuite/test/make/Makefile.rules @@ -387,8 +387,7 @@ endif ifeq (1,$(USE_LIBCPP)) - # TODO: Teach LLDB to handle ABI tags in libc++ namespaces. - CXXFLAGS += -DLLDB_USING_LIBCPP -D_LIBCPP_NO_ABI_TAG + CXXFLAGS += -DLLDB_USING_LIBCPP ifeq "$(OS)" "Android" # Nothing to do, this is already handled in # Android.rules. diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp @@ -1248,6 +1248,20 @@ lldbassert(function_decl); if (function_decl) { + // Attach an asm() label to the FunctionDecl. + // This ensures that clang::CodeGen emits function calls + // using symbols that are mangled according to the DW_AT_linkage_name. + // If we didn't do this, the external symbols wouldn't exactly + // match the mangled name LLDB knows about and the IRExecutionUnit + // would have to fall back to searching object files for + // approximately matching function names. The motivating + // example is generating calls to ABI-tagged template functions. + // This is done separately for member functions in + // AddMethodToCXXRecordType. + if (attrs.mangled_name && attrs.storage == clang::SC_Extern) + function_decl->addAttr(clang::AsmLabelAttr::CreateImplicit( + m_ast.getASTContext(), attrs.mangled_name, /*literal=*/false)); + LinkDeclContextToDIE(function_decl, die); if (!function_param_decls.empty()) { diff --git a/lldb/test/API/lang/cpp/abi_tag_lookup/Makefile b/lldb/test/API/lang/cpp/abi_tag_lookup/Makefile new file mode 100644 --- /dev/null +++ b/lldb/test/API/lang/cpp/abi_tag_lookup/Makefile @@ -0,0 +1,3 @@ +CXX_SOURCES := main.cpp + +include Makefile.rules diff --git a/lldb/test/API/lang/cpp/abi_tag_lookup/TestAbiTagLookup.py b/lldb/test/API/lang/cpp/abi_tag_lookup/TestAbiTagLookup.py new file mode 100644 --- /dev/null +++ b/lldb/test/API/lang/cpp/abi_tag_lookup/TestAbiTagLookup.py @@ -0,0 +1,52 @@ +""" +Test that we can call functions and use types +annotated (and thus mangled) with ABI tags. +""" + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + +class AbiTagLookupTestCase(TestBase): + + @skipIfWindows + @expectedFailureAll(debug_info=["dwarf", "gmodules", "dwo"]) + def test_abi_tag_lookup(self): + self.build() + lldbutil.run_to_source_breakpoint(self, 'Break here', + lldb.SBFileSpec("main.cpp", False)) + + # Qualified/unqualified lookup to templates in namespace + self.expect_expr("operator<(b1, b2)", result_type="bool", result_value="true") + self.expect_expr("A::operator<(b1, b2)", result_type="bool", result_value="true") + self.expect_expr("b1 < b2", result_type="bool", result_value="true") + + # Qualified/unqualified lookup to templates with ABI tags in namespace + self.expect_expr("operator>(b1, b2)", result_type="bool", result_value="true") + self.expect_expr("A::operator>(b1, b2)", result_type="bool", result_value="true") + self.expect_expr("b1 > b2", result_type="bool", result_value="true") + + # Call non-operator templates with ABI tags + self.expect_expr("A::withAbiTagInNS(1, 1)", result_type="int", result_value="1") + + self.expect_expr("A::withAbiTagInNS(1.0, 1.0)", result_type="int", result_value="2") + self.expect_expr("withAbiTagInNS(b1, b2)", result_type="int", result_value="2") + self.expect_expr("A::withAbiTagInNS(b1, b2)", result_type="int", result_value="2") + + self.expect_expr("withAbiTag(b1, b2)", result_type="int", result_value="3") + self.expect_expr("withAbiTag(0, 0)", result_type="int", result_value="-3") + + # Structures with ABI tags + self.expect_expr("t.Value()", result_type="const int", result_value="4") + self.expect_expr("tt.Value()", result_type="const int", result_value="5") + + self.expect_expr("Tagged{.mem = 6}", result_type="Tagged", + result_children=[ValueCheck(name="mem", value="6")]) + + # Inline namespaces with ABI tags + self.expect_expr("v1::withImplicitTag(Simple{.mem = 6})", result_type="int", result_value="6") + self.expect_expr("withImplicitTag(Simple{.mem = 6})", result_type="int", result_value="6") + + self.expect_expr("v1::withImplicitTag(Tagged{.mem = 6})", result_type="int", result_value="6") + self.expect_expr("withImplicitTag(Tagged{.mem = 6})", result_type="int", result_value="6") diff --git a/lldb/test/API/lang/cpp/abi_tag_lookup/main.cpp b/lldb/test/API/lang/cpp/abi_tag_lookup/main.cpp new file mode 100644 --- /dev/null +++ b/lldb/test/API/lang/cpp/abi_tag_lookup/main.cpp @@ -0,0 +1,71 @@ +#include + +namespace A { +template bool operator<(const T &, const T &) { return true; } + +template +[[gnu::abi_tag("Two", "Tags")]] bool operator>(const T &, const T &) { + return true; +} + +template +[[gnu::abi_tag("OneTag")]] bool operator==(const T &, const T &) { + return true; +} + +[[gnu::abi_tag("Foo")]] int withAbiTagInNS(const int &, const int &) { + return 1; +} + +template +[[gnu::abi_tag("Bar")]] int withAbiTagInNS(const T &, const T &) { + return 2; +} + +struct B {}; +} // namespace A + +template +[[gnu::abi_tag("Baz")]] int withAbiTag(const T &, const T &) { + return 3; +} + +[[gnu::abi_tag("Baz")]] int withAbiTag(const int &, const int &) { return -3; } + +struct Simple { + int mem; +}; + +struct [[gnu::abi_tag("Qux")]] Tagged { + int mem; + + int const &Value() const { return mem; } +}; + +template struct [[gnu::abi_tag("Quux", "Quuux")]] TaggedTemplate { + T mem; + + T const &Value() const { return mem; } +}; + +// clang-format off +inline namespace [[gnu::abi_tag("Inline", "NS")]] v1 { +template int withImplicitTag(T const &t) { return t.mem; } +} // namespace +// clang-format on + +int main() { + A::B b1; + A::B b2; + Tagged t{.mem = 4}; + TaggedTemplate tt{.mem = 5}; + + int result = (b1 < b2) + (b1 > b2) + (b1 == b2) + withAbiTag(b1, b2) + + A::withAbiTagInNS(1.0, 2.0) + withAbiTagInNS(b1, b2) + + A::withAbiTagInNS(1, 2) + withImplicitTag(Tagged{.mem = 6}) + + withImplicitTag(Simple{.mem = 6}) + t.Value() + tt.Value(); + + std::puts("Break here"); + + return result; +}