Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cached build: Re-build for every sanitizer. #12695

Merged
merged 3 commits into from
Nov 7, 2024
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
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
Loading