From c569ac46ebd59ee9e6a40f2e6cb90bd83c3e1dd1 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Mon, 19 Jan 2015 17:30:24 +0000 Subject: [PATCH] Produce errors when an assignment expression would use a common symbol. An assignment will produce a symbol with a given section and offset. There is no way to represent something like "1 byte after a common symbol". This matches the behavior of GNU as. Part of PR22217. llvm-svn: 226470 --- llvm/lib/MC/MCAssembler.cpp | 12 +++++++++++- llvm/test/MC/ELF/common-error1.s | 6 ++++++ llvm/test/MC/ELF/common-error2.s | 6 ++++++ 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 llvm/test/MC/ELF/common-error1.s create mode 100644 llvm/test/MC/ELF/common-error2.s diff --git a/llvm/lib/MC/MCAssembler.cpp b/llvm/lib/MC/MCAssembler.cpp index e3c2443..b5b7282 100644 --- a/llvm/lib/MC/MCAssembler.cpp +++ b/llvm/lib/MC/MCAssembler.cpp @@ -201,7 +201,17 @@ const MCSymbol *MCAsmLayout::getBaseSymbol(const MCSymbol &Symbol) const { if (!A) return nullptr; - return &A->getSymbol(); + const MCSymbol &ASym = A->getSymbol(); + const MCAssembler &Asm = getAssembler(); + const MCSymbolData &ASD = Asm.getSymbolData(ASym); + if (ASD.isCommon()) { + // FIXME: we should probably add a SMLoc to MCExpr. + Asm.getContext().FatalError(SMLoc(), + "Common symbol " + ASym.getName() + + " cannot be used in assignment expr"); + } + + return &ASym; } uint64_t MCAsmLayout::getSectionAddressSize(const MCSectionData *SD) const { diff --git a/llvm/test/MC/ELF/common-error1.s b/llvm/test/MC/ELF/common-error1.s new file mode 100644 index 0000000..a413885b --- /dev/null +++ b/llvm/test/MC/ELF/common-error1.s @@ -0,0 +1,6 @@ +// RUN: not llvm-mc -filetype=obj -triple x86_64-pc-linux < %s 2>&1 | FileCheck %s + + .comm C,4,4 + .set A,C + +// CHECK: Common symbol C cannot be used in assignment expr diff --git a/llvm/test/MC/ELF/common-error2.s b/llvm/test/MC/ELF/common-error2.s new file mode 100644 index 0000000..d666fee --- /dev/null +++ b/llvm/test/MC/ELF/common-error2.s @@ -0,0 +1,6 @@ +// RUN: not llvm-mc -filetype=obj -triple x86_64-pc-linux < %s 2>&1 | FileCheck %s + + .set A,C + .comm C,4,4 + +// CHECK: Common symbol C cannot be used in assignment expr -- 2.7.4