On Thu, Oct 24, 2024 at 9:48 PM David Brown via Gcc <gcc@gcc.gnu.org> wrote:
>
> On 24/10/2024 16:35, Jonathan Wakely via Gcc wrote:
> > On Thu, 24 Oct 2024 at 15:00, Mateusz Guzik via Gcc <gcc@gcc.gnu.org> wrote:
> >
> >> I understand the stock behavior of pilling variables on may happen to
> >> improve cache usage.
> >>
> >> However, in a multicore setting it is a never-ending source of
> >> unintentionally showing up and disappearing false-sharing depending on
> >> unrelated variables being added or removed.
> >>
> >> I'm aware one can manually add padding or explicitly tell the linker
> >> to put a specific variable elsewhere, but in large codebases getting
> >> to a point where everything is annotated is quite a challenge. To give
> >> you one example of a project which did not get there despite literally
> >> decades of multicore development: the Linux kernel (or in fact any
> >> open-source kernel out there, last I checked).
> >>
> >> In the meantime a great clutch would contain such problems to a
> >> specific .o file.
> >>
> ...
> >> For illustrative purposes, I don't care about the name:
> >> -align-object-data-section=64
> >>
> >> Thoughts?
> >>
> >
> > Wouldn't that be a linker option, and so not part of GCC?
> >
>
> I would have thought it would be better as part of the compiler.

It also would need compiler support for the LTO case where what is
a linker "object unit" is different from the source "translation
unit".  But there
the question is what's the desired behavior?  Currently you'd need to use
-flto-partition=1to1 to get the mapping of translation unit to object
unit the same
as when not using LTO.

Richard.

>  For
> each compilation unit, you generate one or more data sections depending
> on the variable initialisations, compiler options and target (.bss,
> .data, .rodata, .sbss, etc.).  If the compiler has
> "-align-object-data-section=64" in effect, then you could add ".align
> 64" to the start and the end of each section.  As far as I can see, that
> would give the effect the OP is looking for in a simple manner that can
> also be different for different translation units in the same program
> (which would be hard to do with a linker flag).  And if this is a flag
> in gcc, then it will work for any ld-compatible linker (gold, mold, etc.).
>
> gcc already generates a ".align" linker command with the minimum
> alignment required by the variables in the section.  This new flag would
> then do two things - one is set a minimum alignment for the data
> sections (it can still increase if a variable has bigger alignment, such
> as via an "_Alignas" specifier or an "aligned" attribute).  Secondly, it
> would add another ".align" command at the end of the section so that if
> a section with a small alignment specifier is linked after one with a
> specified large alignment, you'll get padding inserted.
>
> mvh.,
>
> David
>

Reply via email to