From 1e0e90651b33809ff9bad9620ed2d6666b3fcf3a Mon Sep 17 00:00:00 2001 From: Nick Clifton Date: Wed, 26 Aug 2009 13:08:07 +0000 Subject: [PATCH] PR ld/10555 * emultempl/elf32.em (_after_open): Do not create a .note.gnu-build-id section if there are no input files. --- ld/ChangeLog | 6 ++++++ ld/emultempl/elf32.em | 53 +++++++++++++++++++++++++++++++-------------------- 2 files changed, 38 insertions(+), 21 deletions(-) diff --git a/ld/ChangeLog b/ld/ChangeLog index 49d2d6dfa..a24bbca88 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,3 +1,9 @@ +2009-08-26 Nick Clifton + + PR ld/10555 + * emultempl/elf32.em (_after_open): Do not create a + .note.gnu-build-id section if there are no input files. + 2009-08-24 Nick Clifton * scripttempl/elfxtensa.sc (DISCARDED): Discard sections with diff --git a/ld/emultempl/elf32.em b/ld/emultempl/elf32.em index cd7f2d4e3..534a69c2c 100644 --- a/ld/emultempl/elf32.em +++ b/ld/emultempl/elf32.em @@ -1049,37 +1049,48 @@ gld${EMULATION_NAME}_after_open (void) abfd = link_info.input_bfds; - size = gld${EMULATION_NAME}_id_note_section_size (abfd, &link_info); - if (size == 0) + if (abfd == NULL) { - einfo ("%P: warning: unrecognized --build-id style ignored.\n"); + /* PR 10555: If there are no input files do not + try to create a .note.gnu-build-id section. */ free (link_info.emit_note_gnu_build_id); link_info.emit_note_gnu_build_id = NULL; } else { - s = bfd_make_section_with_flags (abfd, ".note.gnu.build-id", - SEC_ALLOC | SEC_LOAD - | SEC_IN_MEMORY | SEC_LINKER_CREATED - | SEC_READONLY | SEC_DATA); - if (s != NULL && bfd_set_section_alignment (abfd, s, 2)) + size = gld${EMULATION_NAME}_id_note_section_size (abfd, &link_info); + if (size == 0) { - struct elf_obj_tdata *t = elf_tdata (link_info.output_bfd); - struct build_id_info *b = xmalloc (sizeof *b); - b->style = link_info.emit_note_gnu_build_id; - b->sec = s; - elf_section_type (s) = SHT_NOTE; - s->size = size; - t->after_write_object_contents - = &gld${EMULATION_NAME}_write_build_id_section; - t->after_write_object_contents_info = b; + einfo ("%P: warning: unrecognized --build-id style ignored.\n"); + free (link_info.emit_note_gnu_build_id); + link_info.emit_note_gnu_build_id = NULL; } else { - einfo ("%P: warning: Cannot create .note.gnu.build-id section," - " --build-id ignored.\n"); - free (link_info.emit_note_gnu_build_id); - link_info.emit_note_gnu_build_id = NULL; + s = bfd_make_section_with_flags (abfd, ".note.gnu.build-id", + SEC_ALLOC | SEC_LOAD + | SEC_IN_MEMORY | SEC_LINKER_CREATED + | SEC_READONLY | SEC_DATA); + if (s != NULL && bfd_set_section_alignment (abfd, s, 2)) + { + struct elf_obj_tdata *t = elf_tdata (link_info.output_bfd); + struct build_id_info *b = xmalloc (sizeof *b); + + b->style = link_info.emit_note_gnu_build_id; + b->sec = s; + elf_section_type (s) = SHT_NOTE; + s->size = size; + t->after_write_object_contents + = &gld${EMULATION_NAME}_write_build_id_section; + t->after_write_object_contents_info = b; + } + else + { + einfo ("%P: warning: Cannot create .note.gnu.build-id section," + " --build-id ignored.\n"); + free (link_info.emit_note_gnu_build_id); + link_info.emit_note_gnu_build_id = NULL; + } } } } -- 2.11.4.GIT