hardened.pri 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. load(configure)
  2. # Define common variables; these are used by config tests _and_ the actual build
  3. # Supported in gcc 4.8+
  4. HARDENED_SANITIZE_FLAGS = -fsanitize=address
  5. # Supported in gcc 4.9+
  6. HARDENED_SANITIZE_UBSAN_FLAGS = -fsanitize=undefined -fsanitize=integer-divide-by-zero -fsanitize=bounds -fsanitize=alignment -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -fno-sanitize-recover
  7. # Supported in gcc 5.0+
  8. HARDENED_SANITIZE_UBSAN_MORE_FLAGS = -fsanitize=vptr -fsanitize=object-size
  9. # vtable-verify requires some OS support; see https://bugzilla.novell.com/show_bug.cgi?id=877239
  10. HARDENED_VTABLE_VERIFY_FLAGS = -fvtable-verify=std
  11. HARDENED_STACK_PROTECTOR_STRONG_FLAGS = -fstack-protector-strong
  12. HARDENED_STACK_PROTECTOR_FLAGS = -fstack-protector --param=ssp-buffer-size=4
  13. HARDENED_MINGW_64ASLR_FLAGS = -Wl,--dynamicbase -Wl,--high-entropy-va
  14. # Run tests and apply options where possible
  15. CONFIG(hardened) {
  16. # mingw is always PIC, and complains about the flag
  17. !mingw:HARDEN_FLAGS = -fPIC
  18. CONFIG(debug,debug|release): qtCompileTest(sanitize):HARDEN_FLAGS += $$HARDENED_SANITIZE_FLAGS
  19. qtCompileTest(sanitize-ubsan):HARDEN_FLAGS += $$HARDENED_SANITIZE_UBSAN_FLAGS
  20. qtCompileTest(sanitize-ubsan-more):HARDEN_FLAGS += $$HARDENED_SANITIZE_UBSAN_MORE_FLAGS
  21. qtCompileTest(vtable-verify):HARDEN_FLAGS += $$HARDENED_VTABLE_VERIFY_FLAGS
  22. qtCompileTest(stack-protector-strong) {
  23. HARDEN_FLAGS += $$HARDENED_STACK_PROTECTOR_STRONG_FLAGS
  24. } else {
  25. qtCompileTest(stack-protector):HARDEN_FLAGS += $$HARDENED_STACK_PROTECTOR_FLAGS
  26. }
  27. mingw {
  28. qtCompileTest(mingw-64aslr):QMAKE_LFLAGS *= $$HARDENED_MINGW_64ASLR_FLAGS
  29. QMAKE_LFLAGS *= -Wl,--nxcompat -Wl,--dynamicbase
  30. }
  31. QMAKE_CXXFLAGS *= $$HARDEN_FLAGS
  32. QMAKE_LFLAGS *= $$HARDEN_FLAGS
  33. # _FORTIFY_SOURCE requires -O, so only use on release builds
  34. CONFIG(release,debug|release):QMAKE_CXXFLAGS *= -D_FORTIFY_SOURCE=2
  35. # Linux specific
  36. unix:!macx:QMAKE_LFLAGS *= -pie -Wl,-z,relro,-z,now
  37. }