[llvm-dev] Any LLD guarantees on section alignment across TUs?

Zachary Turner via llvm-dev llvm-dev at lists.llvm.org
Fri Jul 24 23:32:10 PDT 2020


Suppose i write

// foo.cpp
__attribute__((section(“foo”))) int x;

// bar.cpp
__attribute__((section(“foo”))) int y;

And i compile and link these two object files together using lld.  What
assumptions can I make regarding alignment/padding between the two symbols?

I’m comfortable getting an answer by reading the source, but that won’t
tell if any properties i discover  are guaranteed or just happenstance.

Are all of the following guaranteed ?
A) relative order of symbols within a TU is not modified by the linker
B) No padding is inserted by the linker between symbols in a TU aside from
that which was already inserted by the compiler/assembler
C) When merging section A from inputs B and C, the minimal amount of
padding necessary so that the first symbol from C is properly aligned is
inserted.

I think(?) these conditions would be sufficient to guarantee, for example,
that I could implement my own .ctor / @init_array logic using only the
front end.

And are there any subtle interactions here with -fdata-sections or
behavioral differences across COFF/ELF/MachO?

Is there anyone who can provide some insight on this?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20200724/4ed41c9c/attachment.html>


More information about the llvm-dev mailing list