Open de9ccd5f-6521-4b39-ab30-f4e04ed39258 opened 3 years ago
I've stumbled across a simpler case that doesn't require boost or fPIC/fPIE. Here Derived is a template that is instantiated with 2 structs, one global and another one local to a function. In the first case the dynamic type is detected correctly, in the second case it is not.
struct Base { virtual ~Base() {} };
template
struct OuterFoo { };
int main() { struct InnerFoo { };
Derived<OuterFoo> od;
Base* ob = &od;
Derived<InnerFoo> id;
Base* ib = &id;
return 0;
$ clang++ --version Ubuntu clang version 12.0.0-3ubuntu1~21.04.2 Target: x86_64-pc-linux-gnu Thread model: posix InstalledDir: /usr/bin
lldb depends on there being a vtable symbol for the classes. Can you dump the symbol table (e.g. "image dump symtab" in lldb) and see if there is a vtable symbol.
If there is and we're not matching it up this the object, then that's some kind of lldb bug. If it is not present, lldb can't do this detection, and to resolve the issue you will have to figure out what it takes to get the compilation not to elide that symbol.
Extended Description
If I compile the following code with fPIC or fPIE:
include <boost/asio/io_context.hpp>
include <boost/asio/strand.hpp>
void foo(boost::asio::io_context& context) { boost::asio::io_context::strand s{context}; }
struct Base { virtual ~Base() {} };
struct Derived: Base { Derived(int zzz) : zzz(zzz) {}
};
int main() { Derived d{123}; Base* b = &d;
}
and run it in lldb, "print b" will print: (Base *) $0 = 0x00007fffffffdc58
But if I compile it without fPIC/fPIE, or modify the code slightly, e.g. by commenting out the unused function "foo", I get the expected output: (Derived *) $0 = 0x00007fffffffdc58
The behaviour doesn't depend on the compiler; I tried clang 11.0 and gcc-10.2 and the result was the same.
Since the code depends on boost, I'm attaching the preprocessed version too.
I compile it as follows: $ clang++ -g -fPIC test_preproc_clang.cpp -o test -lpthread
Clang version: Ubuntu clang version 11.0.0-2
LLDB version: lldb version 12.0.0 (git@github.com:llvm/llvm-project.git revision d28af7c654d8db0b68c175db5ce212d74fb5e9bc) clang revision d28af7c654d8db0b68c175db5ce212d74fb5e9bc llvm revision d28af7c654d8db0b68c175db5ce212d74fb5e9bc
boost version: 1.73.0