jart / jart/blink

Help on compiling for iOS

Open
#151 12 comments 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
7.6k
Forks
278
PR merge metrics
No merged PRs in 30d

Description

Hi,
I've been trying to cross-compile blink for iOS. Part of the problem is that, from the compiler viewpoint, it is very difficult to separate iOS from a M1 Mac: both have `__APPLE__` and `__aarch64__` defined.

(There are other issues, such as `/tmp` not being accessible, the need to redirect standard output, and the fact that many files don't have the X-bit set even though they're executable, but I'm used to these by now).

So far, my efforts have resulted into:
- compile with the JIT enabled: it compiles, but it breaks when loading an executable.
- without the `-m` flag when launching blink:
```
E2023-08-14T18:05:14.583468:blink/memorymalloc.c:913:8640 mmap(0x400000[0x88800400000], 0x4000) -> 0xfffff77909274000[0x109274000] crisis: requested memory overlapped blink image or system memory. try using `blink -m` to disable memory optimizations, or try compiling blink using -Wl,--image-base=0x23000000 or possibly -Wl,-Ttext-segment=0x23000000 in LDFLAGS
unrecoverable mmap() crisis: see log for further details
```

- with the `-m` flag: it crashes the entire app (that's expected) and `blink.log` contains the following:

```
I2023-08-14T18:07:17.450723:blink/random.c:88:8640 generating weak random data
E2023-08-14T18:07:17.454305:blink/blink.c:174:8640 terminating due to SIGSEGV (rip=0x400078 code=2 faultaddr=0x400078)
I2023-08-14T18:07:17.454714:blink/diself.c:115:8640 could not load elf string table
E2023-08-14T18:07:17.454898:blink/blink.c:158:8640 additional information
PC 400078 push $1 6a 01 5f 48 8d 35 11 00
AX 0000000000000000 CX 0000000000000000 DX 0000000000000000 BX 0000000000000000
SP 00004fffffffea50 BP 0000000000000000 SI 0000000000000000 DI 0000000000000000
R8 0000000000000000 R9 0000000000000000 R10 0000000000000000 R11 0000000000000000
R12 0000000000000000 R13 0000000000000000 R14 0000000000000000 R15 0000000000000000
FS 0000000000000
```

- compile without the JIT enabled (which is probably a good idea since the AppStore rules sort of forbid JIT, although there are some apps that still provide it): compilation fails with the following error:
```
Undefined symbols for architecture arm64:
"_FastCall", referenced from:
_OpCallJvds in blink.a(stack.o)
"_FastLeave", referenced from:
_OpLeave in blink.a(stack.o)
"_Jitter", referenced from:
_OpLeave in blink.a(stack.o)
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
```
Compiling for OSX with `--disable-jit` does work, it's just with iOS that I have this weird issue. I don't understand what is happening; I'd appreciate if anyone could point me in the right direction.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reproducing the iOS builds with and without JIT, then inspect the platform decisions behind memorymalloc.c, blink.c, diself.c, and the unresolved symbols from stack.o. Done means Blink compiles for iOS and launches without the reported memory, crash, or linker failures.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, ios, macos
Domain
build-system, mobile-dev, operating-systems
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.