[lld] r265059 - [ELF] Implement infrastructure for thunk code creation

Rafael EspĂ­ndola via llvm-commits llvm-commits at lists.llvm.org
Sat Apr 2 18:35:24 PDT 2016


>  template <class ELFT>
> +bool MipsTargetInfo<ELFT>::needsThunk(uint32_t Type, const InputFile &File,
> +                                      const SymbolBody &S) const {
> +  // Any MIPS PIC code function is invoked with its address in register $t9.
> +  // So if we have a branch instruction from non-PIC code to the PIC one
> +  // we cannot make the jump directly and need to create a small stubs
> +  // to save the target function address.
> +  // See page 3-38 ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf
> +  if (Type != R_MIPS_26)
> +    return false;
> +  auto *F = dyn_cast<ELFFileBase<ELFT>>(&File);
> +  if (!F)
> +    return false;
> +  // If current file has PIC code, LA25 stub is not required.
> +  if (F->getObj().getHeader()->e_flags & EF_MIPS_PIC)
> +    return false;
> +  auto *D = dyn_cast<DefinedRegular<ELFT>>(&S);
> +  if (!D || !D->Section)
> +    return false;
> +  // LA25 is required if target file has PIC code
> +  // or target symbol is a PIC symbol.
> +  return (D->Section->getFile()->getObj().getHeader()->e_flags & EF_MIPS_PIC) ||
> +         (D->Sym.st_other & STO_MIPS_MIPS16) == STO_MIPS_PIC;

I just noticed that this last part is not tested. All tests pass if I
replace st_other with 0.

Cheers,
Rafael


More information about the llvm-commits mailing list