Skip to content

Instantly share code, notes, and snippets.

@Amanieu
Created January 28, 2022 11:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Amanieu/b7523fa69adf5cefab3ab5269602d4db to your computer and use it in GitHub Desktop.
Save Amanieu/b7523fa69adf5cefab3ab5269602d4db to your computer and use it in GitHub Desktop.
// Helper macros to deal with platform-specific differences in assembly code
// between ELF, Mach-O and COFF file formats.
cfg_if::cfg_if! {
if #[cfg(windows)] {
// COFF
macro_rules! asm_function_begin {
($name:tt) => {
concat!(
".globl ", $name, "\n",
".def ", $name, "\n",
".scl 2\n",
".type 32\n",
".endef ", $name, "\n",
$name, ":\n",
)
};
}
macro_rules! asm_function_end {
($name:tt) => {
""
};
}
} else if #[cfg(target_vendor = "apple")] {
// Mach-O
macro_rules! asm_function_begin {
($name:tt) => {
concat!(
".globl _", $name, "\n",
".private_extern _", $name, "\n",
"_", $name, ":\n",
)
};
}
macro_rules! asm_function_end {
($name:tt) => {
""
};
}
} else {
// Everything else uses ELF
macro_rules! asm_function_begin {
($name:tt) => {
concat!(
".globl ", $name, "\n",
".hidden ", $name, "\n",
".type ", $name, ", @function\n",
$name, ":\n",
)
};
}
macro_rules! asm_function_end {
($name:tt) => {
concat!(".size ", $name, ", . - ", $name, "\n")
};
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment