[lld] r270910 - [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 13:46:01 PDT 2016
Author: atanasyan
Date: Thu May 26 15:46:01 2016
New Revision: 270910
URL: http://llvm.org/viewvc/llvm-project?rev=270910&view=rev
Log:
[ELF][MIPS] Handle section symbol points to the .MIPS.options / .reginfo section
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.
Differential Revision: http://reviews.llvm.org/D20688
Added:
lld/trunk/test/ELF/Inputs/mips-options.o
lld/trunk/test/ELF/mips-options-r.test
Modified:
lld/trunk/ELF/InputSection.cpp
lld/trunk/ELF/OutputSections.cpp
Modified: lld/trunk/ELF/InputSection.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.cpp?rev=270910&r1=270909&r2=270910&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.cpp (original)
+++ lld/trunk/ELF/InputSection.cpp Thu May 26 15:46:01 2016
@@ -67,8 +67,13 @@ typename ELFT::uint InputSectionBase<ELF
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.
+ if (Offset != 0)
+ fatal("Unsupported reference to the middle of '" + getSectionName() +
+ "' section");
+ return this->OutSec->getVA();
}
llvm_unreachable("invalid section kind");
}
Modified: lld/trunk/ELF/OutputSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.cpp?rev=270910&r1=270909&r2=270910&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.cpp (original)
+++ lld/trunk/ELF/OutputSections.cpp Thu May 26 15:46:01 2016
@@ -1582,6 +1582,7 @@ void MipsReginfoOutputSection<ELFT>::add
// 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 @@ void MipsOptionsOutputSection<ELFT>::add
auto *S = cast<MipsOptionsInputSection<ELFT>>(C);
if (S->Reginfo)
GprMask |= S->Reginfo->ri_gprmask;
+ S->OutSec = this;
}
namespace lld {
Added: lld/trunk/test/ELF/Inputs/mips-options.o
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/Inputs/mips-options.o?rev=270910&view=auto
==============================================================================
Binary files lld/trunk/test/ELF/Inputs/mips-options.o (added) and lld/trunk/test/ELF/Inputs/mips-options.o Thu May 26 15:46:01 2016 differ
Added: lld/trunk/test/ELF/mips-options-r.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/mips-options-r.test?rev=270910&view=auto
==============================================================================
--- lld/trunk/test/ELF/mips-options-r.test (added)
+++ lld/trunk/test/ELF/mips-options-r.test Thu May 26 15:46:01 2016
@@ -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
More information about the llvm-commits
mailing list