[llvm] r239227 - [MC] Common symbols weren't being checked for redeclaration which allowed an assembly file to generate an assertion in setCommon(): !isCommon(). This change allows redeclaration as long as the size and alignment match exactly, otherwise report a fatal error.

colinl at codeaurora.org colinl at codeaurora.org
Sat Jun 6 13:26:31 PDT 2015


Sure enough.  I'll mark it resolved once it passes more buildbots.

> This fixes https://llvm.org/bugs/show_bug.cgi?id=23621, no?
>
> Thanks,
> Rafael
>
>
> On 6 June 2015 at 16:12, Colin LeMahieu <colinl at codeaurora.org> wrote:
>> Author: colinl
>> Date: Sat Jun  6 15:12:40 2015
>> New Revision: 239227
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=239227&view=rev
>> Log:
>> [MC] Common symbols weren't being checked for redeclaration which
>> allowed an assembly file to generate an assertion in setCommon():
>> !isCommon().  This change allows redeclaration as long as the size and
>> alignment match exactly, otherwise report a fatal error.
>>
>> Added:
>>     llvm/trunk/test/MC/ELF/common-error3.s
>>     llvm/trunk/test/MC/ELF/common-redeclare.s
>> Modified:
>>     llvm/trunk/include/llvm/MC/MCSymbol.h
>>     llvm/trunk/lib/MC/MCELFStreamer.cpp
>>
>> Modified: llvm/trunk/include/llvm/MC/MCSymbol.h
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCSymbol.h?rev=239227&r1=239226&r2=239227&view=diff
>> ==============================================================================
>> --- llvm/trunk/include/llvm/MC/MCSymbol.h (original)
>> +++ llvm/trunk/include/llvm/MC/MCSymbol.h Sat Jun  6 15:12:40 2015
>> @@ -258,6 +258,21 @@ public:
>>      return CommonAlign;
>>    }
>>
>> +  /// Declare this symbol as being 'common'.
>> +  ///
>> +  /// \param Size - The size of the symbol.
>> +  /// \param Align - The alignment of the symbol.
>> +  /// \return True if symbol was already declared as a different type
>> +  bool declareCommon(uint64_t Size, unsigned Align) {
>> +    assert(isCommon() || getOffset() == 0);
>> +    if(isCommon()) {
>> +      if(CommonSize != Size || CommonAlign != Align)
>> +       return true;
>> +    } else
>> +      setCommon(Size, Align);
>> +    return false;
>> +  }
>> +
>>    /// Is this a 'common' symbol.
>>    bool isCommon() const { return CommonAlign != -1U; }
>>
>>
>> Modified: llvm/trunk/lib/MC/MCELFStreamer.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCELFStreamer.cpp?rev=239227&r1=239226&r2=239227&view=diff
>> ==============================================================================
>> --- llvm/trunk/lib/MC/MCELFStreamer.cpp (original)
>> +++ llvm/trunk/lib/MC/MCELFStreamer.cpp Sat Jun  6 15:12:40 2015
>> @@ -320,7 +320,9 @@ void MCELFStreamer::EmitCommonSymbol(MCS
>>      struct LocalCommon L = {Symbol, Size, ByteAlignment};
>>      LocalCommons.push_back(L);
>>    } else {
>> -    Symbol->setCommon(Size, ByteAlignment);
>> +    if(Symbol->declareCommon(Size, ByteAlignment))
>> +      report_fatal_error("Symbol: " + Symbol->getName() +
>> +                         " redeclared as different type");
>>    }
>>
>>    cast<MCSymbolELF>(Symbol)
>>
>> Added: llvm/trunk/test/MC/ELF/common-error3.s
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ELF/common-error3.s?rev=239227&view=auto
>> ==============================================================================
>> --- llvm/trunk/test/MC/ELF/common-error3.s (added)
>> +++ llvm/trunk/test/MC/ELF/common-error3.s Sat Jun  6 15:12:40 2015
>> @@ -0,0 +1,5 @@
>> +# RUN: not llvm-mc -filetype=obj -triple x86_64-pc-linux %s 2>&1 |
>> FileCheck %s
>> +
>> +# CHECK: Symbol: C redeclared as different type
>> +        .comm   C,4,4
>> +        .comm   C,8,4
>> \ No newline at end of file
>>
>> Added: llvm/trunk/test/MC/ELF/common-redeclare.s
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ELF/common-redeclare.s?rev=239227&view=auto
>> ==============================================================================
>> --- llvm/trunk/test/MC/ELF/common-redeclare.s (added)
>> +++ llvm/trunk/test/MC/ELF/common-redeclare.s Sat Jun  6 15:12:40 2015
>> @@ -0,0 +1,5 @@
>> +# RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux %s | llvm-objdump
>> -t - | FileCheck %s
>> +
>> +# CHECK: 0000000000000004 g       *COM*  00000004 C
>> +        .comm   C,4,4
>> +        .comm   C,4,4
>> \ No newline at end of file
>>
>>
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>





More information about the llvm-commits mailing list