rubycc 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (159) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +56 -0
  3. data/LICENSE.txt +21 -0
  4. data/NOTICE +52 -0
  5. data/README.md +208 -0
  6. data/data/README.md +117 -0
  7. data/data/r10_corpus_scan.json +4082 -0
  8. data/data/r10_manual_classification.json +5342 -0
  9. data/data/r10_verification_m4a.json +1531 -0
  10. data/data/r10_verification_m4b.json +1818 -0
  11. data/data/r10_verification_m4c.json +1489 -0
  12. data/data/r10_verification_m4d.json +318 -0
  13. data/data/r10_verification_rbs.json +192 -0
  14. data/data/verified_gems.json +397 -0
  15. data/exe/rmake +16 -0
  16. data/exe/rubycc +9 -0
  17. data/exe/rubycc-ar +114 -0
  18. data/exe/rubycc-doctor +14 -0
  19. data/exe/rubycc-pkgconf +8 -0
  20. data/include/float.h +87 -0
  21. data/include/iso646.h +18 -0
  22. data/include/libc/alloca.h +18 -0
  23. data/include/libc/arpa/inet.h +61 -0
  24. data/include/libc/assert.h +43 -0
  25. data/include/libc/dirent.h +72 -0
  26. data/include/libc/dlfcn.h +58 -0
  27. data/include/libc/features.h +205 -0
  28. data/include/libc/glibc/aarch64/ctype.h +108 -0
  29. data/include/libc/glibc/aarch64/endian.h +54 -0
  30. data/include/libc/glibc/aarch64/errno.h +154 -0
  31. data/include/libc/glibc/aarch64/fcntl.h +144 -0
  32. data/include/libc/glibc/aarch64/inttypes.h +182 -0
  33. data/include/libc/glibc/aarch64/limits.h +63 -0
  34. data/include/libc/glibc/aarch64/pthread.h +131 -0
  35. data/include/libc/glibc/aarch64/setjmp.h +84 -0
  36. data/include/libc/glibc/aarch64/stdint.h +174 -0
  37. data/include/libc/glibc/aarch64/sys/epoll.h +88 -0
  38. data/include/libc/glibc/aarch64/sys/fcntl.h +19 -0
  39. data/include/libc/glibc/aarch64/sys/select.h +75 -0
  40. data/include/libc/glibc/aarch64/sys/stat.h +136 -0
  41. data/include/libc/glibc/aarch64/sys/syscall.h +167 -0
  42. data/include/libc/glibc/aarch64/sys/time.h +74 -0
  43. data/include/libc/glibc/aarch64/sys/types.h +127 -0
  44. data/include/libc/glibc/aarch64/time.h +113 -0
  45. data/include/libc/glibc/x86_64/ctype.h +108 -0
  46. data/include/libc/glibc/x86_64/endian.h +54 -0
  47. data/include/libc/glibc/x86_64/errno.h +154 -0
  48. data/include/libc/glibc/x86_64/fcntl.h +134 -0
  49. data/include/libc/glibc/x86_64/inttypes.h +182 -0
  50. data/include/libc/glibc/x86_64/limits.h +61 -0
  51. data/include/libc/glibc/x86_64/pthread.h +111 -0
  52. data/include/libc/glibc/x86_64/setjmp.h +82 -0
  53. data/include/libc/glibc/x86_64/stdint.h +163 -0
  54. data/include/libc/glibc/x86_64/sys/epoll.h +91 -0
  55. data/include/libc/glibc/x86_64/sys/fcntl.h +19 -0
  56. data/include/libc/glibc/x86_64/sys/select.h +75 -0
  57. data/include/libc/glibc/x86_64/sys/stat.h +130 -0
  58. data/include/libc/glibc/x86_64/sys/syscall.h +188 -0
  59. data/include/libc/glibc/x86_64/sys/time.h +74 -0
  60. data/include/libc/glibc/x86_64/sys/types.h +123 -0
  61. data/include/libc/glibc/x86_64/time.h +113 -0
  62. data/include/libc/grp.h +50 -0
  63. data/include/libc/langinfo.h +126 -0
  64. data/include/libc/link.h +18 -0
  65. data/include/libc/locale.h +83 -0
  66. data/include/libc/math.h +191 -0
  67. data/include/libc/netinet/in.h +126 -0
  68. data/include/libc/netinet/tcp.h +44 -0
  69. data/include/libc/poll.h +46 -0
  70. data/include/libc/pwd.h +58 -0
  71. data/include/libc/regex.h +53 -0
  72. data/include/libc/sched.h +35 -0
  73. data/include/libc/signal.h +204 -0
  74. data/include/libc/stdio.h +157 -0
  75. data/include/libc/stdlib.h +92 -0
  76. data/include/libc/string.h +74 -0
  77. data/include/libc/strings.h +25 -0
  78. data/include/libc/sys/cdefs.h +126 -0
  79. data/include/libc/sys/inotify.h +111 -0
  80. data/include/libc/sys/ioctl.h +36 -0
  81. data/include/libc/sys/mman.h +65 -0
  82. data/include/libc/sys/param.h +41 -0
  83. data/include/libc/sys/resource.h +109 -0
  84. data/include/libc/sys/socket.h +167 -0
  85. data/include/libc/sys/statfs.h +82 -0
  86. data/include/libc/sys/timerfd.h +55 -0
  87. data/include/libc/sys/uio.h +40 -0
  88. data/include/libc/sys/un.h +25 -0
  89. data/include/libc/sys/utsname.h +35 -0
  90. data/include/libc/sys/wait.h +135 -0
  91. data/include/libc/termios.h +179 -0
  92. data/include/libc/unistd.h +194 -0
  93. data/include/stdalign.h +16 -0
  94. data/include/stdarg.h +31 -0
  95. data/include/stdatomic.h +158 -0
  96. data/include/stdbool.h +15 -0
  97. data/include/stdckdint.h +28 -0
  98. data/include/stddef.h +60 -0
  99. data/include/stdnoreturn.h +18 -0
  100. data/include/x86intrin.h +16 -0
  101. data/lib/rubycc/backend/aarch64.rb +1724 -0
  102. data/lib/rubycc/backend/x86_64.rb +1369 -0
  103. data/lib/rubycc/compile_error.rb +36 -0
  104. data/lib/rubycc/compiler.rb +305 -0
  105. data/lib/rubycc/doctor/builder.rb +151 -0
  106. data/lib/rubycc/doctor/cli.rb +190 -0
  107. data/lib/rubycc/doctor/fetcher.rb +84 -0
  108. data/lib/rubycc/doctor/gemfile.rb +115 -0
  109. data/lib/rubycc/doctor/verified_gems.rb +114 -0
  110. data/lib/rubycc/doctor.rb +16 -0
  111. data/lib/rubycc/driver.rb +463 -0
  112. data/lib/rubycc/front/ast.rb +528 -0
  113. data/lib/rubycc/front/constant_evaluator.rb +631 -0
  114. data/lib/rubycc/front/initializer_resolver.rb +592 -0
  115. data/lib/rubycc/front/lexeme_reader.rb +460 -0
  116. data/lib/rubycc/front/lexer.rb +232 -0
  117. data/lib/rubycc/front/parser.rb +4122 -0
  118. data/lib/rubycc/front/token.rb +49 -0
  119. data/lib/rubycc/ir/call_convention.rb +486 -0
  120. data/lib/rubycc/ir/generator.rb +6036 -0
  121. data/lib/rubycc/ir/ir.rb +417 -0
  122. data/lib/rubycc/link/compat_runtime.rb +89 -0
  123. data/lib/rubycc/link/errors.rb +13 -0
  124. data/lib/rubycc/link/executable_linker.rb +405 -0
  125. data/lib/rubycc/link/library_resolver.rb +437 -0
  126. data/lib/rubycc/link/partial_linker.rb +546 -0
  127. data/lib/rubycc/link/shared_linker.rb +1732 -0
  128. data/lib/rubycc/mkmf_shim.rb +83 -0
  129. data/lib/rubycc/objfile/ar_archive.rb +437 -0
  130. data/lib/rubycc/objfile/elf_reader.rb +646 -0
  131. data/lib/rubycc/objfile/elf_writer.rb +891 -0
  132. data/lib/rubycc/objfile/relocatable_writer.rb +376 -0
  133. data/lib/rubycc/pkgconf/cli.rb +139 -0
  134. data/lib/rubycc/pkgconf/errors.rb +39 -0
  135. data/lib/rubycc/pkgconf/model.rb +28 -0
  136. data/lib/rubycc/pkgconf/parser.rb +109 -0
  137. data/lib/rubycc/pkgconf/pkgconf.rb +15 -0
  138. data/lib/rubycc/pkgconf/resolver.rb +70 -0
  139. data/lib/rubycc/pkgconf/search_path.rb +38 -0
  140. data/lib/rubycc/pkgconf/system_path_filter.rb +131 -0
  141. data/lib/rubycc/preprocess/constant_expression.rb +219 -0
  142. data/lib/rubycc/preprocess/glibc_version.rb +124 -0
  143. data/lib/rubycc/preprocess/pp_token.rb +62 -0
  144. data/lib/rubycc/preprocess/preprocessor.rb +2020 -0
  145. data/lib/rubycc/preprocess/scanner.rb +290 -0
  146. data/lib/rubycc/preprocess/token_converter.rb +157 -0
  147. data/lib/rubycc/rmake/cli.rb +143 -0
  148. data/lib/rubycc/rmake/errors.rb +71 -0
  149. data/lib/rubycc/rmake/executor.rb +818 -0
  150. data/lib/rubycc/rmake/expander.rb +251 -0
  151. data/lib/rubycc/rmake/makefile.rb +352 -0
  152. data/lib/rubycc/rmake/model.rb +137 -0
  153. data/lib/rubycc/rmake/parser.rb +226 -0
  154. data/lib/rubycc/rmake/rmake.rb +15 -0
  155. data/lib/rubycc/type.rb +1236 -0
  156. data/lib/rubycc/version.rb +5 -0
  157. data/lib/rubycc.rb +36 -0
  158. data/lib/rubygems_plugin.rb +102 -0
  159. metadata +219 -0
@@ -0,0 +1,204 @@
1
+ /* rubycc bundled <signal.h>: the signal numbers, sigset_t / siginfo_t /
2
+ struct sigaction and the POSIX signalling calls. Provenance: clean room
3
+ against the Linux kernel UAPI and the glibc signal ABI (bits/signum-generic.h,
4
+ bits/signum-arch.h, bits/types/siginfo_t.h, bits/sigaction.h), not derived
5
+ from musl or glibc source. The signal numbers, the SA_ flag values and the
6
+ sigset_t / siginfo_t / struct sigaction layouts are that ABI reproduced as
7
+ measured integer constants and measured field offsets (an ABI fact, not
8
+ copied text -- see docs/HEADER-LICENSING.md), the same treatment as errno.h
9
+ and fcntl.h. signal, raise, kill, sigaction, the sigset_t manipulators and
10
+ kin are POSIX declarations whose bodies resolve from the host libc at link
11
+ time (the same way errno.h's __errno_location does), including glibc's
12
+ __libc_current_sigrtmin / __libc_current_sigrtmax behind SIGRTMIN / SIGRTMAX.
13
+ Common layer: every signal number, SA_ flag and struct layout (sigset_t,
14
+ siginfo_t and struct sigaction all included) is identical on x86-64 and
15
+ aarch64 -- both use glibc's generic sigaction with the trailing sa_restorer
16
+ and the 128-byte sigset_t / siginfo_t. sigset_t's typedef guard and
17
+ spelling (__sigset_t_defined / __sigset_t) are shared literally with
18
+ <sys/select.h>, so a program that pulls in both headers -- directly or via
19
+ ruby.h's <sys/select.h> include -- does not hit a conflicting redefinition,
20
+ regardless of which header is included first. */
21
+
22
+ #ifndef _RUBYCC_SIGNAL_H
23
+ #define _RUBYCC_SIGNAL_H
24
+
25
+ #ifndef _RUBYCC_SIG_ATOMIC_T
26
+ #define _RUBYCC_SIG_ATOMIC_T
27
+ typedef int sig_atomic_t;
28
+ #endif
29
+ #ifndef _RUBYCC_PID_T
30
+ #define _RUBYCC_PID_T
31
+ typedef int pid_t;
32
+ #endif
33
+ #ifndef _RUBYCC_UID_T
34
+ #define _RUBYCC_UID_T
35
+ typedef unsigned int uid_t;
36
+ #endif
37
+
38
+ /* The signal-handler function-pointer type. */
39
+ typedef void (*__sighandler_t)(int);
40
+
41
+ /* Handler sentinels: default action, ignore, and the error return of signal. */
42
+ #define SIG_DFL ((__sighandler_t) 0)
43
+ #define SIG_IGN ((__sighandler_t) 1)
44
+ #define SIG_ERR ((__sighandler_t) -1)
45
+
46
+ /* The signal set: 128 bytes, 8-byte aligned (measured, both arches). The
47
+ typedef guard and spelling (__sigset_t_defined / __sigset_t) are shared
48
+ literally with <sys/select.h>, so the two headers do not redefine sigset_t
49
+ regardless of which one is included first. */
50
+ #ifndef __sigset_t_defined
51
+ #define __sigset_t_defined 1
52
+ typedef struct { unsigned long __val[1024 / (8 * sizeof(unsigned long))]; } __sigset_t;
53
+ typedef __sigset_t sigset_t;
54
+ #endif
55
+
56
+ /* The value delivered with a queued signal (POSIX real-time signals). */
57
+ union sigval {
58
+ int sival_int;
59
+ void *sival_ptr;
60
+ };
61
+
62
+ /* siginfo_t: 128 bytes, 8-byte aligned (measured). The common fields sit at
63
+ fixed offsets ahead of the _sifields union; the union's largest member is the
64
+ 28-int pad that fixes the total size. The user-facing member names below are
65
+ provided as macros onto the union arms, exactly as glibc's ABI exposes them,
66
+ so si_pid / si_addr / si_band and kin resolve to the measured offsets. */
67
+ typedef struct {
68
+ int si_signo; /* offset 0 */
69
+ int si_errno; /* offset 4 */
70
+ int si_code; /* offset 8 */
71
+ int __pad0; /* offset 12 */
72
+ union {
73
+ int __pad[28];
74
+ /* kill / SIGCHLD. */
75
+ struct {
76
+ pid_t si_pid;
77
+ uid_t si_uid;
78
+ int si_status;
79
+ } __sigchld;
80
+ /* SIGSEGV / SIGBUS / SIGILL / SIGFPE. */
81
+ struct {
82
+ void *si_addr;
83
+ } __sigfault;
84
+ /* Real-time signal (sigqueue). */
85
+ struct {
86
+ pid_t si_pid;
87
+ uid_t si_uid;
88
+ union sigval si_value;
89
+ } __rt;
90
+ /* SIGPOLL / SIGIO. */
91
+ struct {
92
+ long si_band;
93
+ int si_fd;
94
+ } __sigpoll;
95
+ } _sifields;
96
+ } siginfo_t;
97
+
98
+ #define si_pid _sifields.__sigchld.si_pid
99
+ #define si_uid _sifields.__sigchld.si_uid
100
+ #define si_status _sifields.__sigchld.si_status
101
+ #define si_addr _sifields.__sigfault.si_addr
102
+ #define si_value _sifields.__rt.si_value
103
+ #define si_band _sifields.__sigpoll.si_band
104
+ #define si_fd _sifields.__sigpoll.si_fd
105
+
106
+ /* struct sigaction: 152 bytes, 8-byte aligned (measured, both arches). The
107
+ handler union is first, then the 128-byte sa_mask, sa_flags at offset 136 and
108
+ the trailing sa_restorer at offset 144. */
109
+ struct sigaction {
110
+ union {
111
+ __sighandler_t sa_handler;
112
+ void (*sa_sigaction)(int, siginfo_t *, void *);
113
+ } __sigaction_handler;
114
+ sigset_t sa_mask; /* offset 8 */
115
+ int sa_flags; /* offset 136 */
116
+ void (*sa_restorer)(void); /* offset 144 */
117
+ };
118
+
119
+ #define sa_handler __sigaction_handler.sa_handler
120
+ #define sa_sigaction __sigaction_handler.sa_sigaction
121
+
122
+ /* Signal numbers (Linux kernel ABI). */
123
+ #define SIGHUP 1
124
+ #define SIGINT 2
125
+ #define SIGQUIT 3
126
+ #define SIGILL 4
127
+ #define SIGTRAP 5
128
+ #define SIGABRT 6
129
+ #define SIGBUS 7
130
+ #define SIGFPE 8
131
+ #define SIGKILL 9
132
+ #define SIGUSR1 10
133
+ #define SIGSEGV 11
134
+ #define SIGUSR2 12
135
+ #define SIGPIPE 13
136
+ #define SIGALRM 14
137
+ #define SIGTERM 15
138
+ #define SIGSTKFLT 16
139
+ #define SIGCHLD 17
140
+ #define SIGCONT 18
141
+ #define SIGSTOP 19
142
+ #define SIGTSTP 20
143
+ #define SIGTTIN 21
144
+ #define SIGTTOU 22
145
+ #define SIGURG 23
146
+ #define SIGXCPU 24
147
+ #define SIGXFSZ 25
148
+ #define SIGVTALRM 26
149
+ #define SIGPROF 27
150
+ #define SIGWINCH 28
151
+ #define SIGIO 29
152
+ #define SIGPWR 30
153
+ #define SIGSYS 31
154
+
155
+ /* Historical aliases. */
156
+ #define SIGIOT SIGABRT
157
+ #define SIGCLD SIGCHLD
158
+ #define SIGPOLL SIGIO
159
+
160
+ /* The signal-number ceiling and the real-time base. */
161
+ #define _NSIG 65
162
+ #define NSIG _NSIG
163
+ #define __SIGRTMIN 32
164
+
165
+ /* The usable real-time signal range is a runtime property in glibc (the loader
166
+ reserves the lowest few for its own use), so SIGRTMIN / SIGRTMAX are function
167
+ calls, not constants; the bodies resolve from the host libc at link time. */
168
+ extern int __libc_current_sigrtmin(void);
169
+ extern int __libc_current_sigrtmax(void);
170
+ #define SIGRTMIN (__libc_current_sigrtmin())
171
+ #define SIGRTMAX (__libc_current_sigrtmax())
172
+
173
+ /* sigprocmask direction (POSIX). */
174
+ #define SIG_BLOCK 0
175
+ #define SIG_UNBLOCK 1
176
+ #define SIG_SETMASK 2
177
+
178
+ /* struct sigaction flags. */
179
+ #define SA_NOCLDSTOP 1
180
+ #define SA_NOCLDWAIT 2
181
+ #define SA_SIGINFO 4
182
+ #define SA_ONSTACK 0x08000000
183
+ #define SA_RESTART 0x10000000
184
+ #define SA_NODEFER 0x40000000
185
+ #define SA_RESETHAND 0x80000000
186
+
187
+ /* BSD aliases. */
188
+ #define SA_NOMASK SA_NODEFER
189
+ #define SA_ONESHOT SA_RESETHAND
190
+
191
+ __sighandler_t signal(int __sig, __sighandler_t __handler);
192
+ int raise(int __sig);
193
+ int kill(pid_t __pid, int __sig);
194
+ int sigaction(int __sig, const struct sigaction *__act, struct sigaction *__oact);
195
+ int sigprocmask(int __how, const sigset_t *__set, sigset_t *__oset);
196
+ int sigemptyset(sigset_t *__set);
197
+ int sigfillset(sigset_t *__set);
198
+ int sigaddset(sigset_t *__set, int __signo);
199
+ int sigdelset(sigset_t *__set, int __signo);
200
+ int sigismember(const sigset_t *__set, int __signo);
201
+ int sigpending(sigset_t *__set);
202
+ int sigsuspend(const sigset_t *__set);
203
+
204
+ #endif /* _RUBYCC_SIGNAL_H */
@@ -0,0 +1,157 @@
1
+ /* rubycc bundled <stdio.h>: the standard I/O declarations and macros (ISO C
2
+ 7.21, POSIX). Derived from musl's <stdio.h> declaration set. FILE is kept
3
+ opaque (an incomplete `struct _IO_FILE`, glibc's tag, reached only through
4
+ FILE*), which is all ruby.h and the surveyed gems need. The macro values
5
+ (BUFSIZ, TMP_MAX, ...) are measured, and the three of them the two C
6
+ libraries disagree on are carried under __RUBYCC_LIBC_MUSL__ (see the
7
+ preprocessor's LIBCS). Common layer: only FILE* crosses the ABI and it is a
8
+ pointer, so nothing here is width sensitive. */
9
+
10
+ #ifndef _RUBYCC_STDIO_H
11
+ #define _RUBYCC_STDIO_H
12
+
13
+ #ifndef NULL
14
+ #define NULL ((void*)0)
15
+ #endif
16
+
17
+ #ifndef _RUBYCC_SIZE_T
18
+ #define _RUBYCC_SIZE_T
19
+ typedef unsigned long size_t;
20
+ #endif
21
+ #ifndef _RUBYCC_SSIZE_T
22
+ #define _RUBYCC_SSIZE_T
23
+ typedef long ssize_t;
24
+ #endif
25
+ #ifndef _RUBYCC_OFF_T
26
+ #define _RUBYCC_OFF_T
27
+ typedef long off_t;
28
+ #endif
29
+ #ifndef _RUBYCC_GNUC_VA_LIST
30
+ #define _RUBYCC_GNUC_VA_LIST
31
+ typedef __builtin_va_list __gnuc_va_list;
32
+ #endif
33
+ /* musl's spelling of the same type; see the note in <stdarg.h>. */
34
+ #ifndef _RUBYCC_ISOC_VA_LIST
35
+ #define _RUBYCC_ISOC_VA_LIST
36
+ typedef __builtin_va_list __isoc_va_list;
37
+ #endif
38
+
39
+ /* FILE: opaque. glibc's tag and guard, so a host <stdio.h> reached later is a
40
+ no-op and code that spells `struct _IO_FILE` stays compatible. */
41
+ #ifndef __FILE_defined
42
+ #define __FILE_defined 1
43
+ struct _IO_FILE;
44
+ typedef struct _IO_FILE FILE;
45
+ #endif
46
+
47
+ /* fpos_t: opaque but sized to match glibc's 16-byte layout, in case a caller
48
+ stores one by value. */
49
+ #ifndef _RUBYCC_FPOS_T
50
+ #define _RUBYCC_FPOS_T
51
+ typedef struct { long __pos; struct { int __count; int __value; } __state; } fpos_t;
52
+ #endif
53
+
54
+ #define EOF (-1)
55
+
56
+ #define SEEK_SET 0
57
+ #define SEEK_CUR 1
58
+ #define SEEK_END 2
59
+
60
+ #define _IOFBF 0
61
+ #define _IOLBF 1
62
+ #define _IONBF 2
63
+
64
+ /* BUFSIZ, FOPEN_MAX and TMP_MAX are the three values in this header the two C
65
+ libraries disagree on: musl reports 1024, 1000 and 10000 where glibc reports
66
+ 8192, 16 and 238328. All six measured with the ABI harness, glibc's on this
67
+ host and musl's on the CI musl run (docs/STEPS.md Step 193). EOF, the SEEK_*
68
+ and _IO*BF sets, FILENAME_MAX and L_tmpnam are probed too and measured
69
+ identical on both; L_ctermid and P_tmpdir are not probed on either. */
70
+ #if defined(__RUBYCC_LIBC_MUSL__)
71
+ #define BUFSIZ 1024
72
+ #define FOPEN_MAX 1000
73
+ #define TMP_MAX 10000
74
+ #else
75
+ #define BUFSIZ 8192
76
+ #define FOPEN_MAX 16
77
+ #define TMP_MAX 238328
78
+ #endif
79
+ #define FILENAME_MAX 4096
80
+ #define L_tmpnam 20
81
+ #define L_ctermid 9
82
+ #define P_tmpdir "/tmp"
83
+
84
+ extern FILE *stdin;
85
+ extern FILE *stdout;
86
+ extern FILE *stderr;
87
+ #define stdin stdin
88
+ #define stdout stdout
89
+ #define stderr stderr
90
+
91
+ int remove(const char *__filename);
92
+ int rename(const char *__old, const char *__new);
93
+ FILE *tmpfile(void);
94
+ char *tmpnam(char *__s);
95
+
96
+ int fclose(FILE *__stream);
97
+ int fflush(FILE *__stream);
98
+ FILE *fopen(const char *__restrict __filename, const char *__restrict __modes);
99
+ FILE *freopen(const char *__restrict __filename, const char *__restrict __modes, FILE *__restrict __stream);
100
+ FILE *fdopen(int __fd, const char *__modes);
101
+ void setbuf(FILE *__restrict __stream, char *__restrict __buf);
102
+ int setvbuf(FILE *__restrict __stream, char *__restrict __buf, int __modes, size_t __n);
103
+
104
+ int fprintf(FILE *__restrict __stream, const char *__restrict __format, ...);
105
+ int printf(const char *__restrict __format, ...);
106
+ int sprintf(char *__restrict __s, const char *__restrict __format, ...);
107
+ int snprintf(char *__restrict __s, size_t __maxlen, const char *__restrict __format, ...);
108
+ int vfprintf(FILE *__restrict __stream, const char *__restrict __format, __gnuc_va_list __arg);
109
+ int vprintf(const char *__restrict __format, __gnuc_va_list __arg);
110
+ int vsprintf(char *__restrict __s, const char *__restrict __format, __gnuc_va_list __arg);
111
+ int vsnprintf(char *__restrict __s, size_t __maxlen, const char *__restrict __format, __gnuc_va_list __arg);
112
+ int dprintf(int __fd, const char *__restrict __format, ...);
113
+ int asprintf(char **__restrict __ptr, const char *__restrict __format, ...);
114
+ int vasprintf(char **__restrict __ptr, const char *__restrict __format, __gnuc_va_list __arg);
115
+
116
+ int fscanf(FILE *__restrict __stream, const char *__restrict __format, ...);
117
+ int scanf(const char *__restrict __format, ...);
118
+ int sscanf(const char *__restrict __s, const char *__restrict __format, ...);
119
+ int vfscanf(FILE *__restrict __stream, const char *__restrict __format, __gnuc_va_list __arg);
120
+ int vscanf(const char *__restrict __format, __gnuc_va_list __arg);
121
+ int vsscanf(const char *__restrict __s, const char *__restrict __format, __gnuc_va_list __arg);
122
+
123
+ int fgetc(FILE *__stream);
124
+ int getc(FILE *__stream);
125
+ int getchar(void);
126
+ int fputc(int __c, FILE *__stream);
127
+ int putc(int __c, FILE *__stream);
128
+ int putchar(int __c);
129
+ int ungetc(int __c, FILE *__stream);
130
+
131
+ char *fgets(char *__restrict __s, int __n, FILE *__restrict __stream);
132
+ int fputs(const char *__restrict __s, FILE *__restrict __stream);
133
+ int puts(const char *__s);
134
+ ssize_t getline(char **__restrict __lineptr, size_t *__restrict __n, FILE *__restrict __stream);
135
+ ssize_t getdelim(char **__restrict __lineptr, size_t *__restrict __n, int __delimiter, FILE *__restrict __stream);
136
+
137
+ size_t fread(void *__restrict __ptr, size_t __size, size_t __n, FILE *__restrict __stream);
138
+ size_t fwrite(const void *__restrict __ptr, size_t __size, size_t __n, FILE *__restrict __stream);
139
+
140
+ int fseek(FILE *__stream, long __off, int __whence);
141
+ long ftell(FILE *__stream);
142
+ void rewind(FILE *__stream);
143
+ int fseeko(FILE *__stream, off_t __off, int __whence);
144
+ off_t ftello(FILE *__stream);
145
+ int fgetpos(FILE *__restrict __stream, fpos_t *__restrict __pos);
146
+ int fsetpos(FILE *__stream, const fpos_t *__pos);
147
+
148
+ void clearerr(FILE *__stream);
149
+ int feof(FILE *__stream);
150
+ int ferror(FILE *__stream);
151
+ int fileno(FILE *__stream);
152
+ void perror(const char *__s);
153
+
154
+ FILE *popen(const char *__command, const char *__modes);
155
+ int pclose(FILE *__stream);
156
+
157
+ #endif /* _RUBYCC_STDIO_H */
@@ -0,0 +1,92 @@
1
+ /* rubycc bundled <stdlib.h>: general utilities (ISO C 7.22, POSIX). Derived from
2
+ musl's <stdlib.h> declaration set; div_t/ldiv_t/lldiv_t carry the LP64 layout
3
+ (measured: ldiv_t is two `long`s), and RAND_MAX/EXIT_* are the glibc values.
4
+ Common layer: the div_t family layout is the same on any LP64 target. */
5
+
6
+ #ifndef _RUBYCC_STDLIB_H
7
+ #define _RUBYCC_STDLIB_H
8
+
9
+ #ifndef NULL
10
+ #define NULL ((void*)0)
11
+ #endif
12
+
13
+ #ifndef _RUBYCC_SIZE_T
14
+ #define _RUBYCC_SIZE_T
15
+ typedef unsigned long size_t;
16
+ #endif
17
+ #ifndef _RUBYCC_WCHAR_T
18
+ #define _RUBYCC_WCHAR_T
19
+ typedef int wchar_t;
20
+ #endif
21
+
22
+ typedef struct { int quot; int rem; } div_t;
23
+ typedef struct { long quot; long rem; } ldiv_t;
24
+ typedef struct { long long quot; long long rem; } lldiv_t;
25
+
26
+ #define EXIT_SUCCESS 0
27
+ #define EXIT_FAILURE 1
28
+ #define RAND_MAX 2147483647
29
+
30
+ extern size_t __ctype_get_mb_cur_max(void);
31
+ #define MB_CUR_MAX (__ctype_get_mb_cur_max())
32
+
33
+ double atof(const char *__nptr);
34
+ int atoi(const char *__nptr);
35
+ long atol(const char *__nptr);
36
+ long long atoll(const char *__nptr);
37
+
38
+ double strtod(const char *__restrict __nptr, char **__restrict __endptr);
39
+ float strtof(const char *__restrict __nptr, char **__restrict __endptr);
40
+ long double strtold(const char *__restrict __nptr, char **__restrict __endptr);
41
+ long strtol(const char *__restrict __nptr, char **__restrict __endptr, int __base);
42
+ unsigned long strtoul(const char *__restrict __nptr, char **__restrict __endptr, int __base);
43
+ long long strtoll(const char *__restrict __nptr, char **__restrict __endptr, int __base);
44
+ unsigned long long strtoull(const char *__restrict __nptr, char **__restrict __endptr, int __base);
45
+
46
+ int rand(void);
47
+ void srand(unsigned int __seed);
48
+ long random(void);
49
+ void srandom(unsigned int __seed);
50
+
51
+ void *malloc(size_t __size);
52
+ void *calloc(size_t __nmemb, size_t __size);
53
+ void *realloc(void *__ptr, size_t __size);
54
+ void free(void *__ptr);
55
+ void *aligned_alloc(size_t __alignment, size_t __size);
56
+ void *reallocarray(void *__ptr, size_t __nmemb, size_t __size);
57
+ int posix_memalign(void **__memptr, size_t __alignment, size_t __size);
58
+
59
+ void abort(void) __attribute__((__noreturn__));
60
+ int atexit(void (*__func)(void));
61
+ int at_quick_exit(void (*__func)(void));
62
+ void exit(int __status) __attribute__((__noreturn__));
63
+ void quick_exit(int __status) __attribute__((__noreturn__));
64
+ void _Exit(int __status) __attribute__((__noreturn__));
65
+
66
+ char *getenv(const char *__name);
67
+ int setenv(const char *__name, const char *__value, int __replace);
68
+ int unsetenv(const char *__name);
69
+ int putenv(char *__string);
70
+ int system(const char *__command);
71
+ char *realpath(const char *__restrict __name, char *__restrict __resolved);
72
+ int mkstemp(char *__template);
73
+
74
+ void *bsearch(const void *__key, const void *__base, size_t __nmemb, size_t __size,
75
+ int (*__compar)(const void *, const void *));
76
+ void qsort(void *__base, size_t __nmemb, size_t __size,
77
+ int (*__compar)(const void *, const void *));
78
+
79
+ int abs(int __x);
80
+ long labs(long __x);
81
+ long long llabs(long long __x);
82
+ div_t div(int __numer, int __denom);
83
+ ldiv_t ldiv(long __numer, long __denom);
84
+ lldiv_t lldiv(long long __numer, long long __denom);
85
+
86
+ int mblen(const char *__s, size_t __n);
87
+ int mbtowc(wchar_t *__restrict __pwc, const char *__restrict __s, size_t __n);
88
+ int wctomb(char *__s, wchar_t __wchar);
89
+ size_t mbstowcs(wchar_t *__restrict __pwcs, const char *__restrict __s, size_t __n);
90
+ size_t wcstombs(char *__restrict __s, const wchar_t *__restrict __pwcs, size_t __n);
91
+
92
+ #endif /* _RUBYCC_STDLIB_H */
@@ -0,0 +1,74 @@
1
+ /* rubycc bundled <string.h>: the memory- and string-manipulation declarations
2
+ (ISO C 7.24, POSIX). Derived from musl's <string.h> declaration set, kept as
3
+ pure prototypes (size_t is the only ABI-typed name, shared via _RUBYCC_SIZE_T)
4
+ so nothing here is arch specific. Common layer. */
5
+
6
+ #ifndef _RUBYCC_STRING_H
7
+ #define _RUBYCC_STRING_H
8
+
9
+ #ifndef NULL
10
+ #define NULL ((void*)0)
11
+ #endif
12
+
13
+ #ifndef _RUBYCC_SIZE_T
14
+ #define _RUBYCC_SIZE_T
15
+ typedef unsigned long size_t;
16
+ #endif
17
+
18
+ void *memcpy(void *__restrict __dest, const void *__restrict __src, size_t __n);
19
+ void *memmove(void *__dest, const void *__src, size_t __n);
20
+ void *memset(void *__s, int __c, size_t __n);
21
+ int memcmp(const void *__s1, const void *__s2, size_t __n);
22
+ void *memchr(const void *__s, int __c, size_t __n);
23
+
24
+ char *strcpy(char *__restrict __dest, const char *__restrict __src);
25
+ char *strncpy(char *__restrict __dest, const char *__restrict __src, size_t __n);
26
+ char *strcat(char *__restrict __dest, const char *__restrict __src);
27
+ char *strncat(char *__restrict __dest, const char *__restrict __src, size_t __n);
28
+ int strcmp(const char *__s1, const char *__s2);
29
+ int strncmp(const char *__s1, const char *__s2, size_t __n);
30
+ int strcoll(const char *__s1, const char *__s2);
31
+ size_t strxfrm(char *__restrict __dest, const char *__restrict __src, size_t __n);
32
+
33
+ char *strchr(const char *__s, int __c);
34
+ char *strrchr(const char *__s, int __c);
35
+ size_t strcspn(const char *__s, const char *__reject);
36
+ size_t strspn(const char *__s, const char *__accept);
37
+ char *strpbrk(const char *__s, const char *__accept);
38
+ char *strstr(const char *__haystack, const char *__needle);
39
+ char *strtok(char *__restrict __s, const char *__restrict __delim);
40
+ char *strtok_r(char *__restrict __s, const char *__restrict __delim, char **__restrict __save_ptr);
41
+
42
+ size_t strlen(const char *__s);
43
+ size_t strnlen(const char *__s, size_t __maxlen);
44
+
45
+ char *strerror(int __errnum);
46
+ int strerror_r(int __errnum, char *__buf, size_t __buflen);
47
+
48
+ char *strdup(const char *__s);
49
+ char *strndup(const char *__s, size_t __n);
50
+
51
+ /* POSIX/glibc extensions commonly relied on. */
52
+ void *memccpy(void *__restrict __dest, const void *__restrict __src, int __c, size_t __n);
53
+ void *mempcpy(void *__restrict __dest, const void *__restrict __src, size_t __n);
54
+ void *memmem(const void *__haystack, size_t __haystacklen, const void *__needle, size_t __needlelen);
55
+ void *memrchr(const void *__s, int __c, size_t __n);
56
+ char *stpcpy(char *__restrict __dest, const char *__restrict __src);
57
+ char *stpncpy(char *__restrict __dest, const char *__restrict __src, size_t __n);
58
+ /* BSD size-bounded copies, in glibc since 2.38; used by date's strftime. */
59
+ size_t strlcpy(char *__restrict __dest, const char *__restrict __src, size_t __size);
60
+ size_t strlcat(char *__restrict __dest, const char *__restrict __src, size_t __size);
61
+ char *strsep(char **__restrict __stringp, const char *__restrict __delim);
62
+ char *strchrnul(const char *__s, int __c);
63
+ char *strcasestr(const char *__haystack, const char *__needle);
64
+ char *strsignal(int __sig);
65
+
66
+ /* glibc's <string.h> pulls in <strings.h> under __USE_MISC (the default GNU
67
+ environment), so a translation unit that includes only <string.h> still sees
68
+ strcasecmp/strncasecmp. Real-world sources (e.g. redcarpet's autolink.c) rely
69
+ on that, so mirror it here. Our headers don't gate glibc extensions behind
70
+ feature-test macros, so include it unconditionally. The lone overlapping
71
+ prototype (memchr) is an identical, compatible redeclaration. */
72
+ #include <strings.h>
73
+
74
+ #endif /* _RUBYCC_STRING_H */
@@ -0,0 +1,25 @@
1
+ /* rubycc bundled <strings.h>: the BSD byte-string declarations (POSIX). Derived
2
+ from musl's <strings.h> declaration set; pure prototypes, nothing arch
3
+ specific. Common layer. */
4
+
5
+ #ifndef _RUBYCC_STRINGS_H
6
+ #define _RUBYCC_STRINGS_H
7
+
8
+ #ifndef _RUBYCC_SIZE_T
9
+ #define _RUBYCC_SIZE_T
10
+ typedef unsigned long size_t;
11
+ #endif
12
+
13
+ int bcmp(const void *__s1, const void *__s2, size_t __n);
14
+ void bcopy(const void *__src, void *__dest, size_t __n);
15
+ void bzero(void *__s, size_t __n);
16
+ void *memchr(const void *__s, int __c, size_t __n);
17
+ int ffs(int __i);
18
+ int ffsl(long __i);
19
+ int ffsll(long long __i);
20
+ char *index(const char *__s, int __c);
21
+ char *rindex(const char *__s, int __c);
22
+ int strcasecmp(const char *__s1, const char *__s2);
23
+ int strncasecmp(const char *__s1, const char *__s2, size_t __n);
24
+
25
+ #endif /* _RUBYCC_STRINGS_H */
@@ -0,0 +1,126 @@
1
+ /* rubycc bundled <sys/cdefs.h>: the glibc compiler-abstraction macros
2
+ (__BEGIN_DECLS, __THROW, __attribute_* and kin) that glibc's own headers lean
3
+ on. Written clean room against glibc's published macro contract rather than
4
+ derived from musl (which has no equivalent) or copied from glibc: the bodies
5
+ reproduce the observable behaviour (a name that expands to a usable attribute
6
+ or to nothing), not glibc's source. Common layer: the definitions are the same
7
+ for any x86-64 target. */
8
+
9
+ #ifndef _RUBYCC_SYS_CDEFS_H
10
+ #define _RUBYCC_SYS_CDEFS_H
11
+
12
+ /* glibc's own guard, so a later real <sys/cdefs.h> (reached via the host path in
13
+ the non-distroless configuration) becomes a no-op and does not redefine. */
14
+ #ifndef _SYS_CDEFS_H
15
+ #define _SYS_CDEFS_H 1
16
+
17
+ #ifdef __cplusplus
18
+ # define __BEGIN_DECLS extern "C" {
19
+ # define __END_DECLS }
20
+ #else
21
+ # define __BEGIN_DECLS
22
+ # define __END_DECLS
23
+ #endif
24
+
25
+ /* Token-pasting and stringizing helpers. */
26
+ #define __CONCAT(x, y) x ## y
27
+ #define __STRING(x) #x
28
+
29
+ /* Pre-standard spellings still used by a few headers. */
30
+ #define __P(args) args
31
+ #define __PMT(args) args
32
+ #define __ptr_t void *
33
+
34
+ /* GCC version predicate. rubycc identifies as a recent GCC-compatible compiler,
35
+ so headers gate their newest spellings on this. */
36
+ #if defined __GNUC__ && defined __GNUC_MINOR__
37
+ # define __GNUC_PREREQ(maj, min) \
38
+ ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
39
+ #else
40
+ # define __GNUC_PREREQ(maj, min) 0
41
+ #endif
42
+
43
+ #ifndef __glibc_clang_prereq
44
+ # define __glibc_clang_prereq(maj, min) 0
45
+ #endif
46
+
47
+ /* Function-annotation macros. They carry no ABI meaning, so expanding them to
48
+ nothing (or, for the wrappers, to their argument) is behaviourally faithful
49
+ while keeping the token stream simple. */
50
+ #define __THROW
51
+ #define __THROWNL
52
+ #define __NTH(fct) fct
53
+ #define __NTHNL(fct) fct
54
+
55
+ #define __attribute_malloc__
56
+ #define __attribute_pure__
57
+ #define __attribute_const__
58
+ #define __attribute_used__
59
+ #define __attribute_unused__
60
+ #define __attribute_noinline__
61
+ #define __attribute_deprecated__
62
+ #define __attribute_deprecated_msg__(msg)
63
+ #define __attribute_warn_unused_result__
64
+ #define __attribute_alloc_size__(params)
65
+ #define __attribute_alloc_align__(param)
66
+ #define __attribute_nonstring__
67
+ #define __attribute_maybe_unused__
68
+ #define __attribute_returns_twice__
69
+ #define __attribute_format_arg__(x)
70
+ #define __attribute_format_strfmon__(a, b)
71
+ #define __wur
72
+ #define __result_use_check
73
+ #define __COLD
74
+
75
+ #define __nonnull(params)
76
+ #define __always_inline __inline
77
+ #define __extern_inline extern __inline
78
+ #define __extern_always_inline extern __inline
79
+ #define __fortify_function __extern_always_inline __attribute_artificial__
80
+ #define __attribute_artificial__
81
+
82
+ /* restrict/inline keyword spellings for pre-C99 fallbacks. */
83
+ #ifndef __restrict
84
+ # define __restrict restrict
85
+ #endif
86
+ #define __restrict_arr
87
+
88
+ /* Branch-prediction hints: identities without the underlying builtin. */
89
+ #define __glibc_likely(cond) (cond)
90
+ #define __glibc_unlikely(cond) (cond)
91
+ #define __glibc_unsigned_or_positive(v) 1
92
+
93
+ /* Flexible array members: C99 spelling is available. */
94
+ #define __flexarr [ ]
95
+ #define __glibc_c99_flexarr_available 1
96
+ #define __glibc_flexarr_length(arr) 1
97
+
98
+ /* Symbol-redirection and asm-name helpers: the plain (unredirected) form is what
99
+ a bundled libc offers, so these degrade to a straight declaration. */
100
+ #define __ASMNAME(cname) cname
101
+ #define __ASMNAME2(prefix, cname) cname
102
+ #define __REDIRECT(name, proto, alias) name proto
103
+ #define __REDIRECT_NTH(name, proto, alias) name proto
104
+ #define __REDIRECT_NTHNL(name, proto, alias) name proto
105
+ #define __LDBL_REDIR(name, proto) name proto
106
+ #define __LDBL_REDIR_NTH(name, proto) name proto
107
+ #define __LDBL_REDIR1(name, proto, alias) name proto
108
+ #define __LDBL_REDIR1_NTH(name, proto, alias) name proto
109
+ #define __LDBL_REDIR_DECL(name)
110
+
111
+ /* Variadic-macro argument pack forwarding (GCC builtins). */
112
+ #define __va_arg_pack() __builtin_va_arg_pack()
113
+ #define __va_arg_pack_len() __builtin_va_arg_pack_len()
114
+
115
+ /* Bounds/fortify plumbing: no fortification, no BOS instrumentation. */
116
+ #define __bos(ptr) __builtin_object_size(ptr, __USE_FORTIFY_LEVEL > 1)
117
+ #define __bos0(ptr) __builtin_object_size(ptr, 0)
118
+ #define __glibc_objsize(obj) __bos(obj)
119
+ #define __glibc_objsize0(obj) __bos0(obj)
120
+
121
+ /* Wide-character / locale plumbing spellings some headers reference. */
122
+ #define __LEAF
123
+ #define __LEAF_ATTR
124
+
125
+ #endif /* !_SYS_CDEFS_H */
126
+ #endif /* _RUBYCC_SYS_CDEFS_H */