This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [RFC][PATCH] Check ELF relocs after opening all all input files
- From: "H.J. Lu" <hjl dot tools at gmail dot com>
- To: Alan Modra <amodra at gmail dot com>
- Cc: Nick Clifton <nickc at redhat dot com>, Binutils <binutils at sourceware dot org>
- Date: Wed, 20 Apr 2016 11:34:07 -0700
- Subject: Re: [RFC][PATCH] Check ELF relocs after opening all all input files
- Authentication-results: sourceware.org; auth=none
- References: <20160419134956 dot GA12310 at intel dot com> <57165642 dot 1070808 at redhat dot com> <CAMe9rOrydGcortz2AsujVSQYZCRbSPsi7CFQRnA6ZZiicbUvTA at mail dot gmail dot com> <20160419232457 dot GB20119 at bubble dot grove dot modra dot org> <CAMe9rOrQ3QqrBmw206e3_F1f3zbnS7+tUGh5MxmUq-Z_EQskYQ at mail dot gmail dot com>
On Tue, Apr 19, 2016 at 4:47 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
>> Now, if you run check_relocs even later, say at
>> ldemul_before_allocation, after gc-sections has run, then all the
>> reference counting code for plt and got relocs can be removed too.
>>
>
> That is on my to-do list. One step at a time :-). We can start
> with x86 and enable it for other after we have worked out all the issues
>
Here is the first step. OK for master?
--
H.J.
From 9b5c177dd8957627b028c0bb52d09fef3155a093 Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Wed, 20 Apr 2016 05:23:45 -0700
Subject: [PATCH] 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.
---
ld/emultempl/elf32.em | 14 --------------
ld/ldlang.c | 24 ++++++++++++++++++++++++
2 files changed, 24 insertions(+), 14 deletions(-)
diff --git a/ld/emultempl/elf32.em b/ld/emultempl/elf32.em
index 312f935..4f5d1a4 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 856e3e2..2ae3640 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);
--
2.5.5