facebookexperimental / object-introspection

Object Introspection (OI) enables on-demand, hierarchical profiling of objects in arbitrary C/C++ programs with no recompilation.
Apache License 2.0
161 stars 14 forks source link

oilgen: create directly from the weak (impl) symbol by using `-fstandalone-debug` on the input object file #61

Closed JakeHillion closed 8 months ago

JakeHillion commented 1 year ago

Currently OIGenerator.cpp forms a relationship between ObjectIntrospection::getObjectSize<T>(...) and ObjectIntrospection::getObjectSizeImpl<T>(...) by symbol name because the Impl isn't in the debug due to being a weak symbol with no body.

By passing the -fstandalone-debug to the compiler we cause the function to appear in the DWARF, as well as ensuring all the necessary type information is available even through pointers. This removes the need for the quite fragile symbol matching.

JakeHillion commented 1 year ago

This is a little bit weird. I'm getting the debug information show up on an internal BUCK build, but not an external hand driven one.

Internal object:

$ llvm-dwarfdump .../VectorOfStrings-GetSize.cpp.o | grep 'getObjectSizeImpl' -B 20 -A 20
...
0x00004a90:     DW_TAG_subprogram
                  DW_AT_linkage_name    ("_ZN19ObjectIntrospection17getObjectSizeImplIN8facebook6detail15VectorOfStringsEEEiRKT_Rm")
                  DW_AT_name    ("getObjectSizeImpl<facebook::detail::VectorOfStrings>")
                  DW_AT_decl_file       ("ObjectIntrospection.h")
                  DW_AT_decl_line       (243)
                  DW_AT_type    (0x000049ef "int")
                  DW_AT_declaration     (true)
                  DW_AT_external        (true)
...

External build (with -fstandalone-debug -fno-debug-types-section -gno-split-dwarf -g):

$ llvm-dwarfdump OilVectorOfStrings.o | grep 'getObjectSizeImpl' -B 20 -A 20

These are the only explicit flags added when compiling internally, so there must be something else somewhere. Will come back to this in the future as the two symbol approach works fine for now.

JakeHillion commented 8 months ago

This is no longer relevant with the Clang AST based approach that Oilgen now uses.