~widelands-dev/widelands/trunk

« back to all changes in this revision

Viewing changes to compile.sh

  • Committer: The Widelands Bunnybot
  • Date: 2021-11-16 20:15:52 UTC
  • Revision ID: bunnybot@widelands.org-20211116201552-j10a1djci333kc00
Resolve thread sanitizer issues (#5114)

- Increased thread safety using atomic member variables
- New compile option to build with TSan

(by Noordfrees)
17705ed8390c7d6654ddc3aa6dcd1a1b80270d39

Show diffs side-by-side

added added

removed removed

Lines of Context:
58
58
    echo "                      Debug builds are created with AddressSanitizer by"
59
59
    echo "                      default."
60
60
    echo " "
 
61
    echo "-m or --no-tsan       Switch off the ThreadSanitizer (default)."
 
62
    echo "+m or --with-tsan     Switch on the ThreadSanitizer."
 
63
    echo "                      Can only be used with --no-asan, because AddressSanitizer"
 
64
    echo "                      cannot be enabled at the same time."
 
65
    echo " "
61
66
    echo "-x or --without-xdg   Disable support for the XDG Base Directory Specification."
62
67
    echo "+x or --with-xdg      Enable support for the XDG Base Directory Specification."
63
68
    echo " "
121
126
USE_FLTO="yes"
122
127
USE_ASAN="default"
123
128
USE_ASAN_DEFAULT="ON"
 
129
USE_TSAN="OFF"
124
130
COMPILER="default"
125
131
USE_XDG="ON"
126
132
EXTRA_OPTS=""
179
185
      USE_ASAN="ON"
180
186
    shift
181
187
    ;;
 
188
    -m|--no-tsan)
 
189
      USE_TSAN="OFF"
 
190
    shift
 
191
    ;;
 
192
    +m|--with-tsan)
 
193
      USE_TSAN="ON"
 
194
    shift
 
195
    ;;
182
196
    -h|--help)
183
197
      print_help
184
198
      exit 0
213
227
    ;;
214
228
    -d|--debug)
215
229
      BUILD_TYPE="Debug"
216
 
      if [ "${USE_ASAN}" = "default" ]; then
 
230
      if [ "${USE_ASAN}" = "default" ] && [ "${USE_TSAN}" = "OFF" ]; then
217
231
        USE_ASAN="ON"
218
232
      fi
219
233
    shift
302
316
done
303
317
 
304
318
if [ "${USE_ASAN}" = "default" ]; then
305
 
  USE_ASAN="${USE_ASAN_DEFAULT}"
 
319
  if [ "${USE_TSAN}" = "ON" ]; then
 
320
    USE_ASAN="OFF"
 
321
  else
 
322
    USE_ASAN="${USE_ASAN_DEFAULT}"
 
323
  fi
 
324
fi
 
325
if [ "${USE_ASAN}" = "ON" ] && [ "${USE_TSAN}" = "ON" ]; then
 
326
  echo " "
 
327
  echo "Cannot compile with both Address and Thread Sanitizer enabled!"
 
328
  exit 1
306
329
fi
307
330
 
308
331
if [ $QUIET -eq 0 ]; then
417
440
  echo "You can use +a or --with-asan to switch it on."
418
441
  CMD_ADD "--no-asan"
419
442
fi
 
443
if [ $USE_TSAN = "ON" ]; then
 
444
  echo "Will build with ThreadSanitizer."
 
445
  echo "https://clang.llvm.org/docs/ThreadSanitizer.html"
 
446
  echo "You can use -m or --no-tsan to switch it off."
 
447
  CMD_ADD "--with-tsan"
 
448
else
 
449
  echo "Will build without ThreadSanitizer."
 
450
  echo "You can use +m or --with-tsan to switch it on."
 
451
  CMD_ADD "--no-tsan"
 
452
fi
420
453
if [ $USE_XDG = "ON" ]; then
421
454
  echo " "
422
455
  echo "Basic XDG Base Directory Specification will be used on Linux"
494
527
 
495
528
  # Compile Widelands
496
529
  compile_widelands () {
497
 
    cmake $GENERATOR .. $EXTRA_OPTS -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DOPTION_BUILD_WEBSITE_TOOLS=$BUILD_WEBSITE -DOPTION_BUILD_TRANSLATIONS=$BUILD_TRANSLATIONS -DOPTION_BUILD_TESTS=$BUILD_TESTS -DOPTION_ASAN=$USE_ASAN -DUSE_XDG=$USE_XDG -DUSE_FLTO_IF_AVAILABLE=${USE_FLTO}
 
530
    cmake $GENERATOR .. $EXTRA_OPTS -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DOPTION_BUILD_WEBSITE_TOOLS=$BUILD_WEBSITE -DOPTION_BUILD_TRANSLATIONS=$BUILD_TRANSLATIONS -DOPTION_BUILD_TESTS=$BUILD_TESTS -DOPTION_ASAN=$USE_ASAN -DOPTION_TSAN=$USE_TSAN -DUSE_XDG=$USE_XDG -DUSE_FLTO_IF_AVAILABLE=${USE_FLTO}
498
531
 
499
532
    $buildtool -j $CORES
500
533