pcc wrote:

> This patch has a few problems
> 
> * The check in `processAux` was moved to the wrong place (it will never get 
> hit because this is after we deal with all symbols not defined locally). This 
> patch moves it to approximately the right place but will need some logic 
> changes to `isStaticLinkTimeConstant` to recognize ifuncs as not being static 
> link time constants:
> 
> ```
> diff --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp
> index 1439fd859f51..969d71461cb1 100644
> --- a/lld/ELF/Relocations.cpp
> +++ b/lld/ELF/Relocations.cpp
> @@ -1127,6 +1127,8 @@ void RelocationScanner::processAux(RelExpr expr, 
> RelType type, uint64_t offset,
>    // handling of GOT-generating relocations.
>    if (isStaticLinkTimeConstant(expr, type, sym, offset) ||
>        (!ctx.arg.isPic && sym.isUndefWeak())) {
> +    if (LLVM_UNLIKELY(isIfunc && !needsGot(expr) && !needsPlt(expr)))
> +      sym.setFlags(HAS_DIRECT_RELOC);
>      sec->addReloc({expr, type, offset, addend, &sym});
>      return;
>    }
> @@ -1194,9 +1196,6 @@ void RelocationScanner::processAux(RelExpr expr, 
> RelType type, uint64_t offset,
>      }
>    }
>  
> -  if (LLVM_UNLIKELY(isIfunc && !needsGot(expr) && !needsPlt(expr)))
> -    sym.setFlags(HAS_DIRECT_RELOC);
> -
>    // When producing an executable, we can perform copy relocations (for
>    // STT_OBJECT) and canonical PLT (for STT_FUNC) if sym is defined by a DSO.
>    // Copy relocations/canonical PLT entries are unsupported for
> ```
> 
> * Need to adjust how IRELATIVE relocations get emitted. Currently we emit 
> relocations with the wrong type (assuming they will be demoted) and fix up 
> the type in `RelocationBaseSection::partitionRels` if they turn out to not be 
> demoted. But this isn't good enough for PDEs which need them to be static 
> relocations. Here's what I think we should do instead:
>   
>   * Always emit ifunc relocations as IRELATIVE during `processAux`
>   * In `handleNonPreemptibleIfunc`, when we demote an ifunc to an iplt entry, 
> loop over all irelatives pointing to the symbol and rewrite them as either 
> relative (for PIE/shared) or static relocations (for PDE). It's fine to loop 
> over the irelatives every time because they are rare.

All of this is done in the latest change (except that I decided to handle the 
demotion in a separate loop instead of `handleNonPreemptibleIfunc`, PTAL

https://github.com/llvm/llvm-project/pull/133531
_______________________________________________
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

Reply via email to