OSDev.org

The Place to Start for Operating System Developers
It is currently Wed Feb 19, 2020 9:09 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 17 posts ]  Go to page Previous  1, 2
Author Message
 Post subject: Re: True cross-platform development
PostPosted: Thu Feb 06, 2020 7:18 am 
Offline
Member
Member
User avatar

Joined: Thu Oct 13, 2016 4:55 pm
Posts: 501
SpyderTL wrote:
To be clear, I want to write an application once, and run it on any OS (or even no OS), as long as the CPU matches the compile target for the executable.
I see. I was confused because your examples (like Java and WebAssembly) uses machine-independent bytecode. Thanks for the clarification!

SpyderTL wrote:
If Windows, Linux, OSX and GRUB could all load the same ELF file, then the application would just need to figure out which one actually loaded it, and it could call the appropriate syscalls for that environment. With some static libraries to abstract this away, the application wouldn't even necessarily be aware of the platform details.
Yes, exactly. You are absolutely correct about this.

SpyderTL wrote:
Unfortunately, Windows can't load ELF files, and GRUB has some limitations on it's ELF support. See here: https://stackoverflow.com/questions/253 ... 1#25492131

But the ELF format is probably the closest thing to a universally supported format, so it may just be a matter of writing a custom ELF loader for Windows, and working out an ELF format that works on all other platforms.

If I can somehow get my one executable loaded into memory on all platforms, without any interpreter, and without any Just-in-time compiler, I would consider that to be a success.
Now that I know what your goal is, I'd like to revise my former advice. I think if you're not up to fat binaries nor machine independent bytecode, then PE format is better for you.

Windows supports it, and you can't expand the Windows kernel with ELF support easily, so it makes sense to rely on the smallest common denominator.
For Linux, you can use binfmtpe module as a base for your loader.
For Grub, you'll have to create a PE support module (maybe there's already one, but I don't know about it). I'd recommend to start from the aout.c.

As for the services, on Windows you could use a dll instead of a loader. For Linux and Grub, you have the source so you can implement a run-time linker in the loader as you like.

SpyderTL wrote:
Write once, compile once, run nearly anywhere, at native speeds.

To put it another way, .NET and Java both use native runtimes that are responsible for both loading the actual program, and re-compiling it into native code for the current platform. In my situation, the code is already in the correct format for the current platform. It just needs to be loaded into memory. So, similar to Java and .NET, you could create an install for your loader, just like you "install" .NET or the JRE now. Then, you could run any program that was compiled for your CPU, regardless of whether you had Windows, or Linux, or MacOS, or just wanted to put the program on a boot floppy with GRUB. The program would work virtually the same on all 4 environments, either in console mode or in windowed mode.

It seems like this should be possible, if not entirely practical. But in either case, it's a good excuse for me to learn the PE and ELF file formats, if nothing else.
Yeah, I agree. It is doable, it is a good exercize, and I'm not entirely sure it wouldn't be practical. I can see valid use cases for it.

Cheers,
bzt


Top
 Profile  
 
 Post subject: Re: True cross-platform development
PostPosted: Thu Feb 06, 2020 11:14 am 
Offline
User avatar

Joined: Fri Nov 22, 2019 5:46 am
Posts: 8
zaval wrote:
to PeterX, expandability is not a virtue of being opensource, it's a virtue of a good design and being well documented. Candy demonstrated how one can add ELF loading support to Windows. just having million of lines of foreign code in front of your eyes is not a guarantee you are at the easiest way of achieving your goals of expanding something over there. I'd rather want to deal with a well structured system, that describes well how it can be extended. you got the point. ;)


Yeah, you are right about both: Good design and being well-documented! I assumed it's not possible with Windows, but I was wrong! (And I hope my answer wasn't of the kind "Don't do it". Because nobody needs people discouraging developers.)

You guys named several interesting solutions.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 17 posts ]  Go to page Previous  1, 2

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group