<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Tim,</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Thanks for the explanation.</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
"<font size="2"><span style="font-size:11pt">it tells the linker to insert the address of<br>
date when converting this .o file into a final executable.</span></font>"</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Which utility do you use to convert .o to .elf and insert the address of 'date'? llvm-objcopy?<br>
</div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> Tim Northover <t.p.northover@gmail.com><br>
<b>Sent:</b> Wednesday, March 13, 2019 3:20 AM<br>
<b>To:</b> Josh Sharp<br>
<b>Cc:</b> via llvm-dev<br>
<b>Subject:</b> Re: [llvm-dev] Need help implementing relocations</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">Hi Josh,<br>
<br>
On Wed, 13 Mar 2019 at 00:18, Josh Sharp via llvm-dev<br>
<llvm-dev@lists.llvm.org> wrote:<br>
> which yields the following assembly lines<br>
><br>
> ...<br>
> MOVI $r0, date<br>
> LD $r4, $r0, 8 // load the content of [$r0 + 8] into return register $r4<br>
> JAL<br>
> ...<br>
><br>
> When I look at the text section (llvm-objdump -s output), I see this<br>
><br>
> 0000 00c2<br>
><br>
> This is the correct MOVI opcode but the instead of the 0s, I should see the address of 'date'<br>
<br>
I don't think you should see "date" there yet. That's the whole reason<br>
for R_XXX_MOVI to exist: it tells the linker to insert the address of<br>
date when converting this .o file into a final executable.<br>
<br>
The only time you might see something in that field is if you managed<br>
to fold the GEP into the MOVI. This would end up written in the .s fie<br>
as something like:<br>
<br>
    MOVI $r0, date+8<br>
    LD $r4, $r0<br>
    JAL<br>
<br>
and then because you've chosen to use ".rel" relocations[*] the offset<br>
8 would be put into the instruction stream and used by the linker.<br>
Instead of putting just "date" into the MOVI it would add the 8 that<br>
was already there first so you would end up with date+8 and then the<br>
load instruction might be simpler (depending on the target).<br>
<br>
But that's all a more advanced use of global addressing and you'd have<br>
to modify your CodeGen specifically to try and produce that kind of<br>
thing. For a first pass, what you're seeing is exactly what I'd expect<br>
if everything was working properly.<br>
<br>
Cheers.<br>
<br>
Tim.<br>
<br>
[*] The alternative scheme, where relocations end up in a section<br>
starting with ".rela" puts the offset in with the relocation itself.<br>
IMO it's simpler and neater, but it makes the object file slightly<br>
bigger. If I was designing a backend and had the freedom, it's what<br>
I'd choose to do. If you want to change it you set the<br>
"HasRelocationAddend" variable to true in your XYZELFObjectWriter.<br>
</div>
</span></font></div>
</body>
</html>