diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..96ef6c0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/target +Cargo.lock diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..1c1864b --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "align" +version = "0.1.0" +authors = ["Dave Hylands "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] + +[lib] +name = "align" +path = "src/lib.rs" +crate-type = ["staticlib"] + diff --git a/README.md b/README.md new file mode 100644 index 0000000..986f8aa --- /dev/null +++ b/README.md @@ -0,0 +1,19 @@ +Simple project for determining the alignment for various architectures. + +To use, install an appropriate target using `rustup target add TARGETNAME` + +You can then build using `cargo build --target=TARGETNAME` and disassemble the lib using: +`llvm-objdump -d target/TARGETNAME/debug/libalign.a` + +I tested the following: + +* aarch64-apple-ios +* armv5te-unknown-linux-gnueabi +* armv7-linux-androideabi +* i686-linux-android +* x86_64-apple-darwin +* x86_64-apple-ios + +and they all produced 1, 2, 4, and 8 for the alignment of u8, u16, u32, and u64 +with the exception that i686-linux-android produced an alignment of 4 for u64. + diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..a7cccd2 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,24 @@ +#[inline(never)] +#[no_mangle] +pub unsafe extern "C" fn align_of_u8() -> usize { + std::mem::align_of::() +} + +#[inline(never)] +#[no_mangle] +pub unsafe extern "C" fn align_of_u16() -> usize { + std::mem::align_of::() +} + +#[inline(never)] +#[no_mangle] +pub unsafe extern "C" fn align_of_u32() -> usize { + std::mem::align_of::() +} + +#[inline(never)] +#[no_mangle] +pub unsafe extern "C" fn align_of_u64() -> usize { + std::mem::align_of::() +} +