[PATCH] LoongArch: Disallow TLS transition when a section contains TLS_IE64 or TLS_DESC64 reloc

mengqinggang mengqinggang@loongson.cn
Fri Jan 26 08:40:19 GMT 2024


We will send a patch to fix this and some other questions today.


在 2024/1/26 下午4:19, Xi Ruoyao 写道:
> On Fri, 2024-01-26 at 16:12 +0800, Xi Ruoyao wrote:
>> On Fri, 2024-01-26 at 09:43 +0800, mengqinggang wrote:
>>> Hi,
>>>
>>> For TLS transition, we want to change to that the instructions that can be
>>> converted must have a R_LARCH_RELAX relocation.
> So we need something like
>
> diff --git a/bfd/elfnn-loongarch.c b/bfd/elfnn-loongarch.c
> index b62bb424644..63aa7e254b5 100644
> --- a/bfd/elfnn-loongarch.c
> +++ b/bfd/elfnn-loongarch.c
> @@ -818,7 +818,10 @@ loongarch_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
>         int need_dynreloc = 0;
>         int only_need_pcrel = 0;
>   
> -      r_type = loongarch_tls_transition (info, r_type, h, abfd, r_symndx);
> +      if (rel + 1 != relocs + sec->reloc_count
> +	  && ELFNN_R_TYPE (rel[1].r_info) == R_LARCH_RELAX)
> +	r_type = loongarch_tls_transition (info, r_type, h, abfd, r_symndx);
> +
>         switch (r_type)
>   	{
>   	case R_LARCH_GOT_PC_HI20:
> @@ -2789,7 +2792,12 @@ loongarch_elf_relocate_section (bfd *output_bfd, struct bfd_link_info *info,
>   
>         BFD_ASSERT (!resolved_local || defined_local);
>   
> -      relaxed_r_type = loongarch_tls_transition (info, r_type, h, input_bfd, r_symndx);
> +      relaxed_r_type = r_type;
> +      if (rel + 1 != relend
> +	  && ELFNN_R_TYPE (rel[1].r_info) == R_LARCH_RELAX)
> +	relaxed_r_type = loongarch_tls_transition (info, r_type, h,
> +						   input_bfd, r_symndx);
> +
>         if (relaxed_r_type != r_type)
>         {
>   	howto = loongarch_elf_rtype_to_howto (input_bfd, relaxed_r_type);
>
> and this is missing in the master branch?
>
>>> After 32ee2b4b71c78d3dc0c0b1f87f25fe5df8786b71 commit, the gas not
>>> emit R_LARCH_RELAX for two register macros.
>> But with master branch at e14f7abaf81d5d0aa7898570024286de8c188817:
>>
>> $ cat t.s
>> .globl _start
>> _start:
>>    la.tls.ie $a0, $a1, foo
>>
>> .section .tdata
>> foo: .word 114514
>> $ gas/as-new t.s -o t.o
>> $ ld/ld-new t.o
>> [1]    7202 segmentation fault (core dumped)  ld/ld-new t.o
>>
>>



More information about the Binutils mailing list