Giter VIP home page Giter VIP logo

Comments (7)

saagarjha avatar saagarjha commented on August 25, 2024 3

System call numbers on macOS are not stable, so Apple would like you to go through libc. Go used to create static binaries on macOS but they would constantly break whenever an update came out, so they've starting linking against the system libraries. The only reason you should be making system calls yourself is curiosity or if you have an extremely good reason that you cannot link against libSystem ;)

from hellosilicon.

saagarjha avatar saagarjha commented on August 25, 2024 2

Oh, no, Mach-O totally does static binaries. In fact, here's how to make one you can run on your Intel machine:

$ clang -x assembler-with-cpp -static -nostdlib -
.intel_syntax noprefix

#include <sys/syscall.h>

#define UNIX_SYSCALL 0x2000000

.globl start
start:
	mov rax, UNIX_SYSCALL | SYS_write
	mov rdi, 1
	lea rsi, text[rip]
	lea rdx, length
	syscall
	mov rax, UNIX_SYSCALL | SYS_exit
	xor rdi, rdi
	syscall

text:
.asciz "Hello, world!\n"
.equ length, . - text
$ ./a.out
Hello, world!

from hellosilicon.

DarkDust avatar DarkDust commented on August 25, 2024 2

Oh, no, Mach-O totally does static binaries. In fact, here's how to make one you can run on your Intel machine:

While you can create static binaries, the macOS kernel (XNU) allows the execution of static binaries on x86_64 only (or with debug kernels, which probably nobody outside Apple is using). On all other platforms (ARM64), the kernel enforces that an executable must use the dynamic linker (this was already linked to in the issue above). It's a restriction that cannot be bypassed. However, you can create a dynamically linked executable and simply not link to any library/framework.

from hellosilicon.

saagarjha avatar saagarjha commented on August 25, 2024 1

I lied, that code is likely outdated/not complete. I know of at least one statically linked binary running.

from hellosilicon.

below avatar below commented on August 25, 2024

That's cool to know! Although now that I have solved the issue of in the makefile, I will continue to work on that!

from hellosilicon.

below avatar below commented on August 25, 2024

I lied, that code is likely outdated/not complete. I know of at least one statically linked binary running.

Most interesting, the documentation I could find is also that Mach-O doesn't do static binaries.

That said, currently I am happy as long as I can easily build and deploy assembler source from the command line, and I might come back to the issue of building a Mach-O binary later ;)

from hellosilicon.

below avatar below commented on August 25, 2024

Most interesting! Any idea why the documentation would claim such a thing?

from hellosilicon.

Related Issues (15)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.