Wrapper Functions for Private Symbol Access in Legacy Binaries
Find Innovative SolutionsGenerate Solutions
Solution Overview
Problem
Legacy C or C++ code often has private symbols that are not accessible for dynamic linking, preventing new modules from being integrated, as static linkers resolve symbols differently and dynamic linkers struggle with private symbols unless all symbols are exported, which is impractical or error-prone.
Innovation Solution
Generating an intermediate representation (IR) of the program to discover private symbols, creating wrapper functions to make them accessible, and recompiling to include these functions in the executable binary, allowing dynamic linking and hot patching without rewriting entire programs.
Engineering Contradictions & Design Principles
Engineering Contradiction Analysis
1Adaptability or versatility
If all symbols are exported to enable dynamic linking, then new modules can be dynamically linked in, but the complexity of the program increases and maintenance becomes error-prone
Solution Approach 1:
The patent introduces a dynamic linker as an intermediary component that sits between the legacy binary and new modules. This dynamic linker interceptorsymbol resolution requests and dynamically generates the necessary bindings at runtime, allowing new modules to access private symbols without modifying the original binary or manually exporting symbols. This mediator approach enables dynamic linking capability while keeping the original program structure intact and avoiding the complexity of manual symbol export management.
Solution Approach 2:
The patent performs preliminary analysis of the legacy binary to identify private symbols that need to be accessed by new modules. By pre-scanning the binary and building a symbol table of private symbols before runtime, the system prepares the necessary information in advance. This preliminary action allows the dynamic linker to quickly resolve symbols during runtime without requiring all symbols to be pre-exported, thus enabling dynamic linking while maintaining program integrity.
2Adaptability or versatility
If manual inspection and explicit export of private symbols is performed, then new modules can access private symbols, but the process becomes error-prone and requires modifying the original program
Solution Approach 1:
The patent implements a self-service mechanism where the dynamic linker automatically scans the legacy binary, identifies private symbols, and generates appropriate bindings without requiring manual intervention. The system extracts symbol information directly from the binary structure and automatically creates the necessary resolution pathways. This self-service approach eliminates manual inspection and explicit export requirements, reducing errors while maintaining module accessibility.
3Extent of automation
If a C parser is written to resolve private symbols, then automatic symbol resolution is achieved, but the difficulty of implementation increases due to the C macro system
Solution Approach 1:
The patent replaces the mechanical approach of writing a C parser with a binary analysis approach. Instead of parsing C source code through the complex macro system, the system directly analyzes the compiled binary structure to extract symbol information. This substitution avoids the pitfalls of C macro parsing while achieving automatic symbol resolution through binary inspection and pattern recognition.
4Adaptability or versatility
If wrapper functions are generated for private symbols, then dynamic linking is enabled, but performance slightly decreases due to the added level of indirection
Solution Approach 1:
The patent performs preliminary binding of wrapper functions to their target private symbols during the dynamic linker initialization phase. By pre-resolving the addresses and caching the bindings, the system minimizes runtime overhead. When new modules need to access private symbols, the pre-established bindings are used directly without requiring runtime function generation or complex resolution processes, thus reducing the performance impact of the wrapper function indirection.
Data Source
AI summary
A method for generating a binary executable of a program so that private symbols in a module are accessible from another module. In one embodiment, the method compiles a source program to an intermediate representation and scans the representation to find the private symbols in the program's modules. It then wraps a function around each private symbol. When called, the function returns an address of the private symbol, so that the other module can access the symbol from outside the module in which the symbol is found. At run time, a call is made to obtain the address of the function, which is then executed to obtain the address of the private symbol so that the symbol can be accessed. In another embodiment, a Just-In-Time compiler executes the wrapper functions and patches the executable program with the direct address of the private symbol to avoid a call to the wrapper function.


