This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Some extensions to the .section directive for ELF and COFF


Back in LLVM land we have found some limitations of the .section
directives for COFF and ELF and have some tentative extensions.

It would be nice to have them also supported in gas, or at least
agreed that they are reasonable and can be implemented some point in
the future.

The issue with the COFF directive is that it doesn't include a comdat.
The comdat has to be specified with the .linkonce directive. But then
one cannot have multiple sections with the same name but different
comdats:

---------------------------------------------------
.section foo
.linkonce ...
...
.section foo
.linkonce ... ; too late, we already switched to the first section.
-------------------------------------------------

The solutions was to make the COFF .section look a bit more like the ELF one:

 .section foo, "dr", discard, "Symbol1"
 .section foo, "dr", discard, "Symbol2"

creates two sections named foo with different comdat symbols. This is
currently used by LLVM on windows as it matches the behavior of cl.

The issue with the ELF one was similar: We need different section
names unless the comdats are different. This in turn requires the
compiler to be creative with section names when using
-ffunction-section -fdata-sections and those can get quite big.

The extension was to add an optional ",unique":

-----------------------------------------
.section .text,"ax",@progbits,unique
.section .text,"ax",@progbits,unique
-----------------------------------------

Creates two sections named ".text".

Currently this is only used behind a non-default flag. Using it saves
11MB of section names on a build of llvm+clang (total .o size from
241687775 to 230649031 bytes).

Cheers,
Rafael


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]