<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<div class="moz-cite-prefix">FWIW, when we at Concurrent were in the compiler business, our C++ compilers generated two vendor-defined attributes, both hanging off the DW_TAG_{structure,class}_type. Here are a couple with some sample locations:<br>
</div>
<blockquote>
<div class="moz-cite-prefix"><font face="monospace">DW_AT_vtable_location [DW_OP_plus_uconst 0; DW_OP_deref]<br>
</font></div>
<div class="moz-cite-prefix"><font face="monospace">DW_AT_type_vtable_location [DW_OP_addr 0x12345678]</font></div>
</blockquote>
<div class="moz-cite-prefix">The first was a description of how to obtain the address of the vtable tag from an object.</div>
<div class="moz-cite-prefix">The second was a description of the address of the vtable tag from just the type.</div>
<div class="moz-cite-prefix"><br>
</div>
<div class="moz-cite-prefix">As we characterized them internally, they didn't have to be the address of the vtable proper. They just had to be something that could be compared as a positive identification of the actual type. I believe they always were the
actual vtable addresses, though. Because why not?<br>
</div>
<div class="moz-cite-prefix"><br>
</div>
<div class="moz-cite-prefix">We do still have logic in our debugger to use them, too. In addition to the mangling-based approaches.<br>
</div>
<div class="moz-cite-prefix"><br>
</div>
<div class="moz-cite-prefix">It does require walking the whole DWARF tree to find them.</div>
<div class="moz-cite-prefix"><br>
</div>
<div class="moz-cite-prefix">Todd<br>
</div>
<div class="moz-cite-prefix"><br>
</div>
<div class="moz-cite-prefix">On 4/25/25 09:49, Jeremy Morse via Dwarf-discuss wrote:<br>
</div>
<blockquote type="cite" cite="mid:CAB+eix5ucUqwOBr3PGopNYAawRp43AzbPaDj=PZacZjMP8fTCQ@mail.gmail.com">
<div>
<div dir="ltr">Hi all,<br>
<br>
The LLVM discussion linked [0] happens to be us Sony folks, and it's supporting the use-case Kyle described of automatic downcasting, i.e. identifying the most-derived-class of an object from its vtable pointer. Having to demangle the symbol table is a real
pain (Tom, CC'd knows more) especially with things like anonymous namespaces.<br>
<br>
Right now the approach is to have a top-level nameless global variable with the location set to the vtable address, and a DW_AT_specification linking into the class definition:<br>
<br>
<font face="monospace">0x00000082: DW_TAG_variable</font><br>
<font face="monospace"> DW_AT_specification (0x000000b6 "_vtable$")</font><br>
<font face="monospace"> DW_AT_alignment (8)</font><br>
<font face="monospace"> DW_AT_location (DW_OP_addrx 0x1)</font><br>
<br>
<font face="arial, sans-serif">[Then deeper into the DIE tree,]</font>
<div><font face="monospace"><br>
</font></div>
<div><font face="monospace">0x0000008b: DW_TAG_structure_type<br>
DW_AT_containing_type (0x00000034 "CBase")<br>
DW_AT_calling_convention (DW_CC_pass_by_reference)<br>
DW_AT_name ("CDerived")<br>
DW_AT_decl_file ("vtables.cpp")<br>
DW_AT_decl_line (6)</font></div>
<div><font face="monospace"><br>
</font></div>
<div><font face="monospace"> [...]<br>
<br>
0x000000b6: DW_TAG_variable<br>
DW_AT_name ("_vtable$")<br>
DW_AT_type (0x00000081 "void *")<br>
DW_AT_external (true)<br>
DW_AT_declaration (true)<br>
DW_AT_artificial (true)<br>
DW_AT_accessibility (DW_ACCESS_private)</font><br>
<br>
This works well enough for our own debugger use-cases; I agree with Cary that it's hacky to rely on the name of a variable to signify important information like this and an officially blessed way could help.</div>
<div><br>
</div>
<div>I've no opinion on the <span style="font-family:monospace">DW_AT_vtable_elem_location
</span><font face="arial, sans-serif">behaviours, although we can consider it a separate issue.</font><br>
<br>
[0] <a href="https://github.com/llvm/llvm-project/pull/130255" originalsrc="https://github.com/llvm/llvm-project/pull/130255" moz-do-not-send="true">
https://github.com/llvm/llvm-project/pull/130255</a></div>
<div><br>
</div>
<div>--</div>
<div>Thanks,</div>
<div>Jeremy</div>
<div><br>
</div>
</div>
</div>
<br>
<fieldset class="moz-mime-attachment-header"></fieldset> </blockquote>
<p><br>
</p>
</body>
</html>