[PATCH] D72899: [MC] Set sh_link to 0 if the associated symbol is undefined

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 16 14:36:42 PDT 2020


MaskRay added a subscriber: phosek.
MaskRay added a comment.

@pcc @phosek If we want to allow sh_link=0 for SHF_LINK_ORDER sections, we should have an assembler syntax (otherwise `ld.lld --lto-emit-asm` may fail)
We will need ELFObjectWriter.cpp and TargetLoweringObjectFileImpl.cpp changes as made in this patch.

We probably should add the following as well:

  --- a/llvm/lib/MC/MCParser/ELFAsmParser.cpp
  +++ b/llvm/lib/MC/MCParser/ELFAsmParser.cpp
  @@ -450,8 +450,14 @@ bool ELFAsmParser::parseLinkedToSym(MCSymbolELF *&LinkedToSym) {
     Lex();
     StringRef Name;
     SMLoc StartLoc = L.getLoc();
  -  if (getParser().parseIdentifier(Name))
  +  if (getParser().parseIdentifier(Name)) {
  +    if (getParser().getTok().getString() == "0") {
  +      getParser().Lex();
  +      LinkedToSym = nullptr;
  +      return false;
  +    }
       return TokError("invalid linked-to symbol");
  +  }
     LinkedToSym = dyn_cast_or_null<MCSymbolELF>(getContext().lookupSymbol(Name));
     if (!LinkedToSym || !LinkedToSym->isInSection())
       return Error(StartLoc, "linked-to symbol is not in a section: " + Name);

For

  declare void @foo()
  
  @a = global i32 1, !associated !0
  @b = global i32 1, !associated !0
  
  !0 = !{void ()* @foo}

do we still want a diagnostic? If yes, we should do it in a higher level, not in MC.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D72899/new/

https://reviews.llvm.org/D72899





More information about the llvm-commits mailing list