Skip to content

Commit 17fd0f6

Browse files
committed
Add support for building with address, undefined, and thread sanitizers on linux
Signed-off-by: Rye <[email protected]>
1 parent e803bbc commit 17fd0f6

File tree

5 files changed

+171
-15
lines changed

5 files changed

+171
-15
lines changed

indra/cmake/00-Common.cmake

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,39 @@ if (LINUX)
143143
LL_IGNORE_SIGCHLD
144144
)
145145

146-
if(ENABLE_ASAN)
147-
add_compile_options(-U_FORTIFY_SOURCE
148-
-fsanitize=address
149-
--param asan-stack=0
146+
option(ENABLE_ASAN "Enable Address Sanitizer" OFF)
147+
option(ENABLE_UBSAN "Enable Undefined Behavior Sanitizer" OFF)
148+
option(ENABLE_THREADSAN "Enable Thread Sanitizer" OFF)
149+
if(ENABLE_ASAN OR ENABLE_UBSAN OR ENABLE_THREADSAN)
150+
set(GCC_DISABLE_FATAL_WARNINGS ON) # Disable warnings as errors during sanitizer builds due to false positives
151+
152+
add_compile_options(
153+
-U_FORTIFY_SOURCE
154+
-fno-omit-frame-pointer
155+
-fno-common
156+
-fsanitize-recover=all
150157
)
151-
add_link_options(-fsanitize=address)
158+
159+
# libwebrtc is incompatible with sanitizers
160+
set(DISABLE_WEBRTC ON)
161+
add_compile_definitions(DISABLE_WEBRTC=1)
162+
163+
if(ENABLE_ASAN)
164+
add_compile_options(-fsanitize=address)
165+
add_link_options(-fsanitize=address)
166+
endif()
167+
168+
if(ENABLE_UBSAN)
169+
add_compile_options(-fsanitize=undefined)
170+
add_link_options(-fsanitize=undefined)
171+
endif()
172+
173+
if(ENABLE_THREADSAN)
174+
add_compile_options(-fsanitize=thread)
175+
add_link_options(-fsanitize=thread)
176+
endif()
152177
else()
153-
add_compile_definitions($<$<CONFIG:Release>:_FORTIFY_SOURCE=2>)
178+
add_compile_definitions($<$<CONFIG:Release>:_FORTIFY_SOURCE=2>)
154179
endif()
155180

156181
add_compile_options(

indra/llcommon/llinstancetracker.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
#ifndef LL_LLINSTANCETRACKER_H
2929
#define LL_LLINSTANCETRACKER_H
3030

31+
#include "llpreprocessor.h"
32+
3133
#include <map>
3234
#include <set>
3335
#include <vector>
@@ -244,6 +246,9 @@ class LLInstanceTracker
244246
}
245247

246248
protected:
249+
#if LL_CLANG || LL_GNUC
250+
__attribute__((no_sanitize("vptr")))
251+
#endif
247252
LLInstanceTracker(const KEY& key)
248253
{
249254
// We do not intend to manage the lifespan of this object with
@@ -482,6 +487,9 @@ class LLInstanceTracker<T, void, KEY_COLLISION_BEHAVIOR>
482487
using key_snapshot_of = instance_snapshot_of<SUBCLASS>;
483488

484489
protected:
490+
#if LL_CLANG || LL_GNUC
491+
__attribute__((no_sanitize("vptr")))
492+
#endif
485493
LLInstanceTracker()
486494
{
487495
// Since we do not intend for this shared_ptr to manage lifespan, give

indra/newview/CMakeLists.txt

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,6 @@ set(viewer_SOURCE_FILES
718718
llvoiceclient.cpp
719719
llvoicevisualizer.cpp
720720
llvoicevivox.cpp
721-
llvoicewebrtc.cpp
722721
llvoinventorylistener.cpp
723722
llvopartgroup.cpp
724723
llvosky.cpp
@@ -1386,7 +1385,6 @@ set(viewer_HEADER_FILES
13861385
llvoiceclient.h
13871386
llvoicevisualizer.h
13881387
llvoicevivox.h
1389-
llvoicewebrtc.h
13901388
llvoinventorylistener.h
13911389
llvopartgroup.h
13921390
llvosky.h
@@ -1424,6 +1422,11 @@ source_group("CMake Rules" FILES ViewerInstall.cmake)
14241422
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/viewer_version.txt"
14251423
"${VIEWER_SHORT_VERSION}.${VIEWER_VERSION_REVISION}\n")
14261424

1425+
if (NOT DISABLE_WEBRTC)
1426+
LIST(APPEND viewer_SOURCE_FILES llvoicewebrtc.cpp)
1427+
LIST(APPEND viewer_HEADER_FILES llvoicewebrtc.h)
1428+
endif()
1429+
14271430
if (DARWIN)
14281431
LIST(APPEND viewer_SOURCE_FILES llappviewermacosx.cpp)
14291432
LIST(APPEND viewer_SOURCE_FILES llappviewermacosx-objc.mm)
@@ -2014,7 +2017,6 @@ target_link_libraries(${VIEWER_BINARY_NAME}
20142017
llcorehttp
20152018
llcommon
20162019
llmeshoptimizer
2017-
llwebrtc
20182020
lllogin
20192021
llprimitive
20202022
llappearance
@@ -2025,16 +2027,20 @@ target_link_libraries(${VIEWER_BINARY_NAME}
20252027
ll::openxr
20262028
)
20272029

2030+
if (NOT DISABLE_WEBRTC)
2031+
target_link_libraries(${VIEWER_BINARY_NAME} llwebrtc )
2032+
endif()
2033+
20282034
if (USE_DISCORD)
2029-
target_link_libraries(${VIEWER_BINARY_NAME} ll::discord_sdk )
2035+
target_link_libraries(${VIEWER_BINARY_NAME} ll::discord_sdk )
20302036
endif ()
20312037

20322038
if( TARGET ll::intel_memops )
2033-
target_link_libraries(${VIEWER_BINARY_NAME} ll::intel_memops )
2039+
target_link_libraries(${VIEWER_BINARY_NAME} ll::intel_memops )
20342040
endif()
20352041

20362042
if( TARGET ll::nvapi )
2037-
target_link_libraries(${VIEWER_BINARY_NAME} ll::nvapi )
2043+
target_link_libraries(${VIEWER_BINARY_NAME} ll::nvapi )
20382044
endif()
20392045

20402046
if ( TARGET llconvexdecomposition )

indra/newview/linux_tools/wrapper.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ export mesa_glthread=true
1818
## an unstripped binary before you run.
1919
#export LL_WRAPPER='gdb --args'
2020
#export LL_WRAPPER='valgrind --smc-check=all --error-limit=no --log-file=secondlife.vg --leak-check=full --suppressions=/usr/lib/valgrind/glibc-2.5.supp --suppressions=secondlife-i686.supp'
21+
#export ASAN_OPTIONS="halt_on_error=0 detect_leaks=1 symbolize=1"
22+
#export UBSAN_OPTIONS="print_stacktrace=1 print_summary=1 halt_on_error=0"
2123

2224
## Nothing worth editing below this line.
2325
##-------------------------------------------------------------------

0 commit comments

Comments
 (0)