[llvm-dev] Determine the offset of a vtable ptr

Tim Northover via llvm-dev llvm-dev at lists.llvm.org
Fri May 3 00:17:54 PDT 2019

Hi Bjoern,

On Fri, 3 May 2019 at 08:02, Gaier, Bjoern via llvm-dev
<llvm-dev at lists.llvm.org> wrote:
> For this I created two classes A & B which both used virtual functions. Now I created a class C which inherits A & B. In my simple understanding of C++ class 'C' would have two additional vtable pointers for A & B - and I would want to know there offset.

The canonical documentation for this is here (at least on most
non-Windows platforms):

There are a couple of Clang options that can help you by printing out
where Clang thinks these things are: "-Xclang -fdump-record-layouts"
prints the layout of every struct that's actually used in a source
file, and "-Xclang -fdump-vtable-layouts" prints what pointers Clang
puts at each location in the vtables it generates.

> So... Is that possible? And how would I do this via llvm::Module?

There's nothing in Module to help you determine the offsets, you have
to know or discover them by implementing the C++ ABI. Once you do know
the offsets you obviously use a getelementptr instruction to access
the pointers stored there.



More information about the llvm-dev mailing list