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: garbage collect debug sections when no alloc sections are kept


On Thu, May 18, 2017 at 6:36 AM, Alan Modra <amodra@gmail.com> wrote:
> The pr20882 testcase fails on a number of targets that add attribute
> or note sections to object files, and the default linker script says
> those sections should be kept.  This patch changes --gc-sections to
> drop debug and special sections like .comment when no SEC_ALLOC
> section in an object file is kept.  The assumption is that debug
> sections are describing code and data that will become part of the
> final image in memory.
>
> Does this seem reasonable?  I can think of situations where the
> heuristic will fail, for instance when an object file has .text.foo
> that isn't alloc due to a luser getting a .section directive wrong.
> That text section would normally become part of the alloc .text
> output, but we can't test the output because garbage collection runs
> before mapping input sections to output.  I'm not so worried about
> that case but whether I might be overlooking some target wrinkle
> regarding non-alloc sections and debug..
>
> Will commit tomorrow if no one points out a problem.  Cures all the
> pr20882 fails except for crx and xgate, which have broken relocation
> addend processing.
>
>         * elflink.c (_bfd_elf_gc_mark_extra_sections): Don't keep
>         debug and special sections when no alloc sections in an object
>         are kept.
>
> diff --git a/bfd/elflink.c b/bfd/elflink.c
> index 387c6fd..b03dc47 100644
> --- a/bfd/elflink.c
> +++ b/bfd/elflink.c
> @@ -12961,7 +12961,7 @@ _bfd_elf_gc_mark_extra_sections (struct bfd_link_info *info,
>         {
>           if ((isec->flags & SEC_LINKER_CREATED) != 0)
>             isec->gc_mark = 1;
> -         else if (isec->gc_mark)
> +         else if (isec->gc_mark && (isec->flags & SEC_ALLOC) != 0)
>             some_kept = TRUE;
>
>           if (!debug_frag_seen
> @@ -12970,7 +12970,7 @@ _bfd_elf_gc_mark_extra_sections (struct bfd_link_info *info,
>             debug_frag_seen = TRUE;
>         }
>

This doesn't work on .note.gnu.property section since it has SEC_ALLOC:

[hjl@gnu-6 pr20882b]$ cat t1.s
.text
.globl  main
.type   main, %function
main:
.byte 0
[hjl@gnu-6 pr20882b]$ cat t2.s
.section .debug_info,"",%progbits
.hidden t.c.4903c230
.globl t.c.4903c230
t.c.4903c230:
.byte 0x28

.section ".note.gnu.property", "a"
.p2align 3
.long 1f - 0f /* name length.  */
.long 3f - 2f /* data length.  */
/* NT_GNU_PROPERTY_TYPE_0 */
.long 5 /* note type.  */
0: .asciz "GNU" /* vendor name.  */
1: .p2align 3
2:
/* GNU_PROPERTY_NO_COPY_ON_PROTECTED */
.long 2 /* pr_type.  */
.long 0 /* pr_datasz.  */
.p2align 3
3:
[hjl@gnu-6 pr20882b]$ make
as   -o t1.o t1.s
as   -o t2.o t2.s
./ld --gc-sections --entry=main -o x t1.o t2.o
readelf -x .debug_info x

Hex dump of section '.debug_info':
  0x00000000 28                                  (

[hjl@gnu-6 pr20882b]$



-- 
H.J.


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