This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [PATCH] Always keep sections marked with SEC_KEEP
- From: Alan Modra <amodra at gmail dot com>
- To: "H.J. Lu" <hjl dot tools at gmail dot com>
- Cc: binutils at sourceware dot org
- Date: Fri, 23 Oct 2015 10:21:57 +1030
- Subject: Re: [PATCH] Always keep sections marked with SEC_KEEP
- Authentication-results: sourceware.org; auth=none
- References: <1445541893-8228-1-git-send-email-hjl dot tools at gmail dot com>
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.
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