<div dir="ltr">Your .rodata contains a vector of addresses, and we don't know the actual addresses until load-time, because your .so file can be loaded to anywhere in your address space. Thus, we cannot fix .rodata contents at link-time. So your .so needs load-time modifications to the .rodata section. (Does this answer your question?)<br><div><br></div><div>I think our default choice of forbidding relocations against read-only sections is reasonable, because most programs don't need text relocations, and if that happens, it is with a high probability a mistake instead of an intentional behavior.</div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Mar 23, 2017 at 8:47 AM, Martin Richtarsky via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span>Rafael Avila de Espindola wrote:<br>
>> $ gcc -o rodatareloc.s.o -c rodatareloc.s<br>
>> $ lld -o rodatareloc.so -shared rodatareloc.s.o<br>
>><br>
>> ld: error: rodatareloc.s.o:(.rodata+0x0): can't create dynamic<br>
>> relocation<br>
>> R_X86_64_64 against local symbol in readonly segment defined in<br>
>> rodatareloc.s.o<br>
>><br>
>><br>
>> Changing the section from .rodata to .data fixes it, but I guess this<br>
>> should be supported also for .rodata. Should I open a bug?<br>
><br>
> I think this is just a difference in defaults. If you pass "-z notext"<br>
> to lld it should work.<br>
<br>
</span>Thanks, this helps! Any reason why the defaults are different to gold and<br>
presumably bfd-ld?<br>
<br>
I don't understand much of what is happening behind the scenes, but on<br>
loading time, couldn't the rodata section just be mapped read-only, and<br>
still the relocation be applied to the text section, pointing to wherever<br>
rodata was mapped? No modification should be necessary to the rodata<br>
section.<br>
<br>
Thanks and Best regards,<br>
Martin<br>
<div class="m_-7050797736610290542HOEnZb"><div class="m_-7050797736610290542h5">______________________________<wbr>_________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br>
</div></div></blockquote></div><br></div></div>