<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, Feb 22, 2017 at 1:24 PM, George Rimar <span dir="ltr"><<a href="mailto:grimar@accesssoftek.com" target="_blank">grimar@accesssoftek.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">




<div dir="ltr" style="font-size:12pt;color:#000000;background-color:#ffffff;font-family:Calibri,Arial,Helvetica,sans-serif"><span>
<p><span style="color:rgb(33,33,33);font-size:12pt">>I believe GNU linker prints out "relocations against text section; recomiple with -fPIC" warning if the linker is creating a DSO. Does >it warn on text relocations if no -shared is given?</span><br>
</p>
</span><div style="color:rgb(33,33,33)">
<div>
<div class="gmail_extra"><br>
<div class="gmail_quote">Depends on relocation. It will show this error for relocations that may be truncated in runtime:<br>
</div>
<div class="gmail_quote">
<div class="m_1633944853031902047m_-8871393178642781444pre" style="font-family:monospace;font-size:small;white-space:pre-wrap;background-color:rgb(255,255,255)">
<a id="m_1633944853031902047m_-8871393178642781444l2594" href="https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=blob;f=bfd/elf64-x86-64.c;h=a058eca3abf03cc2f79601d170b2d6b9f9c459e5;hb=HEAD#l2594" class="m_1633944853031902047m_-8871393178642781444linenr" style="color:rgb(153,153,153);text-decoration:none" target="_blank">2594</a>
<span class="m_1633944853031902047m_-8871393178642781444hl m_1633944853031902047m_-8871393178642781444kwa" style="font-weight:bold">case</span> R_X86_64_32<span class="m_1633944853031902047m_-8871393178642781444hl m_1633944853031902047m_-8871393178642781444opt">:</span></div>
<div class="m_1633944853031902047m_-8871393178642781444pre" style="font-family:monospace;font-size:small;white-space:pre-wrap;background-color:rgb(255,255,255)">
<a id="m_1633944853031902047m_-8871393178642781444l2595" href="https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=blob;f=bfd/elf64-x86-64.c;h=a058eca3abf03cc2f79601d170b2d6b9f9c459e5;hb=HEAD#l2595" class="m_1633944853031902047m_-8871393178642781444linenr" style="color:rgb(153,153,153);text-decoration:none" target="_blank">2595</a>
<span class="m_1633944853031902047m_-8871393178642781444hl m_1633944853031902047m_-8871393178642781444kwa" style="font-weight:bold">if</span> <span class="m_1633944853031902047m_-8871393178642781444hl m_1633944853031902047m_-8871393178642781444opt">(!</span><span class="m_1633944853031902047m_-8871393178642781444hl m_1633944853031902047m_-8871393178642781444kwd" style="color:rgb(1,1,129)">ABI_64_P</span>
<span class="m_1633944853031902047m_-8871393178642781444hl m_1633944853031902047m_-8871393178642781444opt">(</span>abfd<span class="m_1633944853031902047m_-8871393178642781444hl m_1633944853031902047m_-8871393178642781444opt">))</span></div>
<div class="m_1633944853031902047m_-8871393178642781444pre" style="font-family:monospace;font-size:small;white-space:pre-wrap;background-color:rgb(255,255,255)">
<a id="m_1633944853031902047m_-8871393178642781444l2596" href="https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=blob;f=bfd/elf64-x86-64.c;h=a058eca3abf03cc2f79601d170b2d6b9f9c459e5;hb=HEAD#l2596" class="m_1633944853031902047m_-8871393178642781444linenr" style="color:rgb(153,153,153);text-decoration:none" target="_blank">2596</a>
<span class="m_1633944853031902047m_-8871393178642781444hl m_1633944853031902047m_-8871393178642781444kwa" style="font-weight:bold">goto</span> pointer<span class="m_1633944853031902047m_-8871393178642781444hl m_1633944853031902047m_-8871393178642781444opt">;</span></div>
<div class="m_1633944853031902047m_-8871393178642781444pre" style="font-family:monospace;font-size:small;white-space:pre-wrap;background-color:rgb(255,255,255)">
<a id="m_1633944853031902047m_-8871393178642781444l2597" href="https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=blob;f=bfd/elf64-x86-64.c;h=a058eca3abf03cc2f79601d170b2d6b9f9c459e5;hb=HEAD#l2597" class="m_1633944853031902047m_-8871393178642781444linenr" style="color:rgb(153,153,153);text-decoration:none" target="_blank">2597</a>
<span class="m_1633944853031902047m_-8871393178642781444hl m_1633944853031902047m_-8871393178642781444com" style="color:rgb(131,129,131);font-style:italic">/* Fall through. */</span></div>
<div class="m_1633944853031902047m_-8871393178642781444pre" style="font-family:monospace;font-size:small;white-space:pre-wrap;background-color:rgb(255,255,255)">
<a id="m_1633944853031902047m_-8871393178642781444l2598" href="https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=blob;f=bfd/elf64-x86-64.c;h=a058eca3abf03cc2f79601d170b2d6b9f9c459e5;hb=HEAD#l2598" class="m_1633944853031902047m_-8871393178642781444linenr" style="color:rgb(153,153,153);text-decoration:none" target="_blank">2598</a>
<span class="m_1633944853031902047m_-8871393178642781444hl m_1633944853031902047m_-8871393178642781444kwa" style="font-weight:bold">case</span> R_X86_64_8<span class="m_1633944853031902047m_-8871393178642781444hl m_1633944853031902047m_-8871393178642781444opt">:</span></div>
<div class="m_1633944853031902047m_-8871393178642781444pre" style="font-family:monospace;font-size:small;white-space:pre-wrap;background-color:rgb(255,255,255)">
<a id="m_1633944853031902047m_-8871393178642781444l2599" href="https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=blob;f=bfd/elf64-x86-64.c;h=a058eca3abf03cc2f79601d170b2d6b9f9c459e5;hb=HEAD#l2599" class="m_1633944853031902047m_-8871393178642781444linenr" style="color:rgb(153,153,153);text-decoration:none" target="_blank">2599</a>
<span class="m_1633944853031902047m_-8871393178642781444hl m_1633944853031902047m_-8871393178642781444kwa" style="font-weight:bold">case</span> R_X86_64_16<span class="m_1633944853031902047m_-8871393178642781444hl m_1633944853031902047m_-8871393178642781444opt">:</span></div>
<div class="m_1633944853031902047m_-8871393178642781444pre" style="font-family:monospace;font-size:small;white-space:pre-wrap;background-color:rgb(255,255,255)">
<a id="m_1633944853031902047m_-8871393178642781444l2600" href="https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=blob;f=bfd/elf64-x86-64.c;h=a058eca3abf03cc2f79601d170b2d6b9f9c459e5;hb=HEAD#l2600" class="m_1633944853031902047m_-8871393178642781444linenr" style="color:rgb(153,153,153);text-decoration:none" target="_blank">2600</a>
<span class="m_1633944853031902047m_-8871393178642781444hl m_1633944853031902047m_-8871393178642781444kwa" style="font-weight:bold">case</span> R_X86_64_32S<span class="m_1633944853031902047m_-8871393178642781444hl m_1633944853031902047m_-8871393178642781444opt">:</span></div>
<br>
</div>
<div class="gmail_quote">But if you take <span style="color:rgb(33,33,33);font-family:monospace;font-size:small;white-space:pre-wrap;background-color:rgb(255,255,255)">R_X86_64_64:</span><br>
</div>
<div class="gmail_quote"><span style="color:rgb(33,33,33);font-family:monospace;font-size:small;white-space:pre-wrap;background-color:rgb(255,255,255)"><br>
</span></div>
<div class="gmail_quote">
<div>.text</div>
<div>.global _start</div>
<div>_start:</div>
<div> .quad _start</div></div></div></div></div></div></blockquote><div><br></div><div>OK, so this is a separate issue. If a relocation may not be representable at runtime, the linker prints out a warning. We need to do the same, but this is a different issue than allowing/disallowing text relocations. </div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" style="font-size:12pt;color:#000000;background-color:#ffffff;font-family:Calibri,Arial,Helvetica,sans-serif"><div style="color:rgb(33,33,33)"><div><div class="gmail_extra"><div class="gmail_quote"><div>
<div>llvm-mc -filetype=obj -triple=x86_64-pc-linux test.s -o test.o</div>
<div>ld.bfd test.o -shared -o out<br>
</div>
<br>
</div>
<div>Then no error is produced and DT_<span style="color:rgb(33,33,33);font-family:Calibri,Arial,Helvetica,sans-serif;font-size:16px;background-color:rgb(255,255,255)">TEXTREL</span> is added:<br>
</div>
<div><br>
</div>
<div>
<div> 0x0000000000000016 (TEXTREL)            0x0</div>
<div> 0x0000000000000000 (NULL)               0x0​<br>
</div>
<div>Relocation section '.rela.dyn' at offset 0x1e0 contains 1 entries:</div>
<div>  Offset          Info           Type           Sym. Value    Sym. Name + Addend</div>
<div>0000000001f8  000100000001 R_X86_64_64       00000000000001f8 _start + 0</div></div></div></div></div></div></div></blockquote><div><br></div><div>So I think the answer is that the GNU linker doesn't warn on text relocations at all.</div></div></div></div>