Skip to content

Add build steps for introspector images#7059

Merged
oliverchang merged 9 commits intomasterfrom
images_build
Jan 20, 2022
Merged

Add build steps for introspector images#7059
oliverchang merged 9 commits intomasterfrom
images_build

Conversation

@Navidem
Copy link
Copy Markdown
Contributor

@Navidem Navidem commented Dec 22, 2021

No description provided.

@Navidem Navidem requested a review from oliverchang January 5, 2022 22:46
Copy link
Copy Markdown
Collaborator

@oliverchang oliverchang left a comment

Choose a reason for hiding this comment

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

Nice! Just a general comment on the patching approach below.

BASE_PROJECT = 'oss-fuzz-base'
TAG_PREFIX = f'gcr.io/{BASE_PROJECT}/'
MAJOR_VERSION = 'v1'
INTROSPECTOR_VERSION = 'introspector'
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: s/VERSION/TAG/ to be more precise.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

'bash', '-c',
('cd fuzz-introspector/ && cd oss_fuzz_integration/'
' && sed -i \'s/\.\/infra\/base\-images\/all.sh/'
'#\.\/infra\/base\-images\/all.sh/\''
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Let's upstream as many of the image diffs as possible to avoid this hacky and difficult to maintain patching. Could you create another PR to incorporate the changes in https://github.com/ossf/fuzz-introspector/blob/main/oss_fuzz_integration/oss-fuzz-patches.diff ?

We can guard certain things with env vars if necessary.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

made all.sh conditional to skip it if in cloud build.

@DavidKorczynski
Copy link
Copy Markdown
Collaborator

I think we should consider that fuzz-introspector currently builds a custom Clang with a 2-line patch due to https://reviews.llvm.org/D77704 Please see the lines here: https://github.com/ossf/fuzz-introspector/blob/main/oss_fuzz_integration/oss-fuzz-patches.diff#L127-L129
The cleanest solution when integrating with OSS-Fuzz may be to get rid of those patch lines, which would enable us to have the fuzz-introspector image much smaller in size or simply include it in the base-builder image by default as introspector would only then be a small sized library. I recon that this would benefit future maintenance as well.

Another thought is the use of git-repo-url in fuzz-introspector. In fuzz-introspector, this is only used to create quick URLs to the source code of a given project. The goal was to mimic the URLs in clusterfuzz stack traces, but, to speed up dev I decided to just include a simple param to helper.py in the fuzz-introspector PoC oss-fuzz integration. It would perhaps be nicer to not use that argument to helper.py but instead use the logic from clusterfuzz to get the URLs.

@oliverchang
Copy link
Copy Markdown
Collaborator

I think we should consider that fuzz-introspector currently builds a custom Clang with a 2-line patch due to https://reviews.llvm.org/D77704 Please see the lines here: https://github.com/ossf/fuzz-introspector/blob/main/oss_fuzz_integration/oss-fuzz-patches.diff#L127-L129 The cleanest solution when integrating with OSS-Fuzz may be to get rid of those patch lines, which would enable us to have the fuzz-introspector image much smaller in size or simply include it in the base-builder image by default as introspector would only then be a small sized library. I recon that this would benefit future maintenance as well.

Yes it would be really great if we could get https://reviews.llvm.org/D77704 merged, or alternatively use a different mechanism for computing call graphs. Both of those will take time though, and we'd like to start being able to run this at scale on all of our OSS-Fuzz projects.

Another thought is the use of git-repo-url in fuzz-introspector. In fuzz-introspector, this is only used to create quick URLs to the source code of a given project. The goal was to mimic the URLs in clusterfuzz stack traces, but, to speed up dev I decided to just include a simple param to helper.py in the fuzz-introspector PoC oss-fuzz integration. It would perhaps be nicer to not use that argument to helper.py but instead use the logic from clusterfuzz to get the URLs.

Yep! I also suggested to @Navidem in #7060 (comment) to just use the main_repo property in project.yaml.

@DavidKorczynski
Copy link
Copy Markdown
Collaborator

@Navidem FYI this commit ossf/fuzz-introspector@c27b407 updates such that we no longer require a special version of LLVM in fuzz-introspector. Fuzz-introspector now works with latest oss-fuzz as well

@oliverchang
Copy link
Copy Markdown
Collaborator

@Navidem FYI this commit ossf/fuzz-introspector@c27b407 updates such that we no longer require a special version of LLVM in fuzz-introspector. Fuzz-introspector now works with latest oss-fuzz as well

Nice, thanks!! That makes it so much easier to integrate.

@DavidKorczynski
Copy link
Copy Markdown
Collaborator

DavidKorczynski commented Jan 11, 2022

@Navidem FYI this commit ossf/fuzz-introspector@c27b407 updates such that we no longer require a special version of LLVM in fuzz-introspector. Fuzz-introspector now works with latest oss-fuzz as well

Nice, thanks!! That makes it so much easier to integrate.

Np - notice we do still need to patch clang :/ i.e. before we needed LLVM 12 + patching. Now we only need patching.

@oliverchang
Copy link
Copy Markdown
Collaborator

oliverchang commented Jan 13, 2022

@Navidem FYI this commit ossf/fuzz-introspector@c27b407 updates such that we no longer require a special version of LLVM in fuzz-introspector. Fuzz-introspector now works with latest oss-fuzz as well

Nice, thanks!! That makes it so much easier to integrate.

Np - notice we do still need to patch clang :/ i.e. before we needed LLVM 12 + patching. Now we only need patching.

@DavidKorczynski

Re the patches: Are the required changes self contained in a bunch of LLVM tools (i.e. ranlib, ar) such that we can just copy out these binaries into the main base-clang image to be used on demand for introspector runs together with vanilla clang? Or are there more widespread changes that make this hard to do?

@DavidKorczynski
Copy link
Copy Markdown
Collaborator

DavidKorczynski commented Jan 13, 2022

@Navidem FYI this commit ossf/fuzz-introspector@c27b407 updates such that we no longer require a special version of LLVM in fuzz-introspector. Fuzz-introspector now works with latest oss-fuzz as well

Nice, thanks!! That makes it so much easier to integrate.

Np - notice we do still need to patch clang :/ i.e. before we needed LLVM 12 + patching. Now we only need patching.

@DavidKorczynski

Re the patches: Are the required changes self contained in a bunch of LLVM tools (i.e. ranlib, ar) such that we can just copy out these binaries into the main base-clang image to be used on demand for introspector runs together with vanilla clang? Or are there more widespread changes that make this hard to do?

@oliverchang the patch is a single line in terms of code, and then a header file inclusion. See this comment I wrote in another PR #7059 (comment) #7122 (comment)

The patch is simply to add a line before here: https://github.com/llvm/llvm-project/blob/main/llvm/lib/Transforms/IPO/PassManagerBuilder.cpp#L997 and then we add the required plugin header as well.

The line we add is PM.add(createInspectorPass()); and the specific sed used is here: https://github.com/ossf/fuzz-introspector/blob/main/oss_fuzz_integration/oss-fuzz-patches.diff#L124-L128

@oliverchang
Copy link
Copy Markdown
Collaborator

@Navidem FYI this commit ossf/fuzz-introspector@c27b407 updates such that we no longer require a special version of LLVM in fuzz-introspector. Fuzz-introspector now works with latest oss-fuzz as well

Nice, thanks!! That makes it so much easier to integrate.

Np - notice we do still need to patch clang :/ i.e. before we needed LLVM 12 + patching. Now we only need patching.

@DavidKorczynski
Re the patches: Are the required changes self contained in a bunch of LLVM tools (i.e. ranlib, ar) such that we can just copy out these binaries into the main base-clang image to be used on demand for introspector runs together with vanilla clang? Or are there more widespread changes that make this hard to do?

@oliverchang the patch is a single line in terms of code, and then a header file inclusion. See this comment I wrote in another PR #7059 (comment) #7122 (comment)

The patch is simply to add a line before here: https://github.com/llvm/llvm-project/blob/main/llvm/lib/Transforms/IPO/PassManagerBuilder.cpp#L997 and then we add the required plugin header as well.

The line we add is PM.add(createInspectorPass()); and the specific sed used is here: https://github.com/ossf/fuzz-introspector/blob/main/oss_fuzz_integration/oss-fuzz-patches.diff#L124-L128

Thanks for explaining! Re just including this into base-clang, my one concern is that it's one more thing that may block us from doing clang upgrades in the future, even if the patch is fairly small. Are there any expectations around stability with the plugin interface that's being used for the inspector pass for future llvm updates?

In any case, it's probably safer to start with a separate image first for testing and move to a single image in the future. Perhaps we may even find another mechanism for generating the call graph that doesn't require LTO?

'gcr.io/oss-fuzz-base/base-runner',
'args': [
'bash', '-c',
(f'sed -i s/base-clang/base-clang:{INTROSPECTOR_TAG}/g'
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

let's set the replace pattern to 'base-clang:.*' in case the base-clang is already set to a tag.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

First, probably you meant 'base-clang.*', right?
Second, the replacement is applied on vanilla oss-fuzz clone, so there won't be an explicit tag for the image used by base-builder. Unless you are assuming in future we may have such tagging.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

applied.

steps.append({
'args': [
'build',
'--build-arg': build_arg,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Does passing --build-arg with an empty string work as expected (i.e. a no-op) ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

You're right, the empty string breaks the build, did not test it properly last night!
Probably better approach would be passing build-arg for both image builds, in case of base-clang:introspector it is consumed. For the case of base-builder:introspector it produces a benign warning, but build succeeds.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

applied.

@DavidKorczynski
Copy link
Copy Markdown
Collaborator

Thanks for explaining! Re just including this into base-clang, my one concern is that it's one more thing that may block us from doing clang upgrades in the future, even if the patch is fairly small. Are there any expectations around stability with the plugin interface that's being used for the inspector pass for future llvm updates?

Atm the goal is to maintain a stable interface for OSS-Fuzz so we wont run into updating issues, but also enable non-oss-fuzz builds which may have more experimental features.

Another aspect that may make things unstable in the long-term is introducing new languages into fuzz-introspector.

In any case, it's probably safer to start with a separate image first for testing and move to a single image in the future. Perhaps we may even find another mechanism for generating the call graph that doesn't require LTO?

Sounds good and I agree that it's probably safer. It would also be nice to not alert users on failed introspector builds (at least in the beginning) and instead give us a chance of going through them to correct potential issues.

FYI I don't think LTO will be removed in the near future - we still get significant benefits from it. However, if the OSS-Fuzz integration shows it's a problem for many projects then we should reconsider. With that said, the only project I know of that does not go well with LTO atm is bitcoin-core. Other projects that have failed with LTO has been due to memory exhaustion and this can sometimes be fixed by constraining the build (e.g. from N processes to just a few). We track these issues here


introspector_steps = _get_introspector_base_images_steps(
INTROSPECTOR_BASE_IMAGES, tag_prefix)
intro_images = [
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: s/intro/introspector/. Always better to be more explicit (and consistent) here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

@oliverchang
Copy link
Copy Markdown
Collaborator

Please also fix the lint issues.

@Navidem
Copy link
Copy Markdown
Contributor Author

Navidem commented Jan 20, 2022

@oliverchang this should be ready for merge.

@oliverchang oliverchang merged commit 43bccdd into master Jan 20, 2022
@oliverchang oliverchang deleted the images_build branch January 20, 2022 01:22
MartinPetkov pushed a commit to MartinPetkov/oss-fuzz that referenced this pull request Aug 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants