This is an archive of the discontinued LLVM Phabricator instance.

[MC][PowerPC] Fix a crash when redefining a symbol after .set
ClosedPublic

Authored by MaskRay on Dec 12 2019, 4:56 PM.

Details

Summary

Fix PR44284.

This is probably not valid assembly but we should not crash.

Diff Detail

Event Timeline

MaskRay created this revision.Dec 12 2019, 4:56 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 12 2019, 4:56 PM
MaskRay edited the summary of this revision. (Show Details)Dec 12 2019, 5:01 PM
MaskRay added a reviewer: Restricted Project.Dec 12 2019, 9:55 PM
steven.zhang accepted this revision.Dec 13 2019, 12:45 AM
steven.zhang added a subscriber: steven.zhang.

LGTM, thank you for the fixing.

This revision is now accepted and ready to land.Dec 13 2019, 12:45 AM
luporl accepted this revision.Dec 13 2019, 3:15 AM

LGTM. It seems I did not consider that Symbol could change its type between when it was added in emitAssignment() and when processed in finish().

This revision was automatically updated to reflect the committed changes.

@MaskRay @luporl Is it possible for Sym to be null here? Do we need a nullptr check? I ask because we seem to have a crash here reported in https://bugs.llvm.org/show_bug.cgi?id=45366 that we cannot reproduce. But I wonder if perhaps this might be the issue.

I have asked the OP of the PR to try the patch that adds the null check, but I was hoping to get your opinion on this as well.

MaskRay added a comment.EditedApr 9 2020, 10:25 PM

@MaskRay @luporl Is it possible for Sym to be null here? Do we need a nullptr check? I ask because we seem to have a crash here reported in https://bugs.llvm.org/show_bug.cgi?id=45366 that we cannot reproduce. But I wonder if perhaps this might be the issue.

I have asked the OP of the PR to try the patch that adds the null check, but I was hoping to get your opinion on this as well.

In a -DLLVM_ENABLE_ASSERTIONS=on build, Sym can't be nullptr. Might to good to ask the OP of https://bugs.llvm.org/show_bug.cgi?id=45366 whether this can be reproduced

void emitAssignment(MCSymbol *S, const MCExpr *Value) override {
  auto *Symbol = cast<MCSymbolELF>(S); //////////// asserted to be non-null

  // When encoding an assignment to set symbol A to symbol B, also copy
  // the st_other bits encoding the local entry point offset.
  if (copyLocalEntry(Symbol, Value))
    UpdateOther.insert(Symbol); ///////// only way an element is inserted into UpdateOther
  else
    UpdateOther.erase(Symbol);
}

Here is the only caller of llvm::MCTargetStreamer::emitAssignment

// https://github.com/llvm/llvm-project/blob/master/llvm/lib/MC/MCStreamer.cpp#L966
void MCStreamer::emitAssignment(MCSymbol *Symbol, const MCExpr *Value) {
  visitUsedExpr(*Value);
  Symbol->setVariableValue(Value);

  MCTargetStreamer *TS = getTargetStreamer();
  if (TS)
    TS->emitAssignment(Symbol, Value);  //////////// Symbol can't be nullptr
}