From c983b20661d574b7adb2675478210c03ad1d0a33 Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Wed, 18 Aug 2010 18:22:37 +0000 Subject: [PATCH] MC/ELF: Allow null values in virtual sections, ELF doesn't use special directives for putting contents in .bss, for example. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@111376 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/MC/MCAssembler.cpp | 17 ++++++++++++++++- test/MC/ELF/bss.ll | 8 ++++++++ test/MC/ELF/dg.exp | 5 +++++ 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 test/MC/ELF/bss.ll create mode 100644 test/MC/ELF/dg.exp diff --git a/lib/MC/MCAssembler.cpp b/lib/MC/MCAssembler.cpp index 35f39564cd5..f0e1d7fbc21 100644 --- a/lib/MC/MCAssembler.cpp +++ b/lib/MC/MCAssembler.cpp @@ -628,8 +628,23 @@ void MCAssembler::WriteSectionData(const MCSectionData *SD, switch (it->getKind()) { default: assert(0 && "Invalid fragment in virtual section!"); + case MCFragment::FT_Data: { + // Check that we aren't trying to write a non-zero contents (or fixups) + // into a virtual section. This is to support clients which use standard + // directives to fill the contents of virtual sections. + MCDataFragment &DF = cast(*it); + 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!"); + break; + } case MCFragment::FT_Align: - assert(!cast(it)->getValueSize() && + // Check that we aren't trying to write a non-zero value into a virtual + // section. + assert((!cast(it)->getValueSize() || + !cast(it)->getValue()) && "Invalid align in virtual section!"); break; case MCFragment::FT_Fill: diff --git a/test/MC/ELF/bss.ll b/test/MC/ELF/bss.ll new file mode 100644 index 00000000000..5112d2c9b0a --- /dev/null +++ b/test/MC/ELF/bss.ll @@ -0,0 +1,8 @@ +; RUN: llc -filetype=obj %s -o %t +; FIXME: Add ELF dumping tool to check results. + +target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32" +target triple = "i386-pc-linux-gnu" + +@g0 = global i8* null, align 4 ; [#uses=0] + diff --git a/test/MC/ELF/dg.exp b/test/MC/ELF/dg.exp new file mode 100644 index 00000000000..7b7bd4e7380 --- /dev/null +++ b/test/MC/ELF/dg.exp @@ -0,0 +1,5 @@ +load_lib llvm.exp + +if { [llvm_supports_target X86] } { + RunLLVMTests [lsort [glob -nocomplain $srcdir/$subdir/*.{ll}]] +}