-
Notifications
You must be signed in to change notification settings - Fork 165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PIC medany: Fix parameters of load instruction #446
Conversation
@@ -122,7 +122,7 @@ This model is similar to the medium any code model, but uses the | |||
|
|||
# Calculate address of non-local symbol | |||
.Ltmp3: auipc a0, %got_pcrel_hi(symbol) | |||
l[w|d] a0, a0, %pcrel_lo(.Ltmp3) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uh, a0 is being use as the base address register here. It's just using the ISA manual's syntax rather than the canonical GNU one by putting the immediate after the register as a separate operand rather than parenthesising the register and putting the immediate before it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i.e.:
- l[w|d] a0, a0, %pcrel_lo(.Ltmp3)
+ l[w|d] a0, %pcrel_lo(.Ltmp3)(a0)
is the right fix here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. Do you prefer to keep it that way or should I adjust to lw a0, %pcrel_lo(.Ltmp3)(a0)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since all examples in this section focus on RV32, this patch also replaces l[w|d] by lw.
They don't, they are just as valid on RV64 if symbol is an int.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(it's important here to be clear about the difference between the value and the address, rather than make everything a word, and we don't want to be assuming a specific XLEN either)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please keep the [w|d]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
I guessed that the sequence focuses on 32-bit loads/stores for simplicity (-> RV32).
But you are right that this only affects the size of the value.
When calculating the address, the addi
(in the examples above) works for 32-bit and 64-bit addresses.
The explanation of the medium position independent code model includes the instruction `l[w|d] a0, a0, %pcrel_lo(.Ltmp3)` to calculate the address of a non-local symbol. That's not the correct RISC-V syntax for a load instruction. Let's fix that. Signed-off-by: Christoph Müllner <christoph.muellner@vrull.eu>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks :)
The explanation of the medium position independent code model
includes the instruction
l[w|d] a0, a0, %pcrel_lo(.Ltmp3)
to calculate the address of a non-local symbol.
That's not the correct RISC-V syntax for a load instruction.
Let's fix that.