Skip to content

Commit 7acdeac

Browse files
authored
Allow compiling 32bit (#1666)
* Allow compiling for 32bit * Fmt * Clean up minibsod for 32bit * fmt
1 parent 8c62d33 commit 7acdeac

File tree

6 files changed

+34
-7
lines changed

6 files changed

+34
-7
lines changed

libafl_bolts/src/minibsod.rs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,23 @@ fn write_crash<W: Write>(
467467
Ok(())
468468
}
469469

470+
#[cfg(all(any(target_os = "linux", target_os = "android"), target_arch = "x86"))]
471+
fn write_crash<W: Write>(
472+
writer: &mut BufWriter<W>,
473+
signal: Signal,
474+
ucontext: &ucontext_t,
475+
) -> Result<(), std::io::Error> {
476+
writeln!(
477+
writer,
478+
"Received signal {} at {:#08x}, fault address: {:#08x}",
479+
signal,
480+
ucontext.uc_mcontext.gregs[libc::REG_EIP as usize],
481+
ucontext.uc_mcontext.gregs[libc::REG_ERR as usize]
482+
)?;
483+
484+
Ok(())
485+
}
486+
470487
#[cfg(all(
471488
any(target_os = "linux", target_os = "android"),
472489
target_arch = "aarch64"
@@ -896,8 +913,12 @@ pub fn generate_minibsod<W: Write>(
896913
writeln!(writer, "{:━^100}", " CRASH ")?;
897914
if let Some(uctx) = ucontext {
898915
write_crash(writer, signal, uctx)?;
899-
writeln!(writer, "{:━^100}", " REGISTERS ")?;
900-
dump_registers(writer, uctx)?;
916+
917+
#[cfg(target_pointer_width = "64")]
918+
{
919+
writeln!(writer, "{:━^100}", " REGISTERS ")?;
920+
dump_registers(writer, uctx)?;
921+
}
901922
} else {
902923
writeln!(writer, "Received signal {signal}")?;
903924
}

libafl_cc/build.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ fn build_pass(
159159
let r = if cfg!(unix) {
160160
let r = Command::new(bindir_path.join("clang++"))
161161
.arg("-v")
162+
.arg(format!("--target={}", env::var("HOST").unwrap()))
162163
.args(cxxflags)
163164
.arg(src_dir.join(src_file))
164165
.args(additionals)
@@ -171,6 +172,7 @@ fn build_pass(
171172
} else if cfg!(windows) {
172173
let r = Command::new(bindir_path.join("clang-cl.exe"))
173174
.arg("-v")
175+
.arg(format!("--target={}", env::var("HOST").unwrap()))
174176
.args(cxxflags)
175177
.arg(src_dir.join(src_file))
176178
.args(additionals)

libafl_cc/src/no-link-rt.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include <stdint.h>
22

3-
#ifndef _WIN32
3+
#if !defined(_WIN32) && defined(__SIZEOF_INT128__)
44
typedef unsigned __int128 uint128_t;
55
typedef uint128_t u128;
66
#endif
@@ -56,7 +56,7 @@ void __cmplog_ins_hook8(uint64_t arg1, uint64_t arg2) {
5656
(void)arg2;
5757
}
5858

59-
#ifndef _WIN32
59+
#if !defined(_WIN32) && defined(__SIZEOF_INT128__)
6060
void __cmplog_ins_hook16_extended(uint128_t arg1, uint128_t arg2,
6161
uint8_t attr) {
6262
(void)attr;

libafl_targets/build.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ fn main() {
137137
println!("cargo:rerun-if-changed=src/common.c");
138138

139139
#[cfg(feature = "sanitizer_interfaces")]
140-
{
140+
if env::var("CARGO_CFG_TARGET_POINTER_WIDTH").unwrap() == "64" {
141141
println!("cargo:rerun-if-changed=src/sanitizer_interfaces.h");
142142

143143
let build = bindgen::builder()
@@ -151,6 +151,10 @@ fn main() {
151151
build
152152
.write_to_file(Path::new(&out_dir).join("sanitizer_interfaces.rs"))
153153
.expect("Couldn't write the sanitizer headers!");
154+
} else {
155+
let mut file = File::create(Path::new(&out_dir).join("sanitizer_interfaces.rs"))
156+
.expect("Could not create file");
157+
write!(file, "").unwrap();
154158
}
155159

156160
let mut common = cc::Build::new();

libafl_targets/src/cmplog.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ void __cmplog_ins_hook8(uint64_t arg1, uint64_t arg2) {
252252
__libafl_targets_cmplog_instructions(k, 8, arg1, arg2);
253253
}
254254

255-
#ifndef _WIN32
255+
#if !defined(_WIN32) && defined(__SIZEOF_INT128__)
256256
void __cmplog_ins_hook16_extended(uint128_t arg1, uint128_t arg2,
257257
uint8_t attr) {
258258
uintptr_t k = RETADDR;

libafl_targets/src/common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#define true 1
77
#define false 0
88

9-
#ifndef _WIN32
9+
#if !defined(_WIN32) && defined(__SIZEOF_INT128__)
1010
typedef unsigned __int128 uint128_t;
1111
typedef uint128_t u128;
1212
#endif

0 commit comments

Comments
 (0)