[libFuzzer] [NFC] Make compiler command generation more readable.
Use config.clang as a more general option than config.c_compiler.
@@ -50,22 +50,35 @@ libfuzzer_src_root = os.path.join(config.compiler_rt_src_root, "lib", "fuzzer")
config.substitutions.append(('%libfuzzer_src', libfuzzer_src_root))
def generate_compiler_cmd(is_cpp=True, fuzzer_enabled=True):
- compiler_cmd = config.c_compiler
+ compiler_cmd = config.clang
if config.clang and config.stdlib == 'libc++':
link_cmd = '-stdlib=libc++ -Wl,-rpath=%s' % config.llvm_library_dir
elif config.clang and config.stdlib == 'static-libc++':
- link_cmd = '-stdlib=libc++ -lc++abi -static-libstdc++ -Wl,-rpath=%s' % config.llvm_library_dir
+ link_cmd = '-stdlib=libc++ -lc++abi -static-libstdc++ -Wl,-rpath=%s' % (
+ config.llvm_library_dir)
+ elif any(x in config.target_triple for x in ('darwin', 'freebsd')):
+ link_cmd = '-lc++'
else:
- link_cmd = '-lc++' if any(x in config.target_triple for x in ('darwin', 'freebsd')) else '-lstdc++'
+ link_cmd = '-lstdc++'
+
std_cmd = '--driver-mode=g++ -std=c++11' if is_cpp else ''
sanitizers = ['address']
if fuzzer_enabled:
sanitizers.append('fuzzer')
sanitizers_cmd = ('-fsanitize=%s' % ','.join(sanitizers))
- isysroot_cmd = config.osx_sysroot_flag if config.osx_sysroot_flag else ''
- include_cmd = '-I%s' % libfuzzer_src_root
- return '%s %s %s -O2 -gline-tables-only %s %s %s' % (
- compiler_cmd, std_cmd, link_cmd, isysroot_cmd, sanitizers_cmd, include_cmd)
+ if config.osx_sysroot_flag:
+ isysroot_cmd = config.osx_sysroot_flag
+ else:
+ isysroot_cmd = ''
+ return " ".join([
+ compiler_cmd,
+ std_cmd,
+ link_cmd,
+ "-O2 -gline-tables-only",
+ isysroot_cmd,
+ sanitizers_cmd,
+ "-I%s" % libfuzzer_src_root
+ ])
config.substitutions.append(('%cpp_compiler',
generate_compiler_cmd(is_cpp=True, fuzzer_enabled=True)
