This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [RFC][PATCH] Check ELF relocs after opening all all input files


On Thu, Apr 28, 2016 at 6:09 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Thu, Apr 28, 2016 at 6:07 AM, Alan Modra <amodra@gmail.com> wrote:
>> On Thu, Apr 28, 2016 at 05:49:57AM -0700, H.J. Lu wrote:
>>> On Wed, Apr 27, 2016 at 6:11 PM, Alan Modra <amodra@gmail.com> wrote:
>>> > On Wed, Apr 27, 2016 at 03:24:48PM -0700, H.J. Lu wrote:
>>> >> bfd_elf_record_link_assignment
>>> >> is called after check_relocs.  bfd_elf_record_link_assignment sets non_elf,
>>> >> def_regular and  forced_local.   For PROVIDE, it also updates root.type. They
>>> >> are needed in reloc_checks.
>>> >
>>> > My guess is that symbol twiddling done in before_allocation should be
>>> > moved to a new ldemul hook called at the start of lang_do_assignments.
>>> > The idea being to stabilize symbols earlier.
>>> >
>>> > The hook would twiddle __ehdr_start and call find_statement_assignment
>>> > when lang_mark_phase_enum.  Reversing the __ehdr_start twiddle stays
>>> > in before_allocation.
>>> >
>>>
>>> I tried this.  But it doesn't work with __start/__stop symbols.  I
>>> need to know if they are defined and referenced local in check_relocs.
>> [snip]
>>
>>> --- a/ld/ldlang.c
>>> +++ b/ld/ldlang.c
>>> @@ -6930,6 +6930,8 @@ lang_process (void)
>>>       collection in order to make sure that all symbol aliases are resolved.  */
>>>    lang_do_assignments (lang_mark_phase_enum);
>>>
>>> +  ldemul_record_link_assignments (lang_mark_phase_enum);
>>> +
>>>    lang_do_memory_regions();
>>>    expld.phase = lang_first_phase_enum;
>>
>> You'll need to run ldemul_record_link_assignments before
>> lang_do_assignments if you want provided symbols to be defined.
>
> I got many more failures when I did that since many assignments
> haven't been processed yet.
>
>> I suggest renaming to ldemul_do_assignments and putting
>>   ldemul_do_assignments (phase);
>> inside lang_do_assignments just before the call to
>> lang_do_assignments_1.
>>

With this patch, I only got 2 failures on x86-64.



-- 
H.J.
From 16526e42c26b00e2424a0d0b5a73c04f010f7a9e Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Thu, 28 Apr 2016 06:38:41 -0700
Subject: [PATCH] Add _bfd_elf_record_start_stop

---
 bfd/elf-bfd.h         |  3 +++
 bfd/elflink.c         | 21 +++++++++++++++++++++
 ld/emultempl/elf32.em |  2 ++
 3 files changed, 26 insertions(+)

diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h
index 6c05b55..480f1cb 100644
--- a/bfd/elf-bfd.h
+++ b/bfd/elf-bfd.h
@@ -2339,6 +2339,9 @@ extern bfd_boolean bfd_elf_gc_common_final_link
 extern asection *_bfd_elf_is_start_stop
   (const struct bfd_link_info *, struct elf_link_hash_entry *);
 
+extern void _bfd_elf_record_start_stop
+  (const struct bfd_link_info *);
+
 extern bfd_boolean bfd_elf_reloc_symbol_deleted_p
   (bfd_vma, void *);
 
diff --git a/bfd/elflink.c b/bfd/elflink.c
index b6ff6b6..6c2ddb4 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -13791,3 +13791,24 @@ elf_append_rel (bfd *abfd, asection *s, Elf_Internal_Rela *rel)
   BFD_ASSERT (loc + bed->s->sizeof_rel <= s->contents + s->size);
   bed->s->swap_reloc_out (abfd, rel, loc);
 }
+
+/* For undefined __start_<name> and __stop_<name> symbols, set
+   def_regular to 1.  This is called via elf_link_hash_traverse.  */
+
+static bfd_boolean
+elf_link_record_start_stop (struct elf_link_hash_entry *h, void *data)
+{
+  const struct bfd_link_info * info
+    = (const struct bfd_link_info *) data;
+  if (_bfd_elf_is_start_stop (info, h) != NULL)
+    h->def_regular = 1;
+  return TRUE;
+}
+
+void
+_bfd_elf_record_start_stop (const struct bfd_link_info * info)
+{
+  elf_link_hash_traverse (elf_hash_table (info),
+			  elf_link_record_start_stop,
+			  (void *) info);
+}
diff --git a/ld/emultempl/elf32.em b/ld/emultempl/elf32.em
index cc2f056..ad48ce4 100644
--- a/ld/emultempl/elf32.em
+++ b/ld/emultempl/elf32.em
@@ -1445,6 +1445,8 @@ gld${EMULATION_NAME}_record_link_assignments (lang_phase_type phase)
 	 let the ELF backend know about them in case the variables are
 	 referred to by dynamic objects.  */
       lang_for_each_statement (gld${EMULATION_NAME}_find_statement_assignment);
+
+      _bfd_elf_record_start_stop (&link_info);
     }
 }
 
-- 
2.5.5


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]