You can link in an additional object file through the function.
LinkObjectFileNew(t_object * obj, t_string object_filename, t_string symbol_prefix, t_bool read_debug);
This function can be called after LinkEmulate
. The functions from object_filename are then known as symbol_prefix concatenated with the name of the function in the objectfile.
To prevent the newly added functions from being removed by unreachable code elimination, they should be passed in force_reachable
to
ObjectFlowgraph (t_object * obj, t_string * force_leader, t_string * force_reachable)
If you want the newly added functions to use a function from the original program, you need to create an alias the name of that function. For example, if the additional object file calls printf
, but does not define it, it can use the
printf
function of the original program by:
t_symbol * sym = SymbolTableGetSymbolByName (OBJECT_SUB_SYMBOL_TABLE(obj), "printf"); SymbolTableAddSymbolToSubSection(OBJECT_SUB_SYMBOL_TABLE(obj), SYMBOL_TYPE(sym), SYMBOL_BASE(sym), AddressAdd(SYMBOL_OFFSET_FROM_START(sym),SECTION_CADDRESS(SYMBOL_BASE(sym))), StringConcat2(symbol_prefix,"printf"), SYMBOL_LOCAL(sym));