Drop empty .relr.dyn from segments given by PHDRS
Binutils linker now correctly excludes empty .relr.dyn section from segments when using PHDRS.
This commit ensures that the Binutils linker correctly excludes empty .relr.dyn sections from segments when program headers (PHDRS) are used. Previously, this section could remain in a segment, causing issues with segment sizing and reporting, especially when relative relocations were not needed.
In Details
When using -z pack-relative-relocs and PHDRS in the linker script, an empty .relr.dyn section could cause problems. The _bfd_elf_x86_size_relative_relocs function removed the section but did not mark it as SEC_EXCLUDE. This prevented elf_modify_segment_map from dropping it from the segment map derived from PHDRS. This change adds the SEC_EXCLUDE flag before removing the section, aligning its behavior with other output section stripping mechanisms and fixing issues with segment sizing and reporting.
- .relr.dyn
- A section in ELF binaries that contains relative relocation entries. These are used to adjust addresses at runtime, often for Position-Independent Executables (PIE).
- PHDRS
- Program Headers in an ELF file, which describe how the segments of the program should be mapped into memory. They are used by the operating system to load and run the executable.
- linker script
- A file that controls the output of the linker, specifying how input sections should be arranged into output sections and segments.
- SEC_EXCLUDE
- A flag associated with a section in Binutils' internal representation, indicating that the section should not be included in the final output or mapped into memory.