Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .gitlab/fuzzing/.gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ fuzz_infra:
image: registry.ddbuild.io/images/docker:27.3.1
tags: ["arch:amd64"]
stage: fuzz
timeout: 30m
timeout: 1h30m
allow_failure: true
id_tokens:
DDSIGN_ID_TOKEN:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,26 @@ class FuzzTargetsPlugin : Plugin<Project> {
val crashDir = extension.crashDir.get().asFile
val duration = extension.duration.get()

// Profiler sources are identical for every fuzz target (same compiler args and
// includes), so compile them once and share the resulting objects across targets
// instead of recompiling the whole profiler per target.
val sharedObjDir = project.file("${project.layout.buildDirectory.get()}/obj/fuzz/_profiler")
val compileProfilerTask = project.tasks.register("compileFuzzProfilerSources", NativeCompileTask::class.java) {
onlyIf { hasFuzzer && !project.hasProperty("skip-tests") && !project.hasProperty("skip-native") && !project.hasProperty("skip-fuzz") }
group = "build"
description = "Compile the profiler sources shared by all fuzz targets"

this.compiler.set(compiler)
this.compilerArgs.set(compilerArgs)
sources.from(
extension.profilerSourceDir.map { dir ->
project.fileTree(dir) { include("**/*.cpp") }
}
)
includes.from(includeFiles)
objectFileDir.set(sharedObjDir)
}

// Discover and create tasks for each fuzz target
if (fuzzSourceDir.exists()) {
fuzzSourceDir.listFiles()?.filter { file -> file.name.endsWith(".cpp") }?.forEach { fuzzFile ->
Expand All @@ -119,34 +139,33 @@ class FuzzTargetsPlugin : Plugin<Project> {
val binary = project.file("$binDir/$fuzzName")
val targetCorpusDir = File(corpusBaseDir, fuzzName)

// Compile task
// Compile task - only compiles this target's own fuzz driver; profiler
// sources come from the shared compileFuzzProfilerSources task.
val compileTask = project.tasks.register("compileFuzz_$fuzzName", NativeCompileTask::class.java) {
onlyIf { hasFuzzer && !project.hasProperty("skip-tests") && !project.hasProperty("skip-native") && !project.hasProperty("skip-fuzz") }
group = "build"
description = "Compile the fuzz target $fuzzName"

this.compiler.set(compiler)
this.compilerArgs.set(compilerArgs)
sources.from(
extension.profilerSourceDir.map { dir ->
project.fileTree(dir) { include("**/*.cpp") }
},
fuzzFile
)
sources.from(fuzzFile)
includes.from(includeFiles)
objectFileDir.set(objDir)
}

// Link task
val linkTask = project.tasks.register("linkFuzz_$fuzzName", NativeLinkExecutableTask::class.java) {
onlyIf { hasFuzzer && !project.hasProperty("skip-tests") && !project.hasProperty("skip-native") && !project.hasProperty("skip-fuzz") }
dependsOn(compileTask)
dependsOn(compileProfilerTask, compileTask)
group = "build"
description = "Link the fuzz target $fuzzName"

linker.set(compiler)
this.linkerArgs.set(linkerArgs)
objectFiles.from(project.fileTree(objDir) { include("*.o") })
objectFiles.from(
project.fileTree(sharedObjDir) { include("*.o") },
project.fileTree(objDir) { include("*.o") }
Comment on lines +165 to +167

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 Avoid linking stale per-target profiler objects

When a developer or CI runner reuses a workspace that already built fuzz targets before this change, the old per-target directories still contain profiler objects because NativeCompileTask.compile() only creates the output directory and writes the current sources; it does not remove obsolete *.o files. This link input now adds the new shared profiler objects and every *.o left in objDir, so linkFuzz_* can link duplicate copies of profiler objects such as arguments.o and fail with duplicate symbols. Please clean/relocate the target object directory or include only the fuzz driver object from objDir.

Useful? React with 👍 / 👎.

)
outputFile.set(binary)
}

Expand Down
Loading