Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use -nostdlibinc for non-Apple, non-X86_64 targets when using clang. #2065

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
20 changes: 8 additions & 12 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ const X86: &str = "x86";
const X86_64: &str = "x86_64";
const AARCH64: &str = "aarch64";
const ARM: &str = "arm";
const WASM32: &str = "wasm32";

#[rustfmt::skip]
const RING_SRCS: &[(&[&str], &str)] = &[
Expand Down Expand Up @@ -299,8 +298,8 @@ fn ring_build_rs_main(c_root_dir: &Path, core_name_and_version: &str) {
let out_dir = PathBuf::from(out_dir);

let arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap();
let vendor = env::var("CARGO_CFG_TARGET_VENDOR").unwrap();
let os = env::var("CARGO_CFG_TARGET_OS").unwrap();
let env = env::var("CARGO_CFG_TARGET_ENV").unwrap();

let is_git = fs::metadata(c_root_dir.join(".git")).is_ok();

Expand All @@ -315,8 +314,8 @@ fn ring_build_rs_main(c_root_dir: &Path, core_name_and_version: &str) {

let target = Target {
arch,
vendor,
os,
env,
is_debug,
force_warnings_into_errors,
};
Expand Down Expand Up @@ -395,8 +394,8 @@ fn generate_sources_and_preassemble<'a>(

struct Target {
arch: String,
vendor: String,
os: String,
env: String,

/// Is this a debug build? This affects whether assertions might be enabled
/// in the C code. For packaged builds, this should always be `false`.
Expand Down Expand Up @@ -573,14 +572,11 @@ fn configure_cc(c: &mut cc::Build, target: &Target, c_root_dir: &Path, include_d
}

// Allow cross-compiling without a target sysroot for these targets.
if (target.arch == WASM32)
|| (target.os == "linux" && target.env == "musl" && target.arch != X86_64)
{
// TODO: Expand this to non-clang compilers in 0.17.0 if practical.
if compiler.is_like_clang() {
let _ = c.flag("-nostdlibinc");
let _ = c.define("RING_CORE_NOSTDLIBINC", "1");
}
// curve25519_adx.h includes <immintrin.h> which requires <stdlib.h>.
// TODO: Expand this to non-clang compilers in 0.17.0 if practical.
if target.vendor != "apple" && target.arch != X86_64 && compiler.is_like_clang() {
let _ = c.flag("-nostdlibinc");
let _ = c.define("RING_CORE_NOSTDLIBINC", "1");
}

if target.force_warnings_into_errors {
Expand Down
2 changes: 1 addition & 1 deletion crypto/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ static inline crypto_word_t constant_time_declassify_w(crypto_word_t v) {

// Endianness conversions.

#if defined(__GNUC__) && __GNUC__ >= 2
#if defined(__clang__) || (defined(__GNUC__) && __GNUC__ >= 2)
static inline uint32_t CRYPTO_bswap4(uint32_t x) {
return __builtin_bswap32(x);
}
Expand Down
7 changes: 7 additions & 0 deletions include/ring-core/check.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@
# else
# define debug_assert_nonsecret(x) ((void)0)
# endif
# if defined(__has_include)
# if __has_include(<assert.h>)
# include <assert.h>
# undef debug_assert_nonsecret
# define debug_assert_nonsecret(x) assert(x)
# endif
# endif
#endif

// |dev_assert_secret| is like |assert| and should be used (only) when the
Expand Down
Loading