[Lldb-commits] [lldb] [lldb][test] Avoid namespace name colliding with dyld symbols in TestAbiTagLookup (PR #203984)

Yao Qi via lldb-commits lldb-commits at lists.llvm.org
Tue Jun 16 08:39:55 PDT 2026


qiyao wrote:

> I thought about fixing this the same way you did, but something feels wrong about this. Clang is trying to do a namespace lookup here but LLDB is finding global data symbols right?
> 

Yes.

> What if a program has a namespace called `foo` and a dylib that it links against has a global variable in it called `foo` as well? An expression like `foo::MyFunction()` shouldn't fail because another dylib has a global variable of the same name.

Let me quote lldb log to explain this process, the namespace is called `colliding_ns`, and method is called `do_thing`.  When lldb evaluates `colliding_ns::do_thing(5)`:

```
1781621790.991934061  ClangExpressionDeclMap::FindExternalVisibleDecls for 'colliding_ns' in a 'TranslationUnit'
1781621790.991945028    CEDM::FEVD Searching the root namespace
1781621790.992185116    CEDM::FEVD Found variable colliding_ns, returned
VarDecl 0x7bcda84900 <<invalid sloc>> <invalid sloc> colliding_ns 'void *&' static internal-linkage
````
lldb looks for `colliding_ns` and got one, from the dylib.   There is only one internal symbol, so `FindBestGlobalDataSymbol` won't error out.  It errors out when the number of internal symbol is greater than 1.

```
1781621790.992197990  ClangASTSource::FindExternalVisibleDecls on (ASTContext*)0x0000007bc90a0000 'Expression ASTContext for '<user expression 0>'' for 'colliding_ns' in a 'TranslationUnit'
1781621790.992203951    CAS::FEVD Searching the root namespace
1781621790.992213964    CAS::FEVD Found namespace colliding_ns in module main
```

lldb also finds the namespace `colliding_ns`.  It hands over the result to clang, clang discards the non-namespace one, because clang knows it is looking for namespace.

```
1781621790.992255926      [ClangASTImporter] Imported (NamespaceDecl*)0x0000007bcda84980, named colliding_ns (from (Decl*)0x0000007bccf75128), metadata 18446744073709551615
1781621790.992264032      [ClangASTImporter] Decl has no origin information in (ASTContext*)0x0000007bcc69c000
1781621790.992269993  CompleteNamespaceMap on (ASTContext*)0x0000007BC90A0000 'Expression ASTContext for '<user expression 0>'' Searching for namespace colliding_ns
1781621790.992275953    CMN[colliding_ns] Found namespace colliding_ns in module main
1781621790.992309093  ClangExpressionDeclMap::FindExternalVisibleDecls for 'do_thing' in 'colliding_ns'
1781621790.992315054    CEDM::FEVD Searching namespace colliding_ns in module main
```

https://github.com/llvm/llvm-project/pull/203984


More information about the lldb-commits mailing list