[llvm-dev] Need help implementing relocations

Josh Sharp via llvm-dev llvm-dev at lists.llvm.org
Wed Mar 13 08:14:38 PDT 2019


Tim,
Thanks for the explanation.

"it tells the linker to insert the address of
date when converting this .o file into a final executable."

Which utility do you use to convert .o to .elf and insert the address of 'date'? llvm-objcopy?
________________________________
From: Tim Northover <t.p.northover at gmail.com>
Sent: Wednesday, March 13, 2019 3:20 AM
To: Josh Sharp
Cc: via llvm-dev
Subject: Re: [llvm-dev] Need help implementing relocations

Hi Josh,

On Wed, 13 Mar 2019 at 00:18, Josh Sharp via llvm-dev
<llvm-dev at lists.llvm.org> wrote:
> which yields the following assembly lines
>
> ...
> MOVI $r0, date
> LD $r4, $r0, 8 // load the content of [$r0 + 8] into return register $r4
> JAL
> ...
>
> When I look at the text section (llvm-objdump -s output), I see this
>
> 0000 00c2
>
> This is the correct MOVI opcode but the instead of the 0s, I should see the address of 'date'

I don't think you should see "date" there yet. That's the whole reason
for R_XXX_MOVI to exist: it tells the linker to insert the address of
date when converting this .o file into a final executable.

The only time you might see something in that field is if you managed
to fold the GEP into the MOVI. This would end up written in the .s fie
as something like:

    MOVI $r0, date+8
    LD $r4, $r0
    JAL

and then because you've chosen to use ".rel" relocations[*] the offset
8 would be put into the instruction stream and used by the linker.
Instead of putting just "date" into the MOVI it would add the 8 that
was already there first so you would end up with date+8 and then the
load instruction might be simpler (depending on the target).

But that's all a more advanced use of global addressing and you'd have
to modify your CodeGen specifically to try and produce that kind of
thing. For a first pass, what you're seeing is exactly what I'd expect
if everything was working properly.

Cheers.

Tim.

[*] The alternative scheme, where relocations end up in a section
starting with ".rela" puts the offset in with the relocation itself.
IMO it's simpler and neater, but it makes the object file slightly
bigger. If I was designing a backend and had the freedom, it's what
I'd choose to do. If you want to change it you set the
"HasRelocationAddend" variable to true in your XYZELFObjectWriter.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190313/6da7c042/attachment-0001.html>


More information about the llvm-dev mailing list