The present invention may be better understood, and its numerous objects, features, and advantages made apparent to those skilled in the art by referencing the accompanying drawings.
The description that follows includes exemplary systems, methods, techniques, instruction sequences and computer program products that embody techniques of the present invention. However, it is understood that the described invention may be practiced without these specific details. In other instances, well-known instruction instances, protocols, structures and techniques have not been shown in detail in order not to obfuscate the description.
For intelligent insertion, the software tool 105 utilizes information from control flow analysis of the binary file 101. The software tool (or another tool) first reads the binary file and creates a control flow graph. The object file is also read and to generate a control flow graph. Text and data in the object file are added to newly created text and data segments in the binary. Global symbols defined in the object file are compared against symbols in the binary file. If they match, the reference to these symbols in the binary are changed to symbols that came from the object file.
The code unit being added to the binary file 101 may be for all functional code units in the object file 103 or less than all of the functional code units. For example, after indicating the object file 103, the user may be prompted to select or input a function name to be incorporated into the binary file 101. If the entire object file is to be merged, of course some information is not carried along, such as header information.
The incorporated code may make calls to functions defined external to the binary, for example to a function that is in another shared library, such as malloc ( ) in libc. Modification may be performed to address such calls. For example, data structures, such as the procedure linkage table (PLT) may be modified to make such a call.
At block 206, the size of the binary file is updated to account for the code unit.
At block 207, it is determined if the binary file includes an entry in a procedure linkage table (PLT) for the externally defined symbol. Although this example refers to a PLT, those of ordinary skill in the art will appreciate that link tables for dynamic linking have various monikers, but essentially fulfill the same role. If the binary file PLT does not include a corresponding entry, then control flows to block 211. If the binary file does include a corresponding entry, then control flows to block 209.
At block 209, the reference in the code unit to the externally defined symbol is modified to reference the corresponding entry in the binary file PLT. Control flows from block 209 to block 206.
At block 211, the code unit marked for runtime relocation. Other techniques can be employed to reconcile the externally defined symbol. For example, instead of marking for runtime relocation, the code unit can be modified to utilize an available function that opens a particular path. The opened path is then searched for the object file that defines the externally defined symbol. For example, a call to an externally defined function is converted into a dynamic lookup, dlsym ( ). The call to the externally defined function is then made using the function pointer returned by dlsym ( ). If the symbol is not readily available, a dlopen ( ) may be required first. The dlopen ( ) may also be done as part of the initialization process in order to reduce the overhead of dlopen ( ) when the original function is called. Control flows from block 211 to block 206.
At block 405, a new entry is added to the binary file symbol table for the symbol. Control flows to block 409 from block 405.
At block 407, the symbol in the binary file symbol table is redefined in accordance with the corresponding symbol definition in the object file symbol table. However, the old definition for the symbol may not be overwritten. Preserving the old symbol definition allow redo. For example, a user may wish to do tests of functions without recompiling. If the test fails or produces undesirable results, then the old definition can be restored.
At block 409, if the symbol corresponds to a function (method, procedure, etc.), then any calls to the function in the binary file are modified to reference the location of the function within the binary file.
Incorporating functionality from an object file into an already existing binary file provides flexibility in code development. After shipping, a binary file can be modified with functionality written by a third party. Incorporating also reduces logistical overhead since fewer files need to be tracked. The single binary file includes any added object files. Moreover, modifications to the binary file can be performed without the source files.
The described embodiments may be provided as a computer program product, or software, that may include a machine-readable medium having stored thereon instructions, which may be used to program a computer system (or other electronic device(s)) to perform a process according to embodiments of the invention, whether presently described or not, since every conceivable variation is not enumerated herein. A machine readable medium includes any mechanism for storing or transmitting information in a form (e.g., software, processing application) readable by a machine (e.g., a computer). The machine-readable medium may include, but is not limited to, magnetic storage medium (e.g., floppy diskette); optical storage medium (e.g., CD-ROM); magneto-optical storage medium; read only memory (ROM); random access memory (RAM); erasable programmable memory (e.g., EPROM and EEPROM); flash memory; or other types of medium suitable for storing electronic instructions. In addition, embodiments may be embodied in an electrical, optical, acoustical or other form of propagated signal (e.g., carrier waves, infrared signals, digital signals, etc.), or wireline, wireless, or other communications medium.
While the invention(s) is (are) described with reference to various implementations and exploitations, it will be understood that these embodiments are illustrative and that the scope of the invention(s) is not limited to them. In general, techniques for deriving uncoverage information for code described herein may be implemented with facilities consistent with any hardware system or hardware systems hereafter defined. Many variations, modifications, additions, and improvements are possible.
Plural instances may be provided for components, operations or structures described herein as a single instance. Finally, boundaries between various components, operations and data stores are somewhat arbitrary, and particular operations are illustrated in the context of specific illustrative configurations. Other allocations of functionality are envisioned and may fall within the scope of the invention(s). In general, structures and functionality presented as separate components in the exemplary configurations may be implemented as a combined structure or component. Similarly, structures and functionality presented as a single component may be implemented as separate components. These and other variations, modifications, additions, and improvements may fall within the scope of the invention(s).