Skip to content

Commit

Permalink
[compiler-rt] Respect CMAKE_NM
Browse files Browse the repository at this point in the history
The default nm executable may not be able to handle the architecture
we're building the sanitizers for. Respect CMAKE_NM if it's set to
ensure we're using the correct nm tool. Preserve the existing NM
environment variable override to not break its users.

Differential Revision: https://reviews.llvm.org/D63368

llvm-svn: 363483
  • Loading branch information
smeenai committed Jun 15, 2019
1 parent 968b5f8 commit 744870f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
10 changes: 8 additions & 2 deletions compiler-rt/cmake/Modules/SanitizerUtils.cmake
Expand Up @@ -6,6 +6,12 @@ set(SANITIZER_GEN_DYNAMIC_LIST
set(SANITIZER_LINT_SCRIPT
${COMPILER_RT_SOURCE_DIR}/lib/sanitizer_common/scripts/check_lint.sh)

if(CMAKE_NM)
set(SANITIZER_NM "${CMAKE_NM}")
else()
set(SANITIZER_NM nm)
endif()

# Create a target "<name>-<arch>-symbols" that would generate the list of
# symbols that need to be exported from sanitizer runtime "<name>". Function
# interceptors are exported automatically, user can also provide files with
Expand All @@ -30,7 +36,7 @@ macro(add_sanitizer_rt_symbols name)
add_custom_command(OUTPUT ${stamp}
COMMAND ${PYTHON_EXECUTABLE}
${SANITIZER_GEN_DYNAMIC_LIST} ${extra_args} $<TARGET_FILE:${target_name}>
-o $<TARGET_FILE:${target_name}>.syms
--nm-executable "${SANITIZER_NM}" -o $<TARGET_FILE:${target_name}>.syms
COMMAND ${CMAKE_COMMAND} -E touch ${stamp}
DEPENDS ${target_name} ${SANITIZER_GEN_DYNAMIC_LIST} ${ARG_EXTRA}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
Expand Down Expand Up @@ -80,7 +86,7 @@ macro(add_sanitizer_rt_version_list name)
add_custom_command(OUTPUT ${vers}
COMMAND ${PYTHON_EXECUTABLE}
${SANITIZER_GEN_DYNAMIC_LIST} --version-list ${args}
-o ${vers}
--nm-executable "${SANITIZER_NM}" -o ${vers}
DEPENDS ${SANITIZER_GEN_DYNAMIC_LIST} ${ARG_EXTRA} ${ARG_LIBS}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Generating version list for ${name}"
Expand Down
7 changes: 4 additions & 3 deletions compiler-rt/lib/sanitizer_common/scripts/gen_dynamic_list.py
Expand Up @@ -61,9 +61,9 @@
'pthread_cond_wait', 'realpath',
'sched_getaffinity'])

def get_global_functions(library):
def get_global_functions(nm_executable, library):
functions = []
nm = os.environ.get('NM', 'nm')
nm = os.environ.get('NM', nm_executable)
nm_proc = subprocess.Popen([nm, library], stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
nm_out = nm_proc.communicate()[0].decode().split('\n')
Expand All @@ -84,14 +84,15 @@ def main(argv):
parser.add_argument('--version-list', action='store_true')
parser.add_argument('--extra', default=[], action='append')
parser.add_argument('libraries', default=[], nargs='+')
parser.add_argument('--nm-executable', required=True)
parser.add_argument('-o', '--output', required=True)
args = parser.parse_args()

result = []

all_functions = []
for library in args.libraries:
all_functions.extend(get_global_functions(library))
all_functions.extend(get_global_functions(args.nm_executable, library))
function_set = set(all_functions)
for func in all_functions:
# Export new/delete operators.
Expand Down

0 comments on commit 744870f

Please sign in to comment.