Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ object ConfigurationPresets {
configureTsan(this, currentPlatform, currentArch, version, rootDir, compiler)
}
register("fuzzer") {
configureFuzzer(this, currentPlatform, currentArch, version, rootDir)
configureFuzzer(this, currentPlatform, currentArch, version, rootDir, compiler)
}
}

Expand Down Expand Up @@ -313,7 +313,8 @@ object ConfigurationPresets {
platform: Platform,
architecture: Architecture,
version: String,
rootDir: File
rootDir: File,
compiler: String = "gcc"
) {
config.platform.set(platform)
config.architecture.set(architecture)
Expand All @@ -339,7 +340,28 @@ object ConfigurationPresets {
when (platform) {
Platform.LINUX -> {
config.compilerArgs.set(fuzzerCompilerArgs + commonLinuxCompilerArgs(version))
config.linkerArgs.set(commonLinuxLinkerArgs() + fuzzerLinkerArgs)

// commonLinuxLinkerArgs() carries -Wl,-z,defs, which forbids the
// undefined __asan_*/__ubsan_* symbols the instrumented objects
// reference. -fsanitize=address only links the runtime into
// executables, not shared libraries, so the fuzzer .so needs the
// runtime linked explicitly — same treatment (and rationale) as the
// asan config. On clang this resolves both __asan_* and __ubsan_*
// from one clang_rt.asan runtime; on gcc it adds -lubsan.
val libasan = PlatformUtils.locateLibasan(compiler)
val fuzzerRuntimeArgs = if (libasan != null) {
val asanLibDir = File(libasan).parent
val asanLibName = File(libasan).nameWithoutExtension.removePrefix("lib")
val ubsanLibs = if (asanLibName.startsWith("clang_rt")) emptyList()
else listOf("-lubsan")
listOf("-L$asanLibDir", "-l$asanLibName",
"-Wl,-rpath,$asanLibDir") +
ubsanLibs +
fuzzerLinkerArgs
Comment on lines +357 to +360

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preload ASan for fuzzer test JVMs

When the Linux fuzzer config is used by the generated Java tasks (for example testFuzzer from ProfilerTestPlugin), these new link args add a DT_NEEDED dependency on the ASan runtime but the fuzzer testEnvironment still never sets LD_PRELOAD. An unsanitized JVM that later loads this ASan-instrumented libjavaProfiler.so aborts before tests start with the usual “ASan runtime does not come first” error; configureAsan avoids that by preloading the same libasan. Please mirror that here when libasan != null.

Useful? React with 👍 / 👎.

} else {
fuzzerLinkerArgs
}
config.linkerArgs.set(commonLinuxLinkerArgs() + fuzzerRuntimeArgs)

config.testEnvironment.apply {
put("ASAN_OPTIONS", "allocator_may_return_null=1:detect_stack_use_after_return=0:handle_segv=0:abort_on_error=1:symbolize=1:suppressions=$rootDir/gradle/sanitizers/asan.supp")
Expand Down
Loading