This is the mail archive of the binutils@sources.redhat.com 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]

Patch: Zero out the allocated dynamic content space.


Here is a testcase on Linux/ia32:

# make
ld -shared -o test.so --version-script=test.map rtld.os setjmp.os
readelf -r test.so | head -5

Relocation section '.rel.text' at offset 0xcbc contains 1 entries:
  Offset    Info  Type            Symbol's Value  Symbol's Name
  00000609  01c84 unrecognised: 84      00000000  _dl_debug_fd

"unrecognised: 84" is caused by bfd_alloc, which leaves s->contents
uninitialized in certain cases. Most of the ELF targets use bfd_zalloc
instead of bfd_alloc for s->contents. I think all ELF targets should
use bfd_zalloc. At least, it fixes Linux/ia32:

/work/build/gnu/bin/binutils-debug/ld/ld-new -shared -o test.so
--version-script=test.map rtld.os setjmp.os
readelf -r test.so | head -5

Relocation section '.rel.text' at offset 0xcbc contains 1 entries:
  Offset    Info  Type            Symbol's Value  Symbol's Name
  00000000  00000 R_386_NONE


-- 
H.J. Lu (hjl@gnu.org)
---
2000-08-17  H.J. Lu  <hjl@gnu.org>

	* elf32-i386.c (elf_i386_size_dynamic_sections): Zero out the
	dynamic allocated content space.
	* elf32-m68k.c (elf_m68k_size_dynamic_sections): Likewise.
	* elf32-sparc.c (elf32_sparc_size_dynamic_sections): Likewise.
	* elf64-hppa.c (elf64_hppa_size_dynamic_sections): Likewise.

Index: elf32-i386.c
===================================================================
RCS file: /work/cvs/gnu/binutils/bfd/elf32-i386.c,v
retrieving revision 1.16
diff -u -p -r1.16 elf32-i386.c
--- elf32-i386.c	2000/07/20 03:58:11	1.16
+++ elf32-i386.c	2000/08/18 06:50:58
@@ -1198,7 +1198,7 @@ elf_i386_size_dynamic_sections (output_b
 	}
 
       /* Allocate memory for the section contents.  */
-      s->contents = (bfd_byte *) bfd_alloc (dynobj, s->_raw_size);
+      s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->_raw_size);
       if (s->contents == NULL && s->_raw_size != 0)
 	return false;
     }
Index: elf32-m68k.c
===================================================================
RCS file: /work/cvs/gnu/binutils/bfd/elf32-m68k.c,v
retrieving revision 1.7
diff -u -p -r1.7 elf32-m68k.c
--- elf32-m68k.c	2000/07/20 03:58:11	1.7
+++ elf32-m68k.c	2000/08/18 06:54:12
@@ -1267,7 +1267,7 @@ elf_m68k_size_dynamic_sections (output_b
 	}
 
       /* Allocate memory for the section contents.  */
-      s->contents = (bfd_byte *) bfd_alloc (dynobj, s->_raw_size);
+      s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->_raw_size);
       if (s->contents == NULL && s->_raw_size != 0)
 	return false;
     }
Index: elf32-sparc.c
===================================================================
RCS file: /work/cvs/gnu/binutils/bfd/elf32-sparc.c,v
retrieving revision 1.8
diff -u -p -r1.8 elf32-sparc.c
--- elf32-sparc.c	2000/07/20 03:58:11	1.8
+++ elf32-sparc.c	2000/08/18 06:54:28
@@ -1019,7 +1019,7 @@ elf32_sparc_size_dynamic_sections (outpu
 	}
 
       /* Allocate memory for the section contents.  */
-      s->contents = (bfd_byte *) bfd_alloc (dynobj, s->_raw_size);
+      s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->_raw_size);
       if (s->contents == NULL && s->_raw_size != 0)
 	return false;
     }
Index: elf64-hppa.c
===================================================================
RCS file: /work/cvs/gnu/binutils/bfd/elf64-hppa.c,v
retrieving revision 1.1.1.4
diff -u -p -r1.1.1.4 elf64-hppa.c
--- elf64-hppa.c	2000/07/20 03:28:08	1.1.1.4
+++ elf64-hppa.c	2000/08/18 06:54:39
@@ -1740,7 +1740,7 @@ elf64_hppa_size_dynamic_sections (output
 	 been allocated already.  */
       if (s->contents == NULL)
 	{
-	  s->contents = (bfd_byte *) bfd_alloc (dynobj, s->_raw_size);
+	  s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->_raw_size);
 	  if (s->contents == NULL && s->_raw_size != 0)
 	    return false;
 	}

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