aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/MC/MCAssembler.cpp
diff options
context:
space:
mode:
authorFangrui Song <maskray@google.com>2020-04-14 11:05:21 -0700
committerFangrui Song <maskray@google.com>2020-04-15 21:02:47 -0700
commite13a8a1fc56837e2f21b85b89a445fb4f21500d6 (patch)
treebb1ec51c951016932f8fb581775d809b43f5f2a6 /llvm/lib/MC/MCAssembler.cpp
parenta07e5b857425a8d411dbf1cdfca5ba5d6521549d (diff)
downloadllvm-e13a8a1fc56837e2f21b85b89a445fb4f21500d6.zip
llvm-e13a8a1fc56837e2f21b85b89a445fb4f21500d6.tar.gz
llvm-e13a8a1fc56837e2f21b85b89a445fb4f21500d6.tar.bz2
[MC][COFF][ELF] Reject instructions in IMAGE_SCN_CNT_UNINITIALIZED_DATA/SHT_NOBITS sections
For `.bss; nop`, MC inappropriately calls abort() (via report_fatal_error()) with a message `cannot have fixups in virtual section!` It is a bug to crash for invalid user input. Fix it by erroring out early in EmitInstToData(). Similarly, emitIntValue() in a virtual section (SHT_NOBITS in ELF) can crash with the mssage `non-zero initializer found in section '.bss'` (see D4199) It'd be nice to report the location but so many directives can call emitIntValue() and it is difficult to track every location. Note, COFF does not crash because MCAssembler::writeSectionData() is not called for an IMAGE_SCN_CNT_UNINITIALIZED_DATA section. Note, GNU as' arm64 backend reports ``Error: attempt to store non-zero value in section `.bss'`` for a non-zero .inst but fails to do so for other instructions. We simply reject all instructions, even if the encoding is all zeros. The Mach-O counterpart is D48517 (see `test/MC/MachO/zerofill-text.s`) Reviewed By: rnk, skan Differential Revision: https://reviews.llvm.org/D78138
Diffstat (limited to 'llvm/lib/MC/MCAssembler.cpp')
-rw-r--r--llvm/lib/MC/MCAssembler.cpp11
1 files changed, 8 insertions, 3 deletions
diff --git a/llvm/lib/MC/MCAssembler.cpp b/llvm/lib/MC/MCAssembler.cpp
index 0d28827..8949a4d 100644
--- a/llvm/lib/MC/MCAssembler.cpp
+++ b/llvm/lib/MC/MCAssembler.cpp
@@ -683,11 +683,16 @@ void MCAssembler::writeSectionData(raw_ostream &OS, const MCSection *Sec,
// directives to fill the contents of virtual sections.
const MCDataFragment &DF = cast<MCDataFragment>(F);
if (DF.fixup_begin() != DF.fixup_end())
- report_fatal_error("cannot have fixups in virtual section!");
+ getContext().reportError(SMLoc(), Sec->getVirtualSectionKind() +
+ " section '" + Sec->getName() +
+ "' cannot have fixups");
for (unsigned i = 0, e = DF.getContents().size(); i != e; ++i)
if (DF.getContents()[i]) {
- report_fatal_error("non-zero initializer found in section '" +
- Sec->getName() + "'");
+ getContext().reportError(SMLoc(),
+ Sec->getVirtualSectionKind() +
+ " section '" + Sec->getName() +
+ "' cannot have non-zero initializers");
+ break;
}
break;
}