[lld] r231640 - [Mips] Show error message and stop linking in case of cross mode jump errors

Simon Atanasyan simon at atanasyan.com
Mon Mar 9 03:53:24 PDT 2015


Author: atanasyan
Date: Mon Mar  9 05:53:24 2015
New Revision: 231640

URL: http://llvm.org/viewvc/llvm-project?rev=231640&view=rev
Log:
[Mips] Show error message and stop linking in case of cross mode jump errors

Modified:
    lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationHandler.cpp
    lld/trunk/test/elf/Mips/jalx-align-err.test
    lld/trunk/test/elf/Mips/jump-fix-err.test
    lld/trunk/test/elf/Mips/plt-header-micro.test

Modified: lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationHandler.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationHandler.cpp?rev=231640&r1=231639&r2=231640&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationHandler.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationHandler.cpp Mon Mar  9 05:53:24 2015
@@ -148,28 +148,31 @@ static void reloc32hi16(uint32_t &ins, u
   applyReloc(ins, (S + A + 0x8000) & 0xffff0000, 0xffffffff);
 }
 
-static void adjustJumpOpCode(uint32_t &ins, uint64_t tgt, CrossJumpMode mode) {
+static std::error_code adjustJumpOpCode(uint32_t &ins, uint64_t tgt,
+                                        CrossJumpMode mode) {
   if (mode == CrossJumpMode::None)
-    return;
+    return std::error_code();
 
   bool toMicro = mode == CrossJumpMode::ToMicro;
   uint32_t opNative = toMicro ? 0x03 : 0x3d;
   uint32_t opCross = toMicro ? 0x1d : 0x3c;
 
-  // FIXME (simon): Convert this into the regular fatal error.
   if ((tgt & 1) != toMicro)
-    llvm_unreachable("Incorrect bit 0 for the jalx target");
+    return make_dynamic_error_code(
+        Twine("Incorrect bit 0 for the jalx target"));
 
   if (tgt & 2)
-    llvm::errs() << "The jalx target " << llvm::format_hex(tgt, 10)
-                 << " is not word-aligned.\n";
-
+    return make_dynamic_error_code(Twine("The jalx target 0x") +
+                                   Twine::utohexstr(tgt) +
+                                   " is not word-aligned");
   uint8_t op = ins >> 26;
   if (op != opNative && op != opCross)
-    llvm::errs() << "Unsupported jump opcode (" << llvm::format_hex(op, 4)
-                 << ") for ISA modes cross call.\n";
-  else
-    ins = (ins & ~(0x3f << 26)) | (opCross << 26);
+    return make_dynamic_error_code(Twine("Unsupported jump opcode (0x") +
+                                   Twine::utohexstr(op) +
+                                   ") for ISA modes cross call");
+
+  ins = (ins & ~(0x3f << 26)) | (opCross << 26);
+  return std::error_code();
 }
 
 static bool isMicroMipsAtom(const Atom *a) {
@@ -273,7 +276,8 @@ std::error_code RelocationHandler<ELFT>:
     targetVAddress |= 1;
 
   CrossJumpMode crossJump = getCrossJumpMode(ref);
-  adjustJumpOpCode(ins, targetVAddress, crossJump);
+  if (auto ec = adjustJumpOpCode(ins, targetVAddress, crossJump))
+    return ec;
 
   switch (ref.kindValue()) {
   case R_MIPS_NONE:

Modified: lld/trunk/test/elf/Mips/jalx-align-err.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/Mips/jalx-align-err.test?rev=231640&r1=231639&r2=231640&view=diff
==============================================================================
--- lld/trunk/test/elf/Mips/jalx-align-err.test (original)
+++ lld/trunk/test/elf/Mips/jalx-align-err.test Mon Mar  9 05:53:24 2015
@@ -1,9 +1,10 @@
 # Check that LLD shows an error if jalx target value is not word-aligned.
 
 # RUN: yaml2obj -format=elf %s > %t-obj
-# RUN: lld -flavor gnu -target mipsel -e T0 -o %t-exe %t-obj 2>&1 | FileCheck %s
+# RUN: not lld -flavor gnu -target mipsel -e T0 -o %t-exe %t-obj 2>&1 \
+# RUN:       | FileCheck %s
 
-# CHECK: The jalx target 0x00400116 is not word-aligned.
+# CHECK: The jalx target 0x400116 is not word-aligned
 
 !ELF
 FileHeader: !FileHeader

Modified: lld/trunk/test/elf/Mips/jump-fix-err.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/Mips/jump-fix-err.test?rev=231640&r1=231639&r2=231640&view=diff
==============================================================================
--- lld/trunk/test/elf/Mips/jump-fix-err.test (original)
+++ lld/trunk/test/elf/Mips/jump-fix-err.test Mon Mar  9 05:53:24 2015
@@ -2,9 +2,9 @@
 # of replacing an unknown unstruction by jalx.
 
 # RUN: yaml2obj -format=elf %s > %t-obj
-# RUN: lld -flavor gnu -target mipsel -o %t-exe %t-obj 2>&1 | FileCheck %s
+# RUN: not lld -flavor gnu -target mipsel -o %t-exe %t-obj 2>&1 | FileCheck %s
 
-# CHECK: Unsupported jump opcode (0x00) for ISA modes cross call.
+# CHECK: Unsupported jump opcode (0x0) for ISA modes cross call
 
 !ELF
 FileHeader: !FileHeader

Modified: lld/trunk/test/elf/Mips/plt-header-micro.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/Mips/plt-header-micro.test?rev=231640&r1=231639&r2=231640&view=diff
==============================================================================
--- lld/trunk/test/elf/Mips/plt-header-micro.test (original)
+++ lld/trunk/test/elf/Mips/plt-header-micro.test Mon Mar  9 05:53:24 2015
@@ -73,7 +73,8 @@ Sections:
     Type:            SHT_PROGBITS
     Flags:           [ SHF_ALLOC, SHF_EXECINSTR ]
     AddressAlign:    0x04
-    Size:            0x20
+    Content:         '000000000000000000f4000000000000f400000000000000f400000000000000'
+#                                       jal .text     jal glob        jal T1
   - Name:            .rel.text
     Type:            SHT_REL
     Link:            .symtab





More information about the llvm-commits mailing list