I would like to generate a .def file for building a DLL with the MSVC compiler. I used LLVM to search through the compiled .obj files to find all definitions of C++ functions or variables. I would like to distinguish between normal definitions and inline definitions to only export the normal definitions in the DLL. I used this simple .cpp file as an example:
test.cpp:
#include <string>
static std::string static_test() {
return "test.cpp";
}
std::string test() { return static_test(); }
The compiler generates the object file test.cpp.obj that contain several functions defined by the standard library. One of these functions is the inline constructor public: __cdecl std::exception::exception(char const *const, int). The COFF symbol class is IMAGE_SYM_CLASS_EXTERNAL for both std::string test() and std::exception::exception(char const*, int). Is there a way to distiguish these functions?
I found a solution myself, the information is contained in the COMDAT section definition, see https://learn.microsoft.com/en-us/windows/win32/debug/pe-format#comdat-sections-object-only.
This is my code using LLVM to detect definitions: