How can I trace the use of DLL imports that are used by static libraries that are linked in a C++ DLL?

182 Views Asked by At

Apologies for the confusing wording in the title. I will do my best to describe the issue; please let me know if clarification is needed.

I work on a C++ DLL, call it Plugin.dll. I use the Visual Studio 2017 build tools. Plugin.dll depends on several static libraries (.lib) which are also maintained by my organization. There is both a debug and a release version of each static library. Each of these static libraries contains functions that depend on some 3rd-party DLLs. Therefore, a subset of these 3rd-party DLLs needs to be distributed with any software depending on Plugin.dll, depending on what functionality from the static libraries is used in Plugin.dll.

When I build the Plugin project in a debug configuration, the resulting DLL Plugin_d.dll depends on way more 3rd-party DLLs than the release version Plugin.dll. There are no differences in functionality between Plugin.dll and Plugin_d.dll that would require these particular DLLs to be included. The 3rd party DLLs are large and numerous enough that it is a nuisance to keep them in our repo and distribute them on the occasion we need to distribute a debug build internally.

I am pretty sure the reason for all these "extra" dependencies is design problems and unused code in the legacy codebase for the static libraries. The static libraries are not dependencies of anything other than Plugin. My goal is to edit the source for the static libraries to remove these unnecessary dependencies that arise in the debug configuration. But it's not that simple:

I use the VS command dumpbin /IMPORTS:third_party_library.dll C:\path\to\Plugin_d.dll to list the imported functions from third_party_library.dll. I get an output as follows:

    Section contains the following imports:
        third_party_library.dll
            183C7D0B8 Import Address Table
            183C80B18 Import Name Table
                    0 time date stamp
                    0 Index of first forwarder reference

                          0 ?FunctionName@third_party_library@@YA_NAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AEAUX2jfm@1@@Z

So I know that the only function from third_party_library.dll used by Plugin_d.dll is FunctionName. Since FunctionName is not directly called in the source for Plugin, I know that FunctionName must be somewhere along the possible call stack for a function from one of our static libraries that is called by Plugin. However, the output from dumpbin /IMPORTS does not tell me where/what the original call in Plugin is; therefore, I have to search the source for the static libraries and for Plugin to deduce where the call comes from, which is very time consuming. So my question is: Is there a way to automatically trace the origin of the imports from third party DLLs back to the call in Plugin that caused the need for the import, without manually tracing every possible call stack?

To complicate matters: The codebase for the static libraries is organized as a single Visual Studio Solution (.sln) with a Project (.vcxproj) for each library. However, there are several source files included in each library that are not included in the VS solution. I cannot add them to the VS solution because many of them have missing dependencies, naming conflicts, etc. that lead to compilation errors. So I cannot reliably use the IDE tools to trace references of functions within the static libaries' VS solution, because any references that are in files not included in the .vcxproj filters won't show up.

0

There are 0 best solutions below