<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:DengXian;
        panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:"PingFang SC";
        panose-1:2 11 4 0 0 0 0 0 0 0;}
@font-face
        {font-family:"\@DengXian";
        panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
        {font-family:"\@PingFang SC";}
@font-face
        {font-family:-webkit-standard;
        panose-1:2 11 6 4 2 2 2 2 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
span.EmailStyle19
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style>
</head>
<body lang="EN-US" link="blue" vlink="purple" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal">> <span style="font-family:"-webkit-standard",serif;color:black">
Reordering output sections is much more effective.</span><o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">If you have a huge .nv_fatbin, without moving input sections, you may end up with relocation at the beginning as well as at the end, then no matter where you put .nv_fatbin relative to .text (before or after), max relocation distance will
 grow when size of .nv_fatbin grows. <o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">So reordering output section alone isn¡¯t enough. <o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">> Reordering input sections automatically has some small value but it<br>
> would break phase ordering and cause more maintenance burden.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Could you elaborate on phase ordering?<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal" style="margin-bottom:12.0pt"><b><span style="font-size:12.0pt;color:black">From:
</span></b><span style="font-size:12.0pt;color:black">llvm-dev <llvm-dev-bounces@lists.llvm.org> on behalf of F¨¡ng-ru¨¬ S¨°ng via llvm-dev <llvm-dev@lists.llvm.org><br>
<b>Date: </b>Wednesday, September 8, 2021 at 1:19 PM<br>
<b>To: </b>Alexander Yermolovich <ayermolo@fb.com><br>
<b>Cc: </b>llvm-dev@lists.llvm.org <llvm-dev@lists.llvm.org><br>
<b>Subject: </b>Re: [llvm-dev] [LLD] Relocation overflows and .nv_fatbin<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal">On Wed, Sep 8, 2021 at 12:44 PM Alexander Yermolovich <ayermolo@fb.com> wrote:<br>
><br>
> Sorry I wasn't clear. I am not talking about moving .nv_fatbin in its entirety. Although we are also doing it with linker script INSERT AFTER .bss.<br>
> I was referring to re-arranging input sections within the .nv_fatbin output section.<br>
><br>
> So, we have in .text*<br>
> relocation into .nv_fatbin input section from foo3.o<br>
><br>
> In output .nv_fatbin without any changes we will have<br>
> foo1.o input section (some cuda code)<br>
> foo2.o input section (some cuda code)<br>
> foo3.o input section (has relocation in to)<br>
><br>
> With this layout we get relocation overflow.<br>
><br>
> if we shuffle things<br>
> foo3.o (has relocation in to from .text*)<br>
> foo1.o (some cuda code)<br>
> foo2.o (some cuda code)<br>
><br>
> It shortens the distance from src to dst fo relocation, and all other cuda sections can grow.<br>
><br>
> Hopefully, this clarifies things.<br>
> Alex<br>
><br>
<br>
Reordering output sections is much more effective.<br>
<br>
The ELF port has an option --symbol-ordering-file which reorders input<br>
sections within one output section, but I doubt you can find something<br>
as a marker.<br>
The option was originally conceived to improve performance (by<br>
optimizing for instruction cache/iTLB locality), not to mitigate<br>
relocation overflows.<br>
(macOS ld64 has a similar but more powerful -order_file which can<br>
specify input filenames.)<br>
<br>
Reordering input sections automatically has some small value but it<br>
would break phase ordering and cause more maintenance burden. So I<br>
very strongly object to that.<br>
<br>
><br>
><br>
><br>
><br>
> ________________________________<br>
> From: Fangrui Song <maskray@google.com><br>
> Sent: Wednesday, September 8, 2021 12:01 PM<br>
> To: Alexander Yermolovich <ayermolo@fb.com><br>
> Cc: llvm-dev@lists.llvm.org <llvm-dev@lists.llvm.org><br>
> Subject: Re: [llvm-dev] [LLD] Relocation overflows and .nv_fatbin<br>
><br>
> On 2021-09-08, Alexander Yermolovich via llvm-dev wrote:<br>
> >Hello<br>
> ><br>
> >I am seeing relocation overflows from .text section in to .nv_fatbin. The whole thing, nv_fatbin, is a bit of a black box, but there does appear to be only one. We have a downstream patch in LLD, that moves .nv_fatbin section(s) that have relocations in
 to to the "top". Looking around at what's in .nv_fartbin the rest of the code should be bunch of cuda stuff. So, in theory that can grow, and we shouldn't get any more relocation overflows. At least due to the size of .nv_fatbin.<br>
> ><br>
> >I was wondering if there is a better way of doing it. Maybe with a linker script? I investigated it, and that answer seems to be no, but I am not an expert in linker scripts.<br>
> ><br>
> >Thank You<br>
> >Alex<br>
><br>
> I implemented INSERT [AFTER|BEFORE] for orphan sections in <a href="https://reviews.llvm.org/D74375">https://reviews.llvm.org/D74375</a>
<br>
> You may consider moving .nv* and __nv* sections after .bss<br>
><br>
> But linker synthesized etext/_etext may be in a weird position.<br>
> To fix that, use the OVERWRITE_SECTIONS feature I added for LLD 13.0.0<br>
><br>
> OVERWRITE_SECTIONS {<br>
>    .tdata : { etext = .; _etext = .; *(.tdata) }<br>
> }<br>
<br>
<br>
<br>
-- <br>
<span lang="ZH-CN" style="font-family:"PingFang SC",sans-serif">Ëη½î£</span><br>
_______________________________________________<br>
LLVM Developers mailing list<br>
llvm-dev@lists.llvm.org<br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a>
<o:p></o:p></p>
</div>
</div>
</body>
</html>