[4/5] LoongArch: Remove "elf_seg_map (info->output_bfd) == NULL" relaxation condition

Message ID 20231013082445.290062-4-mengqinggang@loongson.cn
State New
Headers
Series [1/5] LoongArch: Fix ld --no-relax bug |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_binutils_check--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_binutils_check--master-arm success Testing passed
linaro-tcwg-bot/tcwg_binutils_build--master-arm success Testing passed
linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 success Testing passed

Commit Message

mengqinggang Oct. 13, 2023, 8:24 a.m. UTC
  ---
 bfd/elfnn-loongarch.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
  

Comments

Xi Ruoyao Oct. 19, 2023, 2:04 p.m. UTC | #1
Hi,

I don't know BFD very well, but IMO this should be applied and
backported to 2.41 ASAP because "not relaxing shared objects" is a very
serious issue.

On Fri, 2023-10-13 at 16:24 +0800, mengqinggang wrote:
> ---
>  bfd/elfnn-loongarch.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/bfd/elfnn-loongarch.c b/bfd/elfnn-loongarch.c
> index 47334943fde..38a25b63813 100644
> --- a/bfd/elfnn-loongarch.c
> +++ b/bfd/elfnn-loongarch.c
> @@ -3747,6 +3747,11 @@ loongarch_relax_pcala_addi (bfd *abfd, asection *sec,
>    uint32_t pca = bfd_get (32, abfd, contents + rel_hi->r_offset);
>    uint32_t add = bfd_get (32, abfd, contents + rel_lo->r_offset);
>    uint32_t rd = pca & 0x1f;
> +
> +  /* Because previous sections' relax, output_offset may increase and need to
> +     be updated before relax. But it update after relax in
> +     size_input_section defaultly, so we manually updating here.  */
> +  sec->output_offset = sec->output_section->size;
>    bfd_vma pc = sec_addr (sec) + rel_hi->r_offset;
>    const uint32_t addi_d = 0x02c00000;
>    const uint32_t pcaddi = 0x18000000;
> @@ -3889,7 +3894,6 @@ loongarch_elf_relax_section (bfd *abfd, asection *sec,
>        || sec->sec_flg0
>        || (sec->flags & SEC_RELOC) == 0
>        || sec->reloc_count == 0
> -      || elf_seg_map (info->output_bfd) == NULL
>        || (info->disable_target_specific_optimizations
>  	  && info->relax_pass == 0)
>        /* The exp_seg_relro_adjust is enum phase_enum (0x4),
  
Xi Ruoyao Oct. 30, 2023, 5:14 a.m. UTC | #2
Ping.

Is there any reason holding this patch?

On Thu, 2023-10-19 at 22:04 +0800, Xi Ruoyao wrote:
> Hi,
> 
> I don't know BFD very well, but IMO this should be applied and
> backported to 2.41 ASAP because "not relaxing shared objects" is a
> very
> serious issue.
> 
> On Fri, 2023-10-13 at 16:24 +0800, mengqinggang wrote:
> > ---
> >  bfd/elfnn-loongarch.c | 6 +++++-
> >  1 file changed, 5 insertions(+), 1 deletion(-)
> > 
> > diff --git a/bfd/elfnn-loongarch.c b/bfd/elfnn-loongarch.c
> > index 47334943fde..38a25b63813 100644
> > --- a/bfd/elfnn-loongarch.c
> > +++ b/bfd/elfnn-loongarch.c
> > @@ -3747,6 +3747,11 @@ loongarch_relax_pcala_addi (bfd *abfd,
> > asection *sec,
> >    uint32_t pca = bfd_get (32, abfd, contents + rel_hi->r_offset);
> >    uint32_t add = bfd_get (32, abfd, contents + rel_lo->r_offset);
> >    uint32_t rd = pca & 0x1f;
> > +
> > +  /* Because previous sections' relax, output_offset may increase
> > and need to
> > +     be updated before relax. But it update after relax in
> > +     size_input_section defaultly, so we manually updating here. 
> > */
> > +  sec->output_offset = sec->output_section->size;
> >    bfd_vma pc = sec_addr (sec) + rel_hi->r_offset;
> >    const uint32_t addi_d = 0x02c00000;
> >    const uint32_t pcaddi = 0x18000000;
> > @@ -3889,7 +3894,6 @@ loongarch_elf_relax_section (bfd *abfd,
> > asection *sec,
> >        || sec->sec_flg0
> >        || (sec->flags & SEC_RELOC) == 0
> >        || sec->reloc_count == 0
> > -      || elf_seg_map (info->output_bfd) == NULL
> >        || (info->disable_target_specific_optimizations
> >  	  && info->relax_pass == 0)
> >        /* The exp_seg_relro_adjust is enum phase_enum (0x4),
>
  
mengqinggang Oct. 30, 2023, 8 a.m. UTC | #3
There are still some other modifications that need to be addend,
and prepare to test whether a clfs system can be successfully compiled.


在 2023/10/30 下午1:14, Xi Ruoyao 写道:
> Ping.
>
> Is there any reason holding this patch?
>
> On Thu, 2023-10-19 at 22:04 +0800, Xi Ruoyao wrote:
>> Hi,
>>
>> I don't know BFD very well, but IMO this should be applied and
>> backported to 2.41 ASAP because "not relaxing shared objects" is a
>> very
>> serious issue.
>>
>> On Fri, 2023-10-13 at 16:24 +0800, mengqinggang wrote:
>>> ---
>>>   bfd/elfnn-loongarch.c | 6 +++++-
>>>   1 file changed, 5 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/bfd/elfnn-loongarch.c b/bfd/elfnn-loongarch.c
>>> index 47334943fde..38a25b63813 100644
>>> --- a/bfd/elfnn-loongarch.c
>>> +++ b/bfd/elfnn-loongarch.c
>>> @@ -3747,6 +3747,11 @@ loongarch_relax_pcala_addi (bfd *abfd,
>>> asection *sec,
>>>     uint32_t pca = bfd_get (32, abfd, contents + rel_hi->r_offset);
>>>     uint32_t add = bfd_get (32, abfd, contents + rel_lo->r_offset);
>>>     uint32_t rd = pca & 0x1f;
>>> +
>>> +  /* Because previous sections' relax, output_offset may increase
>>> and need to
>>> +     be updated before relax. But it update after relax in
>>> +     size_input_section defaultly, so we manually updating here.
>>> */
>>> +  sec->output_offset = sec->output_section->size;
>>>     bfd_vma pc = sec_addr (sec) + rel_hi->r_offset;
>>>     const uint32_t addi_d = 0x02c00000;
>>>     const uint32_t pcaddi = 0x18000000;
>>> @@ -3889,7 +3894,6 @@ loongarch_elf_relax_section (bfd *abfd,
>>> asection *sec,
>>>         || sec->sec_flg0
>>>         || (sec->flags & SEC_RELOC) == 0
>>>         || sec->reloc_count == 0
>>> -      || elf_seg_map (info->output_bfd) == NULL
>>>         || (info->disable_target_specific_optimizations
>>>   	  && info->relax_pass == 0)
>>>         /* The exp_seg_relro_adjust is enum phase_enum (0x4),
  
Xi Ruoyao Nov. 16, 2023, 12:03 a.m. UTC | #4
On Mon, 2023-10-30 at 16:00 +0800, mengqinggang wrote:
> There are still some other modifications that need to be addend,
> and prepare to test whether a clfs system can be successfully
> compiled.

Ping again.  We are very close to the end of GCC 14 stage 1, and we need
to determine if we should default to -mno-relax for -fpic (i. e.
disabling relaxation for anything that may be used in a shared object).
Silently producing broken shared object is not acceptable.

> 在 2023/10/30 下午1:14, Xi Ruoyao 写道:
> > Ping.
> > 
> > Is there any reason holding this patch?
> > 
> > On Thu, 2023-10-19 at 22:04 +0800, Xi Ruoyao wrote:
> > > Hi,
> > > 
> > > I don't know BFD very well, but IMO this should be applied and
> > > backported to 2.41 ASAP because "not relaxing shared objects" is a
> > > very
> > > serious issue.
> > > 
> > > On Fri, 2023-10-13 at 16:24 +0800, mengqinggang wrote:
> > > > ---
> > > >   bfd/elfnn-loongarch.c | 6 +++++-
> > > >   1 file changed, 5 insertions(+), 1 deletion(-)
> > > > 
> > > > diff --git a/bfd/elfnn-loongarch.c b/bfd/elfnn-loongarch.c
> > > > index 47334943fde..38a25b63813 100644
> > > > --- a/bfd/elfnn-loongarch.c
> > > > +++ b/bfd/elfnn-loongarch.c
> > > > @@ -3747,6 +3747,11 @@ loongarch_relax_pcala_addi (bfd *abfd,
> > > > asection *sec,
> > > >     uint32_t pca = bfd_get (32, abfd, contents + rel_hi->r_offset);
> > > >     uint32_t add = bfd_get (32, abfd, contents + rel_lo->r_offset);
> > > >     uint32_t rd = pca & 0x1f;
> > > > +
> > > > +  /* Because previous sections' relax, output_offset may increase
> > > > and need to
> > > > +     be updated before relax. But it update after relax in
> > > > +     size_input_section defaultly, so we manually updating here.
> > > > */
> > > > +  sec->output_offset = sec->output_section->size;
> > > >     bfd_vma pc = sec_addr (sec) + rel_hi->r_offset;
> > > >     const uint32_t addi_d = 0x02c00000;
> > > >     const uint32_t pcaddi = 0x18000000;
> > > > @@ -3889,7 +3894,6 @@ loongarch_elf_relax_section (bfd *abfd,
> > > > asection *sec,
> > > >         || sec->sec_flg0
> > > >         || (sec->flags & SEC_RELOC) == 0
> > > >         || sec->reloc_count == 0
> > > > -      || elf_seg_map (info->output_bfd) == NULL
> > > >         || (info->disable_target_specific_optimizations
> > > >   	  && info->relax_pass == 0)
> > > >         /* The exp_seg_relro_adjust is enum phase_enum (0x4),
>
  
mengqinggang Nov. 16, 2023, 2:06 a.m. UTC | #5
I will send a new patch today, it fix some bugs caused by address changed.


在 2023/11/16 上午8:03, Xi Ruoyao 写道:
> On Mon, 2023-10-30 at 16:00 +0800, mengqinggang wrote:
>> There are still some other modifications that need to be addend,
>> and prepare to test whether a clfs system can be successfully
>> compiled.
> Ping again.  We are very close to the end of GCC 14 stage 1, and we need
> to determine if we should default to -mno-relax for -fpic (i. e.
> disabling relaxation for anything that may be used in a shared object).
> Silently producing broken shared object is not acceptable.
>
>> 在 2023/10/30 下午1:14, Xi Ruoyao 写道:
>>> Ping.
>>>
>>> Is there any reason holding this patch?
>>>
>>> On Thu, 2023-10-19 at 22:04 +0800, Xi Ruoyao wrote:
>>>> Hi,
>>>>
>>>> I don't know BFD very well, but IMO this should be applied and
>>>> backported to 2.41 ASAP because "not relaxing shared objects" is a
>>>> very
>>>> serious issue.
>>>>
>>>> On Fri, 2023-10-13 at 16:24 +0800, mengqinggang wrote:
>>>>> ---
>>>>>    bfd/elfnn-loongarch.c | 6 +++++-
>>>>>    1 file changed, 5 insertions(+), 1 deletion(-)
>>>>>
>>>>> diff --git a/bfd/elfnn-loongarch.c b/bfd/elfnn-loongarch.c
>>>>> index 47334943fde..38a25b63813 100644
>>>>> --- a/bfd/elfnn-loongarch.c
>>>>> +++ b/bfd/elfnn-loongarch.c
>>>>> @@ -3747,6 +3747,11 @@ loongarch_relax_pcala_addi (bfd *abfd,
>>>>> asection *sec,
>>>>>      uint32_t pca = bfd_get (32, abfd, contents + rel_hi->r_offset);
>>>>>      uint32_t add = bfd_get (32, abfd, contents + rel_lo->r_offset);
>>>>>      uint32_t rd = pca & 0x1f;
>>>>> +
>>>>> +  /* Because previous sections' relax, output_offset may increase
>>>>> and need to
>>>>> +     be updated before relax. But it update after relax in
>>>>> +     size_input_section defaultly, so we manually updating here.
>>>>> */
>>>>> +  sec->output_offset = sec->output_section->size;
>>>>>      bfd_vma pc = sec_addr (sec) + rel_hi->r_offset;
>>>>>      const uint32_t addi_d = 0x02c00000;
>>>>>      const uint32_t pcaddi = 0x18000000;
>>>>> @@ -3889,7 +3894,6 @@ loongarch_elf_relax_section (bfd *abfd,
>>>>> asection *sec,
>>>>>          || sec->sec_flg0
>>>>>          || (sec->flags & SEC_RELOC) == 0
>>>>>          || sec->reloc_count == 0
>>>>> -      || elf_seg_map (info->output_bfd) == NULL
>>>>>          || (info->disable_target_specific_optimizations
>>>>>    	  && info->relax_pass == 0)
>>>>>          /* The exp_seg_relro_adjust is enum phase_enum (0x4),
  

Patch

diff --git a/bfd/elfnn-loongarch.c b/bfd/elfnn-loongarch.c
index 47334943fde..38a25b63813 100644
--- a/bfd/elfnn-loongarch.c
+++ b/bfd/elfnn-loongarch.c
@@ -3747,6 +3747,11 @@  loongarch_relax_pcala_addi (bfd *abfd, asection *sec,
   uint32_t pca = bfd_get (32, abfd, contents + rel_hi->r_offset);
   uint32_t add = bfd_get (32, abfd, contents + rel_lo->r_offset);
   uint32_t rd = pca & 0x1f;
+
+  /* Because previous sections' relax, output_offset may increase and need to
+     be updated before relax. But it update after relax in
+     size_input_section defaultly, so we manually updating here.  */
+  sec->output_offset = sec->output_section->size;
   bfd_vma pc = sec_addr (sec) + rel_hi->r_offset;
   const uint32_t addi_d = 0x02c00000;
   const uint32_t pcaddi = 0x18000000;
@@ -3889,7 +3894,6 @@  loongarch_elf_relax_section (bfd *abfd, asection *sec,
       || sec->sec_flg0
       || (sec->flags & SEC_RELOC) == 0
       || sec->reloc_count == 0
-      || elf_seg_map (info->output_bfd) == NULL
       || (info->disable_target_specific_optimizations
 	  && info->relax_pass == 0)
       /* The exp_seg_relro_adjust is enum phase_enum (0x4),