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]
Other format: [Raw text]

Committed, CRIS: elf32-cris.c section creation order goof


The comment in libdso-2.d says it; a section creation order goof
caused a SEGV because the input section wasn't created at the
time map_input_to_output_sections ran.  And a silly typo.
I'd like to put this on the 2.12 branch too.

ld/testsuite:
	* ld-cris/libdso-2.d, ld-cris/dso-2.s, ld-cris/hide1: New test.

bfd:
	* elf32-cris.c (cris_elf_howto_table) <R_CRIS_16_PCREL,
	R_CRIS_32_PCREL>: Fix typo in name.
	(cris_elf_check_relocs): Always create .rela.got here when
	R_CRIS_16_GOTPLT or R_CRIS_32_GOTPLT is seen.
	(elf_cris_adjust_gotplt_to_got): Don't create .rela.got here;
	assume it's created.

Index: elf32-cris.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-cris.c,v
retrieving revision 1.28
diff -p -c -r1.28 elf32-cris.c
*** elf32-cris.c	2002/04/04 19:53:36	1.28
--- elf32-cris.c	2002/04/05 05:04:38
*************** static reloc_howto_type cris_elf_howto_t
*** 180,186 ****
  	 0,			/* bitpos */
  	 complain_overflow_bitfield, /* complain_on_overflow */
  	 bfd_elf_generic_reloc,	/* special_function */
! 	 "R_CRIS_16",		/* name */
  	 false,			/* partial_inplace */
  	 0x00000000,		/* src_mask */
  	 0x0000ffff,		/* dst_mask */
--- 180,186 ----
  	 0,			/* bitpos */
  	 complain_overflow_bitfield, /* complain_on_overflow */
  	 bfd_elf_generic_reloc,	/* special_function */
! 	 "R_CRIS_16_PCREL",	/* name */
  	 false,			/* partial_inplace */
  	 0x00000000,		/* src_mask */
  	 0x0000ffff,		/* dst_mask */
*************** static reloc_howto_type cris_elf_howto_t
*** 195,201 ****
  	 0,			/* bitpos */
  	 complain_overflow_bitfield, /* complain_on_overflow */
  	 bfd_elf_generic_reloc,	/* special_function */
! 	 "R_CRIS_32",		/* name */
  	 false,			/* partial_inplace */
  	 0x00000000,		/* src_mask */
  	 0xffffffff,		/* dst_mask */
--- 195,201 ----
  	 0,			/* bitpos */
  	 complain_overflow_bitfield, /* complain_on_overflow */
  	 bfd_elf_generic_reloc,	/* special_function */
! 	 "R_CRIS_32_PCREL",	/* name */
  	 false,			/* partial_inplace */
  	 0x00000000,		/* src_mask */
  	 0xffffffff,		/* dst_mask */
*************** elf_cris_adjust_gotplt_to_got (h, p)
*** 1957,1985 ****
  
        h->gotplt_refcount = -1;
  
!       /* We always have a .got section when there are dynamic
! 	 relocs.  */
!       BFD_ASSERT (sgot != NULL /* Surely have .got section.  */);
! 
!       /* We might have had a PLT but with no GOT entry and
! 	 further no GOT reloc section at all needed before.
! 	 Add it.  */
!       if (srelgot == NULL)
! 	{
! 	  srelgot = bfd_make_section (dynobj, ".rela.got");
  
- 	  if (srelgot == NULL
- 	      || !bfd_set_section_flags (dynobj, srelgot,
- 					 (SEC_ALLOC
- 					  | SEC_LOAD
- 					  | SEC_HAS_CONTENTS
- 					  | SEC_IN_MEMORY
- 					  | SEC_LINKER_CREATED
- 					  | SEC_READONLY))
- 	      || !bfd_set_section_alignment (dynobj, srelgot, 2))
- 	    return false;
- 	}
- 
        /* Allocate space in the .got section.  */
        sgot->_raw_size += 4;
  
--- 1957,1966 ----
  
        h->gotplt_refcount = -1;
  
!       /* We always have a .got and a .rela.got section if there were
! 	 GOTPLT relocs in input.  */
!       BFD_ASSERT (sgot != NULL && srelgot != NULL);
  
        /* Allocate space in the .got section.  */
        sgot->_raw_size += 4;
  
*************** cris_elf_check_relocs (abfd, info, sec, 
*** 2368,2375 ****
--- 2349,2386 ----
  	 specific GOT entry).  */
        switch (r_type)
  	{
+ 	  /* For R_CRIS_16_GOTPLT and R_CRIS_32_GOTPLT, we need a GOT
+ 	     entry only for local symbols.  Unfortunately, we don't know
+ 	     until later on if there's a version script that forces the
+ 	     symbol local.  We must have the .rela.got section in place
+ 	     before we know if the symbol looks global now, so we need
+ 	     to treat the reloc just like for R_CRIS_16_GOT and
+ 	     R_CRIS_32_GOT.  */
+ 	case R_CRIS_16_GOTPLT:
+ 	case R_CRIS_32_GOTPLT:
  	case R_CRIS_16_GOT:
  	case R_CRIS_32_GOT:
+ 	  if (srelgot == NULL
+ 	      && (h != NULL || info->shared))
+ 	    {
+ 	      srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
+ 	      if (srelgot == NULL)
+ 		{
+ 		  srelgot = bfd_make_section (dynobj, ".rela.got");
+ 		  if (srelgot == NULL
+ 		      || !bfd_set_section_flags (dynobj, srelgot,
+ 						 (SEC_ALLOC
+ 						  | SEC_LOAD
+ 						  | SEC_HAS_CONTENTS
+ 						  | SEC_IN_MEMORY
+ 						  | SEC_LINKER_CREATED
+ 						  | SEC_READONLY))
+ 		      || !bfd_set_section_alignment (dynobj, srelgot, 2))
+ 		    return false;
+ 		}
+ 	    }
+ 	  /* Fall through.  */
+ 
  	case R_CRIS_32_GOTREL:
  	case R_CRIS_32_PLT_GOTREL:
  	  if (sgot == NULL)
*************** cris_elf_check_relocs (abfd, info, sec, 
*** 2416,2442 ****
  	case R_CRIS_16_GOT:
  	case R_CRIS_32_GOT:
  	  /* This symbol requires a global offset table entry.  */
- 
- 	  if (srelgot == NULL
- 	      && (h != NULL || info->shared))
- 	    {
- 	      srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
- 	      if (srelgot == NULL)
- 		{
- 		  srelgot = bfd_make_section (dynobj, ".rela.got");
- 		  if (srelgot == NULL
- 		      || !bfd_set_section_flags (dynobj, srelgot,
- 						 (SEC_ALLOC
- 						  | SEC_LOAD
- 						  | SEC_HAS_CONTENTS
- 						  | SEC_IN_MEMORY
- 						  | SEC_LINKER_CREATED
- 						  | SEC_READONLY))
- 		      || !bfd_set_section_alignment (dynobj, srelgot, 2))
- 		    return false;
- 		}
- 	    }
- 
  	  if (h != NULL)
  	    {
  	      if (h->got.refcount == 0)
--- 2427,2432 ----
*** /dev/null	Tue Jan  1 05:00:00 1980
--- libdso-2.d	Fri Apr  5 07:14:00 2002
***************
*** 0 ****
--- 1,75 ----
+ #source: dso-1.s
+ #source: dso-2.s
+ #as: --pic --no-underscore
+ #ld: --shared -m crislinux --version-script $srcdir/$subdir/hide1
+ #readelf: -S -s -r
+ 
+ # Use "dsofn" from dso-1 in a GOTPLT reloc, but hide it in a
+ # version script.  This will change the incoming GOTPLT reloc to
+ # instead be a (local) GOT reloc.  There are no other .rela.got
+ # entries.  This formerly SEGV:ed because .rela.got was created
+ # too late to have it mapped to an output section.
+ 
+ There are 15 section headers.*
+ #...
+   \[ 1\] \.hash             HASH            [0-9a-f]+ [0-9a-f]+ 00004c 04   A  2   0  4
+   \[ 2\] \.dynsym           DYNSYM          [0-9a-f]+ [0-9a-f]+ 0000e0 10   A  3   c  4
+   \[ 3\] \.dynstr           STRTAB          [0-9a-f]+ [0-9a-f]+ 000014 00   A  0   0  1
+   \[ 4\] \.gnu\.version      VERSYM          [0-9a-f]+ [0-9a-f]+ 00001c 02   A  2   0  2
+   \[ 5\] \.gnu\.version_d    VERDEF          [0-9a-f]+ [0-9a-f]+ 000038 00   A  3   2  4
+   \[ 6\] \.rela\.got         RELA            [0-9a-f]+ [0-9a-f]+ 00000c 0c   A  2   a  4
+   \[ 7\] \.text             PROGBITS        [0-9a-f]+ [0-9a-f]+ 000014 00  AX  0   0  1
+   \[ 8\] \.data             PROGBITS        [0-9a-f]+ [0-9a-f]+ 000000 00  WA  0   0  1
+   \[ 9\] \.dynamic          DYNAMIC         [0-9a-f]+ [0-9a-f]+ 000088 08  WA  3   0  4
+   \[10\] \.got              PROGBITS        [0-9a-f]+ [0-9a-f]+ 000010 04  WA  0   0  4
+   \[11\] \.bss              NOBITS          [0-9a-f]+ [0-9a-f]+ 000008 00  WA  0   0  1
+   \[12\] \.shstrtab         STRTAB          [0-9a-f]+ [0-9a-f]+ 000071 00      0   0  1
+   \[13\] \.symtab           SYMTAB          [0-9a-f]+ [0-9a-f]+ 000170 10     14  15  4
+   \[14\] \.strtab           STRTAB          [0-9a-f]+ [0-9a-f]+ 00004c 00      0   0  1
+ #...
+ Relocation section '\.rela\.got' at offset 0x[0-9a-f]+ contains 1 entries:
+ #...
+ 000022f4  0000000c R_CRIS_RELATIVE                              00000234
+ #...
+ Symbol table '\.dynsym' contains 14 entries:
+    Num:    Value  Size Type    Bind   Vis      Ndx Name
+      0: 0+     0 NOTYPE  LOCAL  DEFAULT  UND 
+      1: [0-9a-f]+     0 SECTION LOCAL  DEFAULT    1 
+      2: [0-9a-f]+     0 SECTION LOCAL  DEFAULT    2 
+      3: [0-9a-f]+     0 SECTION LOCAL  DEFAULT    3 
+      4: [0-9a-f]+     0 SECTION LOCAL  DEFAULT    4 
+      5: [0-9a-f]+     0 SECTION LOCAL  DEFAULT    5 
+      6: [0-9a-f]+     0 SECTION LOCAL  DEFAULT    6 
+      7: [0-9a-f]+     0 SECTION LOCAL  DEFAULT    7 
+      8: [0-9a-f]+     0 SECTION LOCAL  DEFAULT    8 
+      9: [0-9a-f]+     0 SECTION LOCAL  DEFAULT    9 
+     10: [0-9a-f]+     0 SECTION LOCAL  DEFAULT   10 
+     11: [0-9a-f]+     0 SECTION LOCAL  DEFAULT   11 
+     12: 0+     0 OBJECT  GLOBAL DEFAULT  ABS TST1
+     13: 0+238     0 FUNC    GLOBAL DEFAULT    7 export_1@@TST1
+ 
+ Symbol table '\.symtab' contains 23 entries:
+    Num:    Value  Size Type    Bind   Vis      Ndx Name
+      0: 0+     0 NOTYPE  LOCAL  DEFAULT  UND 
+      1: [0-9a-f]+     0 SECTION LOCAL  DEFAULT    1 
+      2: [0-9a-f]+     0 SECTION LOCAL  DEFAULT    2 
+      3: [0-9a-f]+     0 SECTION LOCAL  DEFAULT    3 
+      4: [0-9a-f]+     0 SECTION LOCAL  DEFAULT    4 
+      5: [0-9a-f]+     0 SECTION LOCAL  DEFAULT    5 
+      6: [0-9a-f]+     0 SECTION LOCAL  DEFAULT    6 
+      7: [0-9a-f]+     0 SECTION LOCAL  DEFAULT    7 
+      8: [0-9a-f]+     0 SECTION LOCAL  DEFAULT    8 
+      9: [0-9a-f]+     0 SECTION LOCAL  DEFAULT    9 
+     10: [0-9a-f]+     0 SECTION LOCAL  DEFAULT   10 
+     11: [0-9a-f]+     0 SECTION LOCAL  DEFAULT   11 
+     12: [0-9a-f]+     0 SECTION LOCAL  DEFAULT   12 
+     13: [0-9a-f]+     0 SECTION LOCAL  DEFAULT   13 
+     14: [0-9a-f]+     0 SECTION LOCAL  DEFAULT   14 
+     15: 0+2260     0 OBJECT  LOCAL  DEFAULT  ABS _DYNAMIC
+     16: 0+22f8     0 NOTYPE  LOCAL  DEFAULT  ABS __bss_start
+     17: 0+22f8     0 NOTYPE  LOCAL  DEFAULT  ABS _edata
+     18: 0+22e8     0 OBJECT  LOCAL  DEFAULT  ABS _GLOBAL_OFFSET_TABLE_
+     19: 0+2300     0 NOTYPE  LOCAL  DEFAULT  ABS _end
+     20: 0+234     0 FUNC    LOCAL  DEFAULT    7 dsofn
+     21: 0+     0 OBJECT  GLOBAL DEFAULT  ABS TST1
+     22: 0+238     0 FUNC    GLOBAL DEFAULT    7 export_1
*** /dev/null	Tue Jan  1 05:00:00 1980
--- dso-2.s	Fri Apr  5 05:15:51 2002
***************
*** 0 ****
--- 1,6 ----
+ 	.text
+ 	.global	export_1
+ 	.type	export_1,@function
+ export_1:
+ 	jump [$r1+dsofn:GOTPLT16]
+ 	jump [$r1+dsofn:GOTPLT]
*** /dev/null	Tue Jan  1 05:00:00 1980
--- hide1	Fri Apr  5 05:05:16 2002
***************
*** 0 ****
--- 1 ----
+ TST1 { global: export_*; local: *; };

brgds, H-P


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