Skip to content

Commit fa46848

Browse files
committed
scons: Allow building with Address Sanitizer.
libasan is never linked to shared objects (which doesn't go well with -z,defs). It must either be linked to the main executable, or (more practically for OpenGL drivers) be pre-loaded via LD_PRELOAD. Otherwise works. I didn't find anything with llvmpipe. I suspect the fact that the JIT compiled code isn't instrumented means there are lots of errors it can't catch. But for non-JIT drivers, the Address/Leak Sanitizers seem like a faster alternative to Valgrind. Usage (Ubuntu 15.10): scons asan=1 libgl-xlib export LD_LIBRARY_PATH=$PWD/build/linux-x86_64-debug/gallium/targets/libgl-xlib LD_PRELOAD=libasan.so.2 any-opengl-application Acked-by: Roland Scheidegger <[email protected]>
1 parent d1c89f6 commit fa46848

File tree

4 files changed

+26
-7
lines changed

4 files changed

+26
-7
lines changed

common.py

+1
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ def AddOptions(opts):
9797
opts.Add(BoolOption('embedded', 'embedded build', 'no'))
9898
opts.Add(BoolOption('analyze',
9999
'enable static code analysis where available', 'no'))
100+
opts.Add(BoolOption('asan', 'enable Address Sanitizer', 'no'))
100101
opts.Add('toolchain', 'compiler toolchain', default_toolchain)
101102
opts.Add(BoolOption('gles', 'EXPERIMENTAL: enable OpenGL ES support',
102103
'no'))

scons/gallium.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ def generate(env):
410410
# Work around aliasing bugs - developers should comment this out
411411
ccflags += ['-fno-strict-aliasing']
412412
ccflags += ['-g']
413-
if env['build'] in ('checked', 'profile'):
413+
if env['build'] in ('checked', 'profile') or env['asan']:
414414
# See http://code.google.com/p/jrfonseca/wiki/Gprof2Dot#Which_options_should_I_pass_to_gcc_when_compiling_for_profiling?
415415
ccflags += [
416416
'-fno-omit-frame-pointer',
@@ -540,6 +540,16 @@ def generate(env):
540540
# scan-build will produce more comprehensive output
541541
env.Append(CCFLAGS = ['--analyze'])
542542

543+
# https://github.com/google/sanitizers/wiki/AddressSanitizer
544+
if env['asan']:
545+
if gcc_compat:
546+
env.Append(CCFLAGS = [
547+
'-fsanitize=address',
548+
])
549+
env.Append(LINKFLAGS = [
550+
'-fsanitize=address',
551+
])
552+
543553
# Assembler options
544554
if gcc_compat:
545555
if env['machine'] == 'x86':

src/gallium/targets/libgl-xlib/SConscript

+8-4
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,15 @@ if env['llvm']:
4848
env.Prepend(LIBS = [llvmpipe])
4949

5050
if env['platform'] != 'darwin':
51+
# Disallow undefined symbols, except with Address Sanitizer, since libasan
52+
# is not linked on shared libs, as it should be LD_PRELOAD'ed instead
53+
if not env['asan']:
54+
env.Append(SHLINKFLAGS = [
55+
'-Wl,-z,defs',
56+
])
5157
env.Append(SHLINKFLAGS = [
52-
# Disallow undefined symbols
53-
'-Wl,-z,defs',
54-
# Restrict exported symbols
55-
'-Wl,--version-script=%s' % File("libgl-xlib.sym").srcnode().path,
58+
# Restrict exported symbols
59+
'-Wl,--version-script=%s' % File("libgl-xlib.sym").srcnode().path,
5660
])
5761

5862
# libGL.so.1.5

src/mesa/drivers/x11/SConscript

+6-2
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,13 @@ sources = [
3434
'xm_tri.c',
3535
]
3636

37-
# Disallow undefined symbols
3837
if env['platform'] != 'darwin':
39-
env.Append(SHLINKFLAGS = ['-Wl,-z,defs'])
38+
# Disallow undefined symbols, except with Address Sanitizer, since libasan
39+
# is not linked on shared libs, as it should be LD_PRELOAD'ed instead
40+
if not env['asan']:
41+
env.Append(SHLINKFLAGS = [
42+
'-Wl,-z,defs',
43+
])
4044

4145
# libGL.so.1.6
4246
libgl_1_6 = env.SharedLibrary(

0 commit comments

Comments
 (0)