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

Linking arguments for LLVM passes #1273

Merged
merged 1 commit into from
May 17, 2023
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
18 changes: 18 additions & 0 deletions libafl_cc/src/clang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ pub struct ClangWrapper {
link_args: Vec<String>,
passes: Vec<LLVMPasses>,
passes_args: Vec<String>,
passes_linking_args: Vec<String>,
}

#[allow(clippy::match_same_arms)] // for the linking = false wip for "shared"
Expand Down Expand Up @@ -302,6 +303,8 @@ impl CompilerWrapper for ClangWrapper {

fn command(&mut self) -> Result<Vec<String>, Error> {
let mut args = vec![];
let mut use_pass = false;

if self.is_cpp {
args.push(self.wrapped_cxx.clone());
} else {
Expand All @@ -324,6 +327,7 @@ impl CompilerWrapper for ClangWrapper {
}
}
for pass in &self.passes {
use_pass = true;
if self.use_new_pm {
// https://github.com/llvm/llvm-project/issues/56137
// Need this -Xclang -load -Xclang -<pass>.so thing even with the new PM
Expand Down Expand Up @@ -358,6 +362,10 @@ impl CompilerWrapper for ClangWrapper {

args.extend_from_slice(self.link_args.as_slice());

if use_pass {
args.extend_from_slice(self.passes_linking_args.as_slice());
}

if cfg!(unix) {
args.push("-pthread".into());
args.push("-ldl".into());
Expand Down Expand Up @@ -423,6 +431,7 @@ impl ClangWrapper {
link_args: vec![],
passes: vec![],
passes_args: vec![],
passes_linking_args: vec![],
is_silent: false,
}
}
Expand Down Expand Up @@ -466,6 +475,15 @@ impl ClangWrapper {
self
}

/// Add arguments for LLVM passes during linking. For example, ngram needs -lm
pub fn add_passes_linking_arg<S>(&mut self, arg: S) -> &'_ mut Self
where
S: AsRef<str>,
{
self.passes_linking_args.push(arg.as_ref().to_string());
self
}

/// Set if linking
pub fn linking(&mut self, value: bool) -> &'_ mut Self {
self.linking = value;
Expand Down