3 ms·
What is the point of it?
by johnisgood 2y ago
What is the point of it?
- rasjani 2y agoWithout actually knowing, i'd guess that would generate bytecode's that could be modified later by patching the resulting binary ? I remember few buddies using similar pattern in ASM that just added n NOP's into code to allow patching and thus eliminating possible recompilation..
- ChrisMarshallNY 2y agoI suspect that’s it. There was a lot of self-modification, going on, in those days. Old machine language stuff had very limited resources, so we often modified code, or reused code space.
- agumonkey 2y agowarm up the stack ? (no idea to be honest)
- tanelpoder 2y agoThe C alternative for the hardware "halt and catch fire" instruction?
- kps 2y agoThe C alternative for the Fortran COMMON block.
- aap_ 2y agoIt's an awkward way to reserve memory. The important detail here is that both compiler phases do this, and the way the programs are linked guarantees that the reserved region has the same address in both phases. Therefore an expression tree involving pointers can be passed to the second phase very succinctly. Not pretty, no, but hardware limitations force you to do come up with strange solutions sometimes.
- johnisgood 2y agoThank you! Is it relevant today at all, or is there an use-case for it today?
- aap_ 2y agoNo, if you need fixed addresses i suppose a linker script would be the way to go? Or in this case you'd just serialize the data such that it doesn't contain any pointers in the first place.
- ddulaney 2y agoIf you even can with ASLR. Most modern boxes would disable stuff like this.
- mananaysiempre 2y agoThere are better tools to do this these days—with the GNU toolchain, for example, you’d use a linker script and make sure you’re building a non-position-independent static executable. Alternatively, you could use self-relative pointers: instead of having foo_t *foo and putting p there, have ptrdiff_t foo and put ((char *)p - (char *)&foo) there.
- colejohnson66 2y agoHere's the actual code that references the 'ospace' from before 'waste': https://github.com/mortdeus/legacy-cc/blob/936e12cfc756773cb14c56a935a53220b883c429/last1120c/c01.c#L178 https://github.com/mortdeus/legacy-cc/blob/936e12cfc756773cb...
- fxtentacle 2y agoIt's an obscure way to statically allocate memory for the ospace pointer.
- account42 2y agoWhat's the advantage over an array though, which would allow you to better control the size without making assumptions about code generation. edit: http://cm.bell-labs.co/who/dmr/primevalC.html http://cm.bell-labs.co/who/dmr/primevalC.html (linked from another comment has the answer): > A second, less noticeable, but astonishing peculiarity is the space allocation: temporary storage is allocated that deliberately overwrites the beginning of the program, smashing its initialization code to save space. The two compilers differ in the details in how they cope with this. In the earlier one, the start is found by naming a function; in the later, the start is simply taken to be 0. This indicates that the first compiler was written before we had a machine with memory mapping, so the origin of the program was not at location 0, whereas by the time of the second, we had a PDP-11 that did provide mapping. (See the Unix History paper). In one of the files (prestruct-c/c10.c) the kludgery is especially evident. So I guess it has to be a function in order to be placed in front of main() so the buffer can overflow into the no longer needed code at the start of it.