ubsan-dg.exp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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=undefined is error-free for trivial
  16. # code, 0 otherwise.
  17. proc check_effective_target_fsanitize_undefined {} {
  18. return [check_runtime fsanitize_undefined {
  19. int main (void) { return 0; }
  20. } "-fsanitize=undefined"]
  21. }
  22. #
  23. # ubsan_link_flags -- compute library path and flags to find libubsan.
  24. # (originally from g++.exp)
  25. #
  26. proc ubsan_link_flags { paths } {
  27. global srcdir
  28. global ld_library_path
  29. global shlib_ext
  30. global ubsan_saved_library_path
  31. set gccpath ${paths}
  32. set flags ""
  33. set shlib_ext [get_shlib_extension]
  34. set ubsan_saved_library_path $ld_library_path
  35. if { $gccpath != "" } {
  36. if { [file exists "${gccpath}/libsanitizer/ubsan/.libs/libubsan.a"]
  37. || [file exists "${gccpath}/libsanitizer/ubsan/.libs/libubsan.${shlib_ext}"] } {
  38. append flags " -B${gccpath}/libsanitizer/ "
  39. append flags " -B${gccpath}/libsanitizer/ubsan/ "
  40. append flags " -L${gccpath}/libsanitizer/ubsan/.libs"
  41. append ld_library_path ":${gccpath}/libsanitizer/ubsan/.libs"
  42. append ld_library_path ":${gccpath}/libstdc++-v3/src/.libs"
  43. }
  44. } else {
  45. global tool_root_dir
  46. set libubsan [lookfor_file ${tool_root_dir} libubsan]
  47. if { $libubsan != "" } {
  48. append flags "-L${libubsan} "
  49. append ld_library_path ":${libubsan}"
  50. }
  51. }
  52. set_ld_library_path_env_vars
  53. return "$flags"
  54. }
  55. #
  56. # ubsan_init -- called at the start of each subdir of tests
  57. #
  58. proc ubsan_init { args } {
  59. global TEST_ALWAYS_FLAGS
  60. global ALWAYS_CXXFLAGS
  61. global TOOL_OPTIONS
  62. global ubsan_saved_TEST_ALWAYS_FLAGS
  63. global ubsan_saved_ALWAYS_CXXFLAGS
  64. set link_flags ""
  65. if ![is_remote host] {
  66. if [info exists TOOL_OPTIONS] {
  67. set link_flags "[ubsan_link_flags [get_multilibs ${TOOL_OPTIONS}]]"
  68. } else {
  69. set link_flags "[ubsan_link_flags [get_multilibs]]"
  70. }
  71. }
  72. if [info exists TEST_ALWAYS_FLAGS] {
  73. set ubsan_saved_TEST_ALWAYS_FLAGS $TEST_ALWAYS_FLAGS
  74. }
  75. if [info exists ALWAYS_CXXFLAGS] {
  76. set ubsan_saved_ALWAYS_CXXFLAGS $ALWAYS_CXXFLAGS
  77. set ALWAYS_CXXFLAGS [concat "{ldflags=$link_flags}" $ALWAYS_CXXFLAGS]
  78. } else {
  79. if [info exists TEST_ALWAYS_FLAGS] {
  80. set TEST_ALWAYS_FLAGS "$link_flags $TEST_ALWAYS_FLAGS"
  81. } else {
  82. set TEST_ALWAYS_FLAGS "$link_flags"
  83. }
  84. }
  85. }
  86. #
  87. # ubsan_finish -- called at the end of each subdir of tests
  88. #
  89. proc ubsan_finish { args } {
  90. global TEST_ALWAYS_FLAGS
  91. global ubsan_saved_TEST_ALWAYS_FLAGS
  92. global ubsan_saved_ALWAYS_CXXFLAGS
  93. global ubsan_saved_library_path
  94. global ld_library_path
  95. if [info exists ubsan_saved_ALWAYS_CXXFLAGS ] {
  96. set ALWAYS_CXXFLAGS $ubsan_saved_ALWAYS_CXXFLAGS
  97. } else {
  98. if [info exists ubsan_saved_TEST_ALWAYS_FLAGS] {
  99. set TEST_ALWAYS_FLAGS $ubsan_saved_TEST_ALWAYS_FLAGS
  100. } else {
  101. unset TEST_ALWAYS_FLAGS
  102. }
  103. }
  104. set ld_library_path $ubsan_saved_library_path
  105. set_ld_library_path_env_vars
  106. }