This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new 5c3d6bba6d libs: risc-v: Add R_RISCV_JAL support to arch_elf.c
5c3d6bba6d is described below

commit 5c3d6bba6d9ec5015896c3019cd2064696373210
Author: Masayuki Ishikawa <[email protected]>
AuthorDate: Mon May 9 19:08:49 2022 +0900

    libs: risc-v: Add R_RISCV_JAL support to arch_elf.c
    
    Summary:
    - This commit adds R_RISCV_JAL support to arch_elf.c
    - The code only checks the immediate value but does not relocate it
      because it is done by the compiler.
    
    Impact:
    - None
    
    Testing:
    - Tested with rv-virt:knsh64 (not merged yet)
    
    Signed-off-by: Masayuki Ishikawa <[email protected]>
---
 libs/libc/machine/risc-v/common/arch_elf.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/libs/libc/machine/risc-v/common/arch_elf.c 
b/libs/libc/machine/risc-v/common/arch_elf.c
index 67c89e41aa..245da79e00 100644
--- a/libs/libc/machine/risc-v/common/arch_elf.c
+++ b/libs/libc/machine/risc-v/common/arch_elf.c
@@ -82,6 +82,7 @@ static struct rname_code_s _rname_table[] =
   {"CALL", R_RISCV_CALL},
   {"CALL_PLT", R_RISCV_CALL_PLT},
   {"BRANCH", R_RISCV_BRANCH},
+  {"JAL", R_RISCV_JAL},
   {"RVC_JUMP", R_RISCV_RVC_JUMP},
   {"RVC_BRANCH", R_RISCV_RVC_BRANCH},
 };
@@ -399,6 +400,29 @@ int up_relocateadd(FAR const Elf_Rela *rel, FAR const 
Elf_Sym *sym,
         }
         break;
 
+      case R_RISCV_JAL:
+        {
+          binfo("%s at %08" PRIxPTR " [%08" PRIx32 "] "
+                "to sym=%p st_value=%08lx\n",
+                _get_rname(relotype),
+                addr, _get_val((uint16_t *)addr),
+                sym, sym->st_value);
+
+          /* P.21 Unconditinal Jumps : UJ type (imm=20bit) */
+
+          offset = (long)sym->st_value + (long)rel->r_addend - (long)addr;
+          uint32_t val = _get_val((uint16_t *)addr) & 0xfffff000;
+
+          ASSERT(offset && val);
+
+          /* NOTE: we assume that a compiler adds an immediate value */
+
+          binfo("offset for JAL=%ld (0x%lx) (val=0x%08" PRIx32 ") "
+                "already set!\n",
+                offset, offset, val);
+        }
+        break;
+
       case R_RISCV_HI20:
         {
           binfo("%s at %08" PRIxPTR " [%08" PRIx32 "] "

Reply via email to