Skip to content

Commit 17f3375

Browse files
authored
Enable gcc-4.8 compilation (#1928)
1 parent 40a14b5 commit 17f3375

File tree

5 files changed

+66
-47
lines changed

5 files changed

+66
-47
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* Copyright (C) 2023 Amazon.com, Inc. or its affiliates. All rights reserved.
3+
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4+
*/
5+
6+
#if !defined(__GNUC_PREREQ) && (defined(__GNUC__) || defined(__GNUG__)) \
7+
&& !defined(__clang__) && defined(__GNUC_MINOR__)
8+
/* Depending on the platform the macro is defined in sys/features.h or
9+
features.h Given the macro is simple, we re-implement it here instead of
10+
dealing with two different paths.
11+
*/
12+
#define __GNUC_PREREQ(maj, min) \
13+
((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
14+
#endif

core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/numeric_limits.h

Lines changed: 0 additions & 42 deletions
This file was deleted.

core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#include "bh_platform.h"
1616
#include "wasmtime_ssp.h"
1717
#include "locking.h"
18-
#include "numeric_limits.h"
1918
#include "posix.h"
2019
#include "random.h"
2120
#include "refcount.h"
@@ -2257,8 +2256,7 @@ convert_timestamp(__wasi_timestamp_t in, struct timespec *out)
22572256
in /= 1000000000;
22582257

22592258
// Clamp to the maximum in case it would overflow our system's time_t.
2260-
out->tv_sec =
2261-
(time_t)in < NUMERIC_MAX(time_t) ? (time_t)in : NUMERIC_MAX(time_t);
2259+
out->tv_sec = (time_t)in < BH_TIME_T_MAX ? (time_t)in : BH_TIME_T_MAX;
22622260
}
22632261

22642262
// Converts the provided timestamps and flags to a set of arguments for

core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/refcount.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include "bh_platform.h"
1818
#include "locking.h"
19+
#include "gnuc.h"
1920

2021
#define PRODUCES(...) LOCKS_SHARED(__VA_ARGS__) NO_LOCK_ANALYSIS
2122
#define CONSUMES(...) UNLOCKS(__VA_ARGS__) NO_LOCK_ANALYSIS
@@ -95,6 +96,42 @@ refcount_release(struct refcount *r)
9596
return old == 1;
9697
}
9798

99+
#elif defined(__GNUC_PREREQ)
100+
101+
#if __GNUC_PREREQ(4, 7)
102+
103+
struct refcount {
104+
unsigned int count;
105+
};
106+
107+
/* Initialize the reference counter. */
108+
static inline void
109+
refcount_init(struct refcount *r, unsigned int count)
110+
{
111+
__atomic_store_n(&r->count, count, __ATOMIC_SEQ_CST);
112+
}
113+
114+
/* Increment the reference counter. */
115+
static inline void
116+
refcount_acquire(struct refcount *r)
117+
{
118+
__atomic_fetch_add(&r->count, 1, __ATOMIC_ACQUIRE);
119+
}
120+
121+
/* Decrement the reference counter, returning whether the reference
122+
dropped to zero. */
123+
static inline bool
124+
refcount_release(struct refcount *r)
125+
{
126+
int old = (int)__atomic_fetch_sub(&r->count, 1, __ATOMIC_RELEASE);
127+
bh_assert(old != 0 && "Reference count becoming negative");
128+
return old == 1;
129+
}
130+
131+
#else /* else of __GNUC_PREREQ (4.7) */
132+
#error "Reference counter isn't implemented"
133+
#endif /* end of __GNUC_PREREQ (4.7) */
134+
98135
#else /* else of CONFIG_HAS_STD_ATOMIC */
99136
#error "Reference counter isn't implemented"
100137
#endif /* end of CONFIG_HAS_STD_ATOMIC */

core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/ssp_config.h

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#ifndef SSP_CONFIG_H
1515
#define SSP_CONFIG_H
1616

17+
#include "gnuc.h"
1718
#include <stdlib.h>
1819

1920
#if defined(__FreeBSD__) || defined(__APPLE__) \
@@ -107,10 +108,21 @@
107108
#endif
108109

109110
#if !defined(BH_PLATFORM_LINUX_SGX)
111+
#if defined(__GNUC_PREREQ)
112+
/* Even though older versions of GCC support C11, atomics were
113+
not implemented until 4.9. See
114+
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58016 */
115+
#if __GNUC_PREREQ(4, 9)
110116
#define CONFIG_HAS_STD_ATOMIC 1
111-
#else
117+
#else /* else of __GNUC_PREREQ(4, 9) */
112118
#define CONFIG_HAS_STD_ATOMIC 0
113-
#endif
119+
#endif /* end of __GNUC_PREREQ(4, 9) */
120+
#else /* else of defined(__GNUC_PREREQ) */
121+
#define CONFIG_HAS_STD_ATOMIC 1
122+
#endif /* end of defined(__GNUC_PREREQ) */
123+
#else /* else of !defined(BH_PLATFORM_LINUX_SGX) */
124+
#define CONFIG_HAS_STD_ATOMIC 0
125+
#endif /* end of !defined(BH_PLATFORM_LINUX_SGX) */
114126

115127
#if !defined(__NuttX__)
116128
#define CONFIG_HAS_D_INO 1

0 commit comments

Comments
 (0)