mirror of
https://github.com/bytecodealliance/wasm-micro-runtime.git
synced 2025-05-13 13:11:25 +00:00
Enable gcc-4.8 compilation (#1928)
This commit is contained in:
parent
40a14b51c5
commit
17f3375d53
|
@ -0,0 +1,14 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2023 Amazon.com, Inc. or its affiliates. All rights reserved.
|
||||||
|
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if !defined(__GNUC_PREREQ) && (defined(__GNUC__) || defined(__GNUG__)) \
|
||||||
|
&& !defined(__clang__) && defined(__GNUC_MINOR__)
|
||||||
|
/* Depending on the platform the macro is defined in sys/features.h or
|
||||||
|
features.h Given the macro is simple, we re-implement it here instead of
|
||||||
|
dealing with two different paths.
|
||||||
|
*/
|
||||||
|
#define __GNUC_PREREQ(maj, min) \
|
||||||
|
((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
|
||||||
|
#endif
|
|
@ -1,42 +0,0 @@
|
||||||
// Part of the Wasmtime Project, under the Apache License v2.0 with LLVM
|
|
||||||
// Exceptions. See
|
|
||||||
// https://github.com/bytecodealliance/wasmtime/blob/main/LICENSE for license
|
|
||||||
// information.
|
|
||||||
//
|
|
||||||
// Significant parts of this file are derived from cloudabi-utils. See
|
|
||||||
// https://github.com/bytecodealliance/wasmtime/blob/main/lib/wasi/sandboxed-system-primitives/src/LICENSE
|
|
||||||
// for license information.
|
|
||||||
//
|
|
||||||
// The upstream file contains the following copyright notice:
|
|
||||||
//
|
|
||||||
// Copyright (c) 2015 Nuxi, https://nuxi.nl/
|
|
||||||
|
|
||||||
#ifndef COMMON_LIMITS_H
|
|
||||||
#define COMMON_LIMITS_H
|
|
||||||
|
|
||||||
#define NUMERIC_MIN(t) \
|
|
||||||
_Generic((t)0, char \
|
|
||||||
: CHAR_MIN, signed char \
|
|
||||||
: SCHAR_MIN, unsigned char : 0, short \
|
|
||||||
: SHRT_MIN, unsigned short : 0, int \
|
|
||||||
: INT_MIN, unsigned int : 0, long \
|
|
||||||
: LONG_MIN, unsigned long : 0, long long \
|
|
||||||
: LLONG_MIN, unsigned long long : 0, default \
|
|
||||||
: (void)0)
|
|
||||||
|
|
||||||
#define NUMERIC_MAX(t) \
|
|
||||||
_Generic((t)0, char \
|
|
||||||
: CHAR_MAX, signed char \
|
|
||||||
: SCHAR_MAX, unsigned char \
|
|
||||||
: UCHAR_MAX, short \
|
|
||||||
: SHRT_MAX, unsigned short \
|
|
||||||
: USHRT_MAX, int \
|
|
||||||
: INT_MAX, unsigned int \
|
|
||||||
: UINT_MAX, long \
|
|
||||||
: LONG_MAX, unsigned long \
|
|
||||||
: ULONG_MAX, long long \
|
|
||||||
: LLONG_MAX, unsigned long long \
|
|
||||||
: ULLONG_MAX, default \
|
|
||||||
: (void)0)
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -15,7 +15,6 @@
|
||||||
#include "bh_platform.h"
|
#include "bh_platform.h"
|
||||||
#include "wasmtime_ssp.h"
|
#include "wasmtime_ssp.h"
|
||||||
#include "locking.h"
|
#include "locking.h"
|
||||||
#include "numeric_limits.h"
|
|
||||||
#include "posix.h"
|
#include "posix.h"
|
||||||
#include "random.h"
|
#include "random.h"
|
||||||
#include "refcount.h"
|
#include "refcount.h"
|
||||||
|
@ -2257,8 +2256,7 @@ convert_timestamp(__wasi_timestamp_t in, struct timespec *out)
|
||||||
in /= 1000000000;
|
in /= 1000000000;
|
||||||
|
|
||||||
// Clamp to the maximum in case it would overflow our system's time_t.
|
// Clamp to the maximum in case it would overflow our system's time_t.
|
||||||
out->tv_sec =
|
out->tv_sec = (time_t)in < BH_TIME_T_MAX ? (time_t)in : BH_TIME_T_MAX;
|
||||||
(time_t)in < NUMERIC_MAX(time_t) ? (time_t)in : NUMERIC_MAX(time_t);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Converts the provided timestamps and flags to a set of arguments for
|
// Converts the provided timestamps and flags to a set of arguments for
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
#include "bh_platform.h"
|
#include "bh_platform.h"
|
||||||
#include "locking.h"
|
#include "locking.h"
|
||||||
|
#include "gnuc.h"
|
||||||
|
|
||||||
#define PRODUCES(...) LOCKS_SHARED(__VA_ARGS__) NO_LOCK_ANALYSIS
|
#define PRODUCES(...) LOCKS_SHARED(__VA_ARGS__) NO_LOCK_ANALYSIS
|
||||||
#define CONSUMES(...) UNLOCKS(__VA_ARGS__) NO_LOCK_ANALYSIS
|
#define CONSUMES(...) UNLOCKS(__VA_ARGS__) NO_LOCK_ANALYSIS
|
||||||
|
@ -95,6 +96,42 @@ refcount_release(struct refcount *r)
|
||||||
return old == 1;
|
return old == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#elif defined(__GNUC_PREREQ)
|
||||||
|
|
||||||
|
#if __GNUC_PREREQ(4, 7)
|
||||||
|
|
||||||
|
struct refcount {
|
||||||
|
unsigned int count;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Initialize the reference counter. */
|
||||||
|
static inline void
|
||||||
|
refcount_init(struct refcount *r, unsigned int count)
|
||||||
|
{
|
||||||
|
__atomic_store_n(&r->count, count, __ATOMIC_SEQ_CST);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Increment the reference counter. */
|
||||||
|
static inline void
|
||||||
|
refcount_acquire(struct refcount *r)
|
||||||
|
{
|
||||||
|
__atomic_fetch_add(&r->count, 1, __ATOMIC_ACQUIRE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Decrement the reference counter, returning whether the reference
|
||||||
|
dropped to zero. */
|
||||||
|
static inline bool
|
||||||
|
refcount_release(struct refcount *r)
|
||||||
|
{
|
||||||
|
int old = (int)__atomic_fetch_sub(&r->count, 1, __ATOMIC_RELEASE);
|
||||||
|
bh_assert(old != 0 && "Reference count becoming negative");
|
||||||
|
return old == 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else /* else of __GNUC_PREREQ (4.7) */
|
||||||
|
#error "Reference counter isn't implemented"
|
||||||
|
#endif /* end of __GNUC_PREREQ (4.7) */
|
||||||
|
|
||||||
#else /* else of CONFIG_HAS_STD_ATOMIC */
|
#else /* else of CONFIG_HAS_STD_ATOMIC */
|
||||||
#error "Reference counter isn't implemented"
|
#error "Reference counter isn't implemented"
|
||||||
#endif /* end of CONFIG_HAS_STD_ATOMIC */
|
#endif /* end of CONFIG_HAS_STD_ATOMIC */
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
#ifndef SSP_CONFIG_H
|
#ifndef SSP_CONFIG_H
|
||||||
#define SSP_CONFIG_H
|
#define SSP_CONFIG_H
|
||||||
|
|
||||||
|
#include "gnuc.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#if defined(__FreeBSD__) || defined(__APPLE__) \
|
#if defined(__FreeBSD__) || defined(__APPLE__) \
|
||||||
|
@ -107,10 +108,21 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined(BH_PLATFORM_LINUX_SGX)
|
#if !defined(BH_PLATFORM_LINUX_SGX)
|
||||||
|
#if defined(__GNUC_PREREQ)
|
||||||
|
/* Even though older versions of GCC support C11, atomics were
|
||||||
|
not implemented until 4.9. See
|
||||||
|
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58016 */
|
||||||
|
#if __GNUC_PREREQ(4, 9)
|
||||||
#define CONFIG_HAS_STD_ATOMIC 1
|
#define CONFIG_HAS_STD_ATOMIC 1
|
||||||
#else
|
#else /* else of __GNUC_PREREQ(4, 9) */
|
||||||
#define CONFIG_HAS_STD_ATOMIC 0
|
#define CONFIG_HAS_STD_ATOMIC 0
|
||||||
#endif
|
#endif /* end of __GNUC_PREREQ(4, 9) */
|
||||||
|
#else /* else of defined(__GNUC_PREREQ) */
|
||||||
|
#define CONFIG_HAS_STD_ATOMIC 1
|
||||||
|
#endif /* end of defined(__GNUC_PREREQ) */
|
||||||
|
#else /* else of !defined(BH_PLATFORM_LINUX_SGX) */
|
||||||
|
#define CONFIG_HAS_STD_ATOMIC 0
|
||||||
|
#endif /* end of !defined(BH_PLATFORM_LINUX_SGX) */
|
||||||
|
|
||||||
#if !defined(__NuttX__)
|
#if !defined(__NuttX__)
|
||||||
#define CONFIG_HAS_D_INO 1
|
#define CONFIG_HAS_D_INO 1
|
||||||
|
|
Loading…
Reference in New Issue
Block a user