<div dir="ltr">Hi all,<div><br></div><div>I wanted to summarise some discussion on llvm-commits [0,1] as an RFC, as I felt it demanded wider circulation.</div><div><br></div><div><div>Our support for references to absolute symbols is not very good. The symbol will be resolved accurately in non-PIC code, but suboptimally: the symbol reference cannot currently appear as the immediate operand of an instruction, and the code generator cannot make any assumptions about the value of the symbol (so for example, it could not use a R_X86_64_8 relocation if the value is known to be in the range 0..255).</div><div><br></div><div>In PIC mode, if the reference is not known to be DSO-local, the value is loaded from the GOT (or a synthetic GOT entry), which again means suboptimal code. If the reference is known to be DSO-local, the symbol will be referenced with a PC relative relocation and therefore cannot be resolved properly to an absolute value (c.f. <a href="https://reviews.llvm.org/D19844">https://reviews.llvm.org/D19844</a>). The latter case in particular would seem to indicate that a representational change is required for correctness to distinguish references to absolute symbols from references to regular symbols.</div><div><br></div><div><div>The specific change I have in mind is to allow !range metadata on GlobalObjects. This would</div><div>be similar to existing !range metadata, but it would apply to the "address" of the attached GlobalObject, rather than any value loaded from it. Its presence on a GlobalObject would also imply that the address of the GlobalObject is "fixed" at link time. Alongside !range we could potentially use other sources of information, such as the relocation model, code model and visibility, to identify "fixed" globals, although that can be done separately.</div></div><div><br></div><div>I have been experimenting with a number of approaches to representation in SDAG, and I have found one that seems to work best, and would be the least intrusive (unfortunately most approaches to this problem are somewhat intrusive).</div><div><br></div><div>Specifically, I want to:</div><div>1) move most of the body of ConstantSDNode to a new class, ConstantIntSDNode, which would derives from ConstantSDNode. ConstantSDNode would act as the base class for immediates-post-static-linking. Change most references to ConstantSDNode in C++ code to refer to ConstantIntSDNode. However, "imm" in tblgen code would continue to match ConstantSDNode.</div><div>2) introduce a new derived class of ConstantSDNode for references to globals with !range metadata, and teach SDAG to use this new derived class for fixed address references</div><div><br></div><div>I will shortly be sending out a patch that implements 1.</div><div><br></div><div>Thanks,</div>-- <br><div class="gmail_signature"><div dir="ltr">-- <div>Peter</div><div><br></div><div>[0] <a href="http://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20160926/394194.html">http://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20160926/394194.html</a></div><div>[1] <a href="http://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20161003/394983.html">http://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20161003/394983.html</a></div></div></div>
</div></div>