RISC-V: Restore the typcast to 64bit type
PATCH 1/1 RISC-V: Restore the typcast to 64bit type
this makes the type promotions clear and explicit
It was already typecasted to long but was accidentally dropped in [1] which stated to cause failures on riscv32 as reported in [2]
[1] https://git.savannah.gnu.org/cgit/grub.git/commit/?id=2bf40e9e5be9808b17852e688eead87acff14420
[2] https://savannah.gnu.org/bugs/index.php?60283
--- util/grub-mkimagexx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
util/grub-mkimagexx.c +1 -1
@@ -1242,7 +1242,7 @@ SUFFIX (relocate_addrs) (Elf_Ehdr *e, struct section_metadata *smd,*/ sym_addr += addend; - off = sym_addr - target_section_addr - offset - image_target->vaddr_offset; + off = (grub_int64_t )sym_addr - target_section_addr - offset - image_target->vaddr_offset;switch (ELF_R_TYPE (info)) {
Signature · 1 line
2.31.1
Quoted 2 lines · Khem Raj
this makes the type promotions clear and explicit
It was already typecasted to long but was accidentally dropped in [1]
Note that long is 32-bit on riscv32, so the title is misleading (there was no cast to 64-bit type before). The cast really was a no-op, as it didn't change the resulting type. The issue is that the types of sym_addr, target_section_addr and offset are Elf_Addr (aka Elf32_Addr), which is an unsigned type (image_target->vaddr_offset is signed, but not wider than Elf32_Addr, so it doesn't change the overall type). Thus when the result of the expression is extended to grub_int64_t it is always a positive value instead of the desired sign-extended one.
Quoted 1 line
which stated to cause failures on riscv32 as reported in [2]
Most likely the missing addend masked the error.
Andreas.
Signature · 3 lines
Andreas Schwab, SUSE Labs, [email protected] GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE 1748 E4D4 88E3 0EEA B9D7 "And now for something completely different."
Quoted 6 lines · Andreas Schwab
Quoted 2 lines · Khem Raj
this makes the type promotions clear and explicit
It was already typecasted to long but was accidentally dropped in [1]
Quoted 9 lines
Note that long is 32-bit on riscv32, so the title is misleading (there was no cast to 64-bit type before). The cast really was a no-op, as it didn't change the resulting type. The issue is that the types of
sym_addr,target_section_addrand offset areElf_Addr(akaElf32_Addr), which is an unsigned type (image_target->vaddr_offsetis signed, but not wider thanElf32_Addr, so it doesn't change the overall type). Thus when the result of the expression is extended togrub_int64_tit is always a positive value instead of the desired sign-extended one.
This is right I think, I initially typecasted it to long and then changed to using grub_int64_t
and could have done better on commit message. Do you prefer a new revision with better commit msg.
Quoted 3 lines
Quoted 1 line
which stated to cause failures on riscv32 as reported in [2]
Most likely the missing addend masked the error.
yes that's likely since addressed where it fails are 0xfffff....
Quoted 7 lines
Andreas.
--
Andreas Schwab, SUSE Labs, [email protected]
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE 1748 E4D4 88E3 0EEA B9D7 "And now for something completely different."
Quoted 15 lines · Khem Raj
Quoted 4 lines · Andreas Schwab
Quoted 2 lines · Khem Raj
this makes the type promotions clear and explicit
It was already typecasted to long but was accidentally dropped in [1]Quoted 9 lines
Note that long is 32-bit on riscv32, so the title is misleading (there was no cast to 64-bit type before). The cast really was a no-op, as it didn't change the resulting type. The issue is that the types of
sym_addr,target_section_addrand offset areElf_Addr(akaElf32_Addr), which is an unsigned type (image_target->vaddr_offsetis signed, but not wider thanElf32_Addr, so it doesn't change the overall type). Thus when the result of the expression is extended togrub_int64_tit is always a positive value instead of the desired sign-extended one.
Quoted 4 lines
This is right I think, I initially typecasted it to long and then changed to using
grub_int64_t
and could have done better on commit message. Do you prefer a new revision with better commit msg.
If long is 32-bit on riscv32 should not we cast to grub_int32_t then?
And then next question: Why off is defined as grub_int64_t?
Daniel
Quoted 16 lines · Daniel Kiper
Quoted 15 lines · Khem Raj
Quoted 13 lines · Andreas Schwab
Quoted 2 lines · Khem Raj
this makes the type promotions clear and explicit
It was already typecasted to long but was accidentally dropped in [1]Note that long is 32-bit on riscv32, so the title is misleading (there was no cast to 64-bit type before). The cast really was a no-op, as it didn't change the resulting type. The issue is that the types of
sym_addr,target_section_addrand offset areElf_Addr(akaElf32_Addr), which is an unsigned type (image_target->vaddr_offsetis signed, but not wider thanElf32_Addr, so it doesn't change the overall type). Thus when the result of the expression is extended togrub_int64_tit is always a positive value instead of the desired sign-extended one.
Quoted 8 lines
Quoted 4 lines
This is right I think, I initially typecasted it to long and then changed to using
grub_int64_t
and could have done better on commit message. Do you prefer a new revision with better commit msg.If long is 32-bit on riscv32 should not we cast to
grub_int32_tthen?And then next question: Why off is defined as
grub_int64_t?
Ping? I want get that fixed in 2.06 release...
Daniel