[llvm-dev] Need help implementing relocations

Josh Sharp via llvm-dev llvm-dev at lists.llvm.org
Tue Mar 12 17:18:29 PDT 2019


Hi all,

I have reached the relocation phase of my backend implementation and I'm having some trouble. The LLVM code I'm trying to compile is this:

%struct.Date = type { i32, i32, i32 }
@date = global %struct.Date { i32 2012, i32 10, i32 120000 }, align 4
; Function Attrs: nounwind
define i32 @foo() #0 {
  %1 = load i32, i32* getelementptr inbounds (%struct.Date, %struct.Date* @date, i32 0, i32 2), align 4
  ret i32 %1
}

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'

The ouput of llvm-objdump -r -t  is this:

RELOCATION RECORDS FOR [.rel.text]:
00000000 R_XXX_MOVI date                             (Note: correct relocation type)

RELOCATION RECORDS FOR [.rel.eh_frame]:
0000001c R_XXX_NONE .text

SYMBOL TABLE:
00000000 l    df *ABS*   00000000 array.ll
00000000 l    d  .text   00000000 .text
00000000 g     F .text   0000000e foo
00000000 g     O .data   0000000c date


Why am I missing? Why didn't fill the instruction with the address of 'date'?

Thanks.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190313/56a512bd/attachment.html>


More information about the llvm-dev mailing list