4 ms·
To fix the nomenclature confusion in this thread: a.out was the name of the output file from unix linker. Thus the format of that file was "a.out" format. al
by gumby 8y ago
To fix the nomenclature confusion in this thread:
a.out was the name of the output file from unix linker. Thus the format of that file was "a.out" format. all the other unix toolchains did the same thing for compatibility.
a.out is pretty limited, though fine for small PDP-11 binaries: some text (executable), initialized data, and an amount of RAM to preallocate, plus some symbols.
Even when I was designing bfd back in 1989 it was clear that a.out, while pervasive, just wasn't powerful enough, especially when you added C++ constructors, destructors, atexit stuff etc. SVR4 by then had COFF to be more flexible (Microsoft's PE is a COFF derivative). But COFF was kinda crufty (not bad for a first effort!) and was clumsy for things like shared libraries.
ELF is a good example of a standards committee designing something to handle known problems. It's not perfect, but pretty good.
- egorfine 8y agoI'm curious to learn: what C++ constructors have to do with the executable format? I do get that atexit might require a special place in the binary for the kernel to jump to, but how does a relatively high end language feature drop down to binary format?
- pjmlp 8y agoConstructors of global static objects, they are required to be called before main() starts execution, likewise destructors of such objects are supposed to run in inverse order on program termination, including after call to atexit(). This needs to happen regardless how the binary, or dynamic library gets loaded.
- gumby 8y ago> how does a relatively high end language feature drop down to binary format? All high end language features drop down to binary formats -- that's what ABIs are. In the case of things like constructors and destructors you can of course just stick them all in the text section and have the linker construct call to them in some fashion. You'd have to use some reserved name mangling to distinguish them so that the linker can even find them. If instead you have separate sections the linker can just run through the symbol table; the dynamic loader can even do so so the compile-time linker can ignore those sections (just copy them). You can even play tricks like unloading them after running (or only load exit code upon exit) if memory games like that matter. etc etc. It's all about how you communicate semantic issues from compile time to run time, as with all ABI issues.
- burfog 8y agoCount me as being not a fan of ELF. One can have e_phoff or e_shoff or both... or I suppose neither. Because you can have both, they can conflict. If you have e_phoff, then within that there is the issue of p_vaddr and p_paddr. You could have one or the other or both, or I suppose neither. They can thus conflict. The various flags associated with these things can also conflict. This comes up often with boot loaders and kernels. There are versions of Linux that are described by p_vaddr, p_paddr, and sh_addr. Sometimes one or another has an offset added/subtracted, or is zero, or is simply missing or worse. None of the above even makes sense once you add ASLR. I have no idea how that is expressed, but I'm pretty certain it is a gross hack. There just isn't a proper way to express such a thing. Needlessly, there are two types of symbols. They could conflict. Better formats just use a flag bit. BTW, when I hand-generate ELF files, I hit bugs in BFD. I recall hitting one that relates to string tables, with BFD refusing to accept an index of 0. I had to add a useless NUL byte.
- gumby 8y agoI'm not really sure what your point is; program and section headers are different things. ASLR is, relatively speaking, a recent invention (when compared to ELF). ELF describes memory layout, so if you want to randomize it you pretty much have to do your relocation at runtime...which you can do except for the entry point, but I suppose you could make an extension to relocate even that. For that one small thing I think you could propose a revision to the ELF spec. And I'm sure there are still bugs in bfd! But with ELF being pretty pervasive these days that 30 year-old (just noticed that: 1989-2019) software is less useful than it used to be. But feel free to send in a bug fix if you can't have a string table index of 0 (it would surprise me if that bug really exists, but stranger things have happened...)
- burfog 8y agoProgram and section headers are different things only because ELF makes it so, and this is a bad design. The same mostly goes for having both physical and virtual addresses. Has there ever even existed a loader that would generate page tables according to that? There should have been one kind of address, and possibly header flags to indicate allowable MMU states. If there is no such bug, then you can stop wasting that byte at the beginning of the string tables.