Skip to content
Draft
Show file tree
Hide file tree
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
139 changes: 130 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,12 @@ memmap2 = "0.9.0"
mimalloc = { version = "0.1", default-features = false }
object = { git = "https://github.com/gimli-rs/object", rev = "ae958b9f2c8a3a56fe19bb4b380144a32eebb770", default-features = false, features = [
"elf",
"coff",
"read_core",
"std",
"unaligned",
"archive",
"pe",
] }
os_info = "3.0.0"
paste = "1.0.15"
Expand Down Expand Up @@ -97,9 +99,12 @@ tracing-subscriber = { version = "0.3.16", default-features = false, features =
] }
uuid = { version = "1.0.0", features = ["v4"] }
wait-timeout = "0.2.0"
walkdir = "2"
wait4 = "0.1.3"
which = "8.0.0"
windows-sys = "0.61.2"
winnow = { version = "0.7.13", features = ["simd"] }
phnt = "0.1.2"
zerocopy = { version = "0.8.27", features = ["derive"] }
zstd = "0.13.0"

Expand Down
16 changes: 16 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

# list all available just targets
default:
@just --list


# Dump the symbol table of kernel32.lib using llvm-objdump
dump-kernel32:
@llvm-objdump -a -t "C:/Program Files (x86)/Windows Kits/10/Lib/10.0.22621.0/um/x64/kernel32.Lib" > kernel32.dump

# Compile and link a minimal PE test using clang with wild as the linker
test-pe:
cargo build -p wild-linker --bin wild
mkdir -p target/testing
clang -B./target/debug/ -fuse-ld=wild -target x86_64-pc-windows-msvc -nostdlib -e entry test_pe/test.c -o target/testing/test.exe
./target/testing/test.exe || echo $?
15 changes: 15 additions & 0 deletions libwild/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ sharded-vec-writer = { workspace = true }
smallvec = { workspace = true }
symbolic-common = { workspace = true }
symbolic-demangle = { workspace = true }
target-lexicon = "0.13"
thread_local = { workspace = true }
tracing = { workspace = true }
tracing-subscriber = { workspace = true }
Expand All @@ -56,6 +57,20 @@ zstd = { workspace = true }
[target.'cfg(all(target_os = "linux", any(target_arch = "x86_64", target_arch = "aarch64")))'.dependencies]
perf-event = { workspace = true }

[target.'cfg(target_os = "windows")'.dependencies]
phnt = { workspace = true }

[target.'cfg(target_os = "windows")'.dependencies.windows-sys]
workspace = true
features = [
"Win32_System_Threading",
"Win32_System_Console",
"Win32_System_Pipes",
"Win32_Security",
"Win32_Storage_FileSystem",
"Win32_System_IO",
]

[dev-dependencies]
ar = { workspace = true }
tempfile = { workspace = true }
Expand Down
29 changes: 27 additions & 2 deletions libwild/src/arch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use object::elf::EM_AARCH64;
use object::elf::EM_LOONGARCH;
use object::elf::EM_RISCV;
use object::elf::EM_X86_64;
use object::pe::IMAGE_FILE_MACHINE_AMD64;
use object::pe::IMAGE_FILE_MACHINE_ARM64;
use std::fmt::Display;

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
Expand All @@ -14,13 +16,36 @@ pub(crate) enum Architecture {
LoongArch64,
}

impl Default for Architecture {
fn default() -> Self {
Architecture::DEFAULT
}
}

impl Architecture {
pub const DEFAULT: Self = const {
#[cfg(target_arch = "x86_64")]
{
Architecture::X86_64
}
#[cfg(target_arch = "aarch64")]
{
Architecture::AArch64
}
#[cfg(target_arch = "riscv64")]
{
Architecture::RISCV64
}
};
}

impl TryFrom<u16> for Architecture {
type Error = crate::error::Error;

fn try_from(arch: u16) -> Result<Self, Self::Error> {
match arch {
EM_X86_64 => Ok(Self::X86_64),
EM_AARCH64 => Ok(Self::AArch64),
EM_X86_64 | IMAGE_FILE_MACHINE_AMD64 => Ok(Self::X86_64),
EM_AARCH64 | IMAGE_FILE_MACHINE_ARM64 => Ok(Self::AArch64),
EM_RISCV => Ok(Self::RISCV64),
EM_LOONGARCH => Ok(Self::LoongArch64),
_ => bail!("Unsupported architecture: 0x{:x}", arch),
Expand Down
Loading