<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none"><!-- p { margin-top: 0px; margin-bottom: 0px; }--></style>
</head>
<body dir="ltr" style="font-size:12pt;color:#000000;background-color:#FFFFFF;font-family:Calibri,Arial,Helvetica,sans-serif;">
<p><span style="color: rgb(33, 33, 33); font-size: 12pt;">>> </span><br>
</p>
<div dir="ltr" style="font-size:12pt; color:#000000; background-color:#FFFFFF; font-family:Calibri,Arial,Helvetica,sans-serif">
<div>
<div style="color:rgb(33,33,33)">
<div>
<div dir="ltr">>>Looks like we should do something for them, but can you describe what we should do? I can't find a simple rule to describe the behavior of GNU linkers.<br>
</div>
<div dir="ltr">> </div>
<div dir="ltr">>Description looks to be simple:<br>
</div>
<div dir="ltr">> </div>
<div dir="ltr">>"The linker uses a simple heuristic to do this. It attempts to place orphan sections after non-orphan sections of the same attribute, such as code vs data, loadable vs >non-loadable, etc. If there is not enough room to do this then it places
 at the end of the file."<br>
</div>
<div class="gmail_extra">
<div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex; border-left:1px #ccc solid; padding-left:1ex">
</blockquote>
<span style="font-size:12pt">>(<a href="https://sourceware.org/binutils/docs/ld/Orphan-Sections.html">https://sourceware.org/binutils/docs/ld/Orphan-Sections.html</a>​)</span><br>
</div>
<div class="gmail_quote"><span style="font-size:12pt">> </span></div>
<div class="gmail_quote"><span style="font-size:12pt">>George.</span></div>
<div class="gmail_quote"><span style="font-size:12pt"><br>
</span></div>
<div class="gmail_quote"><span style="font-size:12pt">And behavior of ld and gold differers here. ld seems makes simple thing: it just tries to place orphan sections after sections of the same attribute and does not watch if there is room or not:</span></div>
<div class="gmail_quote"><span style="font-size:12pt"><br>
</span></div>
<div class="gmail_quote">
<div style="color: rgb(33, 33, 33); font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; background-color: rgb(255, 255, 255);">
.global _start</div>
<div style="color: rgb(33, 33, 33); font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; background-color: rgb(255, 255, 255);">
_start:</div>
<div style="color: rgb(33, 33, 33); font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; background-color: rgb(255, 255, 255);">
  nop</div>
<div style="color: rgb(33, 33, 33); font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; background-color: rgb(255, 255, 255);">
<br>
</div>
<div style="color: rgb(33, 33, 33); font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; background-color: rgb(255, 255, 255);">
.section .foo1, "a"</div>
<div style="color: rgb(33, 33, 33); font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; background-color: rgb(255, 255, 255);">
foo1:</div>
<div style="color: rgb(33, 33, 33); font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; background-color: rgb(255, 255, 255);">
 .long 1</div>
<div style="color: rgb(33, 33, 33); font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; background-color: rgb(255, 255, 255);">
<br>
</div>
<div style="color: rgb(33, 33, 33); font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; background-color: rgb(255, 255, 255);">
.section .foo2, "a"</div>
<div style="color: rgb(33, 33, 33); font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; background-color: rgb(255, 255, 255);">
foo2:</div>
<div style="color: rgb(33, 33, 33); font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; background-color: rgb(255, 255, 255);">
 .long 1</div>
<div style="color: rgb(33, 33, 33); font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; background-color: rgb(255, 255, 255);">
<br>
</div>
<div style="color: rgb(33, 33, 33); font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; background-color: rgb(255, 255, 255);">
.section .foo3, "a"<br>
</div>
<div style="color: rgb(33, 33, 33); font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; background-color: rgb(255, 255, 255);">
foo3:</div>
<div style="color: rgb(33, 33, 33); font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; background-color: rgb(255, 255, 255);">
 .long 1</div>
<div style="color: rgb(33, 33, 33); font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; background-color: rgb(255, 255, 255);">
<br>
</div>
<div style="color: rgb(33, 33, 33); font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; background-color: rgb(255, 255, 255);">
.section .bar1, "aw"</div>
<div style="color: rgb(33, 33, 33); font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; background-color: rgb(255, 255, 255);">
bar1:</div>
<div style="color: rgb(33, 33, 33); font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; background-color: rgb(255, 255, 255);">
 .long 1<br>
</div>
<div style="color: rgb(33, 33, 33); font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; background-color: rgb(255, 255, 255);">
<br>
</div>
<span style="font-size:12pt"><br>
</span></div>
<div class="gmail_quote">
<div>SECTIONS { <br>
</div>
<div>. = 0x1000;</div>
<div>.foo1 : { *(.foo1) }</div>
<div>.foo2 : { *(.foo2) }<br>
</div>
<div>. = 0x1009;</div>
<div>.bar1 : { *(.bar1) }<br>
</div>
<div>}<br>
</div>
<div><br>
</div>
<div><span style="font-size: 12pt;">++ ld start.o -script linker.script -o out</span>
<div>
<div>ld: section .foo3 loaded at [0000000000001009,000000000000100c] overlaps section .bar1 loaded at [0000000000001009,000000000000100c]</div>
<div><br>
</div>
<div>gold does not show any errors, but its output seems to be broken for my eye:<br>
</div>
<div>
<div> [ 1] .foo1             PROGBITS         0000000000001000  00001000</div>
<div>       0000000000000004  0000000000000000   A       0     0     1</div>
<div>  [ 2] .foo2             PROGBITS         0000000000001004  00001004</div>
<div>       0000000000000004  0000000000000000   A       0     0     1</div>
<div>  [ 3] .text             PROGBITS         000000000000100c  0000100c</div>
<div>       0000000000000001  0000000000000000  AX       0     0     4</div>
<div>  [ 4] .foo3             PROGBITS         000000000000100d  0000100d</div>
<div>       0000000000000004  0000000000000000   A       0     0     1</div>
<div>  [ 5] .bar1             PROGBITS         0000000000001030  00001030</div>
<div>       0000000000000004  0000000000000000  WA       0     0     1</div>
<div><br>
</div>
<div>Making some room helps ld to work:<br>
</div>
<div>
<div style="color: rgb(33, 33, 33); font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; background-color: rgb(255, 255, 255);">
SECTIONS { <br>
</div>
<div style="color: rgb(33, 33, 33); font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; background-color: rgb(255, 255, 255);">
. = 0x1000;</div>
<div style="color: rgb(33, 33, 33); font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; background-color: rgb(255, 255, 255);">
.foo1 : { *(.foo1) }</div>
<div style="color: rgb(33, 33, 33); font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; background-color: rgb(255, 255, 255);">
.foo2 : { *(.foo2) }<br>
</div>
<div style="color: rgb(33, 33, 33); font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; background-color: rgb(255, 255, 255);">
. = 0x1100;</div>
<div style="color: rgb(33, 33, 33); font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; background-color: rgb(255, 255, 255);">
.bar1 : { *(.bar1) }<br>
</div>
<div style="color: rgb(33, 33, 33); font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; background-color: rgb(255, 255, 255);">
}<br>
</div>
<div style="color: rgb(33, 33, 33); font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; background-color: rgb(255, 255, 255);">
<br>
</div>
</div>
<div style="color: rgb(33, 33, 33); font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; background-color: rgb(255, 255, 255);">
ld output:<br>
</div>
<div>
<div>  [ 1] .text             PROGBITS         0000000000001000  00001000</div>
<div>       0000000000000001  0000000000000000  AX       0     0     4</div>
<div>  [ 2] .foo1             PROGBITS         0000000000001001  00001001</div>
<div>       0000000000000004  0000000000000000   A       0     0     1</div>
<div>  [ 3] .foo2             PROGBITS         0000000000001005  00001005</div>
<div>       0000000000000004  0000000000000000   A       0     0     1</div>
<div>  [ 4] .foo3             PROGBITS         0000000000001009  00001009</div>
<div>       0000000000000004  0000000000000000   A       0     0     1</div>
<div>  [ 5] .bar1             PROGBITS         0000000000001100  00001100</div>
<div>       0000000000000004  0000000000000000  WA       0     0     1</div>
<div><br>
</div>
</div>
<div>So I would start with ld behavior. If I am not missing something ld way would be<br>
</div>
<div>easy to implement and that should keep code simple at the same way.<br>
</div>
<div>I`ll try to prepare a patch.</div>
<div><br>
</div>
<div>George.<br>
<br>
</div>
<br>
</div>
<br>
</div>
<br>
</div>
<div><br>
<br>
</div>
<span style="font-size:12pt"><br>
</span></div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>