News for hackers. Stuff that matters.
Re:Initialization in C++ is Seriously Bonkers by jstimpfle on Saturday January 05, 2019 @02:18PM (#18833609)
It's hard to imagine many situations where you need to give a name to the constant value 0. And think how "optimal" it would be if there were many and we had a read-only BSS! We could cheaply get a huuuge section full of constant zeroes.

I think you can in fact realize the idea in PECOFF, by the way. I still need to figure out some aspects to it these days (it seems a bit arcane and maybe Windows doesn't follow the spec very well). But in any case PECOFF has this notion "VirtualSize" (size of section in running program) and "SizeInFile" (size of the prefix of the section that should be filled with contents from the executable file). If SizeInFile is smaller than VirtualSize then the rest of the image gets filled with zeroes I think.

Re:Initialization in C++ is Seriously Bonkers by userbinator on Saturday January 05, 2019 @02:29PM (#18833668)
But in any case PECOFF has this notion "VirtualSize" (size of section in running program) and "SizeInFile" (size of the prefix of the section that should be filled with contents from the executable file). If SizeInFile is smaller than the rest of the image gets filled with zeroes I think.

Correct. A common and low-hanging-(more like "lying on the ground")fruit optimisation for PE files is to reorder and realign the sections such that all the 0s are at the end, in which case they can be "cut off" by setting those header fields appropriately and not waste storage space.

Re:Initialization in C++ is Seriously Bonkers by ajross on Saturday January 05, 2019 @02:26PM (#18833654)
> I think you can in fact realize the idea in PECOFF, by the way.

You can express it in ELF too, with a NOBITS segment with ALLOC but no WRITE flag. Whether that works or exercises bugs in the dynamic loader is an open question.

Re:Initialization in C++ is Seriously Bonkers by amluto on Sunday January 06, 2019 @11:11AM (#18838979)
On Linux (in the kernel image), it exercises bugs in the dynamic loader. I tried it once :)