Define __start/__stop symbols when there is only a dynamic def

Alan Modra
Tue Jan 30 00:01:00 GMT 2018

On Mon, Jan 29, 2018 at 03:36:05PM -0800, H.J. Lu wrote:
> There is a reason why I have been keeping asking for a testcase.
> I will update my patch with the above testcase.

The last few emails in this thread illustrate just why changes based
on testcases can be suspect.

I don't believe that ld 2.28 or earlier defined dynamic __start and
__stop symbols without a dynamic reference.  In fact, you need to use
-E or some other way of making symbols dynamic in an executable to
support dlsym on *normal* symbols.  I'm going to commit the extra test
I posted earlier without -E, plus this patch.

	* elflink.c (bfd_elf_define_start_stop): Make __start and __stop
	symbols dynamic.

diff --git a/bfd/elflink.c b/bfd/elflink.c
index e81f6c6..f1ec880 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -14354,8 +14354,13 @@ bfd_elf_define_start_stop (struct bfd_link_info *info,
 	  bed = get_elf_backend_data (info->output_bfd);
 	  (*bed->elf_backend_hide_symbol) (info, h, TRUE);
-      else if (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
-	h->other = (h->other & ~ELF_ST_VISIBILITY (-1)) | STV_PROTECTED;
+      else
+	{
+	  if (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
+	    h->other = (h->other & ~ELF_ST_VISIBILITY (-1)) | STV_PROTECTED;
+	  if (h->ref_dynamic || h->def_dynamic)
+	    bfd_elf_link_record_dynamic_symbol (info, h);
+	}
       return &h->root;
   return NULL;

Alan Modra
Australia Development Lab, IBM

More information about the Binutils mailing list