LoginSignup
0
0

More than 5 years have passed since last update.

Static binaries on OSX with syscall on Crystal

Last updated at Posted at 2018-06-07

Static binaries on OSX is a hard issue, but Go achieved by using syscall directly.

There is syscall package on Crystal too. Basic code is as following.

...
str = "Hello, World!\n"
syscall(WRITE, 1_u64, str.to_unsafe, str.size.to_u64)
syscall(EXIT)
% objdump -d hello

hello:  file format Mach-O 64-bit x86-64

Disassembly of section __TEXT,__text:
__text:
    1f60:       48 89 35 99 00 00 00    movq    %rsi, 153(%rip)
    1f67:       c3      retq
    1f68:       0f 1f 84 00 00 00 00 00         nopl    (%rax,%rax)
    1f70:       55      pushq   %rbp
    1f71:       48 89 e5        movq    %rsp, %rbp
    1f74:       48 8d 35 31 00 00 00    leaq    49(%rip), %rsi
    1f7b:       b8 04 00 00 02  movl    $33554436, %eax
    1f80:       bf 01 00 00 00  movl    $1, %edi
    1f85:       ba 0e 00 00 00  movl    $14, %edx
    1f8a:       0f 05   syscall
    1f8c:       b8 01 00 00 02  movl    $33554433, %eax
    1f91:       0f 05   syscall
    1f93:       31 c0   xorl    %eax, %eax
    1f95:       5d      popq    %rbp
    1f96:       c3      retq

% ./hello
Hello, World!
% otool -L hello  
hello:
% 
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0