This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Always keep sections marked with SEC_KEEP


On Thu, Oct 22, 2015 at 4:51 PM, Alan Modra <amodra@gmail.com> wrote:
> On Thu, Oct 22, 2015 at 12:24:53PM -0700, H.J. Lu wrote:
>> diff --git a/bfd/elflink.c b/bfd/elflink.c
>> index 73fe469..06df821 100644
>> --- a/bfd/elflink.c
>> +++ b/bfd/elflink.c
>> @@ -12449,7 +12449,8 @@ elf_gc_sweep (bfd *abfd, struct bfd_link_info *info)
>>             o->gc_mark = first->gc_mark;
>>           }
>>
>> -       if (o->gc_mark)
>> +       /* Always keep sections marked with SEC_KEEP.  */
>> +       if (o->gc_mark || (o->flags & SEC_KEEP))
>>           continue;
>>
>>         /* Skip sweeping sections already excluded.  */
>
> This is wrong.  You're breaking the gc-sections model (and ignoring
> the special combination of both SEC_EXCLUDE and SEC_KEEP).  Sections
> with SEC_KEEP are supposed to have gc_mark set by the call to
> _bfd_elf_gc_mark in bfd_elf_gc_sections.

Do you have a testcase to show the regression my patch caused?
After my patch, the code was

          /* Always keep sections marked with SEC_KEEP.  */
          if (o->gc_mark || (o->flags & SEC_KEEP))
            continue;

          /* Skip sweeping sections already excluded.  */
          if (o->flags & SEC_EXCLUDE)
            continue;

If both SEC_EXCLUDE and SEC_KEEP are set, my patch doesn't
change the behavior of  elf_gc_sweep.

> Hmm, actually the underlying problem is your PR11133 patch.
> _bfd_elf_gc_mark_rsec is too late to be setting SEC_KEEP.
>
>         PR ld/11133
>         PR ld/19161
>         * elflink.c (elf_gc_sweep): Revert last patch.
>         (_bfd_elf_gc_mark_hook): Don't set SEC_KEEP here.
>
> diff --git a/bfd/elflink.c b/bfd/elflink.c
> index 2ed07e0..0bec93d 100644
> --- a/bfd/elflink.c
> +++ b/bfd/elflink.c
> @@ -12109,7 +12109,7 @@ _bfd_elf_gc_mark_hook (asection *sec,
>                 {
>                   sec = bfd_get_section_by_name (i, sec_name);
>                   if (sec)
> -                   sec->flags |= SEC_KEEP;
> +                   return sec;
>                 }
>             }
>           break;
> @@ -12457,8 +12457,7 @@ elf_gc_sweep (bfd *abfd, struct bfd_link_info *info)
>               o->gc_mark = first->gc_mark;
>             }
>
> -         /* Always keep sections marked with SEC_KEEP.  */
> -         if (o->gc_mark || (o->flags & SEC_KEEP))
> +         if (o->gc_mark)
>             continue;
>
>           /* Skip sweeping sections already excluded.  */
> --
> Alan Modra
> Australia Development Lab, IBM



-- 
H.J.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]