[Git][ghc/ghc][wip/supersven/riscv64-ncg] Fix linker issue
Sven Tennie (@supersven)
gitlab at gitlab.haskell.org
Fri Apr 12 07:26:59 UTC 2024
Sven Tennie pushed to branch wip/supersven/riscv64-ncg at Glasgow Haskell Compiler / GHC
Commits:
1bb2fd79 by Sven Tennie at 2024-04-12T07:26:50+00:00
Fix linker issue
Local symbols don't get GOT entries. Fake them with extra symbols instead. Such that R_RISCV_CALL_PLT has an address to load and jump to.
- - - - -
1 changed file:
- rts/linker/elf_reloc_riscv64.c
Changes:
=====================================
rts/linker/elf_reloc_riscv64.c
=====================================
@@ -454,9 +454,23 @@ int32_t computeAddend(ElfRelocationATable * relaTab, unsigned relNo, Elf_Rel *re
return S + A - P;
case R_RISCV_CALL:
case R_RISCV_CALL_PLT: {
+ addr_t GOT_Target;
+ if (GOT_S != 0) {
+ // 1. Public symbol with GOT entry.
+ GOT_Target = GOT_S;
+ } else {
+ // 2. Fake GOT entry with symbol extra entry.
+ SymbolExtra *symbolExtra = makeSymbolExtra(oc, ELF_R_SYM(rel->r_info), S);
+ addr_t* FAKE_GOT_S = &symbolExtra->addr;
+ IF_DEBUG(linker, debugBelch("R_RISCV_CALL_PLT w/ SymbolExtra = %p , "
+ "entry = 0x%lx\n",
+ symbolExtra, FAKE_GOT_S));
+ GOT_Target = FAKE_GOT_S;
+ }
+
if (findStub(section, (void **)&S, 0)) {
/* did not find it. Crete a new stub. */
- if (makeStub(section, (void **)&S, (void *)GOT_S, 0)) {
+ if (makeStub(section, (void **)&S, (void *)GOT_Target, 0)) {
abort(/* could not find or make stub */);
}
}
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/1bb2fd798f14a6a8f06d3193eadebaf102469d83
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/1bb2fd798f14a6a8f06d3193eadebaf102469d83
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/20240412/df748a87/attachment-0001.html>
More information about the ghc-commits
mailing list