3 ms·
I think the exception code _is_ loaded. It is only a theoretical possibility that loading it could be avoided. I just built the following code with g++ v7.4 (f
by abainbridge 7y ago
I think the exception code _is_ loaded. It is only a theoretical possibility that loading it could be avoided.
I just built the following code with g++ v7.4 (from MSYS64 on Windows):
#include <math.h>
#include <stdexcept>
void exitWithMessageException() {
if (random() == 4321)
throw std::runtime_error("Halt! Who goes there?");
}
int main() {
exitWithMessageException();
return 1234;
}
The generated code mixed the exception handlers with the hot-path code. Here are the address ranges of relevant chunks:
100401080 - Hot path of exitWithMessageException
100401099
10040109a - Cold path of exitWithMessageException
10040113f
100401140 - Start of main
- gpderetta 7y agoInteresting, GCC 7.x seems to simply puts the cold branch on a separate nop-padded cacheline. GCC 9 [1] instead moves the exception throwing branch into a cold clone of exitWithMessageException function. The behaviour seems to have changed on starting from GCC 8.x. [1] https://godbolt.org/z/PKKZ8m https://godbolt.org/z/PKKZ8m
- abainbridge 7y agoOoo, fancy. There is still a long way from just that to actually getting the savings in a real program running on a real operating system. For example, if I have thousands of source files, each with a few hundred bytes of cold exception handlers, do they get coalesced into a single block for the whole program?
- gpderetta 7y agocoalescing functions in the same section should be the linker job, yes.