[PATCH] D36351: [lld][ELF] Add profile guided section layout

Michael Spencer via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 2 11:47:31 PST 2018


On Thu, Feb 1, 2018 at 4:25 PM, Rafael Avila de Espindola <
rafael.espindola at gmail.com> wrote:

>
> Testing the patch I have hit a case where the sorted program crashes.
>
> I have uploaded the test to
>
>  https://s3-us-west-2.amazonaws.com/linker-tests/t2.tar.xz


The call graph file reduces down to a single line.

__libc_csu_init _init 1

You told the linker it could reorder _init, so it did. This happens to move
_init to the end of .init. Obviously reordering _init is bad, and I'm
pretty sure --symbol-ordering-file has the same problem (although it
prefers to move to the front, so it would happen to work for _init). This
is part of the reason why I originally restricted this to .text, as it's a
known safe to reorder section.

There are many ways to solve this, but for now I would prefer to white list
the sections that are safe to reorder, and ignore any edges that include
sections not in that list or edges between output sections.

- Michael Spencer


>
>
>
> Michael Spencer via Phabricator <reviews at reviews.llvm.org> writes:
>
>
> > Index: test/ELF/cgprofile-txt.s
> > ===================================================================
> > --- /dev/null
> > +++ test/ELF/cgprofile-txt.s
> > @@ -0,0 +1,69 @@
> > +# REQUIRES: x86
> > +
> > +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
> > +# RUN: ld.lld -e A %t -o %t2
> > +# RUN: llvm-readobj -symbols %t2 | FileCheck %s --check-prefix=NOSORT
> > +
> > +# RUN: echo "A B 100" > %t.call_graph
> > +# RUN: echo "A C 40" >> %t.call_graph
> > +# RUN: echo "B C 30" >> %t.call_graph
> > +# RUN: echo "C D 90" >> %t.call_graph
> > +# RUN: echo "PP TS 100" >> %t.call_graph
> > +# RUN: ld.lld -e A %t --call-graph-ordering-file %t.call_graph -o %t2
> > +# RUN: llvm-readobj -symbols %t2 | FileCheck %s
> > +
> > +    .section    .text.D,"ax", at progbits
> > +D:
> > +    retq
> > +
> > +    .section    .text.C,"ax", at progbits
> > +    .globl  C
> > +C:
> > +    retq
> > +
> > +    .section    .text.B,"ax", at progbits
> > +    .globl  B
> > +B:
> > +    retq
> > +
> > +    .section    .text.A,"ax", at progbits
> > +    .globl  A
> > +A:
> > +    retq
> > +
> trailing white space.
>
> > +    .section    .ponies,"ax", at progbits,unique,1
> > +    .globl TS
> > +TS:
> > +    retq
> > +
>
> trailing white space.
>
> Cheers,
> Rafael
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180202/2500d518/attachment.html>


More information about the llvm-commits mailing list