[PATCH] D20688: [ELF][MIPS] Handle section symbol points to the .MIPS.options / .reginfo section

Simon Atanasyan via llvm-commits llvm-commits at lists.llvm.org
Thu May 26 09:41:57 PDT 2016


atanasyan created this revision.
atanasyan added reviewers: ruiu, rafael.
atanasyan added subscribers: llvm-commits, emaste.
atanasyan set the repository for this revision to rL LLVM.
atanasyan added a project: lld.
Herald added a subscriber: sdardis.

MIPS .reginfo and .MIPS.options sections are consumed by the linker, and the linker produces a single output section. But it is possible that input files contain section symbol points to the corresponding input section. In case of generation a relocatable output we need to write such symbols to the output file.

Fixes bug 27878.

Repository:
  rL LLVM

http://reviews.llvm.org/D20688

Files:
  ELF/InputSection.cpp
  ELF/OutputSections.cpp
  test/ELF/Inputs/mips-options.o
  test/ELF/mips-options-r.test

Index: test/ELF/mips-options-r.test
===================================================================
--- /dev/null
+++ test/ELF/mips-options-r.test
@@ -0,0 +1,19 @@
+# Check that if input file contains .MIPS.options section and symbol
+# points to the section and the linker generates a relocatable output,
+# LLD does not crash and write section symbols point to the output
+# .MIPS.options section.
+#
+# PR 27878
+#
+# Input object file created using the following script:
+# % cat t.s
+#   .text
+#   nop
+# % as -mabi=64 -mips64r2 t.s
+
+# RUN: ld.lld -r %p/Inputs/mips-options.o -o %t.o
+# RUN: llvm-readobj -t %t.o | FileCheck %s
+
+# REQUIRES: mips
+
+# CHECK: Section: .MIPS.options
Index: ELF/OutputSections.cpp
===================================================================
--- ELF/OutputSections.cpp
+++ ELF/OutputSections.cpp
@@ -1582,6 +1582,7 @@
   // Copy input object file's .reginfo gprmask to output.
   auto *S = cast<MipsReginfoInputSection<ELFT>>(C);
   GprMask |= S->Reginfo->ri_gprmask;
+  S->OutSec = this;
 }
 
 template <class ELFT>
@@ -1610,6 +1611,7 @@
   auto *S = cast<MipsOptionsInputSection<ELFT>>(C);
   if (S->Reginfo)
     GprMask |= S->Reginfo->ri_gprmask;
+  S->OutSec = this;
 }
 
 namespace lld {
Index: ELF/InputSection.cpp
===================================================================
--- ELF/InputSection.cpp
+++ ELF/InputSection.cpp
@@ -67,8 +67,12 @@
   case MipsReginfo:
   case MipsOptions:
     // MIPS .reginfo and .MIPS.options sections are consumed by the linker,
-    // so they should never be copied to output.
-    llvm_unreachable("MIPS reginfo/options section reached writeTo().");
+    // and the linker produces a single output section. It is possible that
+    // input files contain section symbol points to the corresponding input
+    // section. Redirect it to the produced output section.
+    assert(Offset == 0 &&
+           "Retrieve offset in the middle of MIPS reginfo/options section");
+    return this->OutSec->getVA();
   }
   llvm_unreachable("invalid section kind");
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D20688.58636.patch
Type: text/x-patch
Size: 2061 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160526/bbb5ede3/attachment.bin>


More information about the llvm-commits mailing list