Skip to content

Commit 0c9b2ac

Browse files
committed
Fixup arm
1 parent 4009bb7 commit 0c9b2ac

File tree

3 files changed

+185
-6
lines changed

3 files changed

+185
-6
lines changed

builder/comp-builder.nix

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,15 @@ let
206206
(enableFeature enableShared "shared")
207207
(enableFeature enableExecutableDynamic "executable-dynamic")
208208
(enableFeature doCoverage "coverage")
209-
(enableFeature (enableLibraryForGhci && !stdenv.hostPlatform.isGhcjs) "library-for-ghci")
209+
# For Android (or really anything that uses lld), -r will silently drop
210+
# "lazy" symbols. Those are leaf symbols with no referenes. This however
211+
# does not work when loading the objects into the linker, because then we
212+
# occationally miss symbols when subsequent libraries depending on the one
213+
# that dropped the symbol are loaded. bfd and lld support --whole-archive
214+
# lld -r --whole-archive ... will _not_ drop lazy symbols. However the
215+
# --whole-archive flag needs to come _before_ the objects, it's applied in
216+
# sequence. The proper fix is thusly to add --while-archive to Cabal.
217+
(enableFeature (enableLibraryForGhci && !stdenv.hostPlatform.isGhcjs && !stdenv.hostPlatform.isAndroid) "library-for-ghci")
210218
] ++ lib.optionals (stdenv.hostPlatform.isMusl && (haskellLib.isExecutableType componentId)) [
211219
# These flags will make sure the resulting executable is statically linked.
212220
# If it uses other libraries it may be necessary for to add more

overlays/linux-cross.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ let
6161
kill $RISERV_PID
6262
'';
6363
qemuIservWrapper = symlinkJoin { name = "iserv-wrapper"; paths = [ (qemuIservWrapperScript false) (qemuIservWrapperScript true) ]; };
64-
configureFlags = lib.optional hostPlatform.isAarch32 "--disable-split-sections";
64+
configureFlags = lib.optional (hostPlatform.isAarch32 || hostPlatform.isAndroid) "--disable-split-sections";
6565
setupBuildFlags = map (opt: "--ghc-option=" + opt) ((lib.optionals isLinuxCross
6666
[ "-fexternal-interpreter"
6767
"-pgmi" "${qemuIservWrapper}/bin/iserv-wrapper"

overlays/patches/iserv-proxy-interpreter-9.3-android.patch

Lines changed: 175 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ new file mode 100644
33
index 0000000..d447895
44
--- /dev/null
55
+++ b/cbits/symbols.c
6-
@@ -0,0 +1,147 @@
6+
@@ -0,0 +1,318 @@
77
+#include <stddef.h>
88
+#include <stdio.h>
99
+#include <string.h>
@@ -24,13 +24,56 @@ index 0000000..d447895
2424
+#include <utime.h>
2525
+#include <poll.h>
2626
+#include <time.h>
27+
+#include <dirent.h>
28+
+#include <netdb.h>
29+
+#include <pthread.h>
30+
+#include <sys/mman.h>
31+
+#include <sys/auxv.h>
32+
+#include <sys/random.h>
33+
+#include <arpa/inet.h>
34+
+#include <sys/time.h>
35+
+#include <sys/stat.h>
36+
+#include <grp.h>
37+
+#include <pwd.h>
38+
+#include <sys/uio.h>
2739
+
2840
+// fnctl stubs, see above
2941
+extern void open(void);
42+
+extern void openat(void);
3043
+extern void creat(void);
3144
+extern void eventfd(void);
3245
+extern void eventfd_write(void);
46+
+
47+
+extern void futimes(void);
48+
+extern void lutimes(void);
49+
+extern void statx(void);
50+
+
3351
+extern void __stack_chk_fail(void);
52+
+extern void __vsprintf_chk(void);
53+
+extern void __open_2(void);
54+
+extern void __memcpy_chk(void);
55+
+extern void __memset_chk(void);
56+
+extern void __memmove_chk(void);
57+
+// GCC stuff
58+
+extern void __addtf3(void);
59+
+extern void __divtf3(void);
60+
+extern void __extenddftf2(void);
61+
+extern void __fixtfsi(void);
62+
+extern void __floatditf(void);
63+
+extern void __floatsitf(void);
64+
+extern void __getf2(void);
65+
+extern void __gttf2(void);
66+
+extern void __lttf2(void);
67+
+extern void __multf3(void);
68+
+extern void __subtf3(void);
69+
+extern void __trunctfdf2(void);
70+
+
71+
+#define MISSING_FUN(f) void (f)(void) { printf("Unknown call to `%s'\n", #f); exit(1); }
72+
+
73+
+MISSING_FUN(c_format_unix_time)
74+
+MISSING_FUN(c_format_unix_time_gmt)
75+
+MISSING_FUN(c_parse_unix_time)
76+
+MISSING_FUN(c_parse_unix_time_gmt)
3477
+
3578
+typedef void SymbolAddr;
3679
+typedef char SymbolName;
@@ -61,11 +104,78 @@ index 0000000..d447895
61104
+typedef mode_t (*umask_func_ptr_t)(mode_t);
62105
+
63106
+RtsSymbolVal my_iserv_syms[] = {
107+
+ // arpa/inet.h
108+
+ SYM(htons),
109+
+ SYM(ntohs),
110+
+ SYM(htonl),
111+
+ SYM(ntohl),
112+
+ // sys/random.h
113+
+ SYM(getentropy),
114+
+ SYM(getrandom),
115+
+ // sys/auxv.h
116+
+ SYM(getauxval),
117+
+ // sys/mman.h
118+
+ SYM(madvise),SYM(mlock),SYM(mmap),SYM(mprotect),SYM(munmap),
119+
+ SYM(mremap),
120+
+ SYM(munlock),
121+
+ // select.h
122+
+ SYM(__FD_SET_chk),
123+
+ // sys/socket
124+
+ SYM(accept),SYM(bind),SYM(connect),SYM(getsockopt),SYM(listen),
125+
+ SYM(setsockopt),SYM(socket),SYM(getsockname),SYM(select),
126+
+ SYM(getpeername),SYM(__cmsg_nxthdr),SYM(recv),SYM(recvfrom),
127+
+ SYM(recvmsg),SYM(send),SYM(sendmsg),SYM(sendto),SYM(writev),
128+
+ SYM(accept4),
129+
+ // pthread.h
130+
+ SYM(pthread_equal),SYM(pthread_getspecific),SYM(pthread_key_create),
131+
+ SYM(pthread_key_delete),SYM(pthread_once),SYM(pthread_rwlock_destroy),
132+
+ SYM(pthread_rwlock_init),SYM(pthread_rwlock_rdlock),SYM(pthread_rwlock_unlock),
133+
+ SYM(pthread_rwlock_wrlock),SYM(pthread_self),SYM(pthread_setspecific),
134+
+ SYM(pthread_create),SYM(pthread_join),SYM(pthread_mutex_destroy),
135+
+ SYM(pthread_mutex_init),SYM(pthread_mutex_lock),SYM(pthread_mutex_trylock),
136+
+ SYM(pthread_mutex_unlock),SYM(pthread_mutexattr_destroy),
137+
+ SYM(pthread_mutexattr_init),SYM(pthread_mutexattr_settype),
138+
+ // chk.h
139+
+ SYM(__read_chk),SYM(__write_chk),
140+
+ // netdb.h
141+
+ SYM(freeaddrinfo),SYM(gai_strerror),SYM(getaddrinfo),SYM(getnameinfo),
142+
+ SYM(gethostbyname),
143+
+ // dirent.h
144+
+ SYM(readdir_r),SYM(readdir),
145+
+ SYM(opendir),SYM(closedir),
64146
+ // time.h
65-
+ SYM(clock),
147+
+ SYM(clock),SYM(gmtime_r),
66148
+ // sys/time.h
67149
+ SYM(gettimeofday),SYM(clock_getres),SYM(clock_gettime),SYM(localtime_r),SYM(tzset),
68150
+ // unistd.h
151+
+ SYM(readlink),
152+
+ SYM(rename),
153+
+ SYM(rmdir),
154+
+ SYM(chown),
155+
+ SYM(realpath),
156+
+ SYM(fchdir),
157+
+ SYM(fdopendir),
158+
+ SYM(rewinddir),
159+
+ SYM(futimens),SYM(futimes),SYM(lutimes),
160+
+ SYM(mknod),
161+
+ SYM(lchown),
162+
+ SYM(symlink),
163+
+ SYM(endgrent),SYM(endpwent),
164+
+ SYM(pathconf),
165+
+ SYM(truncate),
166+
+ SYM(utimensat),
167+
+ SYM(statx),
168+
+ SYM(seekdir),
169+
+ SYM(telldir),
170+
+ SYM(clearenv),
171+
+ SYM(chdir),
172+
+ SYM(sleep),
173+
+ SYM(stdout),
174+
+ SYM(strftime),
175+
+ SYM(utimes),
176+
+ SYM(setenv),
177+
+ SYM(fpathconf),
178+
+ SYM(exit),
69179
+ SYM(environ),
70180
+ SYM(ftruncate),
71181
+ SYM(getenv),
@@ -77,6 +187,8 @@ index 0000000..d447895
77187
+ SYM(link),
78188
+ SYM(pipe),
79189
+ SYM(unlink),
190+
+ SYM(execv),SYM(execve),SYM(execvp),SYM(execvpe),
191+
+ SYM(syscall),SYM(sysconf),
80192
+ // errno.h
81193
+ SYM(__errno),
82194
+ // math.h
@@ -95,6 +207,7 @@ index 0000000..d447895
95207
+ // assert.h
96208
+ SYM(__assert2),
97209
+ // signal.h
210+
+ SYM(signal),SYM(sigaction),
98211
+ SYM(raise), SYM(sigaddset), SYM(sigemptyset), SYM(sigprocmask),
99212
+ // sys/eventfd.h
100213
+ SYM(eventfd), SYM(eventfd_write),
@@ -114,10 +227,14 @@ index 0000000..d447895
114227
+ SYM(poll),
115228
+ // fcntl.h
116229
+ SYM(open), SYM(creat), SYM(fcntl), SYM(ioctl),
230+
+ SYM(openat),SYM(__open_2),
117231
+ // string.h
118232
+ SYM(strerror),
119233
+ SYM(strcmp),
120-
+ SYM(memchr),
234+
+ SYM(memchr),SYM(strcpy),SYM(strchr),SYM(strncpy),SYM(strrchr),
235+
+ SYM(strcat),SYM(strncmp),SYM(strdup),
236+
+ SYM(strtoul),SYM(strspn),SYM(strtol),SYM(strstr),SYM(strcspn),
237+
+ SYM(__strncpy_chk2),SYM(__memcpy_chk),
121238
+ // ctype.h
122239
+ SYM(__ctype_get_mb_cur_max),
123240
+ // wchar.h
@@ -128,8 +245,14 @@ index 0000000..d447895
128245
+ SYM(access), SYM(close), SYM(dup), SYM(dup2), SYM(fork), SYM(getpid),
129246
+ SYM(lseek),
130247
+ // utime.h
131-
+ SYM(utime),
248+
+ SYM(utime),SYM(time),
132249
+ // ...
250+
+ SYM(fileno),
251+
+ SYM(__vsprintf_chk),
252+
+ SYM(__strlen_chk),
253+
+ SYM(__strchr_chk),
254+
+ SYM(__memset_chk),
255+
+ SYM(__memmove_chk),
133256
+ SYM(__stack_chk_fail),
134257
+ SYM(memmove),
135258
+ SYM(memcmp),
@@ -141,10 +264,58 @@ index 0000000..d447895
141264
+ SYM(malloc),
142265
+ SYM(free),
143266
+ SYM(fprintf),
267+
+ SYM(vfprintf),
144268
+ SYM(fopen), SYM(fclose),
269+
+ SYM(getegid),SYM(getgid),
270+
+ SYM(getpwent),
271+
+ SYM(getgrent),
272+
+ SYM(getgroups),
273+
+ SYM(getlogin),
274+
+ SYM(getuid),
275+
+ SYM(getgrgid_r),SYM(getgrnam_r),SYM(getpwnam_r),SYM(getpwuid_r),
276+
+ SYM(setegid),SYM(seteuid),SYM(setgid),SYM(setgrent),SYM(setgroups),
277+
+ SYM(setpwent),SYM(setuid),
145278
+ SYM(fread),
146279
+ SYM(abort),
147280
+ SYM(strlen),
281+
+ SYM(fwrite),
282+
+ SYM(feof),
283+
+ SYM(ferror),
284+
+ SYM(fflush),
285+
+ SYM(fgets),SYM(fputc),SYM(fputs),
286+
+ SYM(fseek),SYM(ftell),
287+
+ SYM(sscanf),
288+
+ SYM(shutdown),
289+
+ SYM(atoi),
290+
+ SYM(stdin),
291+
+ SYM(atexit),
292+
+ SYM(usleep),
293+
+ SYM(fchmod),
294+
+ SYM(fchown),
295+
+ SYM(fsync),
296+
+ SYM(getcwd),
297+
+ SYM(geteuid),
298+
+ SYM(localtime),
299+
+ SYM(lseek64),
300+
+ SYM(mkdir),
301+
+ SYM(mktime),
302+
+ SYM(fdopen),
303+
+ SYM(c_format_unix_time),
304+
+ SYM(c_format_unix_time_gmt),
305+
+ SYM(c_parse_unix_time),
306+
+ SYM(c_parse_unix_time_gmt),
307+
+ SYM(__addtf3),
308+
+ SYM(__divtf3),
309+
+ SYM(__extenddftf2),
310+
+ SYM(__fixtfsi),
311+
+ SYM(__floatditf),
312+
+ SYM(__floatsitf),
313+
+ SYM(__getf2),
314+
+ SYM(__gttf2),
315+
+ SYM(__lttf2),
316+
+ SYM(__multf3),
317+
+ SYM(__subtf3),
318+
+ SYM(__trunctfdf2),
148319
+ { 0, 0, STRENGTH_NORMAL, 1 } /* sentinel */
149320
+};
150321
+

0 commit comments

Comments
 (0)