Skip to content

Commit a27553d

Browse files
authored
libafl_cc: fix configuration support (#1595)
* libafl_cc: fix configuration support * fmt * clippy
1 parent f35c591 commit a27553d

File tree

2 files changed

+39
-32
lines changed

2 files changed

+39
-32
lines changed

libafl_cc/src/clang.rs

Lines changed: 38 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ impl ToolWrapper for ClangWrapper {
194194
continue;
195195
}
196196
}
197-
"--libafl-ignore-configurations" => {
197+
"--libafl-ignore-configurations" | "-print-prog-name=ld" => {
198198
self.ignoring_configurations = true;
199199
i += 1;
200200
continue;
@@ -346,43 +346,52 @@ impl ToolWrapper for ClangWrapper {
346346
})
347347
.collect::<Vec<_>>();
348348

349-
if let Some(output) = self.output.clone() {
349+
if let crate::Configuration::Default = configuration {
350+
if let Some(output) = self.output.clone() {
351+
let output = configuration.replace_extension(&output);
352+
let new_filename = output.into_os_string().into_string().unwrap();
353+
args.push("-o".to_string());
354+
args.push(new_filename);
355+
}
356+
} else if let Some(output) = self.output.clone() {
350357
let output = configuration.replace_extension(&output);
351358
let new_filename = output.into_os_string().into_string().unwrap();
352359
args.push("-o".to_string());
353360
args.push(new_filename);
354-
args.extend_from_slice(base_args.as_slice());
355361
} else {
356-
// No output specified, we need to rewrite the single .c file's name.
357-
args.extend(
358-
base_args
359-
.iter()
360-
.map(|r| {
361-
let arg_as_path = std::path::PathBuf::from(r);
362-
if r.ends_with('.') {
363-
r.to_string()
364-
} else {
365-
if let Some(extension) = arg_as_path.extension() {
366-
let extension = extension.to_str().unwrap();
367-
let extension_lowercase = extension.to_lowercase();
368-
match &extension_lowercase[..] {
369-
"c" | "cc" | "cxx" | "cpp" => {
370-
configuration.replace_extension(&arg_as_path)
371-
}
372-
_ => arg_as_path,
373-
}
374-
} else {
375-
arg_as_path
362+
// No output specified, we need to rewrite the single .c file's name into a -o
363+
// argument.
364+
for arg in &base_args {
365+
let arg_as_path = std::path::PathBuf::from(arg);
366+
if !arg.ends_with('.') && !arg.starts_with('-') {
367+
if let Some(extension) = arg_as_path.extension() {
368+
let extension = extension.to_str().unwrap();
369+
let extension_lowercase = extension.to_lowercase();
370+
match &extension_lowercase[..] {
371+
"c" | "cc" | "cxx" | "cpp" => {
372+
args.push("-o".to_string());
373+
args.push(if self.linking {
374+
configuration
375+
.replace_extension(&std::path::PathBuf::from("a.out"))
376+
.into_os_string()
377+
.into_string()
378+
.unwrap()
379+
} else {
380+
let mut result = configuration.replace_extension(&arg_as_path);
381+
result.set_extension("o");
382+
result.into_os_string().into_string().unwrap()
383+
});
384+
break;
376385
}
377-
.into_os_string()
378-
.into_string()
379-
.unwrap()
386+
_ => {}
380387
}
381-
})
382-
.collect::<Vec<_>>(),
383-
);
388+
}
389+
}
390+
}
384391
}
385392

393+
args.extend_from_slice(base_args.as_slice());
394+
386395
args.extend_from_slice(&configuration.to_flags()?);
387396

388397
if self.need_libafl_arg && !self.has_libafl_arg {

libafl_cc/src/libtool.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,7 @@ impl ToolWrapper for LibtoolWrapper {
178178
let extension = extension.to_str().unwrap();
179179
let extension_lowercase = extension.to_lowercase();
180180
match &extension_lowercase[..] {
181-
"o" | "lo" | "a" | "la" | "so" => {
182-
configuration.replace_extension(&arg_as_path)
183-
}
181+
"lo" | "la" | "so" => configuration.replace_extension(&arg_as_path),
184182
_ => arg_as_path,
185183
}
186184
} else {

0 commit comments

Comments
 (0)