Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
davehylands committed Jan 5, 2022
0 parents commit 2cbfff7
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/target
Cargo.lock
15 changes: 15 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "align"
version = "0.1.0"
authors = ["Dave Hylands <[email protected]>"]
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"]

19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.

24 changes: 24 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#[inline(never)]
#[no_mangle]
pub unsafe extern "C" fn align_of_u8() -> usize {
std::mem::align_of::<u8>()
}

#[inline(never)]
#[no_mangle]
pub unsafe extern "C" fn align_of_u16() -> usize {
std::mem::align_of::<u16>()
}

#[inline(never)]
#[no_mangle]
pub unsafe extern "C" fn align_of_u32() -> usize {
std::mem::align_of::<u32>()
}

#[inline(never)]
#[no_mangle]
pub unsafe extern "C" fn align_of_u64() -> usize {
std::mem::align_of::<u64>()
}

0 comments on commit 2cbfff7

Please sign in to comment.