From: H.J. Lu Date: Thu, 21 Apr 2016 00:06:58 +0000 (-0700) Subject: Move ELF relocation check after lang_gc_sections X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=fbf05aa70d7a6ad3dd92ca718faa4bb383b975ee;p=binutils-gdb.git Move ELF relocation check after lang_gc_sections Move ELF relocation check after lang_gc_sections so that all the reference counting code for plt and got relocs can be removed. This only affects ELF targets which check relocations after opening all input file. * ldlang.c (lang_check_relocs): New function. (lang_process): Call lang_check_relocs after lang_gc_sections. * emultempl/elf32.em (gld${EMULATION_NAME}_before_parse): Don't call _bfd_elf_link_check_relocs here. --- diff --git a/ld/ChangeLog b/ld/ChangeLog index 1963c17ebc4..07209d56d67 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,3 +1,10 @@ +2016-04-20 H.J. Lu + + * ldlang.c (lang_check_relocs): New function. + (lang_process): Call lang_check_relocs after lang_gc_sections. + * emultempl/elf32.em (gld${EMULATION_NAME}_before_parse): Don't + call _bfd_elf_link_check_relocs here. + 2016-04-20 H.J. Lu PR ld/19972 diff --git a/ld/emultempl/elf32.em b/ld/emultempl/elf32.em index 312f935e6a1..4f5d1a4d2c0 100644 --- a/ld/emultempl/elf32.em +++ b/ld/emultempl/elf32.em @@ -1026,20 +1026,6 @@ gld${EMULATION_NAME}_after_open (void) if (!is_elf_hash_table (htab)) return; - if (link_info.check_relocs_after_open_input) - { - bfd *abfd; - - for (abfd = link_info.input_bfds; - abfd != (bfd *) NULL; abfd = abfd->link.next) - if (!_bfd_elf_link_check_relocs (abfd, &link_info)) - { - /* no object output, fail return */ - config.make_executable = FALSE; - return; - } - } - if (emit_note_gnu_build_id != NULL) { bfd *abfd; diff --git a/ld/ldlang.c b/ld/ldlang.c index 856e3e268a6..2ae36409e28 100644 --- a/ld/ldlang.c +++ b/ld/ldlang.c @@ -6778,6 +6778,27 @@ lang_add_gc_name (const char * name) link_info.gc_sym_list = sym; } +/* Check relocations. */ + +static void +lang_check_relocs (void) +{ + if (link_info.check_relocs_after_open_input + && bfd_get_flavour (link_info.output_bfd) == bfd_target_elf_flavour) + { + bfd *abfd; + + for (abfd = link_info.input_bfds; + abfd != (bfd *) NULL; abfd = abfd->link.next) + if (!_bfd_elf_link_check_relocs (abfd, &link_info)) + { + /* no object output, fail return */ + config.make_executable = FALSE; + break; + } + } +} + void lang_process (void) { @@ -6917,6 +6938,9 @@ lang_process (void) /* Remove unreferenced sections if asked to. */ lang_gc_sections (); + /* Check relocations. */ + lang_check_relocs (); + /* Update wild statements. */ update_wild_statements (statement_list.head);