Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
llvm-epi
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Roger Ferrer
llvm-epi
Commits
85bd73d2
Commit
85bd73d2
authored
12 years ago
by
Alexey Samsonov
Browse files
Options
Downloads
Patches
Plain Diff
[ASan] Support building both 32- and 64-bit unit tests if we can target both architectures
llvm-svn: 170549
parent
dcdeecb2
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
compiler-rt/CMakeLists.txt
+10
-0
10 additions, 0 deletions
compiler-rt/CMakeLists.txt
compiler-rt/lib/asan/tests/CMakeLists.txt
+39
-35
39 additions, 35 deletions
compiler-rt/lib/asan/tests/CMakeLists.txt
with
49 additions
and
35 deletions
compiler-rt/CMakeLists.txt
+
10
−
0
View file @
85bd73d2
...
@@ -40,6 +40,16 @@ else()
...
@@ -40,6 +40,16 @@ else()
set
(
TARGET_I386_CFLAGS
"-m32"
)
set
(
TARGET_I386_CFLAGS
"-m32"
)
endif
()
endif
()
function
(
get_target_flags_for_arch arch out_var
)
if
(
${
arch
}
STREQUAL
"x86_64"
)
set
(
${
out_var
}
${
TARGET_X86_64_CFLAGS
}
PARENT_SCOPE
)
elseif
(
${
arch
}
STREQUAL
"i386"
)
set
(
${
out_var
}
${
TARGET_I386_CFLAGS
}
PARENT_SCOPE
)
else
()
message
(
FATAL_ERROR
"Unsupported architecture:
${
arch
}
"
)
endif
()
endfunction
()
# Try to compile a very simple source file to ensure we can target the given
# Try to compile a very simple source file to ensure we can target the given
# platform. We use the results of these tests to build only the various target
# platform. We use the results of these tests to build only the various target
# runtime libraries supported by our current compilers cross-compiling
# runtime libraries supported by our current compilers cross-compiling
...
...
This diff is collapsed.
Click to expand it.
compiler-rt/lib/asan/tests/CMakeLists.txt
+
39
−
35
View file @
85bd73d2
...
@@ -61,15 +61,6 @@ endif()
...
@@ -61,15 +61,6 @@ endif()
# Unit tests require libstdc++.
# Unit tests require libstdc++.
list
(
APPEND ASAN_LINK_FLAGS -lstdc++
)
list
(
APPEND ASAN_LINK_FLAGS -lstdc++
)
# Support 64-bit and 32-bit builds.
if
(
LLVM_BUILD_32_BITS
)
list
(
APPEND ASAN_UNITTEST_COMMON_CFLAGS -m32
)
list
(
APPEND ASAN_LINK_FLAGS -m32
)
else
()
list
(
APPEND ASAN_UNITTEST_COMMON_CFLAGS -m64
)
list
(
APPEND ASAN_LINK_FLAGS -m64
)
endif
()
set
(
ASAN_BLACKLIST_FILE
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/asan_test.ignore"
)
set
(
ASAN_BLACKLIST_FILE
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/asan_test.ignore"
)
set
(
ASAN_UNITTEST_INSTRUMENTED_CFLAGS
set
(
ASAN_UNITTEST_INSTRUMENTED_CFLAGS
...
@@ -83,25 +74,28 @@ set(ASAN_UNITTEST_INSTRUMENTED_CFLAGS
...
@@ -83,25 +74,28 @@ set(ASAN_UNITTEST_INSTRUMENTED_CFLAGS
-mllvm -asan-use-after-return=0
-mllvm -asan-use-after-return=0
)
)
# Compile source
and add it to the object list
using compiler
# Compile source
for the given architecture,
using compiler
# options in ${ARGN}.
# options in ${ARGN}
, and add it to the object list
.
macro
(
asan_compile obj_list source
)
macro
(
asan_compile obj_list source
arch
)
get_filename_component
(
basename
${
source
}
NAME
)
get_filename_component
(
basename
${
source
}
NAME
)
set
(
output_obj
"
${
basename
}
.o"
)
set
(
output_obj
"
${
basename
}
.
${
arch
}
.o"
)
get_target_flags_for_arch
(
${
arch
}
TARGET_CFLAGS
)
clang_compile
(
${
output_obj
}
${
source
}
clang_compile
(
${
output_obj
}
${
source
}
CFLAGS
${
ARGN
}
CFLAGS
${
ARGN
}
${
TARGET_CFLAGS
}
DEPS gtest
${
ASAN_RUNTIME_LIBRARIES
}
DEPS gtest
${
ASAN_RUNTIME_LIBRARIES
}
${
ASAN_BLACKLIST_FILE
}
)
${
ASAN_BLACKLIST_FILE
}
)
list
(
APPEND
${
obj_list
}
${
output_obj
}
)
list
(
APPEND
${
obj_list
}
${
output_obj
}
)
endmacro
()
endmacro
()
# Link ASan unit test from a set of objects in ${ARGN}.
# Link ASan unit test for a given architecture from a set
macro
(
add_asan_test test_suite test_name
)
# of objects in ${ARGN}.
message
(
STATUS
"Link flags:
${
ASAN_LINK_FLAGS
}
"
)
macro
(
add_asan_test test_suite test_name arch
)
get_target_flags_for_arch
(
${
arch
}
TARGET_LINK_FLAGS
)
add_compiler_rt_test
(
${
test_suite
}
${
test_name
}
add_compiler_rt_test
(
${
test_suite
}
${
test_name
}
OBJECTS
${
ARGN
}
OBJECTS
${
ARGN
}
DEPS
${
ASAN_RUNTIME_LIBRARIES
}
DEPS
${
ASAN_RUNTIME_LIBRARIES
}
LINK_FLAGS
${
ASAN_LINK_FLAGS
}
)
LINK_FLAGS
${
ASAN_LINK_FLAGS
}
${
TARGET_LINK_FLAGS
}
)
endmacro
()
endmacro
()
# Main AddressSanitizer unit tests.
# Main AddressSanitizer unit tests.
...
@@ -111,43 +105,53 @@ set_target_properties(AsanUnitTests PROPERTIES FOLDER "ASan unit tests")
...
@@ -111,43 +105,53 @@ set_target_properties(AsanUnitTests PROPERTIES FOLDER "ASan unit tests")
add_custom_target
(
AsanBenchmarks
)
add_custom_target
(
AsanBenchmarks
)
set_target_properties
(
AsanBenchmarks PROPERTIES FOLDER
"Asan benchmarks"
)
set_target_properties
(
AsanBenchmarks PROPERTIES FOLDER
"Asan benchmarks"
)
# We only support building instrumented tests when we're not cross compiling
# Adds ASan unit tests and benchmarks for architecture.
# and targeting a unix-like system where we can predict viable compilation and
macro
(
add_asan_tests_for_arch arch
)
# linking strategies.
# We use a different approach to build these tests for Android. See below.
if
(
"
${
CMAKE_HOST_SYSTEM
}
"
STREQUAL
"
${
CMAKE_SYSTEM
}
"
AND UNIX AND NOT ANDROID
)
# Build gtest instrumented with ASan.
# Build gtest instrumented with ASan.
set
(
ASAN_INST_GTEST
)
set
(
ASAN_INST_GTEST
)
asan_compile
(
ASAN_INST_GTEST
${
COMPILER_RT_GTEST_SOURCE
}
asan_compile
(
ASAN_INST_GTEST
${
COMPILER_RT_GTEST_SOURCE
}
${
arch
}
${
ASAN_UNITTEST_INSTRUMENTED_CFLAGS
}
)
${
ASAN_UNITTEST_INSTRUMENTED_CFLAGS
}
)
# Instrumented tests.
# Instrumented tests.
set
(
ASAN_INST_TEST_OBJECTS
)
set
(
ASAN_INST_TEST_OBJECTS
)
asan_compile
(
ASAN_INST_TEST_OBJECTS asan_globals_test.cc
asan_compile
(
ASAN_INST_TEST_OBJECTS asan_globals_test.cc
${
arch
}
${
ASAN_UNITTEST_INSTRUMENTED_CFLAGS
}
)
${
ASAN_UNITTEST_INSTRUMENTED_CFLAGS
}
)
asan_compile
(
ASAN_INST_TEST_OBJECTS asan_test.cc
asan_compile
(
ASAN_INST_TEST_OBJECTS asan_test.cc
${
arch
}
${
ASAN_UNITTEST_INSTRUMENTED_CFLAGS
}
)
${
ASAN_UNITTEST_INSTRUMENTED_CFLAGS
}
)
if
(
APPLE
)
if
(
APPLE
)
asan_compile
(
ASAN_INST_TEST_OBJECTS asan_mac_test.mm
asan_compile
(
ASAN_INST_TEST_OBJECTS asan_mac_test.mm
${
arch
}
${
ASAN_UNITTEST_INSTRUMENTED_CFLAGS
}
-ObjC
)
${
ASAN_UNITTEST_INSTRUMENTED_CFLAGS
}
-ObjC
)
endif
()
endif
()
# Uninstrumented tests.
# Uninstrumented tests.
set
(
ASAN_NOINST_TEST_OBJECTS
)
set
(
ASAN_NOINST_TEST_OBJECTS
)
asan_compile
(
ASAN_NOINST_TEST_OBJECTS asan_noinst_test.cc
asan_compile
(
ASAN_NOINST_TEST_OBJECTS asan_noinst_test.cc
${
arch
}
${
ASAN_UNITTEST_COMMON_CFLAGS
}
)
${
ASAN_UNITTEST_COMMON_CFLAGS
}
)
asan_compile
(
ASAN_NOINST_TEST_OBJECTS asan_test_main.cc
asan_compile
(
ASAN_NOINST_TEST_OBJECTS asan_test_main.cc
${
arch
}
${
ASAN_UNITTEST_COMMON_CFLAGS
}
)
${
ASAN_UNITTEST_COMMON_CFLAGS
}
)
# Link everything together.
# Link everything together.
add_asan_test
(
AsanUnitTests AsanTest
${
ASAN_NOINST_TEST_OBJECTS
}
add_asan_test
(
AsanUnitTests
"Asan-
${
arch
}
-Test"
${
arch
}
${
ASAN_NOINST_TEST_OBJECTS
}
${
ASAN_INST_TEST_OBJECTS
}
${
ASAN_INST_GTEST
}
)
${
ASAN_INST_TEST_OBJECTS
}
${
ASAN_INST_GTEST
}
)
# Instrumented benchmarks.
# Instrumented benchmarks.
set
(
ASAN_BENCHMARKS_OBJECTS
)
set
(
ASAN_BENCHMARKS_OBJECTS
)
asan_compile
(
ASAN_BENCHMARKS_OBJECTS asan_benchmarks_test.cc
asan_compile
(
ASAN_BENCHMARKS_OBJECTS asan_benchmarks_test.cc
${
arch
}
${
ASAN_UNITTEST_INSTRUMENTED_CFLAGS
}
)
${
ASAN_UNITTEST_INSTRUMENTED_CFLAGS
}
)
# Link benchmarks.
# Link benchmarks.
add_asan_test
(
AsanBenchmarks AsanBenchmark
${
ASAN_BENCHMARKS_OBJECTS
}
add_asan_test
(
AsanBenchmarks
"Asan-
${
arch
}
-Benchmark"
${
arch
}
${
ASAN_INST_GTEST
}
)
${
ASAN_BENCHMARKS_OBJECTS
}
${
ASAN_INST_GTEST
}
)
endmacro
()
# We only support building instrumented tests when we're not cross compiling
# and targeting a unix-like system where we can predict viable compilation and
# linking strategies.
# We use a different approach to build these tests for Android. See below.
if
(
"
${
CMAKE_HOST_SYSTEM
}
"
STREQUAL
"
${
CMAKE_SYSTEM
}
"
AND UNIX AND NOT ANDROID
)
if
(
CAN_TARGET_X86_64
)
add_asan_tests_for_arch
(
x86_64
)
endif
()
if
(
CAN_TARGET_I386
)
add_asan_tests_for_arch
(
i386
)
endif
()
endif
()
endif
()
if
(
ANDROID
)
if
(
ANDROID
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment