News for hackers. Stuff that matters.
Re:BOLT: Binary Optimization and Layout Tool by q3k on Sunday March 22, 2020 @12:13PM (#22656044)
Okay, I don't get it.

Why not hook this into LLVM's compiler infrastructure, instead of recovering the CFG from a binary - and not any binary, but one that has to built with special flags anyway? This seems backwards.

Re:BOLT: Binary Optimization and Layout Tool by marklacey on Sunday March 22, 2020 @01:38PM (#22656792)
Because if you statically link libraries like the language runtime it allows you to reorder the blocks in those as well to improve locality and instruction cache utilization.

For example if your code calls a particular runtime function shortly after starting, that function (or the basic blocks from that function that are executed frequently) can be placed close to the call site.

Re:BOLT: Binary Optimization and Layout Tool by ndesaulniers on Sunday March 22, 2020 @03:05PM (#22657596)
If you're statically linking, then LTO would give you cross TU visibility to do the same optimization at link time, not post link when you've lost a lot of fidelity.
Re:BOLT: Binary Optimization and Layout Tool by marklacey on Sunday March 22, 2020 @03:33PM (#22657845)
Not if it’s a library that you’re not compiling, like language runtimes or system libraries.

LTO requires that you’re compiling all the code to get the benefits.

I’m also not sure if either gcc or clang’s LTO does layout at the basic block level or at the function level. There is a lot of benefit from doing it at the basic block level. You can literally lay out all the code that runs at application start time so that it is mostly adjacent and fall-through from block to block during execution.

This isn’t something you necessarily do instead of LTO, but rather something you can do in addition to it.

Re:BOLT: Binary Optimization and Layout Tool by ndesaulniers on Sunday March 22, 2020 @03:03PM (#22657576)
This is the argument the authors of propeller make.
Re:BOLT: Binary Optimization and Layout Tool by thedance on Sunday March 22, 2020 @03:32PM (#22657826)
What if your binary, or one of its libraries, is not built with LLVM?
Re:BOLT: Binary Optimization and Layout Tool by convolvatron on Sunday March 22, 2020 @12:35PM (#22656216)
you're absolutely right. it seems like a huge number of comilers have had 'global optimization' on their todo list, but never got around to it.

i think this paper (cant find a non-paywalled copy) https://dl.acm.org/doi/10.1145/12276.13338 got around 10% just by attempting to align the allocation of the callers and the callee.

maybe memories are large enough now, and the whole proprietary binary-only library business model is gone, that we should really be abandoning the idea of seperate compilation units as the default.