libafl_cc: fix configuration support (#1595)

* libafl_cc: fix configuration support

* fmt

* clippy
This commit is contained in:
s1341 2023-10-02 17:48:33 +03:00 committed by GitHub
parent f35c59131d
commit a27553daec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 32 deletions

View File

@ -194,7 +194,7 @@ impl ToolWrapper for ClangWrapper {
continue; continue;
} }
} }
"--libafl-ignore-configurations" => { "--libafl-ignore-configurations" | "-print-prog-name=ld" => {
self.ignoring_configurations = true; self.ignoring_configurations = true;
i += 1; i += 1;
continue; continue;
@ -346,43 +346,52 @@ impl ToolWrapper for ClangWrapper {
}) })
.collect::<Vec<_>>(); .collect::<Vec<_>>();
if let Some(output) = self.output.clone() { if let crate::Configuration::Default = configuration {
if let Some(output) = self.output.clone() {
let output = configuration.replace_extension(&output);
let new_filename = output.into_os_string().into_string().unwrap();
args.push("-o".to_string());
args.push(new_filename);
}
} else if let Some(output) = self.output.clone() {
let output = configuration.replace_extension(&output); let output = configuration.replace_extension(&output);
let new_filename = output.into_os_string().into_string().unwrap(); let new_filename = output.into_os_string().into_string().unwrap();
args.push("-o".to_string()); args.push("-o".to_string());
args.push(new_filename); args.push(new_filename);
args.extend_from_slice(base_args.as_slice());
} else { } else {
// No output specified, we need to rewrite the single .c file's name. // No output specified, we need to rewrite the single .c file's name into a -o
args.extend( // argument.
base_args for arg in &base_args {
.iter() let arg_as_path = std::path::PathBuf::from(arg);
.map(|r| { if !arg.ends_with('.') && !arg.starts_with('-') {
let arg_as_path = std::path::PathBuf::from(r); if let Some(extension) = arg_as_path.extension() {
if r.ends_with('.') { let extension = extension.to_str().unwrap();
r.to_string() let extension_lowercase = extension.to_lowercase();
} else { match &extension_lowercase[..] {
if let Some(extension) = arg_as_path.extension() { "c" | "cc" | "cxx" | "cpp" => {
let extension = extension.to_str().unwrap(); args.push("-o".to_string());
let extension_lowercase = extension.to_lowercase(); args.push(if self.linking {
match &extension_lowercase[..] { configuration
"c" | "cc" | "cxx" | "cpp" => { .replace_extension(&std::path::PathBuf::from("a.out"))
configuration.replace_extension(&arg_as_path) .into_os_string()
} .into_string()
_ => arg_as_path, .unwrap()
} } else {
} else { let mut result = configuration.replace_extension(&arg_as_path);
arg_as_path result.set_extension("o");
result.into_os_string().into_string().unwrap()
});
break;
} }
.into_os_string() _ => {}
.into_string()
.unwrap()
} }
}) }
.collect::<Vec<_>>(), }
); }
} }
args.extend_from_slice(base_args.as_slice());
args.extend_from_slice(&configuration.to_flags()?); args.extend_from_slice(&configuration.to_flags()?);
if self.need_libafl_arg && !self.has_libafl_arg { if self.need_libafl_arg && !self.has_libafl_arg {

View File

@ -178,9 +178,7 @@ impl ToolWrapper for LibtoolWrapper {
let extension = extension.to_str().unwrap(); let extension = extension.to_str().unwrap();
let extension_lowercase = extension.to_lowercase(); let extension_lowercase = extension.to_lowercase();
match &extension_lowercase[..] { match &extension_lowercase[..] {
"o" | "lo" | "a" | "la" | "so" => { "lo" | "la" | "so" => configuration.replace_extension(&arg_as_path),
configuration.replace_extension(&arg_as_path)
}
_ => arg_as_path, _ => arg_as_path,
} }
} else { } else {