[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
Tue Jul 26 09:19:32 PDT 2016

On 26 July 2016 at 08:46, Abe Skolnik via llvm-dev
<llvm-dev at lists.llvm.org> wrote:
> AFAIK & TTBOMK, a compiler should do it [if allowed by the language] and a
> linker should not mess it up.  I don`t know that a linker is allowed to make
> assumptions about code not traversing labels in its data accesses.

In ELF land, it's not, which is why you pass -fdata-sections. That
option makes Clang put every global into its own section, and the
linker *is* allowed to assume accesses can't cross section boundaries.

In MachO land, the linker is allowed to make that assumption if the
object file has been marked with a .subsections_via_symbols directive
(which it is by default on all Darwin targets).

It really should be the linker's job in the general case, both for
optimal code and to avoid duplicating effort.


More information about the llvm-dev mailing list