Skip to content

Commit b0555fc

Browse files
Dan Gohmanjohn-sharratt
authored andcommitted
Delete several blocks of unused code. (WebAssembly#294)
* Delete several blocks of unused code. Delete several pieces of code from libc-bottom-half/cloudlibc that aren't in use on wasi-libc. * Delete more of `_CLOCK_PROCESS_CPUTIME_ID` or `_CLOCK_THREAD_CPUTIME_ID`.
1 parent b4c55d2 commit b0555fc

File tree

27 files changed

+6
-7250
lines changed

27 files changed

+6
-7250
lines changed

expected/wasm32-wasi/posix/predefined-macros.txt

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

expected/wasm32-wasi/single/defined-symbols.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
_CLOCK_MONOTONIC
2-
_CLOCK_PROCESS_CPUTIME_ID
32
_CLOCK_REALTIME
4-
_CLOCK_THREAD_CPUTIME_ID
53
_Exit
64
_Fork
75
_IO_feof_unlocked

libc-bottom-half/cloudlibc/src/common/errno.h

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

libc-bottom-half/cloudlibc/src/common/overflow.h

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

libc-bottom-half/cloudlibc/src/common/time.h

Lines changed: 4 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#define COMMON_TIME_H
77

88
#include <common/limits.h>
9-
#include <common/overflow.h>
109

1110
#include <sys/time.h>
1211

@@ -16,43 +15,6 @@
1615

1716
#define NSEC_PER_SEC 1000000000
1817

19-
// Timezone agnostic conversion routines.
20-
int __localtime_utc(time_t, struct tm *);
21-
void __mktime_utc(const struct tm *, struct timespec *);
22-
23-
static inline bool is_leap(time_t year) {
24-
year %= 400;
25-
if (year < 0)
26-
year += 400;
27-
return ((year % 4) == 0 && (year % 100) != 0) || year == 100;
28-
}
29-
30-
// Gets the length of the months in a year.
31-
static inline const char *get_months(time_t year) {
32-
static const char leap[12] = {
33-
31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31,
34-
};
35-
static const char common[12] = {
36-
31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31,
37-
};
38-
return is_leap(year) ? leap : common;
39-
}
40-
41-
// Gets the cumulative length of the months in a year.
42-
static inline const short *get_months_cumulative(time_t year) {
43-
static const short leap[13] = {
44-
0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366,
45-
};
46-
static const short common[13] = {
47-
0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365,
48-
};
49-
return is_leap(year) ? leap : common;
50-
}
51-
52-
static inline short get_ydays(time_t year) {
53-
return is_leap(year) ? 366 : 365;
54-
}
55-
5618
static inline bool timespec_to_timestamp_exact(
5719
const struct timespec *timespec, __wasi_timestamp_t *timestamp) {
5820
// Invalid nanoseconds field.
@@ -64,8 +26,8 @@ static inline bool timespec_to_timestamp_exact(
6426
return false;
6527

6628
// Make sure our timestamp does not overflow.
67-
return !mul_overflow(timespec->tv_sec, NSEC_PER_SEC, timestamp) &&
68-
!add_overflow(*timestamp, timespec->tv_nsec, timestamp);
29+
return !__builtin_mul_overflow(timespec->tv_sec, NSEC_PER_SEC, timestamp) &&
30+
!__builtin_add_overflow(*timestamp, timespec->tv_nsec, timestamp);
6931
}
7032

7133
static inline bool timespec_to_timestamp_clamp(
@@ -77,8 +39,8 @@ static inline bool timespec_to_timestamp_clamp(
7739
if (timespec->tv_sec < 0) {
7840
// Timestamps before the Epoch are not supported.
7941
*timestamp = 0;
80-
} else if (mul_overflow(timespec->tv_sec, NSEC_PER_SEC, timestamp) ||
81-
add_overflow(*timestamp, timespec->tv_nsec, timestamp)) {
42+
} else if (__builtin_mul_overflow(timespec->tv_sec, NSEC_PER_SEC, timestamp) ||
43+
__builtin_add_overflow(*timestamp, timespec->tv_nsec, timestamp)) {
8244
// Make sure our timestamp does not overflow.
8345
*timestamp = NUMERIC_MAX(__wasi_timestamp_t);
8446
}

libc-bottom-half/cloudlibc/src/include/_/cdefs.h

Lines changed: 0 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -24,126 +24,13 @@
2424
#ifndef ___CDEFS_H_
2525
#define ___CDEFS_H_
2626

27-
// Version information.
28-
#define __cloudlibc__ 1
29-
#define __cloudlibc_major__ 0
30-
#define __cloudlibc_minor__ 102
31-
32-
#ifdef __cplusplus
33-
#define __BEGIN_DECLS extern "C" {
34-
#define __END_DECLS }
35-
#else
36-
#define __BEGIN_DECLS
37-
#define __END_DECLS
38-
#endif
39-
40-
// Whether we should provide inline versions of functions. Due to C++'s
41-
// support for namespaces, it is generally a bad idea to declare
42-
// function macros.
43-
#ifdef __cplusplus
44-
#define _CLOUDLIBC_INLINE_FUNCTIONS 0
45-
#else
46-
#define _CLOUDLIBC_INLINE_FUNCTIONS 1
47-
#endif
48-
4927
// Compiler-independent annotations.
5028

51-
#ifndef __has_builtin
52-
#define __has_builtin(x) 0
53-
#endif
54-
#ifndef __has_extension
55-
#define __has_extension(x) __has_feature(x)
56-
#endif
57-
#ifndef __has_feature
58-
#define __has_feature(x) 0
59-
#endif
60-
61-
#define __offsetof(type, member) __builtin_offsetof(type, member)
62-
#define __containerof(ptr, type, member) \
63-
((type *)((char *)(ptr)-__offsetof(type, member)))
64-
65-
#define __extname(x) __asm__(x)
66-
#define __malloc_like __attribute__((__malloc__))
67-
#define __pure2 __attribute__((__const__))
68-
#define __pure __attribute__((__pure__))
69-
#define __section(x) __attribute__((__section__(x)))
70-
#define __unused __attribute__((__unused__))
71-
#define __used __attribute__((__used__))
72-
#define __weak_symbol __attribute__((__weak__))
73-
74-
// Format string argument type checking.
75-
#define __printflike(format, va) \
76-
__attribute__((__format__(__printf__, format, va)))
77-
#define __scanflike(format, va) \
78-
__attribute__((__format__(__scanf__, format, va)))
79-
// TODO(ed): Enable this once supported by LLVM:
80-
// https://llvm.org/bugs/show_bug.cgi?id=16810
81-
#define __wprintflike(format, va)
82-
#define __wscanflike(format, va)
83-
8429
#define __strong_reference(oldsym, newsym) \
8530
extern __typeof__(oldsym) newsym __attribute__((__alias__(#oldsym)))
8631

8732
// Convenience macros.
8833

8934
#define __arraycount(x) (sizeof(x) / sizeof((x)[0]))
90-
#define __howmany(x, y) (((x) + (y)-1) / (y))
91-
#define __rounddown(x, y) (((x) / (y)) * (y))
92-
#define __roundup(x, y) ((((x) + (y)-1) / (y)) * (y))
93-
94-
// Lock annotations.
95-
96-
#if __has_extension(c_thread_safety_attributes)
97-
#define __lock_annotate(x) __attribute__((x))
98-
#else
99-
#define __lock_annotate(x)
100-
#endif
101-
102-
#define __lockable __lock_annotate(lockable)
103-
104-
#define __locks_exclusive(...) \
105-
__lock_annotate(exclusive_lock_function(__VA_ARGS__))
106-
#define __locks_shared(...) __lock_annotate(shared_lock_function(__VA_ARGS__))
107-
108-
#define __trylocks_exclusive(...) \
109-
__lock_annotate(exclusive_trylock_function(__VA_ARGS__))
110-
#define __trylocks_shared(...) \
111-
__lock_annotate(shared_trylock_function(__VA_ARGS__))
112-
113-
#define __unlocks(...) __lock_annotate(unlock_function(__VA_ARGS__))
114-
115-
#define __asserts_exclusive(...) \
116-
__lock_annotate(assert_exclusive_lock(__VA_ARGS__))
117-
#define __asserts_shared(...) __lock_annotate(assert_shared_lock(__VA_ARGS__))
118-
119-
#define __requires_exclusive(...) \
120-
__lock_annotate(exclusive_locks_required(__VA_ARGS__))
121-
#define __requires_shared(...) \
122-
__lock_annotate(shared_locks_required(__VA_ARGS__))
123-
#define __requires_unlocked(...) __lock_annotate(locks_excluded(__VA_ARGS__))
124-
125-
#define __no_lock_analysis __lock_annotate(no_thread_safety_analysis)
126-
127-
#define __guarded_by(x) __lock_annotate(guarded_by(x))
128-
#define __pt_guarded_by(x) __lock_annotate(pt_guarded_by(x))
129-
130-
// Const preservation.
131-
//
132-
// Functions like strchr() allow you to silently discard a const
133-
// qualifier from a string. This macro can be used to wrap such
134-
// functions to propagate the const keyword where possible.
135-
//
136-
// This macro has many limitations, such as only being able to detect
137-
// constness for void, char and wchar_t. For Clang, it also doesn't seem
138-
// to work on string literals.
139-
140-
#define __preserve_const(type, name, arg, ...) \
141-
_Generic(arg, \
142-
const void *: (const type *)name(__VA_ARGS__), \
143-
const char *: (const type *)name(__VA_ARGS__), \
144-
const signed char *: (const type *)name(__VA_ARGS__), \
145-
const unsigned char *: (const type *)name(__VA_ARGS__), \
146-
const __wchar_t *: (const type *)name(__VA_ARGS__), \
147-
default: name(__VA_ARGS__))
14835

14936
#endif

0 commit comments

Comments
 (0)