cris: Don't generate unnecessary dynamic tags

Message ID 20200623121317.212843-1-hjl.tools@gmail.com
State New
Headers show
Series
  • cris: Don't generate unnecessary dynamic tags
Related show

Commit Message

David Faust via Binutils June 23, 2020, 12:13 p.m.
Dynamic tags, DT_JMPREL, PLTREL and PLTRELSZ, are needed only if there
are relocation entries for PLT.  Don't generate them if there are no
relocation entries for PLT.

bfd/

	PR ld/26083
	* elf32-cris.c (elf_cris_size_dynamic_sections): Call
	_bfd_elf_add_dynamic_tags.

ld/

	PR ld/26083
	* testsuite/ld-cris/libdso-15b.d: Updated.
	* testsuite/ld-cris/libdso-1c.d: Likewise.
	* testsuite/ld-cris/libdso-1d.d: Likewise.
	* testsuite/ld-cris/libdso-15c.d: New file.
---
 bfd/elf32-cris.c                  | 48 ++-----------------------------
 ld/testsuite/ld-cris/libdso-15b.d |  6 ++--
 ld/testsuite/ld-cris/libdso-15c.d | 22 ++++++++++++++
 ld/testsuite/ld-cris/libdso-1c.d  |  6 ++--
 ld/testsuite/ld-cris/libdso-1d.d  | 10 +++----
 5 files changed, 35 insertions(+), 57 deletions(-)
 create mode 100644 ld/testsuite/ld-cris/libdso-15c.d

-- 
2.26.2

Comments

David Faust via Binutils June 24, 2020, 3:44 a.m. | #1
> From: "H.J. Lu" <hjl.tools@gmail.com>

> Date: Tue, 23 Jun 2020 14:13:17 +0200


> bfd/

> 

> 	PR ld/26083

> 	* elf32-cris.c (elf_cris_size_dynamic_sections): Call

> 	_bfd_elf_add_dynamic_tags.


> diff --git a/bfd/elf32-cris.c b/bfd/elf32-cris.c

> index bee7108684..d115c7e82d 100644

> --- a/bfd/elf32-cris.c

> +++ b/bfd/elf32-cris.c

> @@ -3585,7 +3583,7 @@ elf_cris_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,

>        if (strcmp (name, ".plt") == 0)

>  	{

>  	  /* Remember whether there is a PLT.  */

> -	  plt = s->size != 0;

> +	  ;


Please also remove that comment on the line above.

Ok with that, thanks.

brgds, H-P

Patch

diff --git a/bfd/elf32-cris.c b/bfd/elf32-cris.c
index bee7108684..d115c7e82d 100644
--- a/bfd/elf32-cris.c
+++ b/bfd/elf32-cris.c
@@ -3513,7 +3513,6 @@  elf_cris_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
   struct elf_cris_link_hash_table * htab;
   bfd *dynobj;
   asection *s;
-  bfd_boolean plt;
   bfd_boolean relocs;
 
   htab = elf_cris_hash_table (info);
@@ -3569,7 +3568,6 @@  elf_cris_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
   /* The check_relocs and adjust_dynamic_symbol entry points have
      determined the sizes of the various dynamic sections.  Allocate
      memory for them.  */
-  plt = FALSE;
   relocs = FALSE;
   for (s = dynobj->sections; s != NULL; s = s->next)
     {
@@ -3585,7 +3583,7 @@  elf_cris_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
       if (strcmp (name, ".plt") == 0)
 	{
 	  /* Remember whether there is a PLT.  */
-	  plt = s->size != 0;
+	  ;
 	}
       else if (strcmp (name, ".got.plt") == 0)
 	{
@@ -3650,49 +3648,7 @@  elf_cris_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
 	return FALSE;
     }
 
-  if (elf_hash_table (info)->dynamic_sections_created)
-    {
-      /* Add some entries to the .dynamic section.  We fill in the
-	 values later, in elf_cris_finish_dynamic_sections, but we
-	 must add the entries now so that we get the correct size for
-	 the .dynamic section.  The DT_DEBUG entry is filled in by the
-	 dynamic linker and used by the debugger.  */
-#define add_dynamic_entry(TAG, VAL) \
-  _bfd_elf_add_dynamic_entry (info, TAG, VAL)
-
-      if (!bfd_link_pic (info))
-	{
-	  if (!add_dynamic_entry (DT_DEBUG, 0))
-	    return FALSE;
-	}
-
-      if (plt)
-	{
-	  if (!add_dynamic_entry (DT_PLTGOT, 0)
-	      || !add_dynamic_entry (DT_PLTRELSZ, 0)
-	      || !add_dynamic_entry (DT_PLTREL, DT_RELA)
-	      || !add_dynamic_entry (DT_JMPREL, 0))
-	    return FALSE;
-	}
-
-      if (relocs)
-	{
-	  if (!add_dynamic_entry (DT_RELA, 0)
-	      || !add_dynamic_entry (DT_RELASZ, 0)
-	      || !add_dynamic_entry (DT_RELAENT, sizeof (Elf32_External_Rela)))
-	    return FALSE;
-	}
-
-      if ((info->flags & DF_TEXTREL) != 0)
-	{
-	  if (!add_dynamic_entry (DT_TEXTREL, 0))
-	    return FALSE;
-	  info->flags |= DF_TEXTREL;
-	}
-    }
-#undef add_dynamic_entry
-
-  return TRUE;
+  return _bfd_elf_add_dynamic_tags (output_bfd, info, relocs);
 }
 
 /* This function is called via elf_cris_link_hash_traverse if we are
diff --git a/ld/testsuite/ld-cris/libdso-15b.d b/ld/testsuite/ld-cris/libdso-15b.d
index 4e2bddb252..39e001a927 100644
--- a/ld/testsuite/ld-cris/libdso-15b.d
+++ b/ld/testsuite/ld-cris/libdso-15b.d
@@ -22,7 +22,7 @@  DYNAMIC SYMBOL TABLE:
 0+[	 ]+DF \*UND\*[	 ]+0+  TST3[	 ]+expfn2
 #...
 Contents of section .rela.dyn:
- 017c a4220000 0a040000 00000000 a8220000  .*
+ 017c 8c220000 0a040000 00000000 90220000  .*
  018c 0a050000 00000000                    .*
 Contents of section .plt:
  0194 fce17e7e 0401307a 08013009 00000000  .*
@@ -34,5 +34,5 @@  Contents of section .text:
  01e0 00006fae d4ffffff                    .*
 #...
 Contents of section .got:
- 2298 e8210000 00000000 00000000 00000000  .*
- 22a8 00000000                             .*
+ 2280 e8210000 00000000 00000000 00000000  .*
+ 2290 00000000                             .*
diff --git a/ld/testsuite/ld-cris/libdso-15c.d b/ld/testsuite/ld-cris/libdso-15c.d
new file mode 100644
index 0000000000..b0359905c2
--- /dev/null
+++ b/ld/testsuite/ld-cris/libdso-15c.d
@@ -0,0 +1,22 @@ 
+#source: expdref2.s
+#as: --pic --no-underscore --em=criself
+#ld: --shared -m crislinux --hash-style=sysv
+#ld_after_inputfiles: tmpdir/libdso-15.so
+#readelf: -d
+
+Dynamic section at offset 0x1e8 contains 14 entries:
+  Tag        Type                         Name/Value
+ 0x00000001 \(NEEDED\)                     Shared library: \[tmpdir/libdso-15.so\]
+ 0x00000004 \(HASH\)                       0x94
+ 0x00000005 \(STRTAB\)                     0x120
+ 0x00000006 \(SYMTAB\)                     0xc0
+ 0x0000000a \(STRSZ\)                      45 \(bytes\)
+ 0x0000000b \(SYMENT\)                     16 \(bytes\)
+ 0x00000003 \(PLTGOT\)                     0x2280
+ 0x00000007 \(RELA\)                       0x17c
+ 0x00000008 \(RELASZ\)                     24 \(bytes\)
+ 0x00000009 \(RELAENT\)                    12 \(bytes\)
+ 0x6ffffffe \(VERNEED\)                    0x15c
+ 0x6fffffff \(VERNEEDNUM\)                 1
+ 0x6ffffff0 \(VERSYM\)                     0x14e
+ 0x00000000 \(NULL\)                       0x0
diff --git a/ld/testsuite/ld-cris/libdso-1c.d b/ld/testsuite/ld-cris/libdso-1c.d
index f02dc5e446..2b9b13b660 100644
--- a/ld/testsuite/ld-cris/libdso-1c.d
+++ b/ld/testsuite/ld-cris/libdso-1c.d
@@ -19,7 +19,7 @@  DYNAMIC SYMBOL TABLE:
 0+[ 	]+DF \*UND\*	0+[ 	]+TST2[	 ]+expfn
 #...
 Contents of section .rela.dyn:
- 0140 68220000 0a020000 00000000 6c220000  .*
+ 0140 50220000 0a020000 00000000 54220000  .*
  0150 0a030000 00000000                    .*
 Contents of section .plt:
  0158 fce17e7e 0401307a 08013009 00000000  .*
@@ -31,5 +31,5 @@  Contents of section .text:
  01a4 00006fae d4ffffff                    .*
 #...
 Contents of section .got:
- 225c ac210000 00000000 00000000 00000000  .*
- 226c 00000000                             .*
+ 2244 ac210000 00000000 00000000 00000000  .*
+ 2254 00000000                             .*
diff --git a/ld/testsuite/ld-cris/libdso-1d.d b/ld/testsuite/ld-cris/libdso-1d.d
index 06e72fc279..83a43372ed 100644
--- a/ld/testsuite/ld-cris/libdso-1d.d
+++ b/ld/testsuite/ld-cris/libdso-1d.d
@@ -14,10 +14,10 @@ 
 DYNAMIC SYMBOL TABLE:
 #...
 0+1a6  w   DF .text	0+2 expfn
-0+2254  w   DO .data	0+4 expobj
+0+223c  w   DO .data	0+4 expobj
 #...
 Contents of section .rela.dyn:
- 0138 4c220000 0a020000 00000000 50220000  .*
+ 0138 34220000 0a020000 00000000 38220000  .*
  0148 0a030000 00000000                    .*
 Contents of section .plt:
  0150 fce17e7e 0401307a 08013009 00000000  .*
@@ -30,7 +30,7 @@  Contents of section .text:
 Contents of section .dynamic:
 #...
 Contents of section .got:
- 2240 a8210000 00000000 00000000 00000000  .*
- 2250 00000000                             .*
+ 2228 a8210000 00000000 00000000 00000000  .*
+ 2238 00000000                             .*
 Contents of section .data:
- 2254 00000000                             .*
+ 223c 00000000                             .*