[PATCH] D81919: [MIPS64] Workaround fixup_Mips_32 for getExprOpValue

Leslie Zhai via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 16 03:17:23 PDT 2020


xiangzhai created this revision.
xiangzhai added reviewers: atanasyan, MaskRay.
Herald added subscribers: jrtc27, hiraditya, arichardson, sdardis.
Herald added a project: LLVM.

Hi,

Testcase:

  $ cat llvm/test/MC/Mips/reloc-directive-bad-n64.s 
  # RUN: llvm-mc -triple mips64el-unknown-linux < %s -show-encoding \
  # RUN:     -target-abi=n64 2>&1 | FileCheck %s
  	.text
         .global main
  main:
         nop
         daddiu $t9, $ra, main - .    # CHECK: :[[@LINE]]:25: warning: should use explicit constraints!
         nop
         .word main

GNU toolchain:

  $ gcc -fPIC -c ./llvm/test/MC/Mips/reloc-directive-bad-n64.s -o t.gnu.o
  $ objdump -r t.gnu.o
  
  t.gnu.o:     file format elf64-tradlittlemips
  
  RELOCATION RECORDS FOR [.text]:
  OFFSET           TYPE              VALUE 
  000000000000000c R_MIPS_32         main
  000000000000000c R_MIPS_NONE       *ABS*
  000000000000000c R_MIPS_NONE       *ABS*

But LLVM toolchain:

  $ clang -fPIC -c ./llvm/test/MC/Mips/reloc-directive-bad-n64.s -o t.llvm.o
  $ objdump -r t.llvm.o 
  
  t.llvm.o:     file format elf64-tradlittlemips
  
  RELOCATION RECORDS FOR [.text]:
  OFFSET           TYPE              VALUE 
  0000000000000004 R_MIPS_32         main
  0000000000000004 R_MIPS_NONE       *ABS*
  0000000000000004 R_MIPS_NONE       *ABS*
  0000000000000004 R_MIPS_32         .text+0x0000000000000004
  0000000000000004 R_MIPS_NONE       *ABS*+0x0000000000000004
  0000000000000004 R_MIPS_NONE       *ABS*+0x0000000000000004
  000000000000000c R_MIPS_32         main
  000000000000000c R_MIPS_NONE       *ABS*
  000000000000000c R_MIPS_NONE       *ABS*

Warning the user and  behaviour same as GNU toolchain after applied the workaround patch:

  $ ./build/bin/clang -fPIC -c ./llvm/test/MC/Mips/reloc-directive-bad-n64.s -o t.llvm.o
  
  ./llvm/test/MC/Mips/reloc-directive-bad-n64.s:7:25: warning: should use explicit constraints!
         daddiu $t9, $ra, main - .    # CHECK: :[[@LINE]]:25: warning: should use explicit constraints!
                          ^
  <unknown>:0: warning: should use explicit constraints!
  
  $ objdump -r t.llvm.o
  
  t.llvm.o:     file format elf64-tradlittlemips
  
  RELOCATION RECORDS FOR [.text]:
  OFFSET           TYPE              VALUE 
  000000000000000c R_MIPS_32         main
  000000000000000c R_MIPS_NONE       *ABS*
  000000000000000c R_MIPS_NONE       *ABS*

Passed `make check-llvm-mc-mips`:

  [100%] Running lit suite /home/loongson/zhaixiang/llvm-project-8.x/llvm/test/MC/Mips
  Testing Time: 5.36s
    Expected Passes    : 415
    Expected Failures  : 19
  [100%] Built target check-llvm-mc-mips

Please review the patch, and give me some advice!

Thanks,
Leslie Zhai


Repository:
  rL LLVM

https://reviews.llvm.org/D81919

Files:
  llvm/include/llvm/MC/MCContext.h
  llvm/lib/MC/MCContext.cpp
  llvm/lib/Target/Mips/MCTargetDesc/MipsMCCodeEmitter.cpp
  llvm/test/MC/Mips/reloc-directive-bad-n64.s


Index: llvm/test/MC/Mips/reloc-directive-bad-n64.s
===================================================================
--- /dev/null
+++ llvm/test/MC/Mips/reloc-directive-bad-n64.s
@@ -0,0 +1,9 @@
+# RUN: llvm-mc -triple mips64el-unknown-linux < %s -show-encoding \
+# RUN:     -target-abi=n64 2>&1 | FileCheck %s
+	.text
+       .global main
+main:
+       nop
+       daddiu $t9, $ra, main - .    # CHECK: :[[@LINE]]:25: warning: should use explicit constraints!
+       nop
+       .word main
Index: llvm/lib/Target/Mips/MCTargetDesc/MipsMCCodeEmitter.cpp
===================================================================
--- llvm/lib/Target/Mips/MCTargetDesc/MipsMCCodeEmitter.cpp
+++ llvm/lib/Target/Mips/MCTargetDesc/MipsMCCodeEmitter.cpp
@@ -722,6 +722,7 @@
   }
 
   if (Kind == MCExpr::SymbolRef) {
+    Ctx.reportWarning(Expr->getLoc(), "should use explicit constraints!");
     Mips::Fixups FixupKind = Mips::Fixups(0);
 
     switch(cast<MCSymbolRefExpr>(Expr)->getKind()) {
@@ -732,7 +733,8 @@
       break;
     } // switch
 
-    Fixups.push_back(MCFixup::create(0, Expr, MCFixupKind(FixupKind)));
+    if (!STI.getFeatureBits()[Mips::FeatureMips64])
+      Fixups.push_back(MCFixup::create(0, Expr, MCFixupKind(FixupKind)));
     return 0;
   }
   return 0;
Index: llvm/lib/MC/MCContext.cpp
===================================================================
--- llvm/lib/MC/MCContext.cpp
+++ llvm/lib/MC/MCContext.cpp
@@ -606,6 +606,19 @@
 }
 
 //===----------------------------------------------------------------------===//
+// Warning Reporting
+//===----------------------------------------------------------------------===//
+
+void MCContext::reportWarning(SMLoc Loc, const Twine &Msg) {
+  // If we have a source manager use it. Otherwise, try using the inline source
+  // manager.
+  if (SrcMgr)
+    SrcMgr->PrintMessage(Loc, SourceMgr::DK_Warning, Msg);
+  else if (InlineSrcMgr)
+    InlineSrcMgr->PrintMessage(Loc, SourceMgr::DK_Warning, Msg);
+}
+
+//===----------------------------------------------------------------------===//
 // Error Reporting
 //===----------------------------------------------------------------------===//
 
Index: llvm/include/llvm/MC/MCContext.h
===================================================================
--- llvm/include/llvm/MC/MCContext.h
+++ llvm/include/llvm/MC/MCContext.h
@@ -645,6 +645,8 @@
 
     void deallocate(void *Ptr) {}
 
+    void reportWarning(SMLoc L, const Twine &Msg);
+
     bool hadError() { return HadError; }
     void reportError(SMLoc L, const Twine &Msg);
     // Unrecoverable error has occurred. Display the best diagnostic we can


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D81919.271008.patch
Type: text/x-patch
Size: 2631 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200616/8a4a0805/attachment-0001.bin>


More information about the llvm-commits mailing list