[llvm-dev] grouping global variables by alignment: safe to do at LLVM level, or only at Clang level?

Tim Northover via llvm-dev llvm-dev at lists.llvm.org
Mon Jul 25 18:58:04 PDT 2016

On 25 July 2016 at 15:36, Abe Skolnik via llvm-dev
<llvm-dev at lists.llvm.org> wrote:
> My question this time is this: is re-ordering globals at the LLVM level both
> possible [without massive rewriting of LLVM] and safe?

First, I think it's completely safe as far as LLVM is concerned (and
have no sympathy for any C or C++ developers who might claim to rely
on the order either). In fact it looks like GCC and Clang already do
it differently so the risk is pretty tiny too.

For LTO it's probably fairly simple to do (sort by alignment during MC
emission would be my first stab). In the general case, it's really an
issue for the linker to resolve though (as the only program that
actually gets to see all globals). Probably with the help of
"-fdata-sections" on ELF targets. But it doesn't look like either of
the GNU linkers do support it.



More information about the llvm-dev mailing list