[PATCH] D42216: Use New Module Metadata String "AvoidPLT" to avoid calls via PLT

Rafael Avila de Espindola via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 17 17:07:55 PST 2018


Sriraman Tallam via Phabricator <reviews at reviews.llvm.org> writes:

> tmsriram created this revision.
> tmsriram added reviewers: rnk, rafael.
>
> Introduce a Module Metadata String "AvoidPLT" to avoid calls via PLT.
>
> Annotating functions with nonlazybind attribute to avoid the PLT does not work for intrinsics.   Intrinsics need to be handled specially and it seems easier to handle them by just annotating the module.

It is not possible to add "options" to intrinsics? That will be annoying
for the transition to dso_local.

> Index: lib/Target/X86/X86ISelLowering.cpp
> ===================================================================
> --- lib/Target/X86/X86ISelLowering.cpp
> +++ lib/Target/X86/X86ISelLowering.cpp
> @@ -3732,11 +3732,23 @@
>      }
>    } else if (ExternalSymbolSDNode *S = dyn_cast<ExternalSymbolSDNode>(Callee)) {
>      const Module *Mod = DAG.getMachineFunction().getFunction().getParent();
> -    unsigned char OpFlags =
> -        Subtarget.classifyGlobalFunctionReference(nullptr, *Mod);
> +    // If PLT must be avoided then the call should be via GOTPCREL.
> +    unsigned char OpFlags = X86II::MO_GOTPCREL;
> +
> +    if (!Mod->getAvoidPLT()) {
> +      OpFlags = Subtarget.classifyGlobalFunctionReference(nullptr, *Mod);
> +    }
>  
>      Callee = DAG.getTargetExternalSymbol(
>          S->getSymbol(), getPointerTy(DAG.getDataLayout()), OpFlags);
> +
> +    if (OpFlags == X86II::MO_GOTPCREL) {
> +      Callee = DAG.getNode(X86ISD::WrapperRIP, dl,
> +          getPointerTy(DAG.getDataLayout()), Callee);
> +      Callee = DAG.getLoad(
> +          getPointerTy(DAG.getDataLayout()), dl, DAG.getEntryNode(), Callee,
> +          MachinePointerInfo::getGOT(DAG.getMachineFunction()));
> +    }

The logic should be added to shouldAssumeDSOLocal.

Cheers,
Rafael


More information about the llvm-commits mailing list