[Git][ghc/ghc][wip/supersven/riscv64-ncg] 3 commits: Linker: Add missing cases

Sven Tennie (@supersven) gitlab at gitlab.haskell.org
Fri Feb 9 16:02:23 UTC 2024



Sven Tennie pushed to branch wip/supersven/riscv64-ncg at Glasgow Haskell Compiler / GHC


Commits:
4d09ce32 by Sven Tennie at 2024-02-09T16:47:54+01:00
Linker: Add missing cases

- - - - -
a5c45b1c by Sven Tennie at 2024-02-09T16:53:50+01:00
Linker: Trace int size issue

- - - - -
c7927d1c by Sven Tennie at 2024-02-09T16:56:30+01:00
Linker: warnings

- - - - -


1 changed file:

- rts/linker/elf_reloc_riscv64.c


Changes:

=====================================
rts/linker/elf_reloc_riscv64.c
=====================================
@@ -42,8 +42,9 @@ int64_t SignExtend64(uint64_t X, unsigned B) {
 
 // Make sure that V can be represented as an N bit signed integer.
 void checkInt(inst_t *loc, int64_t v, int n) {
-  if (v != SignExtend64(v, n))
-    debugBelch("Relocation at %x is out of range: 0x%lx - 0x%x", *loc, v, n);
+  if (v != SignExtend64(v, n)){
+    debugBelch("Relocation at 0x%x is out of range. value: 0x%lx (%ld), sign-extended value: 0x%lx (%ld), max bits 0x%x (%d)", *loc, v, v, SignExtend64(v, n), SignExtend64(v, n), n, n);
+  }
 }
 // RISCV is little-endian by definition.
 void write8le(uint8_t *p, uint8_t v) { *p = v; }
@@ -149,6 +150,12 @@ bool encodeAddendRISCV64(Section *section, Elf_Rel *rel, int64_t addend) {
   addr_t P = (addr_t)((uint8_t *)section->start + rel->r_offset);
   int exp_shift = -1;
   switch (ELF64_R_TYPE(rel->r_info)) {
+  case R_RISCV_32:
+    write32le((inst_t*) P, addend);
+    break;
+  case R_RISCV_64:
+    write64le((uint64_t*) P, addend);
+    break;
   case R_RISCV_GOT_HI20:
   case R_RISCV_PCREL_HI20:
   case R_RISCV_TLS_GD_HI20:
@@ -216,7 +223,7 @@ bool encodeAddendRISCV64(Section *section, Elf_Rel *rel, int64_t addend) {
     // I guess we don't need to implement these relaxations (optimizations).
     break;
   default:
-    debugBelch("Missing relocation 0x%x\n", ELF64_R_TYPE(rel->r_info));
+    debugBelch("Missing relocation 0x%lx\n", ELF64_R_TYPE(rel->r_info));
     abort();
   }
   return EXIT_SUCCESS;
@@ -287,9 +294,10 @@ int64_t computeAddend(Section *section, Elf_Rel *rel, ElfSymbol *symbol,
     // should return the number of blank bytes to insert via NOPs.
     break;
   default:
-    debugBelch("Unimplemented relocation: %x", ELF64_R_TYPE(rel->r_info));
+    debugBelch("Unimplemented relocation: 0x%lx", ELF64_R_TYPE(rel->r_info));
     abort(/* unhandled rel */);
   }
+  abort(/* unhandled rel */);
 }
 
 // TODO: This is duplicated from elf_reloc_aarch64.c



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/c2bc1bffd73eda8f7ed9b9c336b82a075ac66901...c7927d1c83cea4c64dbad1ccb1a8ae0a416c6bd2

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/c2bc1bffd73eda8f7ed9b9c336b82a075ac66901...c7927d1c83cea4c64dbad1ccb1a8ae0a416c6bd2
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20240209/910c2a9c/attachment-0001.html>


More information about the ghc-commits mailing list