halivingston
halivingston

Reputation: 3895

Assuming AMD64 calling convention would be standard could Windows and Linux have shared code?

AMD64 has different calling conventions on Linux and Windows but imagine if they were the same would it be possible to have code share amongst them?

I know there is difference between COFF and ELF, and things like shared libraries are different (GOT vs whatever Windows does) and function names are of course also different.

Barring all this could it be possible? For example ARM has the same convention on both Windows and Linux.

Upvotes: 1

Views: 97

Answers (2)

Marco van de Voort
Marco van de Voort

Reputation: 26356

Maybe codecs in specially crafted libraries.

But any binary (library or executable) links in some OS specific entry code, and when it does something non trivial (like purely stream processing codecs again) it interfaces to the OS. Those will be different.

For that same reason it is impossible to run BSD binaries on Linux (contrary to wrong comments). The BSD syscall is different, processing of parameters to the binary (csu/crt*) are different and some syscalls are inlined.

People get drunk on POSIX api simularities, but forget that POSIX is a source not binary convention.

Upvotes: 0

Sami Kuhmonen
Sami Kuhmonen

Reputation: 31153

Yes. The calling convention defines how parameters are stored in stack/registers, how return values are handled etc. If they were equal, code could be shared, even in binary form.

However, the code must not have any dependencies to a specific platform. For example the code cannot use syscalls for IO, but might use a platform specific library for this.

Upvotes: 2

Related Questions