[PATCH] [AsmPrinter] Fix crash in handleIndirectSymViaGOTPCRel

Rafael EspĂ­ndola rafael.espindola at gmail.com
Thu Jun 25 05:59:26 PDT 2015


On 24 June 2015 at 17:06, Bruno Cardoso Lopes <bruno.cardoso at gmail.com> wrote:
> Hi rafael,
>
> Check for symbols in MCValue before using them. Bail out early in case they are null. Fix for PR23779.
> Rafael, the changes in this patch checks all the possibilities, but do you know if it's possible for evaluateAsRelocatable to return a MCValue with a null SymbolA?


Yes, when given an expression that resolves to an absolute value.

LGTM

Cheers,
Rafael



> Thanks,
>
> REPOSITORY
>   rL LLVM
>
> http://reviews.llvm.org/D10712
>
> Files:
>   lib/CodeGen/AsmPrinter/AsmPrinter.cpp
>   test/MC/MachO/cstexpr-gotpcrel-64.ll
>
> Index: lib/CodeGen/AsmPrinter/AsmPrinter.cpp
> ===================================================================
> --- lib/CodeGen/AsmPrinter/AsmPrinter.cpp
> +++ lib/CodeGen/AsmPrinter/AsmPrinter.cpp
> @@ -2086,17 +2086,24 @@
>    MCValue MV;
>    if (!(*ME)->evaluateAsRelocatable(MV, nullptr, nullptr) || MV.isAbsolute())
>      return;
> +  const MCSymbolRefExpr *SymA = MV.getSymA();
> +  if (!SymA)
> +    return;
>
> -  const MCSymbol *GOTEquivSym = &MV.getSymA()->getSymbol();
> +  // Check that GOT equivalent symbol is cached.
> +  const MCSymbol *GOTEquivSym = &SymA->getSymbol();
>    if (!AP.GlobalGOTEquivs.count(GOTEquivSym))
>      return;
>
>    const GlobalValue *BaseGV = dyn_cast<GlobalValue>(BaseCst);
>    if (!BaseGV)
>      return;
>
> +  // Check for a valid base symbol
>    const MCSymbol *BaseSym = AP.getSymbol(BaseGV);
> -  if (BaseSym != &MV.getSymB()->getSymbol())
> +  const MCSymbolRefExpr *SymB = MV.getSymB();
> +
> +  if (!SymB || BaseSym != &SymB->getSymbol())
>      return;
>
>    // Make sure to match:
> Index: test/MC/MachO/cstexpr-gotpcrel-64.ll
> ===================================================================
> --- test/MC/MachO/cstexpr-gotpcrel-64.ll
> +++ test/MC/MachO/cstexpr-gotpcrel-64.ll
> @@ -84,3 +84,12 @@
>  define i32** @t1() {
>    ret i32** @bargotequiv
>  }
> +
> +; Do not crash when a pattern cannot be matched as a GOT equivalent
> +
> + at a = external global i8
> + at b = internal unnamed_addr constant i8* @a
> +
> +; X86-LABEL: _c:
> +; X86:   .quad _b
> + at c = global i8** @b
>
> EMAIL PREFERENCES
>   http://reviews.llvm.org/settings/panel/emailpreferences/



More information about the llvm-commits mailing list