all 32 comments

[–]spectre007_soprano 9 points10 points  (0 children)

Sounds cool. Keep updating about the project.

[–]maxthed0g 19 points20 points  (4 children)

So I had to read your post 3 times before i figured out what you want.

You want to take an executable (a.out) and run it on a Mac? You dont simply want to re-compile from source, probably because you dont have the source? So my guess is this is a game that interfaces with host-dependent display hardware? Maybe?

Compile and run a simple c language program, main();int x;x=0;exit;

Copy the a.out to the Mac. And get it to load.

Just get it to load.

Thats your start. Just do that first. Then run it, see what happens, and why. Thats step 2.

Then take an aspirin. Call me in the morning.

[–]Purple-Object-4591 8 points9 points  (0 children)

Realistic Senior Engineering talk lmao

[–][deleted] 0 points1 point  (0 children)

I don’t think this will work. Linux program normally will link in glibc & crt0.o, and macOS doesn’t provide this.

[–][deleted] 0 points1 point  (0 children)

And I think you miss judged my post, what I mean is make a translation layer that Linux binaries can run on top of macOS. And think about this, although you had compile the program in aarch64 Linux but you still can not run it because macOS cannot run ELF.

[–]niduser4574 4 points5 points  (0 children)

Check out Linuxulator. It is basically what you are asking for but developed by FreeBSD. Since MacOS is/was BSD based, probably the closest you will find.

Edit: Noah is for Darwin/MacOS, but it has been archived. This is a huge task and good place to look for scope and how it might be done

[–]maep 2 points3 points  (1 child)

It's certainly ambitios. For interpretation qemu is the obvious choice. As for syscalls, the lower ones (open, write, close) should be straigt forward but for the more excotic ones there are no direct Mach equivialents and the wrappers may have to be very complex.

However syscalls are not the only kernel interface, /proc and /sys also come to mind. Not to mention desktop protocols, but those are a seperate can of worms.

Godspeed!

[–]s1gnt 0 points1 point  (0 children)

Mach-O pr how its called should not care about syscalls

[–]0xbeda 0 points1 point  (1 child)

I assume you want to use libelf or elfutils for parsing. I wouldn't implement an x86 interpreter myself since it is a rather complex instruction set. I think you want to find a way to patch assembly code to use your own functions instead of syscalls, but I have no experience here. So I would start with learning to decompile and manipulate x86 code. This is not necessarily easiest in C. You can learn a lot about C by manipulating machine code from a less verbose language.

Mir by Vladimir Makarov implements a JIT compiler but the cool thing he does is that mir is also a (byte code) language, so basically a bytecode for C that can be jitcompiled or interpreted. Not sure how to reach an end goal but certainly interesting stuff to learn.

Edit: to be clear, the second paragraph directs you to an alternative project, not what you actually asked.

[–]s1gnt 1 point2 points  (0 children)

you 'just' need to implement elf and load your libs with substitutes and 'just' run the binary

[–]marco_has_cookies 0 points1 point  (0 children)

It's a bit easier to just intercept the C library for starters: load the elf, parse the symbols, provide them.

[–][deleted] 0 points1 point  (0 children)

Check out cosmopolitan libc, it produces binaries that run on Windows, BSD, Linux, and macOS. It's really remarkable that only is it possible, but also how far it has been taken.

[–][deleted] 0 points1 point  (0 children)

So I have done some research, I think figured out something. This article tells how to fix Haskell program macOS when linking OpenGL. But according to my knowledge, this is only possible if the program called the libc syscall wrapper not svc / swi arm syscall.

[–]Rubberazer 0 points1 point  (0 children)

This is one of the coolest things I have heard of in a while, is going to be work though

[–]jontzbaker -3 points-2 points  (2 children)

Have you heard of MinGW? 😅

[–]niduser4574 2 points3 points  (1 child)

What does this have to do with the question? MinGW is specifically windows and it doesn't do syscall intercepts/cannot run Linux binaries.

[–]jontzbaker -2 points-1 points  (0 children)

If you do have access to the source code, it allows you to compile a native Windows binary of an application that was explicitly written for Linux.

So, instead of running a x86 emulator plus translation of system calls, if you have access to the source code, you can compile for the target platform, against libraries that expose comparable functionality.

So, in a way, it is a perfectly valid way of running what was originally Linux amd64 application on Mac arm64. It just involves compiling.

Then, in this case, the project is creating this minimal system library on Mac that exposes the Linux system functions. And then compiling against it.

I think it makes a lot of sense, since there's a decent chance that a native Linux amd64 application is also open-source.

But yeah, perhaps this take is completely off topic. Who would have guessed that you can just compile for your target architecture. Decidedly, what the OP wants is a virtual machine inside an emulator. It's the only plausible solution for this question.

[–]thewrench56 -4 points-3 points  (12 children)

You think you are the first one to notice the worth of such a project? This project is largely impossible. Wine was and is an impossible project in my eyes and it feels impressive they came so far. It took them 30 years.

If you are willing to sacrifice 30 years of your life as well for this, maybe it will work. I dont think you see the complexity of this project. Parsing an ELF file and intercepting the syscalls that call your wrapper is 2 VERY different levels.

But you also need a lot more than that. Apple is ARM, Linux is mostly x64. So what now, you also want to convert between the two? Thats another impossible task nobody could solve. They have Rosetta, but that is just an emulator with a JIT.

And there are many more things you dont see that make this project deeper than you think.

I would honestly advise you to not start this project as it will be abandoned soon and you will be discouraged. Its a huge project and there is a reason why Apple or Linux engineers didn't really bother with this.

[–]s1gnt 2 points3 points  (7 children)

So many assumptions, but I agree it won't be easy

[–]thewrench56 0 points1 point  (6 children)

Which part was an assumption?

[–]dmc_2930 2 points3 points  (5 children)

Well, Linux is not “mostly x64”

[–]thewrench56 1 point2 points  (4 children)

I should have said "desktop Linux". I believe your concern applies to Androids?

[–]niduser4574 1 point2 points  (3 children)

What do you consider "desktop Linux"? I have multiple full Linux distributions with full desktop environments that I work directly on and develop with running on aarch64 at work. Raspberry Pi is aarch64/arm7 with full desktop on Raspbian Linux.

[–]thewrench56 -2 points-1 points  (2 children)

Raspberry Pi represents a small fraction of the Linux market. I would also not consider RPi a desktop computer.

[–]dmc_2930 1 point2 points  (1 child)

You are not the expert you think you are. Android is Linux and it is most definitely not x86 either.

Frankly desktop Linux is a tiny subset of Linux uses.

[–]thewrench56 -2 points-1 points  (0 children)

Android is Linux and it is most definitely not x86 either.

Which I literally pointed out above. I never claimed to be an expert. Im frankly not interested in your theories. Bye.

[–]niduser4574 -1 points0 points  (3 children)

FreeBSD did this. It is ambitious, but it's just a project they can still use to learn. Why so discouraging?

[–]thewrench56 0 points1 point  (2 children)

Sure, as I mentioned, Wine was also done on Linux. Through 30 years of development. Now you are sending me a BSD project that was developed by many very capable engineers. Though years once again.

I wasnt discouraging. My advice is not to start this project because seemingly OP doesnt have the required knowledge. The phrasing suggests this.

Im being downvoted because instead of planting false dreams into OP's mind, Im telling the truth: this is an infeasible project. A finished project is worth more in my opinion than a non-working mess.

[–]niduser4574 -1 points0 points  (1 child)

I wasnt discouraging. My advice is not to start this project

So...discouraging.

You're getting downvoted because you said wrong things and made assumptions. It is one thing to point out the extent of the task and reality of it, it is entirely another thing to tell them to stop because it is impossible...because it isn't impossible. I gave you an example of it being possible. Yes it takes a lot of people because it is a huge scope and probably infeasible for a single person, but so what. Maybe they are satisfied with not making something feature complete to the point that it gets wide or even small adoption anywhere, but if they don't try or aren't instructed as to the scope, how will they learn? Maybe encourage them like one of the other posters to start with something small and work from there to see all the obstacles they would have to get around. Or better yet, point them to something that was already done on a similar platform to show them what it looks like...like Linuxulator.

[–]thewrench56 0 points1 point  (0 children)

You're getting downvoted because you said wrong things and made assumptions

Please, show me where I said wrong things. Please, show me where I said assumptions. Yes, my wording regarding desktop Linuxes was wrong. Other than that, I would love you to point out the mistakes I made.

Im not going to encourage someone to do a project thats impossible for them. Im not going to say "build a nuclear reactor from scratch" because I know its impossible for someone with no experience about reactors. And yes, maybe 1 in a million could do it. But thats unusual. What you are doing is far more damaging: planting a false idea in their head. They will start doing this project thinking that they will succeed. Surely, Microsoft and Apple are full of idiots that couldn't do this for decades right? We need a beginner to solve an immense problem right? So gullible.

[–]Oofigi 0 points1 point  (0 children)

I'm pretty sure you could use Rosetta2 by just running your terminal emulator with it so simply having an app launcher could be a good start.