Skip to content

Commit eda1cf9

Browse files
committed
gcc: automatically preload ASAN to support analysis of libraries
This fixes analysis of acl. /etc/ld.so.preload is used to deal with test frameworks that explicitly reset LD_PRELOAD. However, LD_PRELOAD is processed before /etc/ld.so.preload. Thus, the preloaded library may still conflict with ASAN if it also wants to intercept symbols like malloc or free.
1 parent f7ef638 commit eda1cf9

1 file changed

Lines changed: 30 additions & 1 deletion

File tree

py/plugins/gcc.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ def enable(self):
5656
def enable_sanitize(self, props, pkgs, flags):
5757
self.enabled = True
5858
self.sanitize = True
59-
props.run_check = True
6059
props.install_pkgs += pkgs
6160
self.flags.append_flags(flags)
6261

@@ -158,21 +157,47 @@ def handle_args(self, parser, args, props):
158157
# -fsanitize=address does not seem to be supported with -static
159158
self.flags.remove_flags(["-static"])
160159

160+
# preload ASAN for %check
161+
def run_asan_hook(results, mock, props):
162+
cmd = "echo /usr/lib64/libasan.so.*.* > /etc/ld.so.preload"
163+
rv = mock.exec_chroot_cmd(cmd)
164+
if 0 != rv:
165+
results.error(f"ASAN plug-in: ASAN preloading failed with exit code {rv}")
166+
return rv
167+
168+
# FIXME: hack
169+
extra_env = {"ASAN_OPTIONS": props.env["ASAN_OPTIONS"] + ",verify_asan_link_order=0"}
170+
ec = mock.exec_rpmbuild_bi(props, extra_env=extra_env)
171+
if 0 != ec:
172+
results.error(f"ASAN plug-in: %install or %check failed with exit code {rv}")
173+
return ec
174+
175+
props.post_install_hooks += [run_asan_hook]
176+
161177
if args.gcc_sanitize_leak:
162178
self.enable_sanitize(props, ["liblsan"], ["-fsanitize=leak"])
163179

180+
# execute %check section
181+
props.run_check = True
182+
164183
# -fsanitize=leak does not seem to work well with -static
165184
self.flags.remove_flags(["-static"])
166185

167186
if args.gcc_sanitize_thread:
168187
self.enable_sanitize(props, ["libtsan"], ["-fsanitize=thread"])
169188

189+
# execute %check section
190+
props.run_check = True
191+
170192
# -fsanitize=thread does not seem to be supported with -static
171193
self.flags.remove_flags(["-static"])
172194

173195
if args.gcc_sanitize_undefined:
174196
self.enable_sanitize(props, ["libubsan", "libubsan-static"], ["-fsanitize=undefined"])
175197

198+
# execute %check section
199+
props.run_check = True
200+
176201
# print full stack traces
177202
props.env["UBSAN_OPTIONS"] += ",print_stacktrace=1"
178203

@@ -190,6 +215,10 @@ def handle_args(self, parser, args, props):
190215
if "valgrind" in props.install_pkgs:
191216
parser.error("GCC sanitizers are not compatible with valgrind")
192217

218+
# %check should not be enabled for ASAN
219+
if args.gcc_sanitize_address:
220+
assert not props.run_check
221+
193222
self.flags.append_flags(['-g', '-fno-omit-frame-pointer',
194223
'-fsanitize-recover=all'])
195224

0 commit comments

Comments
 (0)