elf: Discard input .note.gnu.build-id sections
authorH.J. Lu <hjl.tools@gmail.com>
Wed, 1 Dec 2021 04:40:38 +0000 (20:40 -0800)
committerH.J. Lu <hjl.tools@gmail.com>
Thu, 2 Dec 2021 00:40:43 +0000 (16:40 -0800)
commit1f1d0f8888a6c944e612b416a2a6e11abcf5199f
treec92392d84e68d9335fb7fbd23f075ad1cfb0f449
parentb18c2bb9f30eda51609cf3d2277960fc03920650
elf: Discard input .note.gnu.build-id sections

1. Discard input .note.gnu.build-id sections.
2. Clear the build ID field before writing.
3. Use bfd_make_section_anyway_with_flags to create the output
.note.gnu.build-id section.

PR ld/28639
* ldelf.c (ldelf_after_open): Discard input .note.gnu.build-id
sections, excluding the first one.
(write_build_id): Clear the build ID field before writing.
(ldelf_setup_build_id): Use bfd_make_section_anyway_with_flags
to create the output .note.gnu.build-id section.
* testsuite/ld-elf/build-id.exp: New file.
* testsuite/ld-elf/pr28639a.rd: Likewise.
* testsuite/ld-elf/pr28639b.rd: Likewise.
* testsuite/ld-elf/pr28639c.rd: Likewise.
* testsuite/ld-elf/pr28639d.rd: Likewise.
ld/ldelf.c
ld/testsuite/ld-elf/build-id.exp [new file with mode: 0644]
ld/testsuite/ld-elf/pr28639a.rd [new file with mode: 0644]
ld/testsuite/ld-elf/pr28639b.rd [new file with mode: 0644]
ld/testsuite/ld-elf/pr28639c.rd [new file with mode: 0644]
ld/testsuite/ld-elf/pr28639d.rd [new file with mode: 0644]