[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 06:04:10 PDT 2020


xiangzhai updated this revision to Diff 271067.
xiangzhai added a comment.

Behaviour the same as GNU toolchain:

  $ 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*

The same ABS value `-4`:

  $ objdump -D t.llvm.o 
  
  t.llvm.o:     file format elf64-tradlittlemips
  
  
  Disassembly of section .text:
  
  0000000000000000 <main>:
     0:	00000000 	nop
     4:	67f9fffc 	daddiu	t9,ra,-4


Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D81919/new/

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,10 @@
       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)));
+    else
+      Fixups.push_back(MCFixup::create(0, Expr, MCFixupKind(Mips::fixup_MIPS_PCLO16)));
     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.271067.patch
Type: text/x-patch
Size: 2731 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200616/421f953c/attachment.bin>


More information about the llvm-commits mailing list