LoongArch: Fix a bug of getting relocation type

Message ID 20240126033932.3577932-1-mengqinggang@loongson.cn
State Unresolved
Headers
Series LoongArch: Fix a bug of getting relocation type |

Checks

Context Check Description
snail/binutils-gdb-check warning Git am fail log

Commit Message

mengqinggang Jan. 26, 2024, 3:39 a.m. UTC
  The old code works because R_LARCH_RELAX has no symbol index. It causes
'(rel + 1)->r_info == R_LARCH_RELAX' is 1 and ELFNN_R_TYPE (1) is 1.
---
 bfd/elfnn-loongarch.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

mengqinggang Jan. 26, 2024, 9:01 a.m. UTC | #1
Hi Nick,

This patch and

969f5c0e1        LoongArch: gas: Add support for s9 register
a0aa6f4ab        LoongArch: ld: Add support for TLS LE symbol with addend

need to apply to 2.42 branch.


在 2024/1/26 上午11:39, mengqinggang 写道:
> The old code works because R_LARCH_RELAX has no symbol index. It causes
> '(rel + 1)->r_info == R_LARCH_RELAX' is 1 and ELFNN_R_TYPE (1) is 1.
> ---
>   bfd/elfnn-loongarch.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/bfd/elfnn-loongarch.c b/bfd/elfnn-loongarch.c
> index b2caa5fc3e1..0cc6273726c 100644
> --- a/bfd/elfnn-loongarch.c
> +++ b/bfd/elfnn-loongarch.c
> @@ -4166,7 +4166,7 @@ loongarch_relax_tls_le (bfd *abfd, asection *sec,
>     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))
> +  if (ELFNN_R_TYPE ((rel + 1)->r_info) == R_LARCH_RELAX && (symval < 0x800))
>       {
>         switch (ELFNN_R_TYPE (rel->r_info))
>   	{
  
Nick Clifton Jan. 26, 2024, 10:55 a.m. UTC | #2
Hi mengqinggang,

> This patch and
> 
> 969f5c0e1        LoongArch: gas: Add support for s9 register
> a0aa6f4ab        LoongArch: ld: Add support for TLS LE symbol with addend
> 
> need to apply to 2.42 branch.

Applied.

I am hoping that this is the last of these as I am planning on creating the
release on Monday, and I am always worried that last minute changes will
bring in new bugs rather than fix old ones...

Cheers
   Nick
  
Xi Ruoyao Jan. 26, 2024, 11:02 a.m. UTC | #3
On Fri, 2024-01-26 at 10:55 +0000, Nick Clifton wrote:
> Hi mengqinggang,
> 
> > This patch and
> > 
> > 969f5c0e1        LoongArch: gas: Add support for s9 register
> > a0aa6f4ab        LoongArch: ld: Add support for TLS LE symbol with addend
> > 
> > need to apply to 2.42 branch.
> 
> Applied.
> 
> I am hoping that this is the last of these as I am planning on creating the
> release on Monday, and I am always worried that last minute changes will
> bring in new bugs rather than fix old ones...

Pity that we still have the __thread vs. -mcmodel=extreme issue
(https://sourceware.org/pipermail/binutils/2024-January/132120.html and
all the following discussion) not resolved yet.

Possible to apply my straightforward (stupid) "fix" for 2.42 if a proper
fix cannot be made soon?
  
Nick Clifton Jan. 26, 2024, 11:41 a.m. UTC | #4
Hi Xi,

>> I am hoping that this is the last of these as I am planning on creating the
>> release on Monday, and I am always worried that last minute changes will
>> bring in new bugs rather than fix old ones...
> 
> Pity that we still have the __thread vs. -mcmodel=extreme issue
> (https://sourceware.org/pipermail/binutils/2024-January/132120.html and
> all the following discussion) not resolved yet.
> 
> Possible to apply my straightforward (stupid) "fix" for 2.42 if a proper
> fix cannot be made soon?

Yes.  Please let me know, before Monday, which patch you want to use.

Cheers
   Nick
  
Lulu Cai Jan. 27, 2024, 1:37 p.m. UTC | #5
On 1/26/24 7:02 PM, Xi Ruoyao wrote:
> On Fri, 2024-01-26 at 10:55 +0000, Nick Clifton wrote:
>> Hi mengqinggang,
>>
>>> This patch and
>>>
>>> 969f5c0e1        LoongArch: gas: Add support for s9 register
>>> a0aa6f4ab        LoongArch: ld: Add support for TLS LE symbol with addend
>>>
>>> need to apply to 2.42 branch.
>> Applied.
>>
>> I am hoping that this is the last of these as I am planning on creating the
>> release on Monday, and I am always worried that last minute changes will
>> bring in new bugs rather than fix old ones...
> Pity that we still have the __thread vs. -mcmodel=extreme issue
> (https://sourceware.org/pipermail/binutils/2024-January/132120.html and
> all the following discussion) not resolved yet.
>
> Possible to apply my straightforward (stupid) "fix" for 2.42 if a proper
> fix cannot be made soon?
>

Hi,
We have sent a new patch to fix the incorrect type transition problem 
caused by -mcmodel=extreme.
Now only TLS type transition will be performed for normal.
[PATCH 1/2] LoongArch: Fix incorrect type transition under extreme cmodel
[PATCH 2/2] LoongArch: update test cases about TLS

Can you help us merge it into the 2.42 branch?
Thanks.

Related discussions:
[PATCH] LoongArch: Disallow TLS transition when a section contains 
TLS_IE64 or TLS_DESC64 reloc
  
Lulu Cai Jan. 28, 2024, 4:14 a.m. UTC | #6
On 1/27/2024 9:37 PM, Lulu Cai wrote:
> On 1/26/24 7:02 PM, Xi Ruoyao wrote:
>> On Fri, 2024-01-26 at 10:55 +0000, Nick Clifton wrote:
>>> Hi mengqinggang,
>>>
>>>> This patch and
>>>>
>>>> 969f5c0e1        LoongArch: gas: Add support for s9 register
>>>> a0aa6f4ab        LoongArch: ld: Add support for TLS LE symbol with 
>>>> addend
>>>>
>>>> need to apply to 2.42 branch.
>>> Applied.
>>>
>>> I am hoping that this is the last of these as I am planning on 
>>> creating the
>>> release on Monday, and I am always worried that last minute changes 
>>> will
>>> bring in new bugs rather than fix old ones...
>> Pity that we still have the __thread vs. -mcmodel=extreme issue
>> (https://sourceware.org/pipermail/binutils/2024-January/132120.html and
>> all the following discussion) not resolved yet.
>>
>> Possible to apply my straightforward (stupid) "fix" for 2.42 if a proper
>> fix cannot be made soon?
>>
>
> Hi,
> We have sent a new patch to fix the incorrect type transition problem 
> caused by -mcmodel=extreme.
> Now only TLS type transition will be performed for normal.
> [PATCH 1/2] LoongArch: Fix incorrect type transition under extreme cmodel
> [PATCH 2/2] LoongArch: update test cases about TLS
>

  Here is a link to the relevant patch.

https://sourceware.org/pipermail/binutils/2024-January/132194.html

https://sourceware.org/pipermail/binutils/2024-January/132195.html


> Can you help us merge it into the 2.42 branch?
> Thanks.
>
> Related discussions:
> [PATCH] LoongArch: Disallow TLS transition when a section contains 
> TLS_IE64 or TLS_DESC64 reloc
  
Nick Clifton Jan. 29, 2024, 11:24 a.m. UTC | #7
Hi lulu Tsai,

>   Here is a link to the relevant patch.
> 
> https://sourceware.org/pipermail/binutils/2024-January/132194.html
> https://sourceware.org/pipermail/binutils/2024-January/132195.html

Thanks for the links.  Both of these patches are now in the 2.42 branch.  Just in time! :-)

Cheers
   Nick
  

Patch

diff --git a/bfd/elfnn-loongarch.c b/bfd/elfnn-loongarch.c
index b2caa5fc3e1..0cc6273726c 100644
--- a/bfd/elfnn-loongarch.c
+++ b/bfd/elfnn-loongarch.c
@@ -4166,7 +4166,7 @@  loongarch_relax_tls_le (bfd *abfd, asection *sec,
   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))
+  if (ELFNN_R_TYPE ((rel + 1)->r_info) == R_LARCH_RELAX && (symval < 0x800))
     {
       switch (ELFNN_R_TYPE (rel->r_info))
 	{