[PATCH 1/4] gold/aarch64: Allow TLSLE relocations in PIC outputs

Richard Earnshaw Richard.Earnshaw@arm.com
Tue Jun 3 15:25:15 GMT 2025


On 24/08/2024 00:05, H.J. Lu wrote:
> 	PR gold/19041
> 	* aarch64.cc (Target_aarch64::Scan::local): Allow TLSLE
> 	relocations in PIC outputs.
> 	(Target_aarch64::Scan::global): Likewise.
> 	(Target_aarch64::Relocate::relocate_tls): Likewise.

Hi H.J.

Sorry, it looks like nobody responded to this.  I've never done any 
aarch64 maintenance so I can't really review this.  I'll have to leave 
it to Nick.

I've no objections though, provided it only implements something already 
handled by the bfd linker for aarch64.  I don't think we want to start 
pushing new functionality into gold given the limited maintenance that 
it receives.

R.

> 
> Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
> ---
>   gold/aarch64.cc | 52 +++++++++++++++++--------------------------------
>   1 file changed, 18 insertions(+), 34 deletions(-)
> 
> diff --git a/gold/aarch64.cc b/gold/aarch64.cc
> index e5bd7bda0fe..9419d503ea0 100644
> --- a/gold/aarch64.cc
> +++ b/gold/aarch64.cc
> @@ -6282,13 +6282,7 @@ Target_aarch64<size, big_endian>::Scan::local(
>       case elfcpp::R_AARCH64_TLSLE_LDST32_TPREL_LO12_NC:
>       case elfcpp::R_AARCH64_TLSLE_LDST64_TPREL_LO12:
>       case elfcpp::R_AARCH64_TLSLE_LDST64_TPREL_LO12_NC:
> -      {
> -	layout->set_has_static_tls();
> -	bool output_is_shared = parameters->options().shared();
> -	if (output_is_shared)
> -	  gold_error(_("%s: unsupported TLSLE reloc %u in shared code."),
> -		     object->name().c_str(), r_type);
> -      }
> +      layout->set_has_static_tls();
>         break;
>   
>       case elfcpp::R_AARCH64_TLSLD_ADR_PAGE21:
> @@ -6720,9 +6714,6 @@ Target_aarch64<size, big_endian>::Scan::global(
>       case elfcpp::R_AARCH64_TLSLE_LDST64_TPREL_LO12:
>       case elfcpp::R_AARCH64_TLSLE_LDST64_TPREL_LO12_NC:  // Local executable
>         layout->set_has_static_tls();
> -      if (parameters->options().shared())
> -	gold_error(_("%s: unsupported TLSLE reloc type %u in shared objects."),
> -		   object->name().c_str(), r_type);
>         break;
>   
>       case elfcpp::R_AARCH64_TLSDESC_ADR_PAGE21:
> @@ -7614,33 +7605,26 @@ Target_aarch64<size, big_endian>::Relocate::relocate_tls(
>   	gold_assert(tls_segment != NULL);
>   	AArch64_address value = psymval->value(object, 0);
>   
> -	if (!parameters->options().shared())
> +	AArch64_address aligned_tcb_size =
> +	  align_address(target->tcb_size(),
> +			tls_segment->maximum_alignment());
> +	value += aligned_tcb_size;
> +	switch (r_type)
>   	  {
> -	    AArch64_address aligned_tcb_size =
> -		align_address(target->tcb_size(),
> -			      tls_segment->maximum_alignment());
> -	    value += aligned_tcb_size;
> -	    switch (r_type)
> -	      {
> -	      case elfcpp::R_AARCH64_TLSLE_MOVW_TPREL_G2:
> -	      case elfcpp::R_AARCH64_TLSLE_MOVW_TPREL_G1:
> -	      case elfcpp::R_AARCH64_TLSLE_MOVW_TPREL_G0:
> -		return aarch64_reloc_funcs::movnz(view, value + addend,
> -						  reloc_property);
> -	      default:
> -		return aarch64_reloc_funcs::template
> -		  rela_general<32>(view,
> -				   value,
> -				   addend,
> -				   reloc_property);
> -	      }
> +	  case elfcpp::R_AARCH64_TLSLE_MOVW_TPREL_G2:
> +	  case elfcpp::R_AARCH64_TLSLE_MOVW_TPREL_G1:
> +	  case elfcpp::R_AARCH64_TLSLE_MOVW_TPREL_G0:
> +	    return aarch64_reloc_funcs::movnz(view, value + addend,
> +					      reloc_property);
> +	  default:
> +	    return aarch64_reloc_funcs::template
> +	      rela_general<32>(view,
> +			       value,
> +			       addend,
> +			       reloc_property);
>   	  }
> -	else
> -	  gold_error(_("%s: unsupported reloc %u "
> -		       "in non-static TLSLE mode."),
> -		     object->name().c_str(), r_type);
>         }
> -      break;
> +    break;
>   
>       case elfcpp::R_AARCH64_TLSDESC_ADR_PAGE21:
>       case elfcpp::R_AARCH64_TLSDESC_LD64_LO12:



More information about the Binutils mailing list