-
Notifications
You must be signed in to change notification settings - Fork 571
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rename all global symbols to avoid conflicts when used as a static library #3348
Comments
We're de-prioritizing any large step of renaming all symbols, in favor of incremental tackling of likely-to-conflict symbols: mem{set,cpy,move} (xref #3315), perhaps a few others. For mem*, since we can't easily rename the implicit ones, it may be safe to have a statically-linked DR use compiler-provided versions. These should be re-entrant, and shared DR mostly just wants to avoid imports, rather than having a worry about transparency from non-re-entrant functions. |
As mentioned for #3315 which removed memcpy and memset from static DR: there is a downside to having static DR use libc functions. They can be intercepted, such as by sanitizer tools. There are other interoperability issues with such tools, though, so we live with the potential problem of |
If we remove the objcopy --localize-hidden step, we hit duplicate symbol errors:
So it looks like we may need to solve #1409 and separate out a library with module_get_platform() and os_read(). |
For renames: the plan is to rename only single-word or likely-to-conflict double-word symbols (where underscores divide words), and as mentioned above to not attempt to rename the world. "d_r_" is another candidate prefix for renames. |
The one-word global symbol names in the core library (the ones most likely to conflict) after removing memcpy and memset (this is with a local change to create a _nohide version for testing purposes):
For the string routines, we have two choices: one is to mirror memcpy and make a "strfuncs" library that others can omit. The other is to mirror snprintf which is renamed to our_snprintf. The latter seems the better choice. It may be better long-term to explicitly call the our_str* (or _d_r_str*, however named) or we can minimize code churn by renamed via macro as is done for snprintf (partly b/c of Windows names complicating things). As part of that we'll have to remove |
Another complication: what about __strncpy_chk and the other _chk versions, |
I'm going with
|
Rename our_*snprintf* to d_r_*snprintf* per the new global variable naming policy. Rename our_*sscanf to d_r_*sscanf. Rename DR's internal string routines to use a d_r_ prefix to reduce name conflicts with static linking. Because on Windows we still want to use the standard names (because we import from ntdll), we resort to macro renames within core/ just like we're doing with snprintf. Remove includes of string.h in core/ to avoid macros and inlined functions pulling in libc functions, now that our versions use different names. Issue: #3348
Rename our_*snprintf* to d_r_*snprintf* per the new global variable naming policy. Rename our_*sscanf to d_r_*sscanf. Rename DR's internal string routines to use a d_r_ prefix to reduce name conflicts with static linking. Because on Windows we still want to use the standard names (because we import from ntdll), we resort to macro renames within core/ just like we're doing with snprintf. Remove includes of string.h in core/ to avoid macros and inlined functions pulling in libc functions, now that our versions use different names. Links string.c and io.c into drdecode. Issue: #3348
Adds a new dynamorio_static_nohide library which is only built when tests are built. It is used for sanity checks on global symbol names for better interoperability with toolchains where objcopy --localize-hidden is a pain point. Renames core/CMake_globalize_pic_thunks.cmake to core/CMake_finalize_static_lib.cmake to better reflect the multiple steps it is taking beyond just the thunks. Adds a new test api.static_symbols of linking dynamorio_static_nohide. Adds a new post-build step that runs a new script CMake_symbol_check.cmake which looks for likely-to-conflict symbols in dynamorio_static_nohide. Issue: #3348
) Adds a new dynamorio_static_nohide library which is only built when tests are built. It is used for sanity checks on global symbol names for better interoperability with toolchains where objcopy --localize-hidden is a pain point. Renames core/CMake_globalize_pic_thunks.cmake to core/CMake_finalize_static_lib.cmake to better reflect the multiple steps it is taking beyond just the thunks. Adds a new test api.static_symbols of linking dynamorio_static_nohide. Adds a new post-build step that runs a new script CMake_symbol_check.cmake which looks for likely-to-conflict symbols in dynamorio_static_nohide. Issue: #3348
Adds a weak d_r_strncmp in drlibc to fix a Mac link error in non-core uses of drlibc. Issue: #3348
Adds a weak d_r_strncmp in drlibc to fix a Mac link error in non-core uses of drlibc. Issue: #3348
Renames several single-word global symbols to help reduce the chance of name conflicts: + s/debugRegister/d_r_debug_register/ + s/crc32/d_r_crc32/ + s/dispatch/d_r_dispatch/ + s/emulate/d_r_emulate/ + s/extensions/base_extensions/ Issue: #3348
Renames several single-word global symbols to help reduce the chance of name conflicts: + s/debugRegister/d_r_debug_register/ + s/crc32/d_r_crc32/ + s/dispatch/d_r_dispatch/ + s/emulate/d_r_emulate/ + s/extensions/base_extensions/ Issue: #3348
Renames more single-word global symbols to help reduce the chance of name conflicts: + s/initstack/d_r_initstack/ + s/loginst/d_r_loginst/ + s/logopnd/d_r_logopnd/ + s/logtrace/d_r_logtrace/ + s/mangle/d_r_mangle/ + s/mangle/d_r_mangle/ + s/MD5Init/d_r_md5_init/ + s/MD5Final/d_r_md5_final/ + s/MD5Update/d_r_md5_update/ + s/notify/d_r_notify/ + s/stackdump/d_r_stackdump/ + s/stats/d_r_stats/ Issue: #3348
Renames more single-word global symbols to help reduce the chance of name conflicts: + s/initstack/d_r_initstack/ + s/loginst/d_r_loginst/ + s/logopnd/d_r_logopnd/ + s/logtrace/d_r_logtrace/ + s/mangle/d_r_mangle/ + s/mangle/d_r_mangle/ + s/MD5Init/d_r_md5_init/ + s/MD5Final/d_r_md5_final/ + s/MD5Update/d_r_md5_update/ + s/notify/d_r_notify/ + s/stackdump/d_r_stackdump/ + s/stats/d_r_stats/ Issue: #3348
Renames multi-word global symbols with popular names in other software to help reduce the chance of name conflicts: s/config_{in,ex}it/d_r_config_{in,ex}it/ s/mutex_lock/d_r_mutex_lock/ s/mutex_unlock/d_r_mutex_unlock/ s/mutex_trylock/d_r_mutex_trylock/ s/mutex_delete/d_r_mutex_delete/ s/mutex_lock_app/d_r_mutex_lock_app/ s/mutex_mark_as_app/d_r_mutex_mark_as_app/ s/mutex_fork_reset/d_r_mutex_fork_reset/ s/read_lock/d_r_read_lock/ s/write_lock/d_r_write_lock/ s/write_unlock/d_r_write_unlock/ s/read_unlock/d_r_read_unlock/ s/write_trylock/d_r_write_trylock/ s/parse_word/d_r_parse_word/ s/parse_int/d_r_parse_int/ s/print_timestamp/d_r_print_timestamp/ s/get_thread_id/d_r_get_thread_id/ s/internal_error/d_r_internal_error/ s/safe_read/d_r_safe_read/ Issue: #3348
Renames multi-word global symbols with popular names in other software to help reduce the chance of name conflicts: s/config_{in,ex}it/d_r_config_{in,ex}it/ s/mutex_lock/d_r_mutex_lock/ s/mutex_unlock/d_r_mutex_unlock/ s/mutex_trylock/d_r_mutex_trylock/ s/mutex_delete/d_r_mutex_delete/ s/mutex_lock_app/d_r_mutex_lock_app/ s/mutex_mark_as_app/d_r_mutex_mark_as_app/ s/mutex_fork_reset/d_r_mutex_fork_reset/ s/read_lock/d_r_read_lock/ s/write_lock/d_r_write_lock/ s/write_unlock/d_r_write_unlock/ s/read_unlock/d_r_read_unlock/ s/write_trylock/d_r_write_trylock/ s/parse_word/d_r_parse_word/ s/parse_int/d_r_parse_int/ s/print_timestamp/d_r_print_timestamp/ s/get_thread_id/d_r_get_thread_id/ s/internal_error/d_r_internal_error/ s/safe_read/d_r_safe_read/ Issue: #3348
Renames more global variables whose names are popular in other third-party C libraries: + s/get_parameter/d_r_get_parameter/ + s/get_proc_address/d_r_get_proc_address/ + s/print_log/d_r_print_log/ + s/map_file/d_r_map_file/ + s/unmap_file/d_r_unmap_file/ + s/get_tls/d_r_get_tls/ + s/set_tls/d_r_set_tls/ + s/get_num_threads/d_r_get_num_threads/ + s/get_random_seed/d_r_get_random_seed/ + s/set_random_seed/d_r_set_random_seed/ + s/heap_init/d_r_heap_init/ + s/heap_exit/d_r_heap_exit/ + s/decode_init/d_r_decode_init/ + s/monitor_init/d_r_monitor_init/ + s/monitor_exit/d_r_monitor_exit/ + s/os_init/d_r_os_init/ + s/os_exit/d_r_os_exit/ + s/signal_init/d_r_signal_init/ + s/signal_exit/d_r_signal_exit/ + s/link_init/d_r_link_init/ + s/link_exit/d_r_link_exit/ + s/arch_init/d_r_arch_init/ + s/arch_exit/d_r_arch_exit/ Issue: #3348
Renames more global variables whose names are popular in other third-party C libraries: + s/get_parameter/d_r_get_parameter/ + s/get_proc_address/d_r_get_proc_address/ + s/print_log/d_r_print_log/ + s/map_file/d_r_map_file/ + s/unmap_file/d_r_unmap_file/ + s/get_tls/d_r_get_tls/ + s/set_tls/d_r_set_tls/ + s/get_num_threads/d_r_get_num_threads/ + s/get_random_seed/d_r_get_random_seed/ + s/set_random_seed/d_r_set_random_seed/ + s/heap_init/d_r_heap_init/ + s/heap_exit/d_r_heap_exit/ + s/decode_init/d_r_decode_init/ + s/monitor_init/d_r_monitor_init/ + s/monitor_exit/d_r_monitor_exit/ + s/os_init/d_r_os_init/ + s/os_exit/d_r_os_exit/ + s/signal_init/d_r_signal_init/ + s/signal_exit/d_r_signal_exit/ + s/link_init/d_r_link_init/ + s/link_exit/d_r_link_exit/ + s/arch_init/d_r_arch_init/ + s/arch_exit/d_r_arch_exit/ Issue: #3348
Provides isolation of mem{cpy,set,move} in the DR static library on AArchXX. Moves the assembly mem{cpy,set} into a separate memfuncs.asm for arm and aarch64, and links in memmove.c. Marks the __mem{cpy,set}_chk aliases as weak. This brings AArchXX into parity with x86 on library symbol isolation. Removes the exceptions for AArchXX in the CMake_symbol_check test. Confirms the build-time test fails without the code changes here: CMake Error at xxx/core/CMake_symbol_check.cmake:98 (message): *** Error: xxx/build_a64_dbg_tests/lib64/debug/libdynamorio_static_nohide.a contains a likely-to-conflict symbol: 4279: 00000000002cea3c 0 FUNC GLOBAL HIDDEN 248 memcpy Issue: #3315, #3348
Provides isolation of mem{cpy,set,move} in the DR static library on AArchXX. Moves the assembly mem{cpy,set} into a separate memfuncs.asm for arm and aarch64, and links in memmove.c. Marks the __mem{cpy,set}_chk aliases as weak. This brings AArchXX into parity with x86 on library symbol isolation. Removes the exceptions for AArchXX in the CMake_symbol_check test. Confirms the build-time test fails without the code changes here: CMake Error at xxx/core/CMake_symbol_check.cmake:98 (message): *** Error: xxx/build_a64_dbg_tests/lib64/debug/libdynamorio_static_nohide.a contains a likely-to-conflict symbol: 4279: 00000000002cea3c 0 FUNC GLOBAL HIDDEN 248 memcpy Issue: #3315, #3348
Fixes a symbol conflict with a python package PyTables that is hit when statically linking with certain toolchains where non-exported symbol hiding is not available. The fix is to rename set_cache_size() to proc_set_cache_size(). This also matches the proc_ prefix for related functions, so we do not resort to the d_r_ prefix. Issue: #3348
…5276) Fixes a symbol conflict with a python package PyTables that is hit when statically linking with certain toolchains where non-exported symbol hiding is not available. The fix is to rename set_cache_size() to proc_set_cache_size(). This also matches the proc_ prefix for related functions, so we do not resort to the d_r_ prefix. Issue: #3348
Renames dynamorio_static_nohide to dynamorio_static and deprecates the version where we hide DR symbols using hide_symbols. Removes tobuild_static_nohide_api, since now all static libs use the nohide variant. Documents hide_symbols as unsafe because it may lead to confusing linking behavior. Issue: #5570, #3348
Renames dynamorio_static_nohide to dynamorio_static and deprecates the version where we hide DR symbols using hide_symbols. Removes tobuild_static_nohide_api, since now all static libs use the nohide variant. Documents hide_symbols as unsafe because it may lead to confusing linking behavior. Issue: #5570, #3348
Renames dynamorio_static_nohide to dynamorio_static and deprecates the version where we hide DR symbols using hide_symbols. Removes tobuild_static_nohide_api, since now all static libs use the nohide variant. Documents hide_symbols as unsafe because it may lead to confusing linking behavior. Issue: #5570, #3348
To avoid symbol conflicts with IN, OUT, and INOUT, which are defined in our exported headers, we add DR_PARAM_ to the front. Issue: #3348
To avoid symbol conflicts with IN, OUT, and INOUT, which are defined in our exported headers, we add DR_PARAM_ to the front. The aarch64 codec.c was left as the shorter names since the aarch64_check_codec_order.py assumes single-line signatures. Issue: #3348
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:
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.
The text was updated successfully, but these errors were encountered: