Rename all global symbols to avoid conflicts when used as a static library
Xref #975. We're using DR as a static library more and more these days, and the current solution for hiding its global symbols, running objcopy --localize-hidden
, is a fragile post-link step that conflicts with other build steps such as lld's ICF and which can break when used in complex build configurations.
This issue is a proposal to rename all of DR's global symbols (i.e., everything not file-static) to dramatically reduce the risk of symbol conflicts when statically linked into large applications.
We would leave alone all of the symbols exported as part of the API. Unfortunately these have a variety of prefixes but at least they have prefixes:
$ nm lib64/release/libdynamorio_static.a | grep ' T ' | awk '{print $3}' | perl -p -e 's/^([a-zA-Z0-9]+)_.*/\1/' | sort | uniq -c
10 decode
5 disassemble
311 dr
3 dynamorio
3 get
184 instr
35 instrlist
93 opnd
21 proc
26 reg
1 set
1 __wrap_calloc
1 __wrap_free
1 __wrap_malloc
1 __wrap_realloc
$ nm lib64/release/libdynamorio_static.a | grep ' T ' | awk '{print $3}' | grep '^[gs]et'
get_application_short_name
get_register_name
get_x86_mode
set_x86_mode
Moving on to the non-API routines, there are thousands of them, including functions and variables. Some thoughts on renaming rules:
"dr_": a simple prefix, except today it means "exported for API" and we have several instances of "dr_foo" exported and "foo" internally: e.g., internal "safe_read" and interface "dr_safe_read". So how do we rename the internal one?
"dri_": where "i" means internal.
Sthg specific to the module? "drinterp_xxx", "drvm_xxx", "drxl8_xxx", etc.
"dr__" or "_dr": these violate the C/C++ standards which say no double underscores anywhere, no leading single underscore plus capital letter anywhere, and no leading underscore in global symbols.
Could do a single underscore suffix: arch_init_(), clean_call_opt_exit_(), add_dynamo_vm_area_(), executable_areas_. More of a minimal change. It would mean "global but not in API". Could combine it with a "dr_" prefix.