It turns out to be impossible to create a file that is simultaneously a valid ELF and Windows PE. The solution to this is to make a file that is simultaneously a valid PE and shell script, and have the shell script overwrite the start of the file with an ELF header and re-exec itself.
No, there's a discussion upthread about running on Darwin that specifically says you have to run as `bash ./foo` first time and `./foo` thereafter because it overwrites on disk.