tsan-dg.exp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. # Copyright (C) 2013-2015 Free Software Foundation, Inc.
  2. # This program is free software; you can redistribute it and/or modify
  3. # it under the terms of the GNU General Public License as published by
  4. # the Free Software Foundation; either version 3 of the License, or
  5. # (at your option) any later version.
  6. #
  7. # This program is distributed in the hope that it will be useful,
  8. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. # GNU General Public License for more details.
  11. #
  12. # You should have received a copy of the GNU General Public License
  13. # along with GCC; see the file COPYING3. If not see
  14. # <http://www.gnu.org/licenses/>.
  15. # Return 1 if compilation with -fsanitize=thread is error-free for trivial
  16. # code, 0 otherwise.
  17. proc check_effective_target_fsanitize_thread {} {
  18. return [check_runtime fsanitize_thread {
  19. int main (void) { return 0; }
  20. } "-fsanitize=thread"]
  21. }
  22. #
  23. # tsan_link_flags -- compute library path and flags to find libtsan.
  24. # (originally from g++.exp)
  25. #
  26. proc tsan_link_flags { paths } {
  27. global srcdir
  28. global ld_library_path
  29. global shlib_ext
  30. global tsan_saved_library_path
  31. set gccpath ${paths}
  32. set flags ""
  33. set shlib_ext [get_shlib_extension]
  34. set tsan_saved_library_path $ld_library_path
  35. if { $gccpath != "" } {
  36. if { [file exists "${gccpath}/libsanitizer/tsan/.libs/libtsan.a"]
  37. || [file exists "${gccpath}/libsanitizer/tsan/.libs/libtsan.${shlib_ext}"] } {
  38. append flags " -B${gccpath}/libsanitizer/tsan/ "
  39. append flags " -L${gccpath}/libsanitizer/tsan/.libs "
  40. append ld_library_path ":${gccpath}/libsanitizer/tsan/.libs"
  41. }
  42. } else {
  43. global tool_root_dir
  44. set libtsan [lookfor_file ${tool_root_dir} libtsan]
  45. if { $libtsan != "" } {
  46. append flags "-L${libtsan} "
  47. append ld_library_path ":${libtsan}"
  48. }
  49. }
  50. set_ld_library_path_env_vars
  51. return "$flags"
  52. }
  53. #
  54. # tsan_init -- called at the start of each subdir of tests
  55. #
  56. proc tsan_init { args } {
  57. global TEST_ALWAYS_FLAGS
  58. global ALWAYS_CXXFLAGS
  59. global TOOL_OPTIONS
  60. global tsan_saved_TEST_ALWAYS_FLAGS
  61. global tsan_saved_ALWAYS_CXXFLAGS
  62. global dg-do-what-default
  63. global tsan_saved_dg-do-what-default
  64. set link_flags ""
  65. if ![is_remote host] {
  66. if [info exists TOOL_OPTIONS] {
  67. set link_flags "[tsan_link_flags [get_multilibs ${TOOL_OPTIONS}]]"
  68. } else {
  69. set link_flags "[tsan_link_flags [get_multilibs]]"
  70. }
  71. }
  72. if [info exists dg-do-what-default] {
  73. set tsan_saved_dg-do-what-default ${dg-do-what-default}
  74. }
  75. if [info exists TEST_ALWAYS_FLAGS] {
  76. set tsan_saved_TEST_ALWAYS_FLAGS $TEST_ALWAYS_FLAGS
  77. }
  78. if [info exists ALWAYS_CXXFLAGS] {
  79. set tsan_saved_ALWAYS_CXXFLAGS $ALWAYS_CXXFLAGS
  80. set ALWAYS_CXXFLAGS [concat "{ldflags=$link_flags}" $ALWAYS_CXXFLAGS]
  81. set ALWAYS_CXXFLAGS [concat "{additional_flags=-fsanitize=thread -g}" $ALWAYS_CXXFLAGS]
  82. } else {
  83. if [info exists TEST_ALWAYS_FLAGS] {
  84. set TEST_ALWAYS_FLAGS "$link_flags -fsanitize=thread -g $TEST_ALWAYS_FLAGS"
  85. } else {
  86. set TEST_ALWAYS_FLAGS "$link_flags -fsanitize=thread -g"
  87. }
  88. }
  89. set dg-do-what-default run
  90. if { $link_flags != "" } {
  91. global individual_timeout
  92. # Lower timeout value in case test does not terminate properly.
  93. set individual_timeout 20
  94. if [check_runtime_nocache tsan_works {
  95. int main () { return 0; }
  96. } "-fsanitize=thread -g"] {
  97. set dg-do-what-default run
  98. } else {
  99. set dg-do-what-default compile
  100. }
  101. unset individual_timeout
  102. }
  103. }
  104. #
  105. # tsan_finish -- called at the end of each subdir of tests
  106. #
  107. proc tsan_finish { args } {
  108. global TEST_ALWAYS_FLAGS
  109. global tsan_saved_TEST_ALWAYS_FLAGS
  110. global tsan_saved_ALWAYS_CXXFLAGS
  111. global dg-do-what-default
  112. global tsan_saved_dg-do-what-default
  113. global tsan_saved_library_path
  114. global ld_library_path
  115. if [info exists tsan_saved_ALWAYS_CXXFLAGS ] {
  116. set ALWAYS_CXXFLAGS $tsan_saved_ALWAYS_CXXFLAGS
  117. } else {
  118. if [info exists tsan_saved_TEST_ALWAYS_FLAGS] {
  119. set TEST_ALWAYS_FLAGS $tsan_saved_TEST_ALWAYS_FLAGS
  120. } else {
  121. unset TEST_ALWAYS_FLAGS
  122. }
  123. }
  124. if [info exists tsan_saved_dg-do-what-default] {
  125. set dg-do-what-default ${tsan_saved_dg-do-what-default}
  126. } else {
  127. unset dg-do-what-default
  128. }
  129. set ld_library_path $tsan_saved_library_path
  130. set_ld_library_path_env_vars
  131. }