public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Xi Ruoyao <xry111@xry111.site>
To: Lulu Cai <cailulu@loongson.cn>, binutils@sourceware.org
Cc: xuchenghua@loongson.cn, chenglulu@loongson.cn,
	liuzhensong@loongson.cn,  mengqinggang@loongson.cn,
	i.swmail@xen0n.name, maskray@google.com,  luweining@loongson.cn,
	wanglei@loongson.cn, hejinyang@loongson.cn
Subject: Re: [PATCH 1/2] LoongArch: Delete extra instructions when TLS type transition
Date: Sat, 27 Jan 2024 02:22:05 +0800	[thread overview]
Message-ID: <f75d5c73fb178517863368bb684f763d9d6a9a94.camel@xry111.site> (raw)
In-Reply-To: <20240126135540.3437675-1-cailulu@loongson.cn>

On Fri, 2024-01-26 at 21:55 +0800, Lulu Cai wrote:
> This modification mainly changes the timing of type transition,
> adds relaxation to the old LE instruction sequence, and fixes
> bugs in extreme code models.

I'd suggest to separate the bug fixes (requiring R_LARCH_RELAX for DESC
and IE transition) out into one separate commit and apply it for 2.42. 
And the old LE relaxation & instruction deletion should be only applied
for trunk (2.43).  We are just toooooo close to the 2.42 release, and
deleting instructions is always "dangerous" even if we do it very
carefully.

/* snip */

> +loongarch_can_trans_tls (bfd *input_bfd,
> +			 struct bfd_link_info *info,
> +			 struct elf_link_hash_entry *h,
> +			 const Elf_Internal_Rela *rel,
> +			 unsigned int r_type)
>  {
>    char symbol_tls_type;
>    unsigned int reloc_got_type;
> +  unsigned int r_symndx = ELFNN_R_SYM (rel->r_info);
>  
> -  if (! (IS_LOONGARCH_TLS_DESC_RELOC (r_type)
> -	 || IS_LOONGARCH_TLS_IE_RELOC (r_type)))
> +  /* Only TLS DESC/IE in normal code mode will perform type
> +     transition.  */
> +  if (! (IS_LOONGARCH_TLS_TRANS_RELOC (r_type)
> +	  && ELFNN_R_TYPE ((rel + 1)->r_info) == R_LARCH_RELAX))

We need to check if rel is the last relocation of the section, or rel +
1 may be an OOB read.

>  static bool
>  loongarch_relax_tls_le (bfd *abfd, asection *sec,
> @@ -4165,31 +4198,56 @@ loongarch_relax_tls_le (bfd *abfd, asection *sec,
>    uint32_t insn = bfd_get (32, abfd, contents + rel->r_offset);
>    static uint32_t insn_rj,insn_rd;
>    symval = symval - elf_hash_table (link_info)->tls_sec->vma;
> -  /* Whether the symbol offset is in the interval (offset < 0x800).  */
> -  if (ELFNN_R_TYPE ((rel + 1)->r_info == R_LARCH_RELAX) && (symval < 0x800))
> +  /* The old LE instruction sequence can be relaxed when the symbol offset
> +     is smaller than the 12-bit range.  */
> +  if (ELFNN_R_TYPE ((rel + 1)->r_info) == R_LARCH_RELAX && (symval <= 0xfff))

Likewise.

-- 
Xi Ruoyao <xry111@xry111.site>
School of Aerospace Science and Technology, Xidian University

  parent reply	other threads:[~2024-01-26 18:22 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-26 13:55 Lulu Cai
2024-01-26 13:55 ` [PATCH 2/2] LoongArch: Fix some test cases for TLS transition and relax Lulu Cai
2024-01-26 18:22 ` Xi Ruoyao [this message]
2024-01-27  2:06   ` [PATCH 1/2] LoongArch: Delete extra instructions when TLS type transition Lulu Cai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f75d5c73fb178517863368bb684f763d9d6a9a94.camel@xry111.site \
    --to=xry111@xry111.site \
    --cc=binutils@sourceware.org \
    --cc=cailulu@loongson.cn \
    --cc=chenglulu@loongson.cn \
    --cc=hejinyang@loongson.cn \
    --cc=i.swmail@xen0n.name \
    --cc=liuzhensong@loongson.cn \
    --cc=luweining@loongson.cn \
    --cc=maskray@google.com \
    --cc=mengqinggang@loongson.cn \
    --cc=wanglei@loongson.cn \
    --cc=xuchenghua@loongson.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).