[PATCH] D47126: [RISCV] Add missing fixup_riscv_call in MCFixupKindInfo table

Shiva Chen via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon May 21 00:23:37 PDT 2018


shiva0217 created this revision.
shiva0217 added a reviewer: asb.
Herald added subscribers: mgrang, edward-jones, zzheng, kito-cheng, niosHD, sabuasal, apazos, jordy.potman.lists, simoncook, johnrusso, rbar.

And also adding static_assert after array declaration
to avoid missing any new fixup in MCFixupKindInfo in the future.

ShouldForceRelocation return true for fixup_riscv_call because
currently we fixup function call by the linker.

The patch is according to
https://reviews.llvm.org/D44886#inline-411881


Repository:
  rL LLVM

https://reviews.llvm.org/D47126

Files:
  lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
  test/CodeGen/RISCV/function-call.ll
  test/MC/RISCV/function-call.s


Index: test/MC/RISCV/function-call.s
===================================================================
--- test/MC/RISCV/function-call.s
+++ test/MC/RISCV/function-call.s
@@ -11,29 +11,29 @@
 # RELOC: R_RISCV_CALL foo 0x0
 # INSTR: auipc ra, 0
 # INSTR: jalr  ra
-# FIXUP: fixup A - offset: 0, value: foo, kind:
+# FIXUP: fixup A - offset: 0, value: foo, kind: fixup_riscv_call
 call bar
 # RELOC: R_RISCV_CALL bar 0x0
 # INSTR: auipc ra, 0
 # INSTR: jalr  ra
-# FIXUP: fixup A - offset: 0, value: bar, kind:
+# FIXUP: fixup A - offset: 0, value: bar, kind: fixup_riscv_call
 
 # Ensure that calls to functions whose names coincide with register names work.
 
 call zero
 # RELOC: R_RISCV_CALL zero 0x0
 # INSTR: auipc ra, 0
 # INSTR: jalr  ra
-# FIXUP: fixup A - offset: 0, value: zero, kind:
+# FIXUP: fixup A - offset: 0, value: zero, kind: fixup_riscv_call
 
 call f1
 # RELOC: R_RISCV_CALL f1 0x0
 # INSTR: auipc ra, 0
 # INSTR: jalr  ra
-# FIXUP: fixup A - offset: 0, value: f1, kind:
+# FIXUP: fixup A - offset: 0, value: f1, kind: fixup_riscv_call
 
 call ra
 # RELOC: R_RISCV_CALL ra 0x0
 # INSTR: auipc ra, 0
 # INSTR: jalr  ra
-# FIXUP: fixup A - offset: 0, value: ra, kind:
+# FIXUP: fixup A - offset: 0, value: ra, kind: fixup_riscv_call
Index: test/CodeGen/RISCV/function-call.ll
===================================================================
--- /dev/null
+++ test/CodeGen/RISCV/function-call.ll
@@ -0,0 +1,14 @@
+; RUN: llc -mtriple=riscv32 -filetype=obj < %s\
+; RUN:     | llvm-readobj -r | FileCheck -check-prefix=RELOC %s
+
+define i32 @foo(i32 %a, i32 %b) nounwind {
+  %1 = add i32 %a, %b
+  ret i32 %1
+}
+
+define i32 @bar(i32 %a) nounwind {
+  %1 = add i32 %a, 5
+  %2 = call i32 @foo(i32 %1, i32 %a)
+; RELOC: R_RISCV_CALL foo 0x0
+  ret i32 %2
+}
Index: lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
===================================================================
--- lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
+++ lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
@@ -48,6 +48,10 @@
   // during relaxation.
   bool shouldForceRelocation(const MCAssembler &Asm, const MCFixup &Fixup,
                              const MCValue &Target) override {
+    // Always preserve relocation type for function call.
+    if ((unsigned)Fixup.getKind() == RISCV::fixup_riscv_call)
+      return true;
+
     return STI.getFeatureBits()[RISCV::FeatureRelax];
   }
 
@@ -68,7 +72,7 @@
   }
 
   const MCFixupKindInfo &getFixupKindInfo(MCFixupKind Kind) const override {
-    const static MCFixupKindInfo Infos[RISCV::NumTargetFixupKinds] = {
+    const static MCFixupKindInfo Infos[] = {
       // This table *must* be in the order that the fixup_* kinds are defined in
       // RISCVFixupKinds.h.
       //
@@ -82,8 +86,12 @@
       { "fixup_riscv_jal",          12,     20,  MCFixupKindInfo::FKF_IsPCRel },
       { "fixup_riscv_branch",        0,     32,  MCFixupKindInfo::FKF_IsPCRel },
       { "fixup_riscv_rvc_jump",      2,     11,  MCFixupKindInfo::FKF_IsPCRel },
-      { "fixup_riscv_rvc_branch",    0,     16,  MCFixupKindInfo::FKF_IsPCRel }
+      { "fixup_riscv_rvc_branch",    0,     16,  MCFixupKindInfo::FKF_IsPCRel },
+      { "fixup_riscv_call",          0,     32,  MCFixupKindInfo::FKF_IsPCRel }
     };
+    static_assert((sizeof(Infos) / sizeof(MCFixupKindInfo)) ==
+                  RISCV::NumTargetFixupKinds,
+                  "the MCFixupKind numbers in Infos should equal to RISCV::NumTargetFixupKinds");
 
     if (Kind < FirstTargetFixupKind)
       return MCAsmBackend::getFixupKindInfo(Kind);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D47126.147736.patch
Type: text/x-patch
Size: 3565 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180521/b467dba6/attachment.bin>


More information about the llvm-commits mailing list