Bug 25849 - Many ELF backends generate zero-sized sections
Summary: Many ELF backends generate zero-sized sections
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.35
: P2 normal
Target Milestone: 2.35
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-04-18 12:59 UTC by H.J. Lu
Modified: 2023-01-23 16:35 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
A patch (627 bytes, patch)
2020-04-18 12:59 UTC, H.J. Lu
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description H.J. Lu 2020-04-18 12:59:03 UTC
Created attachment 12482 [details]
A patch

The enclosed patch triggers many linker test failures for multiple ELF
targets.  For alpha-linux:

readelf: Warning: Section '.rela.plt': zero-sized relocation section

FAIL: TLS -fpic and -fno-pic exec -relax


  [ 6] .rela.plt         RELA            00000001200002a8 0002a8 000000 18  AI  3   7  8
  [ 7] .plt              PROGBITS        00000001200002b0 0002b0 000000 00  AX  0   0 16

There are 2 zero-sized sections.
Comment 1 H.J. Lu 2020-04-18 13:21:05 UTC
After bfd_elf_size_dynamic_sections is called, dynamic sections can
change.
Comment 2 Sourceware Commits 2020-04-21 12:26:29 UTC
The master branch has been updated by H.J. Lu <hjl@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=6f6fd151cbf226bbaa66e44977f57b7c6dc33d89

commit 6f6fd151cbf226bbaa66e44977f57b7c6dc33d89
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Tue Apr 21 05:23:51 2020 -0700

    elf: Strip zero-sized dynamic sections
    
    ELF size_dynamic_sections is called by the ELF backend linker after all
    the linker input files have been seen but before the section sizes have
    been set.  After the sections sizes have been set, target-specific,
    global optimizations may make some dynamic sections zero-sized if they
    are no longer needed.
    
    Add ELF strip_zero_sized_dynamic_sections so that ELF backend linker can
    strip zero-sized dynamic sections after the sections sizes have been set.
    
    bfd/
    
            PR ld/25849
            * elf-bfd.h (elf_backend_data): Add
            elf_backend_strip_zero_sized_dynamic_sections.
            (_bfd_elf_strip_zero_sized_dynamic_sections): New prototype.
            * elf64-alpha.c (elf_backend_strip_zero_sized_dynamic_sections):
            New macro.
            * elflink.c (_bfd_elf_strip_zero_sized_dynamic_sections): New
            function.
            * elfxx-target.h (elf_backend_strip_zero_sized_dynamic_sections):
            New macro.
            (elfNN_bed): Add elf_backend_strip_zero_sized_dynamic_sections.
    
    ld/
    
            PR ld/25849
            * ldelfgen.c (ldelf_map_segments): Call
            elf_backend_strip_zero_sized_dynamic_sections.
            * testsuite/ld-alpha/tlsbinr.rd: Updated.
Comment 3 H.J. Lu 2023-01-23 16:35:27 UTC
Fixed.