Skip to content

Commit

Permalink
cached build: Re-build for every sanitizer. (#12695)
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverchang authored Nov 7, 2024
1 parent e3ccf89 commit ff53604
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 33 deletions.
35 changes: 16 additions & 19 deletions infra/build/functions/build_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,8 @@ def get_project_image_steps( # pylint: disable=too-many-arguments
config,
architectures=None,
experiment=False,
cache_image=None):
cache_image=None,
srcmap=True):
"""Returns GCB steps to build OSS-Fuzz project image."""
if architectures is None:
architectures = []
Expand All @@ -459,29 +460,25 @@ def get_project_image_steps( # pylint: disable=too-many-arguments
steps.extend(get_pull_test_images_steps(config.test_image_suffix))
src_root = 'oss-fuzz' if not experiment else '.'

steps.append({
'name': 'ubuntu',
'args': ['bash', '-c', f'cat {src_root}/projects/{name}/Dockerfile'],
})

docker_build_step = get_docker_build_step([image],
os.path.join('projects', name),
src_root=src_root,
cache_image=cache_image)
steps.append(docker_build_step)
srcmap_step_id = get_srcmap_step_id()
steps.extend([{
'name': image,
'args': [
'bash', '-c',
'srcmap > /workspace/srcmap.json && cat /workspace/srcmap.json'
],
'env': [
'OSSFUZZ_REVISION=$REVISION_ID',
'FUZZING_LANGUAGE=%s' % language,
],
'id': srcmap_step_id
}])
if srcmap:
srcmap_step_id = get_srcmap_step_id()
steps.extend([{
'name': image,
'args': [
'bash', '-c',
'srcmap > /workspace/srcmap.json && cat /workspace/srcmap.json'
],
'env': [
'OSSFUZZ_REVISION=$REVISION_ID',
'FUZZING_LANGUAGE=%s' % language,
],
'id': srcmap_step_id
}])

if has_arm_build(architectures):
builder_name = 'buildxbuilder'
Expand Down
34 changes: 20 additions & 14 deletions infra/build/functions/build_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,22 +354,19 @@ def get_build_steps_for_project(project,

timestamp = get_datetime_now().strftime('%Y%m%d%H%M')

# If we use caching, then we need to use the right name. We assume that
# there is only a single sanitizer.
if use_caching:
project.cached_sanitizer = project.sanitizers[0]
cache_image = project.cached_image
# For cached builds: the cache images are sanitizer-specific, so we need to
# do a rebuild prior to each compile.
build_steps = []
else:
cache_image = None

build_steps = build_lib.get_project_image_steps(
project.name,
project.image,
project.fuzzing_language,
config=config,
architectures=project.architectures,
experiment=config.experiment,
cache_image=cache_image)
# Non-cached builds just use a single builder image to build all sanitizers.
build_steps = build_lib.get_project_image_steps(
project.name,
project.image,
project.fuzzing_language,
config=config,
architectures=project.architectures,
experiment=config.experiment)

# Sort engines to make AFL first to test if libFuzzer has an advantage in
# finding bugs first since it is generally built first.
Expand All @@ -379,6 +376,15 @@ def get_build_steps_for_project(project,
for sanitizer in sorted(project.sanitizers):
if use_caching and sanitizer in _CACHED_SANITIZERS:
project.cached_sanitizer = sanitizer
build_steps.extend(
build_lib.get_project_image_steps(
project.name,
project.image,
project.fuzzing_language,
config=config,
architectures=project.architectures,
experiment=config.experiment,
cache_image=project.cached_image))

# Build x86_64 before i386.
for architecture in reversed(sorted(project.architectures)):
Expand Down
9 changes: 9 additions & 0 deletions infra/build/functions/target_experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,15 @@ def run_experiment(project_name,

if use_cached_image:
project.cached_sanitizer = 'coverage'
steps.extend(
build_lib.get_project_image_steps(project.name,
project.image,
project.fuzzing_language,
config=config,
architectures=project.architectures,
experiment=config.experiment,
cache_image=project.cached_image,
srcmap=False))

steps.append(
build_project.get_compile_step(project, build, env, config.parallel))
Expand Down

0 comments on commit ff53604

Please sign in to comment.