<div dir="ltr"><div>Hello,</div><div><br></div><div>According to LLVM documentation (<a href="https://llvm.org/docs/LangRef.html#absolute-symbol-metadata">https://llvm.org/docs/LangRef.html#absolute-symbol-metadata</a>), the 'absolute_symbol' metadata can be applied to a global to force absolute relocations and allows expressing the range of the address for the symbol.</div><div><br></div><div>However, it seems like LLVM miscompiles the following simple example:</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div>target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"<br>target triple = "x86_64-unknown-linux-gnu"<br><br>@f = external dso_local global i32, align 4, !absolute_symbol !0<br><br>define dso_local i64 @g(i64 %0) {<br>  %2 = add i64 %0, ptrtoint (i32* @f to i64)<br>  ret i64 %2<br>}<br><br>!0 = !{ i64 0, i64 1000000000000000000 }</div></blockquote><div><br></div><div>After compiling using 'llc -O=3 -filetype=obj test.ll', I get the following output:</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><br></div>0000000000000000 <g>:<br>   0:       48 8d 87 00 00 00 00    lea    0x0(%rdi),%rax<br>                       3: R_X86_64_32S f<br><div>   7:   c3                     retq   <br></div></blockquote><div><br></div><div>This is wrong because 'f' has an address range larger than signed 32 bits. <br></div><div><br></div><div>However, if I change the IR to <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div>  %2 = add i64 %0, mul(i64 ptrtoint (i32* @f to i64), i64 2)</div></blockquote><div>LLVM compiles correctly and generates an R_X86_64_64 relocation record. <br></div><div><br></div><div>So it seems like a bug in the x86-64 backend lowering where absolute_symbol is not respected in some cases? Any idea on what the problem is and how to fix it?</div><div><br></div><div>Thanks,</div><div>Haoran<br></div></div>