nm symbol both "U" and "T", what does that mean?
Asked Answered
L

2

6

I am having an undefined symbol error at runtime, and when I look for the symbol in the relevant library, I get the result:

nm -C -D /home/farmer/anaconda3/envs/general/lib/python3.6/site-packages/pyscannerbit/libScannerBitCAPI.so | grep empty_
                 U YAML::detail::node_data::empty_scalar[abi:cxx11]
00000000002b5860 T YAML::detail::node_data::empty_scalar[abi:cxx11]()

But how is that possible? The symbol is both undefined, and also in the library? What? Or are these actually different symbols? When mangled the names are indeed slightly different:

nm -D /home/farmer/anaconda3/envs/general/lib/python3.6/site-packages/pyscannerbit/libScannerBitCAPI.so | grep empty_
                 U _ZN4YAML6detail9node_data12empty_scalarB5cxx11E
00000000002b5860 T _ZN4YAML6detail9node_data12empty_scalarB5cxx11Ev

Does this make sense?

Lam answered 16/11, 2018 at 21:38 Comment(3)
Note that the demangled names are also slightly different.Mahalia
Right, I mentioned that. So they are different? That still seems strange though, how is that allowed? Isn't it a compiler error for a name to be used for both a class function and variable (if that's what these are)?Lam
Ahh ok, indeed they probably couldn't both exist at once, but it seems there are two versions of the external library, one used during the compile, and the other used at link time. This symbol changed from a variable to a function between the two versions. So at compile time the build knows it wants a function, but during linking the variable version gets built into my library.Lam
M
2

There are two variants of yaml-cpp:

https://github.com/jbeder/yaml-cpp

https://github.com/jbeder/yaml-cpp.new-api

In the first one the symbol in question is declared as member static const std::string& empty_scalar();. In the second one it is declared as member static std::string empty_scalar;.

The two symbol names you see match to these two different declarations. This should not be allowed by the compiler if it sees empty_scalar declared inconsistently like this.

I think you linked object files which were compiled with different versions of the header file which declared the symbol. The linker would then consider the two symbols different because of their different names. The object file you used did contain the definition for the old-api variant, but some code is using the new one.

Mahalia answered 16/11, 2018 at 22:8 Comment(1)
Yeah I think you are right, I just noticed that indeed the wrong version of the library is found by the linker.Lam
H
2

Letter definitions:

"U" means the symbol is undefined.

"T" means the symbol was found in Text section of the code.

If you see your grep search come up with both that means only one of those symbols has a definition that nm can resolve.

Hluchy answered 31/3, 2020 at 1:37 Comment(1)
To clarify about "U": that symbol is undefined for that specific object file it is listed below. That does not mean that it is undefined in the library or similarHsu

© 2022 - 2024 — McMap. All rights reserved.