From 09f104fc323ff9b8cfcecd1f0ec7b470b38c69a1 Mon Sep 17 00:00:00 2001 From: Weiming Zhao Date: Sun, 22 Jun 2014 00:33:44 +0000 Subject: [PATCH] Report error for non-zero data in .bss User may initialize a var with non-zero value and specify .bss section. E.g. : int a __attribute__((section(".bss"))) = 2; This patch converts an assertion to error report for better user experience. Differential Revision: http://reviews.llvm.org/D4199 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@211455 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/MC/MCAssembler.cpp | 10 ++++++++-- test/MC/ELF/ARM/bss-non-zero-value.s | 9 +++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 test/MC/ELF/ARM/bss-non-zero-value.s diff --git a/lib/MC/MCAssembler.cpp b/lib/MC/MCAssembler.cpp index 886a5f55453..4f876c8ce7d 100644 --- a/lib/MC/MCAssembler.cpp +++ b/lib/MC/MCAssembler.cpp @@ -27,6 +27,7 @@ #include "llvm/Support/LEB128.h" #include "llvm/Support/TargetRegistry.h" #include "llvm/Support/raw_ostream.h" +#include "llvm/MC/MCSectionELF.h" #include using namespace llvm; @@ -782,8 +783,13 @@ void MCAssembler::writeSectionData(const MCSectionData *SD, assert(DF.fixup_begin() == DF.fixup_end() && "Cannot have fixups in virtual section!"); for (unsigned i = 0, e = DF.getContents().size(); i != e; ++i) - assert(DF.getContents()[i] == 0 && - "Invalid data value for virtual section!"); + if (DF.getContents()[i]) { + if (auto *ELFSec = dyn_cast(&SD->getSection())) + report_fatal_error("non-zero initializer found in section '" + + ELFSec->getSectionName() + "'"); + else + report_fatal_error("non-zero initializer found in virtual section"); + } break; } case MCFragment::FT_Align: diff --git a/test/MC/ELF/ARM/bss-non-zero-value.s b/test/MC/ELF/ARM/bss-non-zero-value.s new file mode 100644 index 00000000000..999b8b019c9 --- /dev/null +++ b/test/MC/ELF/ARM/bss-non-zero-value.s @@ -0,0 +1,9 @@ +// RUN: not llvm-mc -filetype=obj -triple arm-linux-gnu %s -o %t 2>%t.out +// RUN: FileCheck --input-file=%t.out %s +// CHECK: non-zero initializer found in section '.bss' + .bss + .globl a + .align 2 +a: + .long 1 + .size a, 4 -- 2.34.1