-
Notifications
You must be signed in to change notification settings - Fork 552
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
i#3348 sym conflicts: support not hiding symbols in static DR lib (#3411
) 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
- Loading branch information
1 parent
a1dbd0b
commit 0bbf5d5
Showing
7 changed files
with
262 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
# ********************************************************** | ||
# Copyright (c) 2019 Google, Inc. All rights reserved. | ||
# ********************************************************** | ||
|
||
# Redistribution and use in source and binary forms, with or without | ||
# modification, are permitted provided that the following conditions are met: | ||
# | ||
# * Redistributions of source code must retain the above copyright notice, | ||
# this list of conditions and the following disclaimer. | ||
# | ||
# * Redistributions in binary form must reproduce the above copyright notice, | ||
# this list of conditions and the following disclaimer in the documentation | ||
# and/or other materials provided with the distribution. | ||
# | ||
# * Neither the name of VMware, Inc. nor the names of its contributors may be | ||
# used to endorse or promote products derived from this software without | ||
# specific prior written permission. | ||
# | ||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
# ARE DISCLAIMED. IN NO EVENT SHALL VMWARE, INC. OR CONTRIBUTORS BE LIABLE | ||
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH | ||
# DAMAGE. | ||
|
||
# i#3348: Avoid symbol conflicts when linking DR statically. | ||
|
||
# Caller must set: | ||
# + "lib_fileloc" to /absolute/path/<name> that represents a file <name>.cmake that | ||
# contains a set(<name> <path>) where path is the target binary location. | ||
# + "READELF_EXECUTABLE" so it can be a cache variable | ||
# + "CMAKE_SYSTEM_PROCESSOR" | ||
|
||
include(${lib_fileloc}.cmake) | ||
|
||
get_filename_component(lib_file ${lib_fileloc} NAME) | ||
|
||
# Get the list of symbols. | ||
execute_process(COMMAND | ||
${READELF_EXECUTABLE} -s ${${lib_file}} | ||
RESULT_VARIABLE readelf_result | ||
ERROR_VARIABLE readelf_error | ||
OUTPUT_VARIABLE output | ||
) | ||
if (readelf_result OR readelf_error) | ||
message(FATAL_ERROR "*** ${READELF_EXECUTABLE} failed: ***\n${readelf_error}") | ||
endif (readelf_result OR readelf_error) | ||
|
||
# Limit to global defined symbols: no "UND". | ||
string(REGEX MATCHALL "([^\n]+ GLOBAL [A-Z]+ +[^U ]+ [^\n]+)\n" globals "${output}") | ||
|
||
# Now limit to single-word symbols, which are most likely to conflict. | ||
string(REGEX MATCHALL " [^_\\.]+\n" oneword "${globals}") | ||
|
||
string(REGEX MATCHALL "([^\n]+)\n" lines "${oneword}") | ||
foreach(line ${lines}) | ||
set(is_ok OFF) | ||
# We have some legacy exceptions we allow until we've renamed them all. | ||
if (line MATCHES "crc32\n" OR | ||
line MATCHES "debugRegister\n" OR | ||
line MATCHES "decode\n" OR | ||
line MATCHES "disassemble\n" OR | ||
line MATCHES "dispatch\n" OR | ||
line MATCHES "emulate\n" OR | ||
line MATCHES "extensions\n" OR | ||
line MATCHES "initstack\n" OR | ||
line MATCHES "loginst\n" OR | ||
line MATCHES "logopnd\n" OR | ||
line MATCHES "logtrace\n" OR | ||
line MATCHES "mangle\n" OR | ||
line MATCHES "MD5Final\n" OR | ||
line MATCHES "MD5Init\n" OR | ||
line MATCHES "MD5Update\n" OR | ||
line MATCHES "notify\n" OR | ||
line MATCHES "regparms\n" OR | ||
line MATCHES "stackdump\n" OR | ||
line MATCHES "stats\n") | ||
# OK: an exception we allow for now. | ||
set(is_ok ON) | ||
endif () | ||
if (CMAKE_SYSTEM_PROCESSOR MATCHES "^arm" OR | ||
CMAKE_SYSTEM_PROCESSOR MATCHES "^aarch64") | ||
if (line MATCHES "memcpy\n" OR | ||
line MATCHES "memset\n") | ||
# XXX i#3348: We need to remove these from the aarchxx builds too. | ||
set(is_ok ON) | ||
endif () | ||
endif () | ||
if (NOT is_ok) | ||
message(FATAL_ERROR | ||
"*** Error: ${${lib_file}} contains a likely-to-conflict symbol: ${line}") | ||
endif () | ||
endforeach() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* ********************************************************** | ||
* Copyright (c) 2019 Google, Inc. All rights reserved. | ||
* **********************************************************/ | ||
|
||
/* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are met: | ||
* | ||
* * Redistributions of source code must retain the above copyright notice, | ||
* this list of conditions and the following disclaimer. | ||
* | ||
* * Redistributions in binary form must reproduce the above copyright notice, | ||
* this list of conditions and the following disclaimer in the documentation | ||
* and/or other materials provided with the distribution. | ||
* | ||
* * Neither the name of Google, Inc. nor the names of its contributors may be | ||
* used to endorse or promote products derived from this software without | ||
* specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
* ARE DISCLAIMED. IN NO EVENT SHALL GOOGLE, INC. OR CONTRIBUTORS BE LIABLE | ||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH | ||
* DAMAGE. | ||
*/ | ||
|
||
/* Ensures that static DR does not produce symbol conflicts with the application. | ||
* We build with -Wl,--warn-common to get warnings about common symbols too. | ||
*/ | ||
|
||
#include "configure.h" | ||
#include "dr_api.h" | ||
#include "tools.h" | ||
|
||
/* We can't really test individual symbols very well here as a future-changes test | ||
* because we can only test those that have conflicted before, but we at least | ||
* test libc startup conflicts and general linking of the no-hide library. | ||
* CMake_symbol_check.cmake does more systematic checks. | ||
*/ | ||
|
||
#if 0 /* i#3348: Disabling until we rename these symbols. */ | ||
int *initstack = NULL; | ||
byte *initstack_app_xsp = NULL; | ||
|
||
bool | ||
is_on_initstack(void) | ||
{ | ||
print("in app's %s\n", __FUNCTION__); | ||
} | ||
|
||
void | ||
add_thread(void) | ||
{ | ||
print("in app's %s\n", __FUNCTION__); | ||
} | ||
#endif | ||
|
||
int | ||
pathcmp(void) | ||
{ | ||
print("in app's %s\n", __FUNCTION__); | ||
return 0; | ||
} | ||
|
||
void | ||
test_symbol_conflicts(void) | ||
{ | ||
#if 0 /* i#3348: Disabling until we rename these symbols. */ | ||
print("initstack is %p\n", initstack); | ||
initstack = NULL; | ||
#endif | ||
pathcmp(); | ||
} | ||
|
||
int | ||
main(int argc, const char *argv[]) | ||
{ | ||
print("pre-DR init\n"); | ||
dr_app_setup(); | ||
assert(!dr_app_running_under_dynamorio()); | ||
|
||
print("pre-DR start\n"); | ||
dr_app_start(); | ||
assert(dr_app_running_under_dynamorio()); | ||
|
||
test_symbol_conflicts(); | ||
|
||
print("pre-DR stop\n"); | ||
dr_app_stop_and_cleanup(); | ||
print("all done\n"); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
pre-DR init | ||
pre-DR start | ||
in app's pathcmp | ||
pre-DR stop | ||
all done |