Josh Sharp via llvm-dev
2019-Mar-13 15:14 UTC
[llvm-dev] Need help implementing relocations
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>
Tim Northover via llvm-dev
2019-Mar-13 15:49 UTC
[llvm-dev] Need help implementing relocations
On Wed, 13 Mar 2019 at 15:14, Josh Sharp <mm92126 at hotmail.com> wrote:> "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?The linker in the LLVM project is called "lld". It's pretty good for ELF, but you'll have to implement the parts for your target (specifically exactly how R_XXX_MOVI does its job in this case). Alternatively, if your platform already has GCC support you can use ld from GNU binutils, but you'll probably have to cross-compile it yourself. Cheers. Tim.
Josh Sharp via llvm-dev
2019-Mar-30 22:21 UTC
[llvm-dev] Need help implementing relocations
In function relocateone() in lld/ELF/Arch/XXX.cpp, I need to compute the difference between the PC and the 'Val' function argument so that I can increment the PC by that difference. Is there a relationship between the PC and 'Loc'? Thanks. ________________________________ From: Tim Northover <t.p.northover at gmail.com> Sent: Wednesday, March 13, 2019 8:49 AM To: Josh Sharp Cc: via llvm-dev Subject: Re: [llvm-dev] Need help implementing relocations On Wed, 13 Mar 2019 at 15:14, Josh Sharp <mm92126 at hotmail.com> wrote:> "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?The linker in the LLVM project is called "lld". It's pretty good for ELF, but you'll have to implement the parts for your target (specifically exactly how R_XXX_MOVI does its job in this case). Alternatively, if your platform already has GCC support you can use ld from GNU binutils, but you'll probably have to cross-compile it yourself. Cheers. Tim. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190330/0d2dde9b/attachment.html>