Skip to content

Commit 58eb5ab

Browse files
author
Weiming Zhao
committedJun 22, 2014
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 llvm-svn: 211455
1 parent 579cf37 commit 58eb5ab

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed
 

‎llvm/lib/MC/MCAssembler.cpp

+8-2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "llvm/Support/LEB128.h"
2828
#include "llvm/Support/TargetRegistry.h"
2929
#include "llvm/Support/raw_ostream.h"
30+
#include "llvm/MC/MCSectionELF.h"
3031
#include <tuple>
3132
using namespace llvm;
3233

@@ -782,8 +783,13 @@ void MCAssembler::writeSectionData(const MCSectionData *SD,
782783
assert(DF.fixup_begin() == DF.fixup_end() &&
783784
"Cannot have fixups in virtual section!");
784785
for (unsigned i = 0, e = DF.getContents().size(); i != e; ++i)
785-
assert(DF.getContents()[i] == 0 &&
786-
"Invalid data value for virtual section!");
786+
if (DF.getContents()[i]) {
787+
if (auto *ELFSec = dyn_cast<const MCSectionELF>(&SD->getSection()))
788+
report_fatal_error("non-zero initializer found in section '" +
789+
ELFSec->getSectionName() + "'");
790+
else
791+
report_fatal_error("non-zero initializer found in virtual section");
792+
}
787793
break;
788794
}
789795
case MCFragment::FT_Align:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// RUN: not llvm-mc -filetype=obj -triple arm-linux-gnu %s -o %t 2>%t.out
2+
// RUN: FileCheck --input-file=%t.out %s
3+
// CHECK: non-zero initializer found in section '.bss'
4+
.bss
5+
.globl a
6+
.align 2
7+
a:
8+
.long 1
9+
.size a, 4

0 commit comments

Comments
 (0)
Please sign in to comment.