Subversion Repositories Kolibri OS

Rev

Rev 5197 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5197 Rev 6324
Line 1... Line 1...
1
/* ELF executable support for BFD.
1
/* ELF executable support for BFD.
Line 2... Line 2...
2
 
2
 
Line 3... Line 3...
3
   Copyright 1993-2013 Free Software Foundation, Inc.
3
   Copyright (C) 1993-2015 Free Software Foundation, Inc.
Line 4... Line 4...
4
 
4
 
5
   This file is part of BFD, the Binary File Descriptor library.
5
   This file is part of BFD, the Binary File Descriptor library.
Line 49... Line 49...
49
#endif
49
#endif
Line 50... Line 50...
50
 
50
 
51
static int elf_sort_sections (const void *, const void *);
51
static int elf_sort_sections (const void *, const void *);
52
static bfd_boolean assign_file_positions_except_relocs (bfd *, struct bfd_link_info *);
52
static bfd_boolean assign_file_positions_except_relocs (bfd *, struct bfd_link_info *);
53
static bfd_boolean prep_headers (bfd *);
53
static bfd_boolean prep_headers (bfd *);
54
static bfd_boolean swap_out_syms (bfd *, struct bfd_strtab_hash **, int) ;
54
static bfd_boolean swap_out_syms (bfd *, struct elf_strtab_hash **, int) ;
55
static bfd_boolean elf_read_notes (bfd *, file_ptr, bfd_size_type) ;
55
static bfd_boolean elf_read_notes (bfd *, file_ptr, bfd_size_type) ;
56
static bfd_boolean elf_parse_notes (bfd *abfd, char *buf, size_t size,
56
static bfd_boolean elf_parse_notes (bfd *abfd, char *buf, size_t size,
Line 57... Line 57...
57
				    file_ptr offset);
57
				    file_ptr offset);
Line 295... Line 295...
295
      shstrtabsize = i_shdrp[shindex]->sh_size;
295
      shstrtabsize = i_shdrp[shindex]->sh_size;
Line 296... Line 296...
296
 
296
 
297
      /* Allocate and clear an extra byte at the end, to prevent crashes
297
      /* Allocate and clear an extra byte at the end, to prevent crashes
298
	 in case the string table is not terminated.  */
298
	 in case the string table is not terminated.  */
-
 
299
      if (shstrtabsize + 1 <= 1
299
      if (shstrtabsize + 1 <= 1
300
	  || bfd_seek (abfd, offset, SEEK_SET) != 0
300
	  || (shstrtab = (bfd_byte *) bfd_alloc (abfd, shstrtabsize + 1)) == NULL
-
 
301
	  || bfd_seek (abfd, offset, SEEK_SET) != 0)
301
	  || (shstrtab = (bfd_byte *) bfd_alloc (abfd, shstrtabsize + 1)) == NULL)
302
	shstrtab = NULL;
302
	shstrtab = NULL;
303
      else if (bfd_bread (shstrtab, shstrtabsize, abfd) != shstrtabsize)
303
      else if (bfd_bread (shstrtab, shstrtabsize, abfd) != shstrtabsize)
304
	{
304
	{
305
	  if (bfd_get_error () != bfd_error_system_call)
305
	  if (bfd_get_error () != bfd_error_system_call)
-
 
306
	    bfd_set_error (bfd_error_file_truncated);
306
	    bfd_set_error (bfd_error_file_truncated);
307
	  bfd_release (abfd, shstrtab);
307
	  shstrtab = NULL;
308
	  shstrtab = NULL;
308
	  /* Once we've failed to read it, make sure we don't keep
309
	  /* Once we've failed to read it, make sure we don't keep
309
	     trying.  Otherwise, we'll keep allocating space for
310
	     trying.  Otherwise, we'll keep allocating space for
310
	     the string table over and over.  */
311
	     the string table over and over.  */
Line 330... Line 331...
330
  if (elf_elfsections (abfd) == NULL || shindex >= elf_numsections (abfd))
331
  if (elf_elfsections (abfd) == NULL || shindex >= elf_numsections (abfd))
331
    return NULL;
332
    return NULL;
Line 332... Line 333...
332
 
333
 
Line 333... Line 334...
333
  hdr = elf_elfsections (abfd)[shindex];
334
  hdr = elf_elfsections (abfd)[shindex];
-
 
335
 
-
 
336
  if (hdr->contents == NULL)
-
 
337
    {
-
 
338
      if (hdr->sh_type != SHT_STRTAB && hdr->sh_type < SHT_LOOS)
-
 
339
	{
-
 
340
	  /* PR 17512: file: f057ec89.  */
-
 
341
	  _bfd_error_handler (_("%B: attempt to load strings from a non-string section (number %d)"),
-
 
342
			      abfd, shindex);
-
 
343
	  return NULL;
334
 
344
	}
335
  if (hdr->contents == NULL
345
 
-
 
346
      if (bfd_elf_get_str_section (abfd, shindex) == NULL)
Line 336... Line 347...
336
      && bfd_elf_get_str_section (abfd, shindex) == NULL)
347
	return NULL;
337
    return NULL;
348
    }
338
 
349
 
339
  if (strindex >= hdr->sh_size)
350
  if (strindex >= hdr->sh_size)
Line 387... Line 398...
387
  if (symcount == 0)
398
  if (symcount == 0)
388
    return intsym_buf;
399
    return intsym_buf;
Line 389... Line 400...
389
 
400
 
390
  /* Normal syms might have section extension entries.  */
401
  /* Normal syms might have section extension entries.  */
-
 
402
  shndx_hdr = NULL;
-
 
403
  if (elf_symtab_shndx_list (ibfd) != NULL)
-
 
404
    {
-
 
405
      elf_section_list * entry;
-
 
406
      Elf_Internal_Shdr **sections = elf_elfsections (ibfd);
-
 
407
 
-
 
408
      /* Find an index section that is linked to this symtab section.  */
-
 
409
      for (entry = elf_symtab_shndx_list (ibfd); entry != NULL; entry = entry->next)
-
 
410
	if (sections[entry->hdr.sh_link] == symtab_hdr)
-
 
411
	  {
-
 
412
	    shndx_hdr = & entry->hdr;
-
 
413
	    break;
-
 
414
	  };
-
 
415
 
-
 
416
      if (shndx_hdr == NULL)
391
  shndx_hdr = NULL;
417
	{
-
 
418
	  if (symtab_hdr == & elf_symtab_hdr (ibfd))
392
  if (symtab_hdr == &elf_tdata (ibfd)->symtab_hdr)
419
	    /* Not really accurate, but this was how the old code used to work.  */
-
 
420
	    shndx_hdr = & elf_symtab_shndx_list (ibfd)->hdr;
-
 
421
	  /* Otherwise we do nothing.  The assumption is that
-
 
422
	     the index table will not be needed.  */
-
 
423
	}
Line 393... Line 424...
393
    shndx_hdr = &elf_tdata (ibfd)->symtab_shndx_hdr;
424
    }
394
 
425
 
395
  /* Read the symbols.  */
426
  /* Read the symbols.  */
396
  alloc_ext = NULL;
427
  alloc_ext = NULL;
Line 606... Line 637...
606
                      bfd_alloc2 (abfd, shdr->sh_size, sizeof (*dest) / 4);
637
                      bfd_alloc2 (abfd, shdr->sh_size, sizeof (*dest) / 4);
607
		  /* PR binutils/4110: Handle corrupt group headers.  */
638
		  /* PR binutils/4110: Handle corrupt group headers.  */
608
		  if (shdr->contents == NULL)
639
		  if (shdr->contents == NULL)
609
		    {
640
		    {
610
		      _bfd_error_handler
641
		      _bfd_error_handler
611
			(_("%B: Corrupt size field in group section header: 0x%lx"), abfd, shdr->sh_size);
642
			(_("%B: corrupt size field in group section header: 0x%lx"), abfd, shdr->sh_size);
612
		      bfd_set_error (bfd_error_bad_value);
643
		      bfd_set_error (bfd_error_bad_value);
613
		      return FALSE;
644
		      -- num_group;
-
 
645
		      continue;
614
		    }
646
		    }
Line 615... Line 647...
615
 
647
 
Line 616... Line 648...
616
		  memset (shdr->contents, 0, amt);
648
		  memset (shdr->contents, 0, amt);
617
 
649
 
618
		  if (bfd_seek (abfd, shdr->sh_offset, SEEK_SET) != 0
650
		  if (bfd_seek (abfd, shdr->sh_offset, SEEK_SET) != 0
-
 
651
		      || (bfd_bread (shdr->contents, shdr->sh_size, abfd)
-
 
652
			  != shdr->sh_size))
-
 
653
		    {
-
 
654
		      _bfd_error_handler
-
 
655
			(_("%B: invalid size field in group section header: 0x%lx"), abfd, shdr->sh_size);
-
 
656
		      bfd_set_error (bfd_error_bad_value);
-
 
657
		      -- num_group;
-
 
658
		      /* PR 17510: If the group contents are even partially
619
		      || (bfd_bread (shdr->contents, shdr->sh_size, abfd)
659
			 corrupt, do not allow any of the contents to be used.  */
-
 
660
		      memset (shdr->contents, 0, amt);
Line 620... Line 661...
620
			  != shdr->sh_size))
661
		      continue;
621
		    return FALSE;
662
		    }
622
 
663
 
623
		  /* Translate raw contents, a flag word followed by an
664
		  /* Translate raw contents, a flag word followed by an
624
		     array of elf section indices all in target byte order,
665
		     array of elf section indices all in target byte order,
625
		     to the flag word followed by an array of elf section
666
		     to the flag word followed by an array of elf section
-
 
667
		     pointers.  */
626
		     pointers.  */
668
		  src = shdr->contents + shdr->sh_size;
627
		  src = shdr->contents + shdr->sh_size;
669
		  dest = (Elf_Internal_Group *) (shdr->contents + amt);
628
		  dest = (Elf_Internal_Group *) (shdr->contents + amt);
670
 
Line 629... Line 671...
629
		  while (1)
671
		  while (1)
Line 649... Line 691...
649
			}
691
			}
650
		      dest->shdr = elf_elfsections (abfd)[idx];
692
		      dest->shdr = elf_elfsections (abfd)[idx];
651
		    }
693
		    }
652
		}
694
		}
653
	    }
695
	    }
-
 
696
 
-
 
697
	  /* PR 17510: Corrupt binaries might contain invalid groups.  */
-
 
698
	  if (num_group != (unsigned) elf_tdata (abfd)->num_group)
-
 
699
	    {
-
 
700
	      elf_tdata (abfd)->num_group = num_group;
-
 
701
 
-
 
702
	      /* If all groups are invalid then fail.  */
-
 
703
	      if (num_group == 0)
-
 
704
		{
-
 
705
		  elf_tdata (abfd)->group_sect_ptr = NULL;
-
 
706
		  elf_tdata (abfd)->num_group = num_group = -1;
-
 
707
		  (*_bfd_error_handler) (_("%B: no valid group sections found"), abfd);
-
 
708
		  bfd_set_error (bfd_error_bad_value);
-
 
709
		}
-
 
710
	    }
654
	}
711
	}
655
    }
712
    }
Line 656... Line 713...
656
 
713
 
657
  if (num_group != (unsigned) -1)
714
  if (num_group != (unsigned) -1)
Line 714... Line 771...
714
 
771
 
715
  if (elf_group_name (newsect) == NULL)
772
  if (elf_group_name (newsect) == NULL)
716
    {
773
    {
717
      (*_bfd_error_handler) (_("%B: no group info for section %A"),
774
      (*_bfd_error_handler) (_("%B: no group info for section %A"),
-
 
775
			     abfd, newsect);
718
			     abfd, newsect);
776
      return FALSE;
719
    }
777
    }
720
  return TRUE;
778
  return TRUE;
Line 721... Line 779...
721
}
779
}
Line 777... Line 835...
777
    return result;
835
    return result;
Line 778... Line 836...
778
 
836
 
779
  for (i = 0; i < num_group; i++)
837
  for (i = 0; i < num_group; i++)
780
    {
838
    {
-
 
839
      Elf_Internal_Shdr *shdr = elf_tdata (abfd)->group_sect_ptr[i];
-
 
840
      Elf_Internal_Group *idx;
-
 
841
      unsigned int n_elt;
-
 
842
 
-
 
843
      /* PR binutils/18758: Beware of corrupt binaries with invalid group data.  */
-
 
844
      if (shdr == NULL || shdr->bfd_section == NULL || shdr->contents == NULL)
-
 
845
	{
-
 
846
	  (*_bfd_error_handler)
-
 
847
	    (_("%B: section group entry number %u is corrupt"),
-
 
848
	     abfd, i);
-
 
849
	  result = FALSE;
-
 
850
	  continue;
-
 
851
	}
781
      Elf_Internal_Shdr *shdr = elf_tdata (abfd)->group_sect_ptr[i];
852
 
782
      Elf_Internal_Group *idx = (Elf_Internal_Group *) shdr->contents;
853
      idx = (Elf_Internal_Group *) shdr->contents;
Line 783... Line 854...
783
      unsigned int n_elt = shdr->sh_size / 4;
854
      n_elt = shdr->sh_size / 4;
784
 
855
 
785
      while (--n_elt != 0)
856
      while (--n_elt != 0)
786
	if ((++idx)->shdr->bfd_section)
857
	if ((++idx)->shdr->bfd_section)
Line 815... Line 886...
815
bfd_elf_is_group_section (bfd *abfd ATTRIBUTE_UNUSED, const asection *sec)
886
bfd_elf_is_group_section (bfd *abfd ATTRIBUTE_UNUSED, const asection *sec)
816
{
887
{
817
  return elf_next_in_group (sec) != NULL;
888
  return elf_next_in_group (sec) != NULL;
818
}
889
}
Line -... Line 890...
-
 
890
 
-
 
891
static char *
-
 
892
convert_debug_to_zdebug (bfd *abfd, const char *name)
-
 
893
{
-
 
894
  unsigned int len = strlen (name);
-
 
895
  char *new_name = bfd_alloc (abfd, len + 2);
-
 
896
  if (new_name == NULL)
-
 
897
    return NULL;
-
 
898
  new_name[0] = '.';
-
 
899
  new_name[1] = 'z';
-
 
900
  memcpy (new_name + 2, name + 1, len);
-
 
901
  return new_name;
-
 
902
}
-
 
903
 
-
 
904
static char *
-
 
905
convert_zdebug_to_debug (bfd *abfd, const char *name)
-
 
906
{
-
 
907
  unsigned int len = strlen (name);
-
 
908
  char *new_name = bfd_alloc (abfd, len);
-
 
909
  if (new_name == NULL)
-
 
910
    return NULL;
-
 
911
  new_name[0] = '.';
-
 
912
  memcpy (new_name + 1, name + 2, len - 1);
-
 
913
  return new_name;
-
 
914
}
819
 
915
 
820
/* Make a BFD section from an ELF section.  We store a pointer to the
916
/* Make a BFD section from an ELF section.  We store a pointer to the
Line 821... Line 917...
821
   BFD section in the bfd_section field of the header.  */
917
   BFD section in the bfd_section field of the header.  */
822
 
918
 
Line 1001... Line 1097...
1001
  if ((flags & SEC_DEBUGGING)
1097
  if ((flags & SEC_DEBUGGING)
1002
      && ((name[1] == 'd' && name[6] == '_')
1098
      && ((name[1] == 'd' && name[6] == '_')
1003
	  || (name[1] == 'z' && name[7] == '_')))
1099
	  || (name[1] == 'z' && name[7] == '_')))
1004
    {
1100
    {
1005
      enum { nothing, compress, decompress } action = nothing;
1101
      enum { nothing, compress, decompress } action = nothing;
1006
      char *new_name;
1102
      int compression_header_size;
-
 
1103
      bfd_size_type uncompressed_size;
-
 
1104
      bfd_boolean compressed
-
 
1105
	= bfd_is_section_compressed_with_header (abfd, newsect,
-
 
1106
						 &compression_header_size,
-
 
1107
						 &uncompressed_size);
Line 1007... Line 1108...
1007
 
1108
 
1008
      if (bfd_is_section_compressed (abfd, newsect))
1109
      if (compressed)
1009
	{
1110
	{
1010
	  /* Compressed section.  Check if we should decompress.  */
1111
	  /* Compressed section.  Check if we should decompress.  */
1011
	  if ((abfd->flags & BFD_DECOMPRESS))
1112
	  if ((abfd->flags & BFD_DECOMPRESS))
1012
	    action = decompress;
1113
	    action = decompress;
-
 
1114
	}
-
 
1115
 
-
 
1116
      /* Compress the uncompressed section or convert from/to .zdebug*
1013
	}
1117
	 section.  Check if we should compress.  */
1014
      else
1118
      if (action == nothing)
-
 
1119
	{
-
 
1120
	  if (newsect->size != 0
1015
	{
1121
	      && (abfd->flags & BFD_COMPRESS)
-
 
1122
	      && compression_header_size >= 0
-
 
1123
	      && uncompressed_size > 0
-
 
1124
	      && (!compressed
1016
	  /* Normal section.  Check if we should compress.  */
1125
		  || ((compression_header_size > 0)
1017
	  if ((abfd->flags & BFD_COMPRESS) && newsect->size != 0)
1126
		      != ((abfd->flags & BFD_COMPRESS_GABI) != 0))))
-
 
1127
	    action = compress;
-
 
1128
	  else
1018
	    action = compress;
1129
	    return TRUE;
Line 1019... Line -...
1019
	}
-
 
1020
 
1130
	}
1021
      new_name = NULL;
1131
 
1022
      switch (action)
-
 
1023
	{
-
 
1024
	case nothing:
-
 
1025
	  break;
1132
      if (action == compress)
1026
	case compress:
1133
	{
1027
	  if (!bfd_init_section_compress_status (abfd, newsect))
1134
	  if (!bfd_init_section_compress_status (abfd, newsect))
1028
	    {
1135
	    {
1029
	      (*_bfd_error_handler)
1136
	      (*_bfd_error_handler)
1030
		(_("%B: unable to initialize compress status for section %s"),
1137
		(_("%B: unable to initialize compress status for section %s"),
1031
		 abfd, name);
1138
		 abfd, name);
1032
	      return FALSE;
-
 
1033
	    }
-
 
1034
	  if (name[1] != 'z')
-
 
1035
	    {
-
 
1036
	      unsigned int len = strlen (name);
-
 
1037
 
-
 
1038
	      new_name = bfd_alloc (abfd, len + 2);
-
 
1039
	      if (new_name == NULL)
-
 
1040
		return FALSE;
-
 
1041
	      new_name[0] = '.';
-
 
1042
	      new_name[1] = 'z';
1139
	      return FALSE;
1043
	      memcpy (new_name + 2, name + 1, len);
1140
	    }
1044
	    }
1141
	}
1045
	  break;
1142
      else
1046
	case decompress:
1143
	{
1047
	  if (!bfd_init_section_decompress_status (abfd, newsect))
1144
	  if (!bfd_init_section_decompress_status (abfd, newsect))
1048
	    {
1145
	    {
1049
	      (*_bfd_error_handler)
1146
	      (*_bfd_error_handler)
1050
		(_("%B: unable to initialize decompress status for section %s"),
1147
		(_("%B: unable to initialize decompress status for section %s"),
1051
		 abfd, name);
1148
		 abfd, name);
1052
	      return FALSE;
-
 
1053
	    }
1149
	      return FALSE;
1054
	  if (name[1] == 'z')
-
 
Line -... Line 1150...
-
 
1150
	    }
-
 
1151
	}
-
 
1152
 
-
 
1153
      if (abfd->is_linker_input)
-
 
1154
	{
-
 
1155
	  if (name[1] == 'z'
-
 
1156
	      && (action == decompress
-
 
1157
		  || (action == compress
-
 
1158
		      && (abfd->flags & BFD_COMPRESS_GABI) != 0)))
-
 
1159
	    {
1055
	    {
1160
	      /* Convert section name from .zdebug_* to .debug_* so
1056
	      unsigned int len = strlen (name);
1161
		 that linker will consider this section as a debug
1057
 
1162
		 section.  */
1058
	      new_name = bfd_alloc (abfd, len);
-
 
1059
	      if (new_name == NULL)
1163
	      char *new_name = convert_zdebug_to_debug (abfd, name);
1060
		return FALSE;
1164
	      if (new_name == NULL)
1061
	      new_name[0] = '.';
-
 
1062
	      memcpy (new_name + 1, name + 2, len - 1);
1165
		return FALSE;
1063
	    }
1166
	      bfd_rename_section (abfd, newsect, new_name);
-
 
1167
	    }
1064
	  break;
1168
	}
-
 
1169
      else
1065
	}
1170
	/* For objdump, don't rename the section.  For objcopy, delay
Line 1066... Line 1171...
1066
      if (new_name != NULL)
1171
	   section rename to elf_fake_sections.  */
1067
	bfd_rename_section (abfd, newsect, new_name);
1172
	newsect->flags |= SEC_ELF_RENAME;
Line 1115... Line 1220...
1115
{
1220
{
1116
  if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
1221
  if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
1117
      || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
1222
      || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
1118
    return TRUE;
1223
    return TRUE;
Line 1119... Line 1224...
1119
 
1224
 
1120
  BFD_ASSERT (!elf_flags_init (obfd)
-
 
1121
	      || (elf_elfheader (obfd)->e_flags
-
 
1122
		  == elf_elfheader (ibfd)->e_flags));
1225
  if (!elf_flags_init (obfd))
1123
 
-
 
1124
  elf_gp (obfd) = elf_gp (ibfd);
1226
    {
1125
  elf_elfheader (obfd)->e_flags = elf_elfheader (ibfd)->e_flags;
1227
      elf_elfheader (obfd)->e_flags = elf_elfheader (ibfd)->e_flags;
-
 
1228
      elf_flags_init (obfd) = TRUE;
-
 
1229
    }
-
 
1230
 
-
 
1231
  elf_gp (obfd) = elf_gp (ibfd);
-
 
1232
 
-
 
1233
  /* Also copy the EI_OSABI field.  */
-
 
1234
  elf_elfheader (obfd)->e_ident[EI_OSABI] =
Line 1126... Line 1235...
1126
  elf_flags_init (obfd) = TRUE;
1235
    elf_elfheader (ibfd)->e_ident[EI_OSABI];
1127
 
1236
 
-
 
1237
  /* Copy object attributes.  */
-
 
1238
  _bfd_elf_copy_obj_attributes (ibfd, obfd);
-
 
1239
 
-
 
1240
  /* This is an feature for objcopy --only-keep-debug:  When a section's type
-
 
1241
     is changed to NOBITS, we preserve the sh_link and sh_info fields so that
-
 
1242
     they can be matched up with the original.  */
-
 
1243
  Elf_Internal_Shdr ** iheaders = elf_elfsections (ibfd);
-
 
1244
  Elf_Internal_Shdr ** oheaders = elf_elfsections (obfd);
-
 
1245
 
-
 
1246
  if (iheaders != NULL && oheaders != NULL)
-
 
1247
    {
-
 
1248
      unsigned int i;
-
 
1249
 
-
 
1250
      for (i = 0; i < elf_numsections (obfd); i++)
-
 
1251
	{
-
 
1252
	  unsigned int j;
-
 
1253
	  Elf_Internal_Shdr * oheader = oheaders[i];
-
 
1254
 
-
 
1255
	  if (oheader == NULL
-
 
1256
	      || oheader->sh_type != SHT_NOBITS
-
 
1257
	      || oheader->sh_size == 0
-
 
1258
	      || (oheader->sh_info != 0 && oheader->sh_link != 0))
-
 
1259
	    continue;
-
 
1260
 
-
 
1261
	  /* Scan for the matching section in the input bfd.
-
 
1262
	     FIXME: We could use something better than a linear scan here.
-
 
1263
	     Unfortunately we cannot compare names as the output string table
-
 
1264
	     is empty, so instead we check size, address and type.  */
-
 
1265
	  for (j = 0; j < elf_numsections (ibfd); j++)
-
 
1266
	    {
-
 
1267
	      Elf_Internal_Shdr * iheader = iheaders[j];
-
 
1268
 
-
 
1269
	      /* Since --only-keep-debug turns all non-debug sections
-
 
1270
		 into SHT_NOBITS sections, the output SHT_NOBITS type
-
 
1271
		 matches any input type.  */
-
 
1272
	      if ((oheader->sh_type == SHT_NOBITS
-
 
1273
		   || iheader->sh_type == oheader->sh_type)
-
 
1274
		  && iheader->sh_flags == oheader->sh_flags
-
 
1275
		  && iheader->sh_addralign == oheader->sh_addralign
-
 
1276
		  && iheader->sh_entsize == oheader->sh_entsize
-
 
1277
		  && iheader->sh_size == oheader->sh_size
-
 
1278
		  && iheader->sh_addr == oheader->sh_addr
-
 
1279
		  && (iheader->sh_info != oheader->sh_info
-
 
1280
		      || iheader->sh_link != oheader->sh_link))
-
 
1281
		{
-
 
1282
		  /* Note: Strictly speaking these assignments are wrong.
-
 
1283
		     The sh_link and sh_info fields should point to the
-
 
1284
		     relevent sections in the output BFD, which may not be in
-
 
1285
		     the same location as they were in the input BFD.  But the
-
 
1286
		     whole point of this action is to preserve the original
-
 
1287
		     values of the sh_link and sh_info fields, so that they
-
 
1288
		     can be matched up with the section headers in the
-
 
1289
		     original file.  So strictly speaking we may be creating
-
 
1290
		     an invalid ELF file, but it is only for a file that just
-
 
1291
		     contains debug info and only for sections without any
-
 
1292
		     contents.  */
-
 
1293
		  if (oheader->sh_link == 0)
-
 
1294
		    oheader->sh_link = iheader->sh_link;
-
 
1295
		  if (oheader->sh_info == 0)
-
 
1296
		    oheader->sh_info = iheader->sh_info;
-
 
1297
		  break;
-
 
1298
		}
-
 
1299
	    }
-
 
1300
	}
1128
  /* Copy object attributes.  */
1301
    }
1129
  _bfd_elf_copy_obj_attributes (ibfd, obfd);
1302
 
Line 1130... Line 1303...
1130
  return TRUE;
1303
  return TRUE;
1131
}
1304
}
Line 1221... Line 1394...
1221
 
1394
 
1222
      extdynsize = get_elf_backend_data (abfd)->s->sizeof_dyn;
1395
      extdynsize = get_elf_backend_data (abfd)->s->sizeof_dyn;
Line 1223... Line 1396...
1223
      swap_dyn_in = get_elf_backend_data (abfd)->s->swap_dyn_in;
1396
      swap_dyn_in = get_elf_backend_data (abfd)->s->swap_dyn_in;
-
 
1397
 
-
 
1398
      extdyn = dynbuf;
-
 
1399
      /* PR 17512: file: 6f427532.  */
1224
 
1400
      if (s->size < extdynsize)
-
 
1401
	goto error_return;
-
 
1402
      extdynend = extdyn + s->size;
1225
      extdyn = dynbuf;
1403
      /* PR 17512: file: id:000006,sig:06,src:000000,op:flip4,pos:5664.
1226
      extdynend = extdyn + s->size;
1404
         Fix range check.  */
1227
      for (; extdyn < extdynend; extdyn += extdynsize)
1405
      for (; extdyn <= (extdynend - extdynsize); extdyn += extdynsize)
1228
	{
1406
	{
1229
	  Elf_Internal_Dyn dyn;
1407
	  Elf_Internal_Dyn dyn;
1230
	  const char *name = "";
1408
	  const char *name = "";
Line 1390... Line 1568...
1390
  if (dynbuf != NULL)
1568
  if (dynbuf != NULL)
1391
    free (dynbuf);
1569
    free (dynbuf);
1392
  return FALSE;
1570
  return FALSE;
1393
}
1571
}
Line -... Line 1572...
-
 
1572
 
-
 
1573
/* Get version string.  */
-
 
1574
 
-
 
1575
const char *
-
 
1576
_bfd_elf_get_symbol_version_string (bfd *abfd, asymbol *symbol,
-
 
1577
				    bfd_boolean *hidden)
-
 
1578
{
-
 
1579
  const char *version_string = NULL;
-
 
1580
  if (elf_dynversym (abfd) != 0
-
 
1581
      && (elf_dynverdef (abfd) != 0 || elf_dynverref (abfd) != 0))
-
 
1582
    {
-
 
1583
      unsigned int vernum = ((elf_symbol_type *) symbol)->version;
-
 
1584
 
-
 
1585
      *hidden = (vernum & VERSYM_HIDDEN) != 0;
-
 
1586
      vernum &= VERSYM_VERSION;
-
 
1587
 
-
 
1588
      if (vernum == 0)
-
 
1589
	version_string = "";
-
 
1590
      else if (vernum == 1)
-
 
1591
	version_string = "Base";
-
 
1592
      else if (vernum <= elf_tdata (abfd)->cverdefs)
-
 
1593
	version_string =
-
 
1594
	  elf_tdata (abfd)->verdef[vernum - 1].vd_nodename;
-
 
1595
      else
-
 
1596
	{
-
 
1597
	  Elf_Internal_Verneed *t;
-
 
1598
 
-
 
1599
	  version_string = "";
-
 
1600
	  for (t = elf_tdata (abfd)->verref;
-
 
1601
	       t != NULL;
-
 
1602
	       t = t->vn_nextref)
-
 
1603
	    {
-
 
1604
	      Elf_Internal_Vernaux *a;
-
 
1605
 
-
 
1606
	      for (a = t->vn_auxptr; a != NULL; a = a->vna_nextptr)
-
 
1607
		{
-
 
1608
		  if (a->vna_other == vernum)
-
 
1609
		    {
-
 
1610
		      version_string = a->vna_nodename;
-
 
1611
		      break;
-
 
1612
		    }
-
 
1613
		}
-
 
1614
	    }
-
 
1615
	}
-
 
1616
    }
-
 
1617
  return version_string;
-
 
1618
}
1394
 
1619
 
Line 1395... Line 1620...
1395
/* Display ELF-specific fields of a symbol.  */
1620
/* Display ELF-specific fields of a symbol.  */
1396
 
1621
 
1397
void
1622
void
Line 1416... Line 1641...
1416
	const char *section_name;
1641
	const char *section_name;
1417
	const char *name = NULL;
1642
	const char *name = NULL;
1418
	const struct elf_backend_data *bed;
1643
	const struct elf_backend_data *bed;
1419
	unsigned char st_other;
1644
	unsigned char st_other;
1420
	bfd_vma val;
1645
	bfd_vma val;
-
 
1646
	const char *version_string;
-
 
1647
	bfd_boolean hidden;
Line 1421... Line 1648...
1421
 
1648
 
Line 1422... Line 1649...
1422
	section_name = symbol->section ? symbol->section->name : "(*none*)";
1649
	section_name = symbol->section ? symbol->section->name : "(*none*)";
1423
 
1650
 
Line 1441... Line 1668...
1441
	else
1668
	else
1442
	  val = ((elf_symbol_type *) symbol)->internal_elf_sym.st_size;
1669
	  val = ((elf_symbol_type *) symbol)->internal_elf_sym.st_size;
1443
	bfd_fprintf_vma (abfd, file, val);
1670
	bfd_fprintf_vma (abfd, file, val);
Line 1444... Line 1671...
1444
 
1671
 
-
 
1672
	/* If we have version information, print it.  */
1445
	/* If we have version information, print it.  */
1673
	version_string = _bfd_elf_get_symbol_version_string (abfd,
1446
	if (elf_dynversym (abfd) != 0
1674
							     symbol,
1447
	    && (elf_dynverdef (abfd) != 0
1675
							     &hidden);
1448
		|| elf_dynverref (abfd) != 0))
1676
	if (version_string)
1449
	  {
-
 
1450
	    unsigned int vernum;
-
 
1451
	    const char *version_string;
-
 
1452
 
-
 
1453
	    vernum = ((elf_symbol_type *) symbol)->version & VERSYM_VERSION;
-
 
1454
 
1677
	  {
1455
	    if (vernum == 0)
-
 
1456
	      version_string = "";
-
 
1457
	    else if (vernum == 1)
-
 
1458
	      version_string = "Base";
-
 
1459
	    else if (vernum <= elf_tdata (abfd)->cverdefs)
-
 
1460
	      version_string =
-
 
1461
		elf_tdata (abfd)->verdef[vernum - 1].vd_nodename;
-
 
1462
	    else
-
 
1463
	      {
-
 
1464
		Elf_Internal_Verneed *t;
-
 
1465
 
-
 
1466
		version_string = "";
-
 
1467
		for (t = elf_tdata (abfd)->verref;
-
 
1468
		     t != NULL;
-
 
1469
		     t = t->vn_nextref)
-
 
1470
		  {
-
 
1471
		    Elf_Internal_Vernaux *a;
-
 
1472
 
-
 
1473
		    for (a = t->vn_auxptr; a != NULL; a = a->vna_nextptr)
-
 
1474
		      {
-
 
1475
			if (a->vna_other == vernum)
-
 
1476
			  {
-
 
1477
			    version_string = a->vna_nodename;
-
 
1478
			    break;
-
 
1479
			  }
-
 
1480
		      }
-
 
1481
		  }
-
 
1482
	      }
-
 
1483
 
-
 
1484
	    if ((((elf_symbol_type *) symbol)->version & VERSYM_HIDDEN) == 0)
1678
	    if (!hidden)
1485
	      fprintf (file, "  %-11s", version_string);
1679
	      fprintf (file, "  %-11s", version_string);
1486
	    else
1680
	    else
1487
	      {
1681
	      {
Line 1512... Line 1706...
1512
      }
1706
      }
1513
      break;
1707
      break;
1514
    }
1708
    }
1515
}
1709
}
Line 1516... Line -...
1516
 
-
 
1517
/* Allocate an ELF string table--force the first byte to be zero.  */
-
 
1518
 
-
 
1519
struct bfd_strtab_hash *
-
 
1520
_bfd_elf_stringtab_init (void)
-
 
1521
{
-
 
1522
  struct bfd_strtab_hash *ret;
-
 
1523
 
-
 
1524
  ret = _bfd_stringtab_init ();
-
 
1525
  if (ret != NULL)
-
 
1526
    {
-
 
1527
      bfd_size_type loc;
-
 
1528
 
-
 
1529
      loc = _bfd_stringtab_add (ret, "", TRUE, FALSE);
-
 
1530
      BFD_ASSERT (loc == 0 || loc == (bfd_size_type) -1);
-
 
1531
      if (loc == (bfd_size_type) -1)
-
 
1532
	{
-
 
1533
	  _bfd_stringtab_free (ret);
-
 
1534
	  ret = NULL;
-
 
1535
	}
-
 
1536
    }
-
 
1537
  return ret;
-
 
1538
}
-
 
1539

1710

Line 1540... Line 1711...
1540
/* ELF .o/exec file reading */
1711
/* ELF .o/exec file reading */
Line 1541... Line 1712...
1541
 
1712
 
Line 1546... Line 1717...
1546
{
1717
{
1547
  Elf_Internal_Shdr *hdr;
1718
  Elf_Internal_Shdr *hdr;
1548
  Elf_Internal_Ehdr *ehdr;
1719
  Elf_Internal_Ehdr *ehdr;
1549
  const struct elf_backend_data *bed;
1720
  const struct elf_backend_data *bed;
1550
  const char *name;
1721
  const char *name;
-
 
1722
  bfd_boolean ret = TRUE;
-
 
1723
  static bfd_boolean * sections_being_created = NULL;
-
 
1724
  static bfd * sections_being_created_abfd = NULL;
-
 
1725
  static unsigned int nesting = 0;
Line 1551... Line 1726...
1551
 
1726
 
1552
  if (shindex >= elf_numsections (abfd))
1727
  if (shindex >= elf_numsections (abfd))
Line -... Line 1728...
-
 
1728
    return FALSE;
-
 
1729
 
-
 
1730
  if (++ nesting > 3)
-
 
1731
    {
-
 
1732
      /* PR17512: A corrupt ELF binary might contain a recursive group of
-
 
1733
	 sections, with each the string indicies pointing to the next in the
-
 
1734
	 loop.  Detect this here, by refusing to load a section that we are
-
 
1735
	 already in the process of loading.  We only trigger this test if
-
 
1736
	 we have nested at least three sections deep as normal ELF binaries
-
 
1737
	 can expect to recurse at least once.
-
 
1738
 
-
 
1739
	 FIXME: It would be better if this array was attached to the bfd,
-
 
1740
	 rather than being held in a static pointer.  */
-
 
1741
 
-
 
1742
      if (sections_being_created_abfd != abfd)
-
 
1743
	sections_being_created = NULL;
-
 
1744
      if (sections_being_created == NULL)
-
 
1745
	{
-
 
1746
	  /* FIXME: It would be more efficient to attach this array to the bfd somehow.  */
-
 
1747
	  sections_being_created = (bfd_boolean *)
-
 
1748
	    bfd_zalloc (abfd, elf_numsections (abfd) * sizeof (bfd_boolean));
-
 
1749
	  sections_being_created_abfd = abfd;
-
 
1750
	}
-
 
1751
      if (sections_being_created [shindex])
-
 
1752
	{
-
 
1753
	  (*_bfd_error_handler)
-
 
1754
	    (_("%B: warning: loop in section dependencies detected"), abfd);
-
 
1755
	  return FALSE;
-
 
1756
	}
-
 
1757
      sections_being_created [shindex] = TRUE;
1553
    return FALSE;
1758
    }
1554
 
1759
 
1555
  hdr = elf_elfsections (abfd)[shindex];
1760
  hdr = elf_elfsections (abfd)[shindex];
1556
  ehdr = elf_elfheader (abfd);
1761
  ehdr = elf_elfheader (abfd);
1557
  name = bfd_elf_string_from_elf_section (abfd, ehdr->e_shstrndx,
1762
  name = bfd_elf_string_from_elf_section (abfd, ehdr->e_shstrndx,
1558
					  hdr->sh_name);
1763
					  hdr->sh_name);
Line 1559... Line 1764...
1559
  if (name == NULL)
1764
  if (name == NULL)
1560
    return FALSE;
1765
    goto fail;
1561
 
1766
 
1562
  bed = get_elf_backend_data (abfd);
1767
  bed = get_elf_backend_data (abfd);
1563
  switch (hdr->sh_type)
1768
  switch (hdr->sh_type)
1564
    {
1769
    {
Line 1565... Line 1770...
1565
    case SHT_NULL:
1770
    case SHT_NULL:
1566
      /* Inactive section. Throw it away.  */
1771
      /* Inactive section. Throw it away.  */
1567
      return TRUE;
1772
      goto success;
1568
 
1773
 
1569
    case SHT_PROGBITS:	/* Normal section with contents.  */
1774
    case SHT_PROGBITS:		/* Normal section with contents.  */
1570
    case SHT_NOBITS:	/* .bss section.  */
1775
    case SHT_NOBITS:		/* .bss section.  */
1571
    case SHT_HASH:	/* .hash section.  */
1776
    case SHT_HASH:		/* .hash section.  */
1572
    case SHT_NOTE:	/* .note section.  */
1777
    case SHT_NOTE:		/* .note section.  */
1573
    case SHT_INIT_ARRAY:	/* .init_array section.  */
1778
    case SHT_INIT_ARRAY:	/* .init_array section.  */
1574
    case SHT_FINI_ARRAY:	/* .fini_array section.  */
1779
    case SHT_FINI_ARRAY:	/* .fini_array section.  */
-
 
1780
    case SHT_PREINIT_ARRAY:	/* .preinit_array section.  */
Line 1575... Line 1781...
1575
    case SHT_PREINIT_ARRAY:	/* .preinit_array section.  */
1781
    case SHT_GNU_LIBLIST:	/* .gnu.liblist section.  */
1576
    case SHT_GNU_LIBLIST:	/* .gnu.liblist section.  */
1782
    case SHT_GNU_HASH:		/* .gnu.hash section.  */
1577
    case SHT_GNU_HASH:		/* .gnu.hash section.  */
1783
      ret = _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex);
-
 
1784
      goto success;
1578
      return _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex);
1785
 
1579
 
1786
    case SHT_DYNAMIC:	/* Dynamic linking information.  */
1580
    case SHT_DYNAMIC:	/* Dynamic linking information.  */
1787
      if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex))
1581
      if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex))
1788
	goto fail;
1582
	return FALSE;
1789
 
Line 1591... Line 1798...
1591
	      if (hdr->sh_link == (SHN_LORESERVE & 0xffff) /* SHN_BEFORE */
1798
	      if (hdr->sh_link == (SHN_LORESERVE & 0xffff) /* SHN_BEFORE */
1592
		  || hdr->sh_link == ((SHN_LORESERVE + 1) & 0xffff) /* SHN_AFTER */)
1799
		  || hdr->sh_link == ((SHN_LORESERVE + 1) & 0xffff) /* SHN_AFTER */)
1593
		break;
1800
		break;
1594
	      /* Otherwise fall through.  */
1801
	      /* Otherwise fall through.  */
1595
	    default:
1802
	    default:
1596
	      return FALSE;
1803
	      goto fail;
1597
	    }
1804
	    }
1598
	}
1805
	}
1599
      else if (elf_elfsections (abfd)[hdr->sh_link] == NULL)
1806
      else if (elf_elfsections (abfd)[hdr->sh_link] == NULL)
1600
	return FALSE;
1807
	goto fail;
1601
      else if (elf_elfsections (abfd)[hdr->sh_link]->sh_type != SHT_STRTAB)
1808
      else if (elf_elfsections (abfd)[hdr->sh_link]->sh_type != SHT_STRTAB)
1602
	{
1809
	{
1603
	  Elf_Internal_Shdr *dynsymhdr;
1810
	  Elf_Internal_Shdr *dynsymhdr;
Line 1604... Line 1811...
1604
 
1811
 
Line 1624... Line 1831...
1624
		      break;
1831
		      break;
1625
		    }
1832
		    }
1626
		}
1833
		}
1627
	    }
1834
	    }
1628
	}
1835
	}
1629
      break;
1836
      goto success;
Line 1630... Line 1837...
1630
 
1837
 
1631
    case SHT_SYMTAB:		/* A symbol table */
1838
    case SHT_SYMTAB:		/* A symbol table.  */
1632
      if (elf_onesymtab (abfd) == shindex)
1839
      if (elf_onesymtab (abfd) == shindex)
Line 1633... Line 1840...
1633
	return TRUE;
1840
	goto success;
1634
 
1841
 
-
 
1842
      if (hdr->sh_entsize != bed->s->sizeof_sym)
1635
      if (hdr->sh_entsize != bed->s->sizeof_sym)
1843
	goto fail;
1636
	return FALSE;
1844
 
1637
      if (hdr->sh_info * hdr->sh_entsize > hdr->sh_size)
1845
      if (hdr->sh_info * hdr->sh_entsize > hdr->sh_size)
1638
	{
1846
	{
1639
	  if (hdr->sh_size != 0)
1847
	  if (hdr->sh_size != 0)
1640
	    return FALSE;
1848
	    goto fail;
1641
	  /* Some assemblers erroneously set sh_info to one with a
1849
	  /* Some assemblers erroneously set sh_info to one with a
1642
	     zero sh_size.  ld sees this as a global symbol count
1850
	     zero sh_size.  ld sees this as a global symbol count
1643
	     of (unsigned) -1.  Fix it here.  */
1851
	     of (unsigned) -1.  Fix it here.  */
-
 
1852
	  hdr->sh_info = 0;
-
 
1853
	  goto success;
-
 
1854
	}
-
 
1855
 
-
 
1856
      /* PR 18854: A binary might contain more than one symbol table.
-
 
1857
	 Unusual, but possible.  Warn, but continue.  */
-
 
1858
      if (elf_onesymtab (abfd) != 0)
-
 
1859
	{
-
 
1860
	  (*_bfd_error_handler)
-
 
1861
	    (_("%B: warning: multiple symbol tables detected - ignoring the table in section %u"),
1644
	  hdr->sh_info = 0;
1862
	     abfd, shindex);
1645
	  return TRUE;
-
 
1646
	}
1863
	  goto success;
1647
      BFD_ASSERT (elf_onesymtab (abfd) == 0);
1864
	}
1648
      elf_onesymtab (abfd) = shindex;
1865
      elf_onesymtab (abfd) = shindex;
1649
      elf_tdata (abfd)->symtab_hdr = *hdr;
1866
      elf_symtab_hdr (abfd) = *hdr;
Line 1650... Line 1867...
1650
      elf_elfsections (abfd)[shindex] = hdr = &elf_tdata (abfd)->symtab_hdr;
1867
      elf_elfsections (abfd)[shindex] = hdr = & elf_symtab_hdr (abfd);
1651
      abfd->flags |= HAS_SYMS;
1868
      abfd->flags |= HAS_SYMS;
1652
 
1869
 
Line 1658... Line 1875...
1658
	 linker.  */
1875
	 linker.  */
1659
      if ((hdr->sh_flags & SHF_ALLOC) != 0
1876
      if ((hdr->sh_flags & SHF_ALLOC) != 0
1660
	  && (abfd->flags & DYNAMIC) != 0
1877
	  && (abfd->flags & DYNAMIC) != 0
1661
	  && ! _bfd_elf_make_section_from_shdr (abfd, hdr, name,
1878
	  && ! _bfd_elf_make_section_from_shdr (abfd, hdr, name,
1662
						shindex))
1879
						shindex))
1663
	return FALSE;
1880
	goto fail;
Line 1664... Line 1881...
1664
 
1881
 
1665
      /* Go looking for SHT_SYMTAB_SHNDX too, since if there is one we
1882
      /* Go looking for SHT_SYMTAB_SHNDX too, since if there is one we
1666
	 can't read symbols without that section loaded as well.  It
1883
	 can't read symbols without that section loaded as well.  It
1667
	 is most likely specified by the next section header.  */
-
 
1668
      if (elf_elfsections (abfd)[elf_symtab_shndx (abfd)]->sh_link != shindex)
1884
	 is most likely specified by the next section header.  */
-
 
1885
      {
1669
	{
1886
	elf_section_list * entry;
Line -... Line 1887...
-
 
1887
	unsigned int i, num_sec;
-
 
1888
 
-
 
1889
	for (entry = elf_symtab_shndx_list (abfd); entry != NULL; entry = entry->next)
-
 
1890
	  if (entry->hdr.sh_link == shindex)
1670
	  unsigned int i, num_sec;
1891
	    goto success;
1671
 
1892
 
1672
	  num_sec = elf_numsections (abfd);
1893
	num_sec = elf_numsections (abfd);
1673
	  for (i = shindex + 1; i < num_sec; i++)
1894
	for (i = shindex + 1; i < num_sec; i++)
-
 
1895
	  {
1674
	    {
1896
	    Elf_Internal_Shdr *hdr2 = elf_elfsections (abfd)[i];
1675
	      Elf_Internal_Shdr *hdr2 = elf_elfsections (abfd)[i];
1897
 
1676
	      if (hdr2->sh_type == SHT_SYMTAB_SHNDX
1898
	    if (hdr2->sh_type == SHT_SYMTAB_SHNDX
1677
		  && hdr2->sh_link == shindex)
1899
		&& hdr2->sh_link == shindex)
-
 
1900
	      break;
1678
		break;
1901
	  }
1679
	    }
1902
 
1680
	  if (i == num_sec)
1903
	if (i == num_sec)
1681
	    for (i = 1; i < shindex; i++)
1904
	  for (i = 1; i < shindex; i++)
-
 
1905
	    {
1682
	      {
1906
	      Elf_Internal_Shdr *hdr2 = elf_elfsections (abfd)[i];
1683
		Elf_Internal_Shdr *hdr2 = elf_elfsections (abfd)[i];
1907
 
1684
		if (hdr2->sh_type == SHT_SYMTAB_SHNDX
1908
	      if (hdr2->sh_type == SHT_SYMTAB_SHNDX
1685
		    && hdr2->sh_link == shindex)
1909
		  && hdr2->sh_link == shindex)
-
 
1910
		break;
1686
		  break;
1911
	    }
1687
	      }
1912
 
-
 
1913
	if (i != shindex)
-
 
1914
	  ret = bfd_section_from_shdr (abfd, i);
1688
	  if (i != shindex)
1915
	/* else FIXME: we have failed to find the symbol table - should we issue an error ? */
1689
	    return bfd_section_from_shdr (abfd, i);
-
 
Line 1690... Line 1916...
1690
	}
1916
	goto success;
1691
      return TRUE;
1917
      }
1692
 
1918
 
Line 1693... Line 1919...
1693
    case SHT_DYNSYM:		/* A dynamic symbol table */
1919
    case SHT_DYNSYM:		/* A dynamic symbol table.  */
1694
      if (elf_dynsymtab (abfd) == shindex)
1920
      if (elf_dynsymtab (abfd) == shindex)
-
 
1921
	goto success;
1695
	return TRUE;
1922
 
1696
 
1923
      if (hdr->sh_entsize != bed->s->sizeof_sym)
1697
      if (hdr->sh_entsize != bed->s->sizeof_sym)
1924
	goto fail;
1698
	return FALSE;
1925
 
-
 
1926
      if (hdr->sh_info * hdr->sh_entsize > hdr->sh_size)
1699
      if (hdr->sh_info * hdr->sh_entsize > hdr->sh_size)
1927
	{
1700
	{
1928
	  if (hdr->sh_size != 0)
1701
	  if (hdr->sh_size != 0)
1929
	    goto fail;
1702
	    return FALSE;
1930
 
1703
	  /* Some linkers erroneously set sh_info to one with a
1931
	  /* Some linkers erroneously set sh_info to one with a
-
 
1932
	     zero sh_size.  ld sees this as a global symbol count
-
 
1933
	     of (unsigned) -1.  Fix it here.  */
-
 
1934
	  hdr->sh_info = 0;
-
 
1935
	  goto success;
-
 
1936
	}
-
 
1937
 
-
 
1938
      /* PR 18854: A binary might contain more than one dynamic symbol table.
-
 
1939
	 Unusual, but possible.  Warn, but continue.  */
-
 
1940
      if (elf_dynsymtab (abfd) != 0)
-
 
1941
	{
1704
	     zero sh_size.  ld sees this as a global symbol count
1942
	  (*_bfd_error_handler)
1705
	     of (unsigned) -1.  Fix it here.  */
-
 
1706
	  hdr->sh_info = 0;
1943
	    (_("%B: warning: multiple dynamic symbol tables detected - ignoring the table in section %u"),
1707
	  return TRUE;
1944
	     abfd, shindex);
1708
	}
1945
	  goto success;
1709
      BFD_ASSERT (elf_dynsymtab (abfd) == 0);
1946
	}
Line 1710... Line 1947...
1710
      elf_dynsymtab (abfd) = shindex;
1947
      elf_dynsymtab (abfd) = shindex;
1711
      elf_tdata (abfd)->dynsymtab_hdr = *hdr;
1948
      elf_tdata (abfd)->dynsymtab_hdr = *hdr;
1712
      elf_elfsections (abfd)[shindex] = hdr = &elf_tdata (abfd)->dynsymtab_hdr;
1949
      elf_elfsections (abfd)[shindex] = hdr = &elf_tdata (abfd)->dynsymtab_hdr;
-
 
1950
      abfd->flags |= HAS_SYMS;
Line 1713... Line 1951...
1713
      abfd->flags |= HAS_SYMS;
1951
 
1714
 
1952
      /* Besides being a symbol table, we also treat this as a regular
1715
      /* Besides being a symbol table, we also treat this as a regular
1953
	 section, so that objcopy can handle it.  */
Line 1716... Line 1954...
1716
	 section, so that objcopy can handle it.  */
1954
      ret = _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex);
1717
      return _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex);
1955
      goto success;
-
 
1956
 
-
 
1957
    case SHT_SYMTAB_SHNDX:	/* Symbol section indices when >64k sections.  */
-
 
1958
      {
-
 
1959
	elf_section_list * entry;
-
 
1960
 
-
 
1961
	for (entry = elf_symtab_shndx_list (abfd); entry != NULL; entry = entry->next)
-
 
1962
	  if (entry->ndx == shindex)
1718
 
1963
	    goto success;
-
 
1964
	
1719
    case SHT_SYMTAB_SHNDX:	/* Symbol section indices when >64k sections */
1965
	entry = bfd_alloc (abfd, sizeof * entry);
-
 
1966
	if (entry == NULL)
1720
      if (elf_symtab_shndx (abfd) == shindex)
1967
	  goto fail;
Line 1721... Line 1968...
1721
	return TRUE;
1968
	entry->ndx = shindex;
1722
 
1969
	entry->hdr = * hdr;
1723
      BFD_ASSERT (elf_symtab_shndx (abfd) == 0);
1970
	entry->next = elf_symtab_shndx_list (abfd);
-
 
1971
	elf_symtab_shndx_list (abfd) = entry;
1724
      elf_symtab_shndx (abfd) = shindex;
1972
	elf_elfsections (abfd)[shindex] = & entry->hdr;
1725
      elf_tdata (abfd)->symtab_shndx_hdr = *hdr;
1973
	goto success;
1726
      elf_elfsections (abfd)[shindex] = &elf_tdata (abfd)->symtab_shndx_hdr;
1974
      }
1727
      return TRUE;
1975
 
1728
 
1976
    case SHT_STRTAB:		/* A string table.  */
1729
    case SHT_STRTAB:		/* A string table */
1977
      if (hdr->bfd_section != NULL)
-
 
1978
	goto success;
1730
      if (hdr->bfd_section != NULL)
1979
 
1731
	return TRUE;
1980
      if (ehdr->e_shstrndx == shindex)
1732
      if (ehdr->e_shstrndx == shindex)
1981
	{
1733
	{
1982
	  elf_tdata (abfd)->shstrtab_hdr = *hdr;
1734
	  elf_tdata (abfd)->shstrtab_hdr = *hdr;
1983
	  elf_elfsections (abfd)[shindex] = &elf_tdata (abfd)->shstrtab_hdr;
1735
	  elf_elfsections (abfd)[shindex] = &elf_tdata (abfd)->shstrtab_hdr;
1984
	  goto success;
1736
	  return TRUE;
1985
	}
-
 
1986
 
1737
	}
1987
      if (elf_elfsections (abfd)[elf_onesymtab (abfd)]->sh_link == shindex)
1738
      if (elf_elfsections (abfd)[elf_onesymtab (abfd)]->sh_link == shindex)
1988
	{
1739
	{
1989
	symtab_strtab:
1740
	symtab_strtab:
1990
	  elf_tdata (abfd)->strtab_hdr = *hdr;
1741
	  elf_tdata (abfd)->strtab_hdr = *hdr;
1991
	  elf_elfsections (abfd)[shindex] = &elf_tdata (abfd)->strtab_hdr;
1742
	  elf_elfsections (abfd)[shindex] = &elf_tdata (abfd)->strtab_hdr;
1992
	  goto success;
1743
	  return TRUE;
1993
	}
1744
	}
1994
 
1745
      if (elf_elfsections (abfd)[elf_dynsymtab (abfd)]->sh_link == shindex)
1995
      if (elf_elfsections (abfd)[elf_dynsymtab (abfd)]->sh_link == shindex)
1746
	{
1996
	{
-
 
1997
	dynsymtab_strtab:
1747
	dynsymtab_strtab:
1998
	  elf_tdata (abfd)->dynstrtab_hdr = *hdr;
Line 1748... Line 1999...
1748
	  elf_tdata (abfd)->dynstrtab_hdr = *hdr;
1999
	  hdr = &elf_tdata (abfd)->dynstrtab_hdr;
1749
	  hdr = &elf_tdata (abfd)->dynstrtab_hdr;
2000
	  elf_elfsections (abfd)[shindex] = hdr;
1750
	  elf_elfsections (abfd)[shindex] = hdr;
2001
	  /* We also treat this as a regular section, so that objcopy
Line 1767... Line 2018...
1767
	      Elf_Internal_Shdr *hdr2 = elf_elfsections (abfd)[i];
2018
	      Elf_Internal_Shdr *hdr2 = elf_elfsections (abfd)[i];
1768
	      if (hdr2->sh_link == shindex)
2019
	      if (hdr2->sh_link == shindex)
1769
		{
2020
		{
1770
		  /* Prevent endless recursion on broken objects.  */
2021
		  /* Prevent endless recursion on broken objects.  */
1771
		  if (i == shindex)
2022
		  if (i == shindex)
1772
		    return FALSE;
2023
		    goto fail;
1773
		  if (! bfd_section_from_shdr (abfd, i))
2024
		  if (! bfd_section_from_shdr (abfd, i))
1774
		    return FALSE;
2025
		    goto fail;
1775
		  if (elf_onesymtab (abfd) == i)
2026
		  if (elf_onesymtab (abfd) == i)
1776
		    goto symtab_strtab;
2027
		    goto symtab_strtab;
1777
		  if (elf_dynsymtab (abfd) == i)
2028
		  if (elf_dynsymtab (abfd) == i)
1778
		    goto dynsymtab_strtab;
2029
		    goto dynsymtab_strtab;
1779
		}
2030
		}
1780
	    }
2031
	    }
1781
	}
2032
	}
1782
      return _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex);
2033
      ret = _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex);
-
 
2034
      goto success;
Line 1783... Line 2035...
1783
 
2035
 
1784
    case SHT_REL:
2036
    case SHT_REL:
1785
    case SHT_RELA:
2037
    case SHT_RELA:
1786
      /* *These* do a lot of work -- but build no sections!  */
2038
      /* *These* do a lot of work -- but build no sections!  */
Line 1792... Line 2044...
1792
	bfd_size_type amt;
2044
	bfd_size_type amt;
Line 1793... Line 2045...
1793
 
2045
 
1794
	if (hdr->sh_entsize
2046
	if (hdr->sh_entsize
1795
	    != (bfd_size_type) (hdr->sh_type == SHT_REL
2047
	    != (bfd_size_type) (hdr->sh_type == SHT_REL
1796
				? bed->s->sizeof_rel : bed->s->sizeof_rela))
2048
				? bed->s->sizeof_rel : bed->s->sizeof_rela))
Line 1797... Line 2049...
1797
	  return FALSE;
2049
	  goto fail;
1798
 
2050
 
1799
	/* Check for a bogus link to avoid crashing.  */
2051
	/* Check for a bogus link to avoid crashing.  */
1800
	if (hdr->sh_link >= num_sec)
2052
	if (hdr->sh_link >= num_sec)
1801
	  {
2053
	  {
1802
	    ((*_bfd_error_handler)
2054
	    ((*_bfd_error_handler)
1803
	     (_("%B: invalid link %lu for reloc section %s (index %u)"),
2055
	     (_("%B: invalid link %lu for reloc section %s (index %u)"),
1804
	      abfd, hdr->sh_link, name, shindex));
2056
	      abfd, hdr->sh_link, name, shindex));
-
 
2057
	    ret = _bfd_elf_make_section_from_shdr (abfd, hdr, name,
1805
	    return _bfd_elf_make_section_from_shdr (abfd, hdr, name,
2058
						   shindex);
Line 1806... Line 2059...
1806
						    shindex);
2059
	    goto success;
1807
	  }
2060
	  }
1808
 
2061
 
Line 1842... Line 2095...
1842
 
2095
 
1843
	/* Get the symbol table.  */
2096
	/* Get the symbol table.  */
1844
	if ((elf_elfsections (abfd)[hdr->sh_link]->sh_type == SHT_SYMTAB
2097
	if ((elf_elfsections (abfd)[hdr->sh_link]->sh_type == SHT_SYMTAB
1845
	     || elf_elfsections (abfd)[hdr->sh_link]->sh_type == SHT_DYNSYM)
2098
	     || elf_elfsections (abfd)[hdr->sh_link]->sh_type == SHT_DYNSYM)
1846
	    && ! bfd_section_from_shdr (abfd, hdr->sh_link))
2099
	    && ! bfd_section_from_shdr (abfd, hdr->sh_link))
Line 1847... Line 2100...
1847
	  return FALSE;
2100
	  goto fail;
1848
 
2101
 
1849
	/* If this reloc section does not use the main symbol table we
2102
	/* If this reloc section does not use the main symbol table we
1850
	   don't treat it as a reloc section.  BFD can't adequately
2103
	   don't treat it as a reloc section.  BFD can't adequately
Line 1857... Line 2110...
1857
	    || hdr->sh_link == SHN_UNDEF
2110
	    || hdr->sh_link == SHN_UNDEF
1858
	    || hdr->sh_info == SHN_UNDEF
2111
	    || hdr->sh_info == SHN_UNDEF
1859
	    || hdr->sh_info >= num_sec
2112
	    || hdr->sh_info >= num_sec
1860
	    || elf_elfsections (abfd)[hdr->sh_info]->sh_type == SHT_REL
2113
	    || elf_elfsections (abfd)[hdr->sh_info]->sh_type == SHT_REL
1861
	    || elf_elfsections (abfd)[hdr->sh_info]->sh_type == SHT_RELA)
2114
	    || elf_elfsections (abfd)[hdr->sh_info]->sh_type == SHT_RELA)
-
 
2115
	  {
1862
	  return _bfd_elf_make_section_from_shdr (abfd, hdr, name,
2116
	    ret = _bfd_elf_make_section_from_shdr (abfd, hdr, name,
1863
						  shindex);
2117
						   shindex);
-
 
2118
	    goto success;
-
 
2119
	  }
Line 1864... Line 2120...
1864
 
2120
 
1865
	if (! bfd_section_from_shdr (abfd, hdr->sh_info))
2121
	if (! bfd_section_from_shdr (abfd, hdr->sh_info))
-
 
2122
	  goto fail;
1866
	  return FALSE;
2123
 
1867
	target_sect = bfd_section_from_elf_index (abfd, hdr->sh_info);
2124
	target_sect = bfd_section_from_elf_index (abfd, hdr->sh_info);
1868
	if (target_sect == NULL)
2125
	if (target_sect == NULL)
Line 1869... Line 2126...
1869
	  return FALSE;
2126
	  goto fail;
1870
 
2127
 
1871
	esdt = elf_section_data (target_sect);
2128
	esdt = elf_section_data (target_sect);
1872
	if (hdr->sh_type == SHT_RELA)
2129
	if (hdr->sh_type == SHT_RELA)
1873
	  p_hdr = &esdt->rela.hdr;
2130
	  p_hdr = &esdt->rela.hdr;
Line -... Line 2131...
-
 
2131
	else
1874
	else
2132
	  p_hdr = &esdt->rel.hdr;
-
 
2133
 
1875
	  p_hdr = &esdt->rel.hdr;
2134
	/* PR 17512: file: 0b4f81b7.  */
1876
 
2135
	if (*p_hdr != NULL)
1877
	BFD_ASSERT (*p_hdr == NULL);
2136
	  goto fail;
1878
	amt = sizeof (*hdr2);
2137
	amt = sizeof (*hdr2);
1879
	hdr2 = (Elf_Internal_Shdr *) bfd_alloc (abfd, amt);
2138
	hdr2 = (Elf_Internal_Shdr *) bfd_alloc (abfd, amt);
1880
	if (hdr2 == NULL)
2139
	if (hdr2 == NULL)
1881
	  return FALSE;
2140
	  goto fail;
1882
	*hdr2 = *hdr;
2141
	*hdr2 = *hdr;
1883
	*p_hdr = hdr2;
2142
	*p_hdr = hdr2;
Line 1892... Line 2151...
1892
	  {
2151
	  {
1893
	    if (hdr->sh_type == SHT_RELA)
2152
	    if (hdr->sh_type == SHT_RELA)
1894
	      target_sect->use_rela_p = 1;
2153
	      target_sect->use_rela_p = 1;
1895
	  }
2154
	  }
1896
	abfd->flags |= HAS_RELOC;
2155
	abfd->flags |= HAS_RELOC;
1897
	return TRUE;
2156
	goto success;
1898
      }
2157
      }
Line 1899... Line 2158...
1899
 
2158
 
1900
    case SHT_GNU_verdef:
2159
    case SHT_GNU_verdef:
1901
      elf_dynverdef (abfd) = shindex;
2160
      elf_dynverdef (abfd) = shindex;
1902
      elf_tdata (abfd)->dynverdef_hdr = *hdr;
2161
      elf_tdata (abfd)->dynverdef_hdr = *hdr;
-
 
2162
      ret = _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex);
Line 1903... Line 2163...
1903
      return _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex);
2163
      goto success;
1904
 
2164
 
1905
    case SHT_GNU_versym:
2165
    case SHT_GNU_versym:
-
 
2166
      if (hdr->sh_entsize != sizeof (Elf_External_Versym))
1906
      if (hdr->sh_entsize != sizeof (Elf_External_Versym))
2167
	goto fail;
1907
	return FALSE;
2168
 
1908
      elf_dynversym (abfd) = shindex;
2169
      elf_dynversym (abfd) = shindex;
-
 
2170
      elf_tdata (abfd)->dynversym_hdr = *hdr;
Line 1909... Line 2171...
1909
      elf_tdata (abfd)->dynversym_hdr = *hdr;
2171
      ret = _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex);
1910
      return _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex);
2172
      goto success;
1911
 
2173
 
1912
    case SHT_GNU_verneed:
2174
    case SHT_GNU_verneed:
-
 
2175
      elf_dynverref (abfd) = shindex;
Line 1913... Line 2176...
1913
      elf_dynverref (abfd) = shindex;
2176
      elf_tdata (abfd)->dynverref_hdr = *hdr;
1914
      elf_tdata (abfd)->dynverref_hdr = *hdr;
2177
      ret = _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex);
Line 1915... Line 2178...
1915
      return _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex);
2178
      goto success;
1916
 
2179
 
1917
    case SHT_SHLIB:
2180
    case SHT_SHLIB:
-
 
2181
      goto success;
1918
      return TRUE;
2182
 
1919
 
2183
    case SHT_GROUP:
-
 
2184
      if (! IS_VALID_GROUP_SECTION_HEADER (hdr, GRP_ENTRY_SIZE))
1920
    case SHT_GROUP:
2185
	goto fail;
1921
      if (! IS_VALID_GROUP_SECTION_HEADER (hdr, GRP_ENTRY_SIZE))
2186
 
1922
	return FALSE;
2187
      if (!_bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex))
1923
      if (!_bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex))
2188
	goto fail;
1924
	return FALSE;
2189
 
Line -... Line 2190...
-
 
2190
      if (hdr->contents != NULL)
-
 
2191
	{
1925
      if (hdr->contents != NULL)
2192
	  Elf_Internal_Group *idx = (Elf_Internal_Group *) hdr->contents;
1926
	{
2193
	  unsigned int n_elt = hdr->sh_size / sizeof (* idx);
1927
	  Elf_Internal_Group *idx = (Elf_Internal_Group *) hdr->contents;
2194
	  asection *s;
Line 1928... Line 2195...
1928
	  unsigned int n_elt = hdr->sh_size / GRP_ENTRY_SIZE;
2195
 
1929
	  asection *s;
2196
	  if (n_elt == 0)
-
 
2197
	    goto fail;
1930
 
2198
	  if (idx->flags & GRP_COMDAT)
1931
	  if (idx->flags & GRP_COMDAT)
2199
	    hdr->bfd_section->flags
1932
	    hdr->bfd_section->flags
2200
	      |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
Line 1933... Line 2201...
1933
	      |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
2201
 
Line 1945... Line 2213...
1945
		  elf_next_in_group (hdr->bfd_section) = s;
2213
		  elf_next_in_group (hdr->bfd_section) = s;
1946
		  break;
2214
		  break;
1947
		}
2215
		}
1948
	    }
2216
	    }
1949
	}
2217
	}
1950
      break;
2218
      goto success;
Line 1951... Line 2219...
1951
 
2219
 
1952
    default:
2220
    default:
1953
      /* Possibly an attributes section.  */
2221
      /* Possibly an attributes section.  */
1954
      if (hdr->sh_type == SHT_GNU_ATTRIBUTES
2222
      if (hdr->sh_type == SHT_GNU_ATTRIBUTES
1955
	  || hdr->sh_type == bed->obj_attrs_section_type)
2223
	  || hdr->sh_type == bed->obj_attrs_section_type)
1956
	{
2224
	{
1957
	  if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex))
2225
	  if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex))
1958
	    return FALSE;
2226
	    goto fail;
1959
	  _bfd_elf_parse_attributes (abfd, hdr);
2227
	  _bfd_elf_parse_attributes (abfd, hdr);
1960
	  return TRUE;
2228
	  goto success;
Line 1961... Line 2229...
1961
	}
2229
	}
1962
 
2230
 
1963
      /* Check for any processor-specific section types.  */
2231
      /* Check for any processor-specific section types.  */
Line 1964... Line 2232...
1964
      if (bed->elf_backend_section_from_shdr (abfd, hdr, name, shindex))
2232
      if (bed->elf_backend_section_from_shdr (abfd, hdr, name, shindex))
1965
	return TRUE;
2233
	goto success;
1966
 
2234
 
1967
      if (hdr->sh_type >= SHT_LOUSER && hdr->sh_type <= SHT_HIUSER)
2235
      if (hdr->sh_type >= SHT_LOUSER && hdr->sh_type <= SHT_HIUSER)
Line 1972... Line 2240...
1972
	    (*_bfd_error_handler)
2240
	    (*_bfd_error_handler)
1973
	      (_("%B: don't know how to handle allocated, application "
2241
	      (_("%B: don't know how to handle allocated, application "
1974
		 "specific section `%s' [0x%8x]"),
2242
		 "specific section `%s' [0x%8x]"),
1975
	       abfd, name, hdr->sh_type);
2243
	       abfd, name, hdr->sh_type);
1976
	  else
2244
	  else
-
 
2245
	    {
1977
	    /* Allow sections reserved for applications.  */
2246
	      /* Allow sections reserved for applications.  */
1978
	    return _bfd_elf_make_section_from_shdr (abfd, hdr, name,
2247
	      ret = _bfd_elf_make_section_from_shdr (abfd, hdr, name,
1979
						    shindex);
2248
						     shindex);
-
 
2249
	      goto success;
-
 
2250
	    }
1980
	}
2251
	}
1981
      else if (hdr->sh_type >= SHT_LOPROC
2252
      else if (hdr->sh_type >= SHT_LOPROC
1982
	       && hdr->sh_type <= SHT_HIPROC)
2253
	       && hdr->sh_type <= SHT_HIPROC)
1983
	/* FIXME: We should handle this section.  */
2254
	/* FIXME: We should handle this section.  */
1984
	(*_bfd_error_handler)
2255
	(*_bfd_error_handler)
Line 1995... Line 2266...
1995
	    (*_bfd_error_handler)
2266
	    (*_bfd_error_handler)
1996
	      (_("%B: don't know how to handle OS specific section "
2267
	      (_("%B: don't know how to handle OS specific section "
1997
		 "`%s' [0x%8x]"),
2268
		 "`%s' [0x%8x]"),
1998
	       abfd, name, hdr->sh_type);
2269
	       abfd, name, hdr->sh_type);
1999
	  else
2270
	  else
-
 
2271
	    {
2000
	    /* Otherwise it should be processed.  */
2272
	      /* Otherwise it should be processed.  */
2001
	    return _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex);
2273
	      ret = _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex);
-
 
2274
	      goto success;
-
 
2275
	    }
2002
	}
2276
	}
2003
      else
2277
      else
2004
	/* FIXME: We should handle this section.  */
2278
	/* FIXME: We should handle this section.  */
2005
	(*_bfd_error_handler)
2279
	(*_bfd_error_handler)
2006
	  (_("%B: don't know how to handle section `%s' [0x%8x]"),
2280
	  (_("%B: don't know how to handle section `%s' [0x%8x]"),
2007
	   abfd, name, hdr->sh_type);
2281
	   abfd, name, hdr->sh_type);
Line 2008... Line 2282...
2008
 
2282
 
2009
      return FALSE;
2283
      goto fail;
Line -... Line 2284...
-
 
2284
    }
-
 
2285
 
-
 
2286
 fail:
-
 
2287
  ret = FALSE;
-
 
2288
 success:
-
 
2289
  if (sections_being_created && sections_being_created_abfd == abfd)
-
 
2290
    sections_being_created [shindex] = FALSE;
-
 
2291
  if (-- nesting == 0)
-
 
2292
    {
-
 
2293
      sections_being_created = NULL;
2010
    }
2294
      sections_being_created_abfd = abfd;
2011
 
2295
    }
Line 2012... Line 2296...
2012
  return TRUE;
2296
  return ret;
Line 2013... Line 2297...
2013
}
2297
}
Line 2514... Line 2798...
2514
    }
2798
    }
2515
  else
2799
  else
2516
    return elf_section_data (sec)->rela.hdr;
2800
    return elf_section_data (sec)->rela.hdr;
2517
}
2801
}
Line -... Line 2802...
-
 
2802
 
-
 
2803
static bfd_boolean
-
 
2804
_bfd_elf_set_reloc_sh_name (bfd *abfd,
-
 
2805
			    Elf_Internal_Shdr *rel_hdr,
-
 
2806
			    const char *sec_name,
-
 
2807
			    bfd_boolean use_rela_p)
-
 
2808
{
-
 
2809
  char *name = (char *) bfd_alloc (abfd,
-
 
2810
				   sizeof ".rela" + strlen (sec_name));
-
 
2811
  if (name == NULL)
-
 
2812
    return FALSE;
-
 
2813
 
-
 
2814
  sprintf (name, "%s%s", use_rela_p ? ".rela" : ".rel", sec_name);
-
 
2815
  rel_hdr->sh_name =
-
 
2816
    (unsigned int) _bfd_elf_strtab_add (elf_shstrtab (abfd), name,
-
 
2817
					FALSE);
-
 
2818
  if (rel_hdr->sh_name == (unsigned int) -1)
-
 
2819
    return FALSE;
-
 
2820
 
-
 
2821
  return TRUE;
-
 
2822
}
2518
 
2823
 
2519
/* Allocate and initialize a section-header for a new reloc section,
2824
/* Allocate and initialize a section-header for a new reloc section,
2520
   containing relocations against ASECT.  It is stored in RELDATA.  If
2825
   containing relocations against ASECT.  It is stored in RELDATA.  If
2521
   USE_RELA_P is TRUE, we use RELA relocations; otherwise, we use REL
2826
   USE_RELA_P is TRUE, we use RELA relocations; otherwise, we use REL
Line 2522... Line 2827...
2522
   relocations.  */
2827
   relocations.  */
2523
 
2828
 
2524
static bfd_boolean
2829
static bfd_boolean
2525
_bfd_elf_init_reloc_shdr (bfd *abfd,
2830
_bfd_elf_init_reloc_shdr (bfd *abfd,
2526
			  struct bfd_elf_section_reloc_data *reldata,
2831
			  struct bfd_elf_section_reloc_data *reldata,
-
 
2832
			  const char *sec_name,
2527
			  asection *asect,
2833
			  bfd_boolean use_rela_p,
2528
			  bfd_boolean use_rela_p)
2834
			  bfd_boolean delay_st_name_p)
2529
{
-
 
2530
  Elf_Internal_Shdr *rel_hdr;
2835
{
2531
  char *name;
2836
  Elf_Internal_Shdr *rel_hdr;
Line 2532... Line 2837...
2532
  const struct elf_backend_data *bed = get_elf_backend_data (abfd);
2837
  const struct elf_backend_data *bed = get_elf_backend_data (abfd);
2533
  bfd_size_type amt;
2838
  bfd_size_type amt;
2534
 
2839
 
2535
  amt = sizeof (Elf_Internal_Shdr);
2840
  amt = sizeof (Elf_Internal_Shdr);
Line 2536... Line -...
2536
  BFD_ASSERT (reldata->hdr == NULL);
-
 
2537
  rel_hdr = bfd_zalloc (abfd, amt);
-
 
2538
  reldata->hdr = rel_hdr;
2841
  BFD_ASSERT (reldata->hdr == NULL);
2539
 
-
 
2540
  amt = sizeof ".rela" + strlen (asect->name);
-
 
2541
  name = (char *) bfd_alloc (abfd, amt);
2842
  rel_hdr = bfd_zalloc (abfd, amt);
2542
  if (name == NULL)
2843
  reldata->hdr = rel_hdr;
2543
    return FALSE;
2844
 
2544
  sprintf (name, "%s%s", use_rela_p ? ".rela" : ".rel", asect->name);
-
 
2545
  rel_hdr->sh_name =
2845
  if (delay_st_name_p)
2546
    (unsigned int) _bfd_elf_strtab_add (elf_shstrtab (abfd), name,
2846
    rel_hdr->sh_name = (unsigned int) -1;
2547
					FALSE);
2847
  else if (!_bfd_elf_set_reloc_sh_name (abfd, rel_hdr, sec_name,
2548
  if (rel_hdr->sh_name == (unsigned int) -1)
2848
					use_rela_p))
2549
    return FALSE;
2849
    return FALSE;
Line 2585... Line 2885...
2585
  struct fake_section_arg *arg = (struct fake_section_arg *)fsarg;
2885
  struct fake_section_arg *arg = (struct fake_section_arg *)fsarg;
2586
  const struct elf_backend_data *bed = get_elf_backend_data (abfd);
2886
  const struct elf_backend_data *bed = get_elf_backend_data (abfd);
2587
  struct bfd_elf_section_data *esd = elf_section_data (asect);
2887
  struct bfd_elf_section_data *esd = elf_section_data (asect);
2588
  Elf_Internal_Shdr *this_hdr;
2888
  Elf_Internal_Shdr *this_hdr;
2589
  unsigned int sh_type;
2889
  unsigned int sh_type;
-
 
2890
  const char *name = asect->name;
-
 
2891
  bfd_boolean delay_st_name_p = FALSE;
Line 2590... Line 2892...
2590
 
2892
 
2591
  if (arg->failed)
2893
  if (arg->failed)
2592
    {
2894
    {
2593
      /* We already failed; just get out of the bfd_map_over_sections
2895
      /* We already failed; just get out of the bfd_map_over_sections
2594
	 loop.  */
2896
	 loop.  */
2595
      return;
2897
      return;
Line 2596... Line 2898...
2596
    }
2898
    }
Line -... Line 2899...
-
 
2899
 
-
 
2900
  this_hdr = &esd->this_hdr;
-
 
2901
 
-
 
2902
  if (arg->link_info)
-
 
2903
    {
-
 
2904
      /* ld: compress DWARF debug sections with names: .debug_*.  */
-
 
2905
      if ((arg->link_info->compress_debug & COMPRESS_DEBUG)
-
 
2906
	  && (asect->flags & SEC_DEBUGGING)
-
 
2907
	  && name[1] == 'd'
-
 
2908
	  && name[6] == '_')
-
 
2909
	{
-
 
2910
	  /* Set SEC_ELF_COMPRESS to indicate this section should be
-
 
2911
	     compressed.  */
-
 
2912
	  asect->flags |= SEC_ELF_COMPRESS;
-
 
2913
 
-
 
2914
	  /* If this section will be compressed, delay adding setion
-
 
2915
	     name to section name section after it is compressed in
-
 
2916
	     _bfd_elf_assign_file_positions_for_non_load.  */
-
 
2917
	  delay_st_name_p = TRUE;
-
 
2918
	}
-
 
2919
    }
-
 
2920
  else if ((asect->flags & SEC_ELF_RENAME))
-
 
2921
    {
-
 
2922
      /* objcopy: rename output DWARF debug section.  */
-
 
2923
      if ((abfd->flags & (BFD_DECOMPRESS | BFD_COMPRESS_GABI)))
-
 
2924
	{
-
 
2925
	  /* When we decompress or compress with SHF_COMPRESSED,
-
 
2926
	     convert section name from .zdebug_* to .debug_* if
-
 
2927
	     needed.  */
-
 
2928
	  if (name[1] == 'z')
-
 
2929
	    {
-
 
2930
	      char *new_name = convert_zdebug_to_debug (abfd, name);
-
 
2931
	      if (new_name == NULL)
-
 
2932
		{
-
 
2933
		  arg->failed = TRUE;
-
 
2934
		  return;
-
 
2935
		}
-
 
2936
	      name = new_name;
-
 
2937
	    }
-
 
2938
	}
-
 
2939
      else if (asect->compress_status == COMPRESS_SECTION_DONE)
-
 
2940
	{
-
 
2941
	  /* PR binutils/18087: Compression does not always make a
-
 
2942
	     section smaller.  So only rename the section when
-
 
2943
	     compression has actually taken place.  If input section
-
 
2944
	     name is .zdebug_*, we should never compress it again.  */
-
 
2945
	  char *new_name = convert_debug_to_zdebug (abfd, name);
-
 
2946
	  if (new_name == NULL)
-
 
2947
	    {
-
 
2948
	      arg->failed = TRUE;
-
 
2949
	      return;
-
 
2950
	    }
-
 
2951
	  BFD_ASSERT (name[1] != 'z');
-
 
2952
	  name = new_name;
-
 
2953
	}
-
 
2954
    }
-
 
2955
 
-
 
2956
  if (delay_st_name_p)
-
 
2957
    this_hdr->sh_name = (unsigned int) -1;
2597
 
2958
  else
2598
  this_hdr = &esd->this_hdr;
2959
    {
2599
 
2960
      this_hdr->sh_name
2600
  this_hdr->sh_name = (unsigned int) _bfd_elf_strtab_add (elf_shstrtab (abfd),
2961
	= (unsigned int) _bfd_elf_strtab_add (elf_shstrtab (abfd),
2601
							  asect->name, FALSE);
2962
					      name, FALSE);
2602
  if (this_hdr->sh_name == (unsigned int) -1)
2963
      if (this_hdr->sh_name == (unsigned int) -1)
2603
    {
2964
	{
-
 
2965
	  arg->failed = TRUE;
Line 2604... Line 2966...
2604
      arg->failed = TRUE;
2966
	  return;
Line 2605... Line 2967...
2605
      return;
2967
	}
2606
    }
2968
    }
Line 2614... Line 2976...
2614
    this_hdr->sh_addr = 0;
2976
    this_hdr->sh_addr = 0;
Line 2615... Line 2977...
2615
 
2977
 
2616
  this_hdr->sh_offset = 0;
2978
  this_hdr->sh_offset = 0;
2617
  this_hdr->sh_size = asect->size;
2979
  this_hdr->sh_size = asect->size;
-
 
2980
  this_hdr->sh_link = 0;
-
 
2981
  /* PR 17512: file: 0eb809fe, 8b0535ee.  */
-
 
2982
  if (asect->alignment_power >= (sizeof (bfd_vma) * 8) - 1)
-
 
2983
    {
-
 
2984
      (*_bfd_error_handler)
-
 
2985
	(_("%B: error: Alignment power %d of section `%A' is too big"),
-
 
2986
	 abfd, asect, asect->alignment_power);
-
 
2987
      arg->failed = TRUE;
-
 
2988
      return;
2618
  this_hdr->sh_link = 0;
2989
    }
2619
  this_hdr->sh_addralign = (bfd_vma) 1 << asect->alignment_power;
2990
  this_hdr->sh_addralign = (bfd_vma) 1 << asect->alignment_power;
2620
  /* The sh_entsize and sh_info fields may have been set already by
2991
  /* The sh_entsize and sh_info fields may have been set already by
Line 2621... Line 2992...
2621
     copy_private_section_data.  */
2992
     copy_private_section_data.  */
Line 2762... Line 3133...
2762
      /* When doing a relocatable link, create both REL and RELA sections if
3133
      /* When doing a relocatable link, create both REL and RELA sections if
2763
	 needed.  */
3134
	 needed.  */
2764
      if (arg->link_info
3135
      if (arg->link_info
2765
	  /* Do the normal setup if we wouldn't create any sections here.  */
3136
	  /* Do the normal setup if we wouldn't create any sections here.  */
2766
	  && esd->rel.count + esd->rela.count > 0
3137
	  && esd->rel.count + esd->rela.count > 0
-
 
3138
	  && (bfd_link_relocatable (arg->link_info)
2767
	  && (arg->link_info->relocatable || arg->link_info->emitrelocations))
3139
	      || arg->link_info->emitrelocations))
2768
	{
3140
	{
2769
	  if (esd->rel.count && esd->rel.hdr == NULL
3141
	  if (esd->rel.count && esd->rel.hdr == NULL
2770
	      && !_bfd_elf_init_reloc_shdr (abfd, &esd->rel, asect, FALSE))
3142
	      && !_bfd_elf_init_reloc_shdr (abfd, &esd->rel, name, FALSE,
-
 
3143
					    delay_st_name_p))
2771
	    {
3144
	    {
2772
	      arg->failed = TRUE;
3145
	      arg->failed = TRUE;
2773
	      return;
3146
	      return;
2774
	    }
3147
	    }
2775
	  if (esd->rela.count && esd->rela.hdr == NULL
3148
	  if (esd->rela.count && esd->rela.hdr == NULL
2776
	      && !_bfd_elf_init_reloc_shdr (abfd, &esd->rela, asect, TRUE))
3149
	      && !_bfd_elf_init_reloc_shdr (abfd, &esd->rela, name, TRUE,
-
 
3150
					    delay_st_name_p))
2777
	    {
3151
	    {
2778
	      arg->failed = TRUE;
3152
	      arg->failed = TRUE;
2779
	      return;
3153
	      return;
2780
	    }
3154
	    }
2781
	}
3155
	}
2782
      else if (!_bfd_elf_init_reloc_shdr (abfd,
3156
      else if (!_bfd_elf_init_reloc_shdr (abfd,
2783
					  (asect->use_rela_p
3157
					  (asect->use_rela_p
2784
					   ? &esd->rela : &esd->rel),
3158
					   ? &esd->rela : &esd->rel),
2785
					  asect,
3159
					  name,
2786
					  asect->use_rela_p))
3160
					  asect->use_rela_p,
-
 
3161
					  delay_st_name_p))
2787
	  arg->failed = TRUE;
3162
	  arg->failed = TRUE;
2788
    }
3163
    }
Line 2789... Line 3164...
2789
 
3164
 
2790
  /* Check for processor-specific section types.  */
3165
  /* Check for processor-specific section types.  */
Line 2915... Line 3290...
2915
    abort ();
3290
    abort ();
Line 2916... Line 3291...
2916
 
3291
 
2917
  H_PUT_32 (abfd, sec->flags & SEC_LINK_ONCE ? GRP_COMDAT : 0, loc);
3292
  H_PUT_32 (abfd, sec->flags & SEC_LINK_ONCE ? GRP_COMDAT : 0, loc);
Line -... Line 3293...
-
 
3293
}
-
 
3294
 
-
 
3295
/* Return the section which RELOC_SEC applies to.  */
-
 
3296
 
-
 
3297
asection *
-
 
3298
_bfd_elf_get_reloc_section (asection *reloc_sec)
-
 
3299
{
-
 
3300
  const char *name;
-
 
3301
  unsigned int type;
-
 
3302
  bfd *abfd;
-
 
3303
 
-
 
3304
  if (reloc_sec == NULL)
-
 
3305
    return NULL;
-
 
3306
 
-
 
3307
  type = elf_section_data (reloc_sec)->this_hdr.sh_type;
-
 
3308
  if (type != SHT_REL && type != SHT_RELA)
-
 
3309
    return NULL;
-
 
3310
 
-
 
3311
  /* We look up the section the relocs apply to by name.  */
-
 
3312
  name = reloc_sec->name;
-
 
3313
  if (type == SHT_REL)
-
 
3314
    name += 4;
-
 
3315
  else
-
 
3316
    name += 5;
-
 
3317
 
-
 
3318
  /* If a target needs .got.plt section, relocations in rela.plt/rel.plt
-
 
3319
     section apply to .got.plt section.  */
-
 
3320
  abfd = reloc_sec->owner;
-
 
3321
  if (get_elf_backend_data (abfd)->want_got_plt
-
 
3322
      && strcmp (name, ".plt") == 0)
-
 
3323
    {
-
 
3324
      /* .got.plt is a linker created input section.  It may be mapped
-
 
3325
	 to some other output section.  Try two likely sections.  */
-
 
3326
      name = ".got.plt";
-
 
3327
      reloc_sec = bfd_get_section_by_name (abfd, name);
-
 
3328
      if (reloc_sec != NULL)
-
 
3329
	return reloc_sec;
-
 
3330
      name = ".got";
-
 
3331
    }
-
 
3332
 
-
 
3333
  reloc_sec = bfd_get_section_by_name (abfd, name);
-
 
3334
  return reloc_sec;
2918
}
3335
}
2919
 
3336
 
2920
/* Assign all ELF section numbers.  The dummy first section is handled here
3337
/* Assign all ELF section numbers.  The dummy first section is handled here
Line 2921... Line 3338...
2921
   too.  The link/info pointers for the standard section types are filled
3338
   too.  The link/info pointers for the standard section types are filled
2922
   in here too, while we're at it.  */
3339
   in here too, while we're at it.  */
2923
 
3340
 
2924
static bfd_boolean
3341
static bfd_boolean
2925
assign_section_numbers (bfd *abfd, struct bfd_link_info *link_info)
3342
assign_section_numbers (bfd *abfd, struct bfd_link_info *link_info)
2926
{
3343
{
2927
  struct elf_obj_tdata *t = elf_tdata (abfd);
3344
  struct elf_obj_tdata *t = elf_tdata (abfd);
2928
  asection *sec;
3345
  asection *sec;
2929
  unsigned int section_number, secn;
3346
  unsigned int section_number;
Line 2930... Line 3347...
2930
  Elf_Internal_Shdr **i_shdrp;
3347
  Elf_Internal_Shdr **i_shdrp;
Line 2931... Line 3348...
2931
  struct bfd_elf_section_data *d;
3348
  struct bfd_elf_section_data *d;
Line 2932... Line 3349...
2932
  bfd_boolean need_symtab;
3349
  bfd_boolean need_symtab;
2933
 
3350
 
2934
  section_number = 1;
3351
  section_number = 1;
2935
 
3352
 
2936
  _bfd_elf_strtab_clear_all_refs (elf_shstrtab (abfd));
3353
  _bfd_elf_strtab_clear_all_refs (elf_shstrtab (abfd));
2937
 
3354
 
2938
  /* SHT_GROUP sections are in relocatable files only.  */
3355
  /* SHT_GROUP sections are in relocatable files only.  */
Line 2961... Line 3378...
2961
    {
3378
    {
2962
      d = elf_section_data (sec);
3379
      d = elf_section_data (sec);
Line 2963... Line 3380...
2963
 
3380
 
2964
      if (d->this_hdr.sh_type != SHT_GROUP)
3381
      if (d->this_hdr.sh_type != SHT_GROUP)
-
 
3382
	d->this_idx = section_number++;
2965
	d->this_idx = section_number++;
3383
      if (d->this_hdr.sh_name != (unsigned int) -1)
2966
      _bfd_elf_strtab_addref (elf_shstrtab (abfd), d->this_hdr.sh_name);
3384
	_bfd_elf_strtab_addref (elf_shstrtab (abfd), d->this_hdr.sh_name);
2967
      if (d->rel.hdr)
3385
      if (d->rel.hdr)
2968
	{
3386
	{
-
 
3387
	  d->rel.idx = section_number++;
2969
	  d->rel.idx = section_number++;
3388
	  if (d->rel.hdr->sh_name != (unsigned int) -1)
2970
	  _bfd_elf_strtab_addref (elf_shstrtab (abfd), d->rel.hdr->sh_name);
3389
	    _bfd_elf_strtab_addref (elf_shstrtab (abfd), d->rel.hdr->sh_name);
2971
	}
3390
	}
2972
      else
3391
      else
Line 2973... Line 3392...
2973
	d->rel.idx = 0;
3392
	d->rel.idx = 0;
2974
 
3393
 
2975
      if (d->rela.hdr)
3394
      if (d->rela.hdr)
-
 
3395
	{
2976
	{
3396
	  d->rela.idx = section_number++;
2977
	  d->rela.idx = section_number++;
3397
	  if (d->rela.hdr->sh_name != (unsigned int) -1)
2978
	  _bfd_elf_strtab_addref (elf_shstrtab (abfd), d->rela.hdr->sh_name);
3398
	    _bfd_elf_strtab_addref (elf_shstrtab (abfd), d->rela.hdr->sh_name);
2979
	}
3399
	}
2980
      else
3400
      else
Line 2993... Line 3413...
2993
    {
3413
    {
2994
      elf_onesymtab (abfd) = section_number++;
3414
      elf_onesymtab (abfd) = section_number++;
2995
      _bfd_elf_strtab_addref (elf_shstrtab (abfd), t->symtab_hdr.sh_name);
3415
      _bfd_elf_strtab_addref (elf_shstrtab (abfd), t->symtab_hdr.sh_name);
2996
      if (section_number > ((SHN_LORESERVE - 2) & 0xFFFF))
3416
      if (section_number > ((SHN_LORESERVE - 2) & 0xFFFF))
2997
	{
3417
	{
-
 
3418
	  elf_section_list * entry;
-
 
3419
 
-
 
3420
	  BFD_ASSERT (elf_symtab_shndx_list (abfd) == NULL);
-
 
3421
 
-
 
3422
	  entry = bfd_zalloc (abfd, sizeof * entry);
-
 
3423
	  entry->ndx = section_number++;
2998
	  elf_symtab_shndx (abfd) = section_number++;
3424
	  elf_symtab_shndx_list (abfd) = entry;
2999
	  t->symtab_shndx_hdr.sh_name
3425
	  entry->hdr.sh_name
3000
	    = (unsigned int) _bfd_elf_strtab_add (elf_shstrtab (abfd),
3426
	    = (unsigned int) _bfd_elf_strtab_add (elf_shstrtab (abfd),
3001
						  ".symtab_shndx", FALSE);
3427
						  ".symtab_shndx", FALSE);
3002
	  if (t->symtab_shndx_hdr.sh_name == (unsigned int) -1)
3428
	  if (entry->hdr.sh_name == (unsigned int) -1)
3003
	    return FALSE;
3429
	    return FALSE;
3004
	}
3430
	}
3005
      elf_strtab_sec (abfd) = section_number++;
3431
      elf_strtab_sec (abfd) = section_number++;
3006
      _bfd_elf_strtab_addref (elf_shstrtab (abfd), t->strtab_hdr.sh_name);
3432
      _bfd_elf_strtab_addref (elf_shstrtab (abfd), t->strtab_hdr.sh_name);
3007
    }
3433
    }
Line 3011... Line 3437...
3011
      _bfd_error_handler (_("%B: too many sections: %u"),
3437
      _bfd_error_handler (_("%B: too many sections: %u"),
3012
			  abfd, section_number);
3438
			  abfd, section_number);
3013
      return FALSE;
3439
      return FALSE;
3014
    }
3440
    }
Line 3015... Line -...
3015
 
-
 
3016
  _bfd_elf_strtab_finalize (elf_shstrtab (abfd));
-
 
3017
  t->shstrtab_hdr.sh_size = _bfd_elf_strtab_size (elf_shstrtab (abfd));
-
 
3018
 
3441
 
3019
  elf_numsections (abfd) = section_number;
3442
  elf_numsections (abfd) = section_number;
Line 3020... Line 3443...
3020
  elf_elfheader (abfd)->e_shnum = section_number;
3443
  elf_elfheader (abfd)->e_shnum = section_number;
3021
 
3444
 
Line 3040... Line 3463...
3040
  if (need_symtab)
3463
  if (need_symtab)
3041
    {
3464
    {
3042
      i_shdrp[elf_onesymtab (abfd)] = &t->symtab_hdr;
3465
      i_shdrp[elf_onesymtab (abfd)] = &t->symtab_hdr;
3043
      if (elf_numsections (abfd) > (SHN_LORESERVE & 0xFFFF))
3466
      if (elf_numsections (abfd) > (SHN_LORESERVE & 0xFFFF))
3044
	{
3467
	{
3045
	  i_shdrp[elf_symtab_shndx (abfd)] = &t->symtab_shndx_hdr;
3468
	  elf_section_list * entry = elf_symtab_shndx_list (abfd);
-
 
3469
	  BFD_ASSERT (entry != NULL);
-
 
3470
	  i_shdrp[entry->ndx] = & entry->hdr;
3046
	  t->symtab_shndx_hdr.sh_link = elf_onesymtab (abfd);
3471
	  entry->hdr.sh_link = elf_onesymtab (abfd);
3047
	}
3472
	}
3048
      i_shdrp[elf_strtab_sec (abfd)] = &t->strtab_hdr;
3473
      i_shdrp[elf_strtab_sec (abfd)] = &t->strtab_hdr;
3049
      t->symtab_hdr.sh_link = elf_strtab_sec (abfd);
3474
      t->symtab_hdr.sh_link = elf_strtab_sec (abfd);
3050
    }
3475
    }
Line 3051... Line 3476...
3051
 
3476
 
3052
  for (sec = abfd->sections; sec; sec = sec->next)
3477
  for (sec = abfd->sections; sec; sec = sec->next)
3053
    {
3478
    {
3054
      asection *s;
-
 
Line 3055... Line 3479...
3055
      const char *name;
3479
      asection *s;
Line 3056... Line 3480...
3056
 
3480
 
3057
      d = elf_section_data (sec);
3481
      d = elf_section_data (sec);
Line 3069... Line 3493...
3069
	 the relocation entries apply.  */
3493
	 the relocation entries apply.  */
3070
      if (d->rel.idx != 0)
3494
      if (d->rel.idx != 0)
3071
	{
3495
	{
3072
	  d->rel.hdr->sh_link = elf_onesymtab (abfd);
3496
	  d->rel.hdr->sh_link = elf_onesymtab (abfd);
3073
	  d->rel.hdr->sh_info = d->this_idx;
3497
	  d->rel.hdr->sh_info = d->this_idx;
-
 
3498
	  d->rel.hdr->sh_flags |= SHF_INFO_LINK;
3074
	}
3499
	}
3075
      if (d->rela.idx != 0)
3500
      if (d->rela.idx != 0)
3076
	{
3501
	{
3077
	  d->rela.hdr->sh_link = elf_onesymtab (abfd);
3502
	  d->rela.hdr->sh_link = elf_onesymtab (abfd);
3078
	  d->rela.hdr->sh_info = d->this_idx;
3503
	  d->rela.hdr->sh_info = d->this_idx;
-
 
3504
	  d->rela.hdr->sh_flags |= SHF_INFO_LINK;
3079
	}
3505
	}
Line 3080... Line 3506...
3080
 
3506
 
3081
      /* We need to set up sh_link for SHF_LINK_ORDER.  */
3507
      /* We need to set up sh_link for SHF_LINK_ORDER.  */
3082
      if ((d->this_hdr.sh_flags & SHF_LINK_ORDER) != 0)
3508
      if ((d->this_hdr.sh_flags & SHF_LINK_ORDER) != 0)
Line 3152... Line 3578...
3152
	     FIXME: How can we be sure?  */
3578
	     FIXME: How can we be sure?  */
3153
	  s = bfd_get_section_by_name (abfd, ".dynsym");
3579
	  s = bfd_get_section_by_name (abfd, ".dynsym");
3154
	  if (s != NULL)
3580
	  if (s != NULL)
3155
	    d->this_hdr.sh_link = elf_section_data (s)->this_idx;
3581
	    d->this_hdr.sh_link = elf_section_data (s)->this_idx;
Line 3156... Line -...
3156
 
-
 
3157
	  /* We look up the section the relocs apply to by name.  */
-
 
3158
	  name = sec->name;
-
 
3159
	  if (d->this_hdr.sh_type == SHT_REL)
-
 
3160
	    name += 4;
-
 
3161
	  else
-
 
3162
	    name += 5;
3582
 
3163
	  s = bfd_get_section_by_name (abfd, name);
3583
	  s = get_elf_backend_data (abfd)->get_reloc_section (sec);
-
 
3584
	  if (s != NULL)
3164
	  if (s != NULL)
3585
	    {
-
 
3586
	      d->this_hdr.sh_info = elf_section_data (s)->this_idx;
-
 
3587
	      d->this_hdr.sh_flags |= SHF_INFO_LINK;
3165
	    d->this_hdr.sh_info = elf_section_data (s)->this_idx;
3588
	    }
Line 3166... Line 3589...
3166
	  break;
3589
	  break;
3167
 
3590
 
3168
	case SHT_STRTAB:
3591
	case SHT_STRTAB:
Line 3231... Line 3654...
3231
	case SHT_GROUP:
3654
	case SHT_GROUP:
3232
	  d->this_hdr.sh_link = elf_onesymtab (abfd);
3655
	  d->this_hdr.sh_link = elf_onesymtab (abfd);
3233
	}
3656
	}
3234
    }
3657
    }
Line 3235... Line 3658...
3235
 
3658
 
3236
  for (secn = 1; secn < section_number; ++secn)
3659
  /* Delay setting sh_name to _bfd_elf_write_object_contents so that
3237
    if (i_shdrp[secn] == NULL)
3660
     _bfd_elf_assign_file_positions_for_non_load can convert DWARF
3238
      i_shdrp[secn] = i_shdrp[0];
3661
     debug section name from .debug_* to .zdebug_* if needed.  */
3239
    else
-
 
3240
      i_shdrp[secn]->sh_name = _bfd_elf_strtab_offset (elf_shstrtab (abfd),
-
 
3241
						       i_shdrp[secn]->sh_name);
3662
 
3242
  return TRUE;
3663
  return TRUE;
Line 3243... Line 3664...
3243
}
3664
}
3244
 
3665
 
Line 3287... Line 3708...
3287
  asymbol **sect_syms;
3708
  asymbol **sect_syms;
3288
  unsigned int num_locals = 0;
3709
  unsigned int num_locals = 0;
3289
  unsigned int num_globals = 0;
3710
  unsigned int num_globals = 0;
3290
  unsigned int num_locals2 = 0;
3711
  unsigned int num_locals2 = 0;
3291
  unsigned int num_globals2 = 0;
3712
  unsigned int num_globals2 = 0;
3292
  int max_index = 0;
3713
  unsigned int max_index = 0;
3293
  unsigned int idx;
3714
  unsigned int idx;
3294
  asection *asect;
3715
  asection *asect;
3295
  asymbol **new_syms;
3716
  asymbol **new_syms;
Line 3296... Line 3717...
3296
 
3717
 
Line 3436... Line 3857...
3436
					 struct bfd_link_info *link_info)
3857
					 struct bfd_link_info *link_info)
3437
{
3858
{
3438
  const struct elf_backend_data *bed = get_elf_backend_data (abfd);
3859
  const struct elf_backend_data *bed = get_elf_backend_data (abfd);
3439
  struct fake_section_arg fsargs;
3860
  struct fake_section_arg fsargs;
3440
  bfd_boolean failed;
3861
  bfd_boolean failed;
3441
  struct bfd_strtab_hash *strtab = NULL;
3862
  struct elf_strtab_hash *strtab = NULL;
3442
  Elf_Internal_Shdr *shstrtab_hdr;
3863
  Elf_Internal_Shdr *shstrtab_hdr;
3443
  bfd_boolean need_symtab;
3864
  bfd_boolean need_symtab;
Line 3444... Line 3865...
3444
 
3865
 
3445
  if (abfd->output_has_begun)
3866
  if (abfd->output_has_begun)
Line 3451... Line 3872...
3451
 
3872
 
3452
  if (! prep_headers (abfd))
3873
  if (! prep_headers (abfd))
Line 3453... Line 3874...
3453
    return FALSE;
3874
    return FALSE;
3454
 
-
 
3455
  /* Post process the headers if necessary.  */
3875
 
Line 3456... Line 3876...
3456
  if (bed->elf_backend_post_process_headers)
3876
  /* Post process the headers if necessary.  */
3457
    (*bed->elf_backend_post_process_headers) (abfd, link_info);
3877
  (*bed->elf_backend_post_process_headers) (abfd, link_info);
3458
 
3878
 
Line 3490... Line 3910...
3490
  shstrtab_hdr = &elf_tdata (abfd)->shstrtab_hdr;
3910
  shstrtab_hdr = &elf_tdata (abfd)->shstrtab_hdr;
3491
  /* sh_name was set in prep_headers.  */
3911
  /* sh_name was set in prep_headers.  */
3492
  shstrtab_hdr->sh_type = SHT_STRTAB;
3912
  shstrtab_hdr->sh_type = SHT_STRTAB;
3493
  shstrtab_hdr->sh_flags = 0;
3913
  shstrtab_hdr->sh_flags = 0;
3494
  shstrtab_hdr->sh_addr = 0;
3914
  shstrtab_hdr->sh_addr = 0;
3495
  shstrtab_hdr->sh_size = _bfd_elf_strtab_size (elf_shstrtab (abfd));
3915
  /* sh_size is set in _bfd_elf_assign_file_positions_for_non_load.  */
3496
  shstrtab_hdr->sh_entsize = 0;
3916
  shstrtab_hdr->sh_entsize = 0;
3497
  shstrtab_hdr->sh_link = 0;
3917
  shstrtab_hdr->sh_link = 0;
3498
  shstrtab_hdr->sh_info = 0;
3918
  shstrtab_hdr->sh_info = 0;
3499
  /* sh_offset is set in assign_file_positions_except_relocs.  */
3919
  /* sh_offset is set in _bfd_elf_assign_file_positions_for_non_load.  */
3500
  shstrtab_hdr->sh_addralign = 1;
3920
  shstrtab_hdr->sh_addralign = 1;
Line 3501... Line 3921...
3501
 
3921
 
3502
  if (!assign_file_positions_except_relocs (abfd, link_info))
3922
  if (!assign_file_positions_except_relocs (abfd, link_info))
Line 3507... Line 3927...
3507
      file_ptr off;
3927
      file_ptr off;
3508
      Elf_Internal_Shdr *hdr;
3928
      Elf_Internal_Shdr *hdr;
Line 3509... Line 3929...
3509
 
3929
 
Line 3510... Line 3930...
3510
      off = elf_next_file_pos (abfd);
3930
      off = elf_next_file_pos (abfd);
3511
 
3931
 
Line -... Line 3932...
-
 
3932
      hdr = & elf_symtab_hdr (abfd);
-
 
3933
      off = _bfd_elf_assign_file_position_for_section (hdr, off, TRUE);
3512
      hdr = &elf_tdata (abfd)->symtab_hdr;
3934
 
3513
      off = _bfd_elf_assign_file_position_for_section (hdr, off, TRUE);
3935
      if (elf_symtab_shndx_list (abfd) != NULL)
3514
 
3936
	{
-
 
3937
	  hdr = & elf_symtab_shndx_list (abfd)->hdr;
-
 
3938
	  if (hdr->sh_size != 0)
Line 3515... Line 3939...
3515
      hdr = &elf_tdata (abfd)->symtab_shndx_hdr;
3939
	    off = _bfd_elf_assign_file_position_for_section (hdr, off, TRUE);
3516
      if (hdr->sh_size != 0)
3940
	  /* FIXME: What about other symtab_shndx sections in the list ?  */
Line 3517... Line 3941...
3517
	off = _bfd_elf_assign_file_position_for_section (hdr, off, TRUE);
3941
	}
Line 3518... Line 3942...
3518
 
3942
 
3519
      hdr = &elf_tdata (abfd)->strtab_hdr;
3943
      hdr = &elf_tdata (abfd)->strtab_hdr;
3520
      off = _bfd_elf_assign_file_position_for_section (hdr, off, TRUE);
3944
      off = _bfd_elf_assign_file_position_for_section (hdr, off, TRUE);
3521
 
3945
 
3522
      elf_next_file_pos (abfd) = off;
3946
      elf_next_file_pos (abfd) = off;
3523
 
3947
 
3524
      /* Now that we know where the .strtab section goes, write it
3948
      /* Now that we know where the .strtab section goes, write it
Line 3525... Line 3949...
3525
	 out.  */
3949
	 out.  */
Line 3526... Line 3950...
3526
      if (bfd_seek (abfd, hdr->sh_offset, SEEK_SET) != 0
3950
      if (bfd_seek (abfd, hdr->sh_offset, SEEK_SET) != 0
Line 3863... Line 4287...
3863
	 a few bytes of the end of the first section.  */
4287
	 a few bytes of the end of the first section.  */
3864
      last_hdr = NULL;
4288
      last_hdr = NULL;
3865
      last_size = 0;
4289
      last_size = 0;
3866
      phdr_index = 0;
4290
      phdr_index = 0;
3867
      maxpagesize = bed->maxpagesize;
4291
      maxpagesize = bed->maxpagesize;
-
 
4292
      /* PR 17512: file: c8455299.
-
 
4293
	 Avoid divide-by-zero errors later on.
-
 
4294
	 FIXME: Should we abort if the maxpagesize is zero ?  */
-
 
4295
      if (maxpagesize == 0)
-
 
4296
	maxpagesize = 1;
3868
      writable = FALSE;
4297
      writable = FALSE;
3869
      dynsec = bfd_get_section_by_name (abfd, ".dynamic");
4298
      dynsec = bfd_get_section_by_name (abfd, ".dynamic");
3870
      if (dynsec != NULL
4299
      if (dynsec != NULL
3871
	  && (dynsec->flags & SEC_LOAD) == 0)
4300
	  && (dynsec->flags & SEC_LOAD) == 0)
3872
	dynsec = NULL;
4301
	dynsec = NULL;
Line 3933... Line 4362...
3933
	      /* If putting this section in this segment would force us to
4362
	      /* If putting this section in this segment would force us to
3934
		 skip a page in the segment, then we need a new segment.  */
4363
		 skip a page in the segment, then we need a new segment.  */
3935
	      new_segment = TRUE;
4364
	      new_segment = TRUE;
3936
	    }
4365
	    }
3937
	  else if ((last_hdr->flags & (SEC_LOAD | SEC_THREAD_LOCAL)) == 0
4366
	  else if ((last_hdr->flags & (SEC_LOAD | SEC_THREAD_LOCAL)) == 0
3938
		   && (hdr->flags & (SEC_LOAD | SEC_THREAD_LOCAL)) != 0)
4367
		   && (hdr->flags & (SEC_LOAD | SEC_THREAD_LOCAL)) != 0
-
 
4368
		   && ((abfd->flags & D_PAGED) == 0
-
 
4369
		       || (((last_hdr->lma + last_size - 1) & -maxpagesize)
-
 
4370
			   != (hdr->lma & -maxpagesize))))
3939
	    {
4371
	    {
3940
	      /* We don't want to put a loadable section after a
4372
	      /* We don't want to put a loaded section after a
3941
		 nonloadable section in the same segment.
4373
		 nonloaded (ie. bss style) section in the same segment
-
 
4374
		 as that will force the non-loaded section to be loaded.
3942
		 Consider .tbss sections as loadable for this purpose.  */
4375
		 Consider .tbss sections as loaded for this purpose.
-
 
4376
		 However, like the writable/non-writable case below,
-
 
4377
		 if they are on the same page then they must be put
-
 
4378
		 in the same segment.  */
3943
	      new_segment = TRUE;
4379
	      new_segment = TRUE;
3944
	    }
4380
	    }
3945
	  else if ((abfd->flags & D_PAGED) == 0)
4381
	  else if ((abfd->flags & D_PAGED) == 0)
3946
	    {
4382
	    {
3947
	      /* If the file is not demand paged, which means that we
4383
	      /* If the file is not demand paged, which means that we
Line 4107... Line 4543...
4107
	  m->p_type = PT_TLS;
4543
	  m->p_type = PT_TLS;
4108
	  m->count = tls_count;
4544
	  m->count = tls_count;
4109
	  /* Mandated PF_R.  */
4545
	  /* Mandated PF_R.  */
4110
	  m->p_flags = PF_R;
4546
	  m->p_flags = PF_R;
4111
	  m->p_flags_valid = 1;
4547
	  m->p_flags_valid = 1;
-
 
4548
	  s = first_tls;
4112
	  for (i = 0; i < (unsigned int) tls_count; ++i)
4549
	  for (i = 0; i < (unsigned int) tls_count; ++i)
4113
	    {
4550
	    {
4114
	      BFD_ASSERT (first_tls->flags & SEC_THREAD_LOCAL);
4551
	      if ((s->flags & SEC_THREAD_LOCAL) == 0)
-
 
4552
		{
-
 
4553
		  _bfd_error_handler
-
 
4554
		    (_("%B: TLS sections are not adjacent:"), abfd);
-
 
4555
		  s = first_tls;
-
 
4556
		  i = 0;
-
 
4557
		  while (i < (unsigned int) tls_count)
-
 
4558
		    {
-
 
4559
		      if ((s->flags & SEC_THREAD_LOCAL) != 0)
-
 
4560
			{
-
 
4561
			  _bfd_error_handler (_("	    TLS: %A"), s);
-
 
4562
			  i++;
-
 
4563
			}
-
 
4564
		      else
-
 
4565
			_bfd_error_handler (_("	non-TLS: %A"), s);
-
 
4566
		      s = s->next;
-
 
4567
		    }
-
 
4568
		  bfd_set_error (bfd_error_bad_value);
-
 
4569
		  goto error_return;
-
 
4570
		}
4115
	      m->sections[i] = first_tls;
4571
	      m->sections[i] = s;
4116
	      first_tls = first_tls->next;
4572
	      s = s->next;
4117
	    }
4573
	    }
Line 4118... Line 4574...
4118
 
4574
 
4119
	  *pm = m;
4575
	  *pm = m;
4120
	  pm = &m->next;
4576
	  pm = &m->next;
Line 4174... Line 4630...
4174
		  while (--i != (unsigned) -1)
4630
		  while (--i != (unsigned) -1)
4175
		    if ((m->sections[i]->flags & (SEC_LOAD | SEC_HAS_CONTENTS))
4631
		    if ((m->sections[i]->flags & (SEC_LOAD | SEC_HAS_CONTENTS))
4176
			== (SEC_LOAD | SEC_HAS_CONTENTS))
4632
			== (SEC_LOAD | SEC_HAS_CONTENTS))
4177
		      break;
4633
		      break;
Line 4178... Line 4634...
4178
 
4634
 
4179
		  if (i == (unsigned) -1)
-
 
4180
		    continue;
-
 
4181
 
-
 
4182
		  if (m->sections[i]->vma + m->sections[i]->size
-
 
4183
		      >= info->relro_end)
4635
		  if (i != (unsigned) -1)
4184
		    break;
4636
		    break;
4185
		}
4637
		}
Line 4186... Line 4638...
4186
	    }
4638
	    }
Line 4192... Line 4644...
4192
	      m = (struct elf_segment_map *) bfd_zalloc (abfd, amt);
4644
	      m = (struct elf_segment_map *) bfd_zalloc (abfd, amt);
4193
	      if (m == NULL)
4645
	      if (m == NULL)
4194
		goto error_return;
4646
		goto error_return;
4195
	      m->next = NULL;
4647
	      m->next = NULL;
4196
	      m->p_type = PT_GNU_RELRO;
4648
	      m->p_type = PT_GNU_RELRO;
4197
	      m->p_flags = PF_R;
-
 
4198
	      m->p_flags_valid = 1;
-
 
4199
 
-
 
4200
	      *pm = m;
4649
	      *pm = m;
4201
	      pm = &m->next;
4650
	      pm = &m->next;
4202
	    }
4651
	    }
4203
	}
4652
	}
Line 4303... Line 4752...
4303
   which can can be collapsed into the expression below.  */
4752
   which can can be collapsed into the expression below.  */
Line 4304... Line 4753...
4304
 
4753
 
4305
static file_ptr
4754
static file_ptr
4306
vma_page_aligned_bias (bfd_vma vma, ufile_ptr off, bfd_vma maxpagesize)
4755
vma_page_aligned_bias (bfd_vma vma, ufile_ptr off, bfd_vma maxpagesize)
-
 
4756
{
-
 
4757
  /* PR binutils/16199: Handle an alignment of zero.  */
-
 
4758
  if (maxpagesize == 0)
4307
{
4759
    maxpagesize = 1;
4308
  return ((vma - off) % maxpagesize);
4760
  return ((vma - off) % maxpagesize);
Line 4309... Line 4761...
4309
}
4761
}
4310
 
4762
 
Line 4779... Line 5231...
4779
		p->p_flags |= PF_X;
5231
		p->p_flags |= PF_X;
4780
	      if ((this_hdr->sh_flags & SHF_WRITE) != 0)
5232
	      if ((this_hdr->sh_flags & SHF_WRITE) != 0)
4781
		p->p_flags |= PF_W;
5233
		p->p_flags |= PF_W;
4782
	    }
5234
	    }
4783
	}
5235
	}
-
 
5236
 
4784
      off -= off_adjust;
5237
      off -= off_adjust;
Line 4785... Line 5238...
4785
 
5238
 
4786
      /* Check that all sections are in a PT_LOAD segment.
5239
      /* Check that all sections are in a PT_LOAD segment.
4787
	 Don't check funky gdb generated core files.  */
5240
	 Don't check funky gdb generated core files.  */
Line 4830... Line 5283...
4830
assign_file_positions_for_non_load_sections (bfd *abfd,
5283
assign_file_positions_for_non_load_sections (bfd *abfd,
4831
					     struct bfd_link_info *link_info)
5284
					     struct bfd_link_info *link_info)
4832
{
5285
{
4833
  const struct elf_backend_data *bed = get_elf_backend_data (abfd);
5286
  const struct elf_backend_data *bed = get_elf_backend_data (abfd);
4834
  Elf_Internal_Shdr **i_shdrpp;
5287
  Elf_Internal_Shdr **i_shdrpp;
4835
  Elf_Internal_Shdr **hdrpp;
5288
  Elf_Internal_Shdr **hdrpp, **end_hdrpp;
4836
  Elf_Internal_Phdr *phdrs;
5289
  Elf_Internal_Phdr *phdrs;
4837
  Elf_Internal_Phdr *p;
5290
  Elf_Internal_Phdr *p;
4838
  struct elf_segment_map *m;
5291
  struct elf_segment_map *m;
4839
  struct elf_segment_map *hdrs_segment;
5292
  struct elf_segment_map *hdrs_segment;
4840
  bfd_vma filehdr_vaddr, filehdr_paddr;
5293
  bfd_vma filehdr_vaddr, filehdr_paddr;
4841
  bfd_vma phdrs_vaddr, phdrs_paddr;
5294
  bfd_vma phdrs_vaddr, phdrs_paddr;
4842
  file_ptr off;
5295
  file_ptr off;
4843
  unsigned int num_sec;
-
 
4844
  unsigned int i;
-
 
4845
  unsigned int count;
5296
  unsigned int count;
Line 4846... Line 5297...
4846
 
5297
 
4847
  i_shdrpp = elf_elfsections (abfd);
5298
  i_shdrpp = elf_elfsections (abfd);
4848
  num_sec = elf_numsections (abfd);
5299
  end_hdrpp = i_shdrpp + elf_numsections (abfd);
4849
  off = elf_next_file_pos (abfd);
5300
  off = elf_next_file_pos (abfd);
4850
  for (i = 1, hdrpp = i_shdrpp + 1; i < num_sec; i++, hdrpp++)
5301
  for (hdrpp = i_shdrpp + 1; hdrpp < end_hdrpp; hdrpp++)
4851
    {
5302
    {
Line 4852... Line 5303...
4852
      Elf_Internal_Shdr *hdr;
5303
      Elf_Internal_Shdr *hdr;
4853
 
5304
 
Line 4876... Line 5327...
4876
	  off = _bfd_elf_assign_file_position_for_section (hdr, off,
5327
	  off = _bfd_elf_assign_file_position_for_section (hdr, off,
4877
							   FALSE);
5328
							   FALSE);
4878
	}
5329
	}
4879
      else if (((hdr->sh_type == SHT_REL || hdr->sh_type == SHT_RELA)
5330
      else if (((hdr->sh_type == SHT_REL || hdr->sh_type == SHT_RELA)
4880
		&& hdr->bfd_section == NULL)
5331
		&& hdr->bfd_section == NULL)
-
 
5332
	       || (hdr->bfd_section != NULL
-
 
5333
		   && (hdr->bfd_section->flags & SEC_ELF_COMPRESS))
-
 
5334
		   /* Compress DWARF debug sections.  */
4881
	       || hdr == i_shdrpp[elf_onesymtab (abfd)]
5335
	       || hdr == i_shdrpp[elf_onesymtab (abfd)]
-
 
5336
	       || (elf_symtab_shndx_list (abfd) != NULL
-
 
5337
		   && hdr == i_shdrpp[elf_symtab_shndx_list (abfd)->ndx])
4882
	       || hdr == i_shdrpp[elf_symtab_shndx (abfd)]
5338
	       || hdr == i_shdrpp[elf_strtab_sec (abfd)]
4883
	       || hdr == i_shdrpp[elf_strtab_sec (abfd)])
5339
	       || hdr == i_shdrpp[elf_shstrtab_sec (abfd)])
4884
	hdr->sh_offset = -1;
5340
	hdr->sh_offset = -1;
4885
      else
5341
      else
4886
	off = _bfd_elf_assign_file_position_for_section (hdr, off, TRUE);
5342
	off = _bfd_elf_assign_file_position_for_section (hdr, off, TRUE);
4887
    }
5343
    }
Line 4980... Line 5436...
4980
		   lm != NULL;
5436
		   lm != NULL;
4981
		   lm = lm->next, lp++)
5437
		   lm = lm->next, lp++)
4982
		{
5438
		{
4983
		  if (lp->p_type == PT_LOAD
5439
		  if (lp->p_type == PT_LOAD
4984
		      && lp->p_vaddr < link_info->relro_end
5440
		      && lp->p_vaddr < link_info->relro_end
4985
		      && lp->p_vaddr + lp->p_filesz >= link_info->relro_end
-
 
4986
		      && lm->count != 0
5441
		      && lm->count != 0
4987
		      && lm->sections[0]->vma >= link_info->relro_start)
5442
		      && lm->sections[0]->vma >= link_info->relro_start)
4988
		    break;
5443
		    break;
4989
		}
5444
		}
Line 4990... Line -...
4990
 
-
 
4991
	      /* PR ld/14207.  If the RELRO segment doesn't fit in the
-
 
4992
		 LOAD segment, it should be removed.  */
5445
 
4993
	      BFD_ASSERT (lm != NULL);
5446
	      BFD_ASSERT (lm != NULL);
4994
	    }
5447
	    }
4995
	  else
5448
	  else
4996
	    {
5449
	    {
Line 5022... Line 5475...
5022
		 otherwise gdb will choke when using separate debug files.
5475
		 otherwise gdb will choke when using separate debug files.
5023
	       */
5476
	       */
5024
	      if (!m->p_align_valid)
5477
	      if (!m->p_align_valid)
5025
		p->p_align = 1;
5478
		p->p_align = 1;
5026
	      if (!m->p_flags_valid)
5479
	      if (!m->p_flags_valid)
5027
		p->p_flags = (lp->p_flags & ~PF_W);
5480
		p->p_flags = PF_R;
5028
	    }
5481
	    }
5029
	  else
5482
	  else
5030
	    {
5483
	    {
5031
	      memset (p, 0, sizeof *p);
5484
	      memset (p, 0, sizeof *p);
5032
	      p->p_type = PT_NULL;
5485
	      p->p_type = PT_NULL;
Line 5037... Line 5490...
5037
	  if (m->p_size_valid)
5490
	  if (m->p_size_valid)
5038
	    p->p_memsz = m->p_size;
5491
	    p->p_memsz = m->p_size;
5039
	}
5492
	}
5040
      else if (m->count != 0)
5493
      else if (m->count != 0)
5041
	{
5494
	{
-
 
5495
	  unsigned int i;
5042
	  if (p->p_type != PT_LOAD
5496
	  if (p->p_type != PT_LOAD
5043
	      && (p->p_type != PT_NOTE
5497
	      && (p->p_type != PT_NOTE
5044
		  || bfd_get_format (abfd) != bfd_core))
5498
		  || bfd_get_format (abfd) != bfd_core))
5045
	    {
5499
	    {
5046
	      BFD_ASSERT (!m->includes_filehdr && !m->includes_phdrs);
5500
	      if (m->includes_filehdr || m->includes_phdrs)
-
 
5501
		{
-
 
5502
		  /* PR 17512: file: 2195325e.  */
-
 
5503
		  (*_bfd_error_handler)
-
 
5504
		    (_("%B: warning: non-load segment includes file header and/or program header"),
-
 
5505
		     abfd);
-
 
5506
		  return FALSE;
-
 
5507
		}
Line 5047... Line 5508...
5047
 
5508
 
5048
	      p->p_filesz = 0;
5509
	      p->p_filesz = 0;
5049
	      p->p_offset = m->sections[0]->filepos;
5510
	      p->p_offset = m->sections[0]->filepos;
5050
	      for (i = m->count; i-- != 0;)
5511
	      for (i = m->count; i-- != 0;)
Line 5077... Line 5538...
5077
  elf_next_file_pos (abfd) = off;
5538
  elf_next_file_pos (abfd) = off;
Line 5078... Line 5539...
5078
 
5539
 
5079
  return TRUE;
5540
  return TRUE;
Line -... Line 5541...
-
 
5541
}
-
 
5542
 
-
 
5543
static elf_section_list *
-
 
5544
find_section_in_list (unsigned int i, elf_section_list * list)
-
 
5545
{
-
 
5546
  for (;list != NULL; list = list->next)
-
 
5547
    if (list->ndx == i)
-
 
5548
      break;
-
 
5549
  return list;
5080
}
5550
}
5081
 
5551
 
5082
/* Work out the file positions of all the sections.  This is called by
5552
/* Work out the file positions of all the sections.  This is called by
Line 5083... Line 5553...
5083
   _bfd_elf_compute_section_file_positions.  All the section sizes and
5553
   _bfd_elf_compute_section_file_positions.  All the section sizes and
Line 5097... Line 5567...
5097
assign_file_positions_except_relocs (bfd *abfd,
5567
assign_file_positions_except_relocs (bfd *abfd,
5098
				     struct bfd_link_info *link_info)
5568
				     struct bfd_link_info *link_info)
5099
{
5569
{
5100
  struct elf_obj_tdata *tdata = elf_tdata (abfd);
5570
  struct elf_obj_tdata *tdata = elf_tdata (abfd);
5101
  Elf_Internal_Ehdr *i_ehdrp = elf_elfheader (abfd);
5571
  Elf_Internal_Ehdr *i_ehdrp = elf_elfheader (abfd);
5102
  file_ptr off;
-
 
5103
  const struct elf_backend_data *bed = get_elf_backend_data (abfd);
5572
  const struct elf_backend_data *bed = get_elf_backend_data (abfd);
Line 5104... Line 5573...
5104
 
5573
 
5105
  if ((abfd->flags & (EXEC_P | DYNAMIC)) == 0
5574
  if ((abfd->flags & (EXEC_P | DYNAMIC)) == 0
5106
      && bfd_get_format (abfd) != bfd_core)
5575
      && bfd_get_format (abfd) != bfd_core)
5107
    {
5576
    {
5108
      Elf_Internal_Shdr ** const i_shdrpp = elf_elfsections (abfd);
5577
      Elf_Internal_Shdr ** const i_shdrpp = elf_elfsections (abfd);
5109
      unsigned int num_sec = elf_numsections (abfd);
5578
      unsigned int num_sec = elf_numsections (abfd);
5110
      Elf_Internal_Shdr **hdrpp;
5579
      Elf_Internal_Shdr **hdrpp;
-
 
5580
      unsigned int i;
Line 5111... Line 5581...
5111
      unsigned int i;
5581
      file_ptr off;
5112
 
5582
 
Line 5113... Line 5583...
5113
      /* Start after the ELF header.  */
5583
      /* Start after the ELF header.  */
Line 5121... Line 5591...
5121
	  Elf_Internal_Shdr *hdr;
5591
	  Elf_Internal_Shdr *hdr;
Line 5122... Line 5592...
5122
 
5592
 
5123
	  hdr = *hdrpp;
5593
	  hdr = *hdrpp;
5124
	  if (((hdr->sh_type == SHT_REL || hdr->sh_type == SHT_RELA)
5594
	  if (((hdr->sh_type == SHT_REL || hdr->sh_type == SHT_RELA)
-
 
5595
	       && hdr->bfd_section == NULL)
-
 
5596
	      || (hdr->bfd_section != NULL
-
 
5597
		  && (hdr->bfd_section->flags & SEC_ELF_COMPRESS))
5125
	       && hdr->bfd_section == NULL)
5598
		  /* Compress DWARF debug sections.  */
-
 
5599
	      || i == elf_onesymtab (abfd)
-
 
5600
	      || (elf_symtab_shndx_list (abfd) != NULL
5126
	      || i == elf_onesymtab (abfd)
5601
		  && hdr == i_shdrpp[elf_symtab_shndx_list (abfd)->ndx])
5127
	      || i == elf_symtab_shndx (abfd)
5602
	      || i == elf_strtab_sec (abfd)
5128
	      || i == elf_strtab_sec (abfd))
5603
	      || i == elf_shstrtab_sec (abfd))
5129
	    {
5604
	    {
5130
	      hdr->sh_offset = -1;
5605
	      hdr->sh_offset = -1;
5131
	    }
5606
	    }
5132
	  else
5607
	  else
5133
	    off = _bfd_elf_assign_file_position_for_section (hdr, off, TRUE);
5608
	    off = _bfd_elf_assign_file_position_for_section (hdr, off, TRUE);
-
 
5609
	}
-
 
5610
 
5134
	}
5611
      elf_next_file_pos (abfd) = off;
5135
    }
5612
    }
5136
  else
5613
  else
5137
    {
5614
    {
Line 5150... Line 5627...
5150
	{
5627
	{
5151
	  if (!(*bed->elf_backend_modify_program_headers) (abfd, link_info))
5628
	  if (!(*bed->elf_backend_modify_program_headers) (abfd, link_info))
5152
	    return FALSE;
5629
	    return FALSE;
5153
	}
5630
	}
Line -... Line 5631...
-
 
5631
 
-
 
5632
      /* Set e_type in ELF header to ET_EXEC for -pie -Ttext-segment=.  */
-
 
5633
      if (link_info != NULL && bfd_link_pie (link_info))
-
 
5634
	{
-
 
5635
	  unsigned int num_segments = elf_elfheader (abfd)->e_phnum;
-
 
5636
	  Elf_Internal_Phdr *segment = elf_tdata (abfd)->phdr;
-
 
5637
	  Elf_Internal_Phdr *end_segment = &segment[num_segments];
-
 
5638
 
-
 
5639
	  /* Find the lowest p_vaddr in PT_LOAD segments.  */
-
 
5640
	  bfd_vma p_vaddr = (bfd_vma) -1;
-
 
5641
	  for (; segment < end_segment; segment++)
-
 
5642
	    if (segment->p_type == PT_LOAD && p_vaddr > segment->p_vaddr)
-
 
5643
	      p_vaddr = segment->p_vaddr;
-
 
5644
 
-
 
5645
	  /* Set e_type to ET_EXEC if the lowest p_vaddr in PT_LOAD
-
 
5646
	     segments is non-zero.  */
-
 
5647
	  if (p_vaddr)
-
 
5648
	    i_ehdrp->e_type = ET_EXEC;
-
 
5649
	}
5154
 
5650
 
5155
      /* Write out the program headers.  */
5651
      /* Write out the program headers.  */
5156
      alloc = elf_program_header_size (abfd) / bed->s->sizeof_phdr;
5652
      alloc = elf_program_header_size (abfd) / bed->s->sizeof_phdr;
5157
      if (bfd_seek (abfd, (bfd_signed_vma) bed->s->sizeof_ehdr, SEEK_SET) != 0
5653
      if (bfd_seek (abfd, (bfd_signed_vma) bed->s->sizeof_ehdr, SEEK_SET) != 0
5158
	  || bed->s->write_out_phdrs (abfd, tdata->phdr, alloc) != 0)
5654
	  || bed->s->write_out_phdrs (abfd, tdata->phdr, alloc) != 0)
5159
	return FALSE;
-
 
5160
 
-
 
5161
      off = elf_next_file_pos (abfd);
5655
	return FALSE;
Line 5162... Line -...
5162
    }
-
 
5163
 
-
 
5164
  /* Place the section headers.  */
-
 
5165
  off = align_file_position (off, 1 << bed->s->log_file_align);
-
 
5166
  i_ehdrp->e_shoff = off;
-
 
5167
  off += i_ehdrp->e_shnum * i_ehdrp->e_shentsize;
-
 
5168
 
-
 
5169
  elf_next_file_pos (abfd) = off;
5656
    }
5170
 
5657
 
Line 5171... Line 5658...
5171
  return TRUE;
5658
  return TRUE;
5172
}
5659
}
Line 5250... Line 5737...
5250
  elf_tdata (abfd)->strtab_hdr.sh_name =
5737
  elf_tdata (abfd)->strtab_hdr.sh_name =
5251
    (unsigned int) _bfd_elf_strtab_add (shstrtab, ".strtab", FALSE);
5738
    (unsigned int) _bfd_elf_strtab_add (shstrtab, ".strtab", FALSE);
5252
  elf_tdata (abfd)->shstrtab_hdr.sh_name =
5739
  elf_tdata (abfd)->shstrtab_hdr.sh_name =
5253
    (unsigned int) _bfd_elf_strtab_add (shstrtab, ".shstrtab", FALSE);
5740
    (unsigned int) _bfd_elf_strtab_add (shstrtab, ".shstrtab", FALSE);
5254
  if (elf_tdata (abfd)->symtab_hdr.sh_name == (unsigned int) -1
5741
  if (elf_tdata (abfd)->symtab_hdr.sh_name == (unsigned int) -1
5255
      || elf_tdata (abfd)->symtab_hdr.sh_name == (unsigned int) -1
5742
      || elf_tdata (abfd)->strtab_hdr.sh_name == (unsigned int) -1
5256
      || elf_tdata (abfd)->shstrtab_hdr.sh_name == (unsigned int) -1)
5743
      || elf_tdata (abfd)->shstrtab_hdr.sh_name == (unsigned int) -1)
5257
    return FALSE;
5744
    return FALSE;
Line 5258... Line 5745...
5258
 
5745
 
5259
  return TRUE;
5746
  return TRUE;
Line 5260... Line 5747...
5260
}
5747
}
5261
 
5748
 
Line 5262... Line 5749...
5262
/* Assign file positions for all the reloc sections which are not part
5749
/* Assign file positions for all the reloc sections which are not part
5263
   of the loadable file image.  */
5750
   of the loadable file image, and the file position of section headers.  */
5264
 
5751
 
5265
void
5752
static bfd_boolean
-
 
5753
_bfd_elf_assign_file_positions_for_non_load (bfd *abfd)
5266
_bfd_elf_assign_file_positions_for_relocs (bfd *abfd)
5754
{
5267
{
5755
  file_ptr off;
-
 
5756
  Elf_Internal_Shdr **shdrpp, **end_shdrpp;
Line 5268... Line 5757...
5268
  file_ptr off;
5757
  Elf_Internal_Shdr *shdrp;
Line 5269... Line 5758...
5269
  unsigned int i, num_sec;
5758
  Elf_Internal_Ehdr *i_ehdrp;
5270
  Elf_Internal_Shdr **shdrpp;
5759
  const struct elf_backend_data *bed;
-
 
5760
 
5271
 
5761
  off = elf_next_file_pos (abfd);
5272
  off = elf_next_file_pos (abfd);
-
 
5273
 
-
 
5274
  num_sec = elf_numsections (abfd);
5762
 
-
 
5763
  shdrpp = elf_elfsections (abfd);
-
 
5764
  end_shdrpp = shdrpp + elf_numsections (abfd);
-
 
5765
  for (shdrpp++; shdrpp < end_shdrpp; shdrpp++)
5275
  for (i = 1, shdrpp = elf_elfsections (abfd) + 1; i < num_sec; i++, shdrpp++)
5766
    {
5276
    {
5767
      shdrp = *shdrpp;
-
 
5768
      if (shdrp->sh_offset == -1)
-
 
5769
	{
-
 
5770
	  asection *sec = shdrp->bfd_section;
-
 
5771
	  bfd_boolean is_rel = (shdrp->sh_type == SHT_REL
-
 
5772
				|| shdrp->sh_type == SHT_RELA);
-
 
5773
	  if (is_rel
-
 
5774
	      || (sec != NULL && (sec->flags & SEC_ELF_COMPRESS)))
-
 
5775
	    {
-
 
5776
	      if (!is_rel)
-
 
5777
		{
-
 
5778
		  const char *name = sec->name;
-
 
5779
		  struct bfd_elf_section_data *d;
-
 
5780
 
-
 
5781
		  /* Compress DWARF debug sections.  */
-
 
5782
		  if (!bfd_compress_section (abfd, sec,
-
 
5783
					     shdrp->contents))
-
 
5784
		    return FALSE;
-
 
5785
 
-
 
5786
		  if (sec->compress_status == COMPRESS_SECTION_DONE
-
 
5787
		      && (abfd->flags & BFD_COMPRESS_GABI) == 0)
-
 
5788
		    {
-
 
5789
		      /* If section is compressed with zlib-gnu, convert
-
 
5790
			 section name from .debug_* to .zdebug_*.  */
-
 
5791
		      char *new_name
-
 
5792
			= convert_debug_to_zdebug (abfd, name);
-
 
5793
		      if (new_name == NULL)
-
 
5794
			return FALSE;
-
 
5795
		      name = new_name;
-
 
5796
		    }
-
 
5797
		  /* Add setion name to section name section.  */
-
 
5798
		  if (shdrp->sh_name != (unsigned int) -1)
-
 
5799
		    abort ();
-
 
5800
		  shdrp->sh_name
-
 
5801
		    = (unsigned int) _bfd_elf_strtab_add (elf_shstrtab (abfd),
-
 
5802
							  name, FALSE);
-
 
5803
		  d = elf_section_data (sec);
-
 
5804
 
-
 
5805
		  /* Add reloc setion name to section name section.  */
-
 
5806
		  if (d->rel.hdr
-
 
5807
		      && !_bfd_elf_set_reloc_sh_name (abfd,
-
 
5808
						      d->rel.hdr,
-
 
5809
						      name, FALSE))
-
 
5810
		    return FALSE;
-
 
5811
		  if (d->rela.hdr
-
 
5812
		      && !_bfd_elf_set_reloc_sh_name (abfd,
-
 
5813
						      d->rela.hdr,
-
 
5814
						      name, TRUE))
-
 
5815
		    return FALSE;
-
 
5816
 
5277
      Elf_Internal_Shdr *shdrp;
5817
		  /* Update section size and contents.  */
-
 
5818
		  shdrp->sh_size = sec->size;
-
 
5819
		  shdrp->contents = sec->contents;
5278
 
5820
		  shdrp->bfd_section->contents = NULL;
-
 
5821
		}
-
 
5822
	      off = _bfd_elf_assign_file_position_for_section (shdrp,
-
 
5823
							       off,
-
 
5824
							       TRUE);
-
 
5825
	    }
-
 
5826
	}
-
 
5827
    }
-
 
5828
 
-
 
5829
  /* Place section name section after DWARF debug sections have been
Line -... Line 5830...
-
 
5830
     compressed.  */
-
 
5831
  _bfd_elf_strtab_finalize (elf_shstrtab (abfd));
-
 
5832
  shdrp = &elf_tdata (abfd)->shstrtab_hdr;
-
 
5833
  shdrp->sh_size = _bfd_elf_strtab_size (elf_shstrtab (abfd));
-
 
5834
  off = _bfd_elf_assign_file_position_for_section (shdrp, off, TRUE);
-
 
5835
 
5279
      shdrp = *shdrpp;
5836
  /* Place the section headers.  */
-
 
5837
  i_ehdrp = elf_elfheader (abfd);
-
 
5838
  bed = get_elf_backend_data (abfd);
5280
      if ((shdrp->sh_type == SHT_REL || shdrp->sh_type == SHT_RELA)
5839
  off = align_file_position (off, 1 << bed->s->log_file_align);
Line 5281... Line 5840...
5281
	  && shdrp->sh_offset == -1)
5840
  i_ehdrp->e_shoff = off;
5282
	off = _bfd_elf_assign_file_position_for_section (shdrp, off, TRUE);
5841
  off += i_ehdrp->e_shnum * i_ehdrp->e_shentsize;
5283
    }
5842
  elf_next_file_pos (abfd) = off;
Line 5303... Line 5862...
5303
  failed = FALSE;
5862
  failed = FALSE;
5304
  bfd_map_over_sections (abfd, bed->s->write_relocs, &failed);
5863
  bfd_map_over_sections (abfd, bed->s->write_relocs, &failed);
5305
  if (failed)
5864
  if (failed)
5306
    return FALSE;
5865
    return FALSE;
Line 5307... Line 5866...
5307
 
5866
 
-
 
5867
  if (!_bfd_elf_assign_file_positions_for_non_load (abfd))
Line 5308... Line 5868...
5308
  _bfd_elf_assign_file_positions_for_relocs (abfd);
5868
    return FALSE;
5309
 
5869
 
5310
  /* After writing the headers, we need to write the sections too...  */
5870
  /* After writing the headers, we need to write the sections too...  */
5311
  num_sec = elf_numsections (abfd);
5871
  num_sec = elf_numsections (abfd);
-
 
5872
  for (count = 1; count < num_sec; count++)
-
 
5873
    {
-
 
5874
      i_shdrp[count]->sh_name
5312
  for (count = 1; count < num_sec; count++)
5875
	= _bfd_elf_strtab_offset (elf_shstrtab (abfd),
5313
    {
5876
				  i_shdrp[count]->sh_name);
5314
      if (bed->elf_backend_section_processing)
5877
      if (bed->elf_backend_section_processing)
5315
	(*bed->elf_backend_section_processing) (abfd, i_shdrp[count]);
5878
	(*bed->elf_backend_section_processing) (abfd, i_shdrp[count]);
5316
      if (i_shdrp[count]->contents)
5879
      if (i_shdrp[count]->contents)
Line 5760... Line 6323...
5760
	  /* Special segments, such as the PT_PHDR segment, may contain
6323
	  /* Special segments, such as the PT_PHDR segment, may contain
5761
	     no sections, but ordinary, loadable segments should contain
6324
	     no sections, but ordinary, loadable segments should contain
5762
	     something.  They are allowed by the ELF spec however, so only
6325
	     something.  They are allowed by the ELF spec however, so only
5763
	     a warning is produced.  */
6326
	     a warning is produced.  */
5764
	  if (segment->p_type == PT_LOAD)
6327
	  if (segment->p_type == PT_LOAD)
5765
	    (*_bfd_error_handler) (_("%B: warning: Empty loadable segment"
6328
	    (*_bfd_error_handler) (_("\
5766
				     " detected, is this intentional ?\n"),
6329
%B: warning: Empty loadable segment detected, is this intentional ?"),
5767
				   ibfd);
6330
				   ibfd);
Line 5768... Line 6331...
5768
 
6331
 
5769
	  map->count = 0;
6332
	  map->count = 0;
5770
	  *pointer_to_map = map;
6333
	  *pointer_to_map = map;
Line 6211... Line 6774...
6211
 
6774
 
6212
	  if (segment->p_type == PT_LOAD && map->includes_phdrs)
6775
	  if (segment->p_type == PT_LOAD && map->includes_phdrs)
6213
	    phdr_included = TRUE;
6776
	    phdr_included = TRUE;
Line 6214... Line 6777...
6214
	}
6777
	}
6215
 
6778
 
6216
      lowest_section = first_section;
6779
      lowest_section = NULL;
6217
      if (section_count != 0)
6780
      if (section_count != 0)
Line 6218... Line 6781...
6218
	{
6781
	{
Line 6228... Line 6791...
6228
		  map->sections[isec++] = section->output_section;
6791
		  map->sections[isec++] = section->output_section;
6229
		  if ((section->flags & SEC_ALLOC) != 0)
6792
		  if ((section->flags & SEC_ALLOC) != 0)
6230
		    {
6793
		    {
6231
		      bfd_vma seg_off;
6794
		      bfd_vma seg_off;
Line -... Line 6795...
-
 
6795
 
6232
 
6796
		      if (lowest_section == NULL
6233
		      if (section->lma < lowest_section->lma)
6797
			  || section->lma < lowest_section->lma)
Line 6234... Line 6798...
6234
			lowest_section = section;
6798
			lowest_section = section;
6235
 
6799
 
6236
		      /* Section lmas are set up from PT_LOAD header
6800
		      /* Section lmas are set up from PT_LOAD header
Line 6373... Line 6937...
6373
      for (i = 0, segment = elf_tdata (ibfd)->phdr;
6937
      for (i = 0, segment = elf_tdata (ibfd)->phdr;
6374
	   i < num_segments;
6938
	   i < num_segments;
6375
	   i++, segment++)
6939
	   i++, segment++)
6376
	if (segment->p_type == PT_LOAD
6940
	if (segment->p_type == PT_LOAD
6377
	    && maxpagesize < segment->p_align)
6941
	    && maxpagesize < segment->p_align)
-
 
6942
	  {
-
 
6943
	    /* PR 17512: file: f17299af.  */
-
 
6944
	    if (segment->p_align > (bfd_vma) 1 << ((sizeof (bfd_vma) * 8) - 2))
-
 
6945
	      (*_bfd_error_handler) (_("\
-
 
6946
%B: warning: segment alignment of 0x%llx is too large"),
-
 
6947
				     ibfd, (long long) segment->p_align);
-
 
6948
	    else
6378
	  maxpagesize = segment->p_align;
6949
	      maxpagesize = segment->p_align;
-
 
6950
	  }
Line 6379... Line 6951...
6379
 
6951
 
6380
      if (maxpagesize != get_elf_backend_data (obfd)->maxpagesize)
6952
      if (maxpagesize != get_elf_backend_data (obfd)->maxpagesize)
6381
	bfd_emul_set_maxpagesize (bfd_get_target (obfd), maxpagesize);
6953
	bfd_emul_set_maxpagesize (bfd_get_target (obfd), maxpagesize);
Line 6393... Line 6965...
6393
				    asection *osec,
6965
				    asection *osec,
6394
				    struct bfd_link_info *link_info)
6966
				    struct bfd_link_info *link_info)
Line 6395... Line 6967...
6395
 
6967
 
6396
{
6968
{
6397
  Elf_Internal_Shdr *ihdr, *ohdr;
6969
  Elf_Internal_Shdr *ihdr, *ohdr;
-
 
6970
  bfd_boolean final_link = (link_info != NULL
Line 6398... Line 6971...
6398
  bfd_boolean final_link = link_info != NULL && !link_info->relocatable;
6971
			    && !bfd_link_relocatable (link_info));
6399
 
6972
 
6400
  if (ibfd->xvec->flavour != bfd_target_elf_flavour
6973
  if (ibfd->xvec->flavour != bfd_target_elf_flavour
Line 6430... Line 7003...
6430
	  if (elf_section_flags (isec) & SHF_GROUP)
7003
	  if (elf_section_flags (isec) & SHF_GROUP)
6431
	    elf_section_flags (osec) |= SHF_GROUP;
7004
	    elf_section_flags (osec) |= SHF_GROUP;
6432
	  elf_next_in_group (osec) = elf_next_in_group (isec);
7005
	  elf_next_in_group (osec) = elf_next_in_group (isec);
6433
	  elf_section_data (osec)->group = elf_section_data (isec)->group;
7006
	  elf_section_data (osec)->group = elf_section_data (isec)->group;
6434
	}
7007
	}
-
 
7008
 
-
 
7009
      /* If not decompress, preserve SHF_COMPRESSED.  */
-
 
7010
      if ((ibfd->flags & BFD_DECOMPRESS) == 0)
-
 
7011
	elf_section_flags (osec) |= (elf_section_flags (isec)
-
 
7012
				     & SHF_COMPRESSED);
6435
    }
7013
    }
Line 6436... Line 7014...
6436
 
7014
 
Line 6437... Line 7015...
6437
  ihdr = &elf_section_data (isec)->this_hdr;
7015
  ihdr = &elf_section_data (isec)->this_hdr;
Line 6608... Line 7186...
6608
	shndx = MAP_DYNSYMTAB;
7186
	shndx = MAP_DYNSYMTAB;
6609
      else if (shndx == elf_strtab_sec (ibfd))
7187
      else if (shndx == elf_strtab_sec (ibfd))
6610
	shndx = MAP_STRTAB;
7188
	shndx = MAP_STRTAB;
6611
      else if (shndx == elf_shstrtab_sec (ibfd))
7189
      else if (shndx == elf_shstrtab_sec (ibfd))
6612
	shndx = MAP_SHSTRTAB;
7190
	shndx = MAP_SHSTRTAB;
6613
      else if (shndx == elf_symtab_shndx (ibfd))
7191
      else if (find_section_in_list (shndx, elf_symtab_shndx_list (ibfd)))
6614
	shndx = MAP_SYM_SHNDX;
7192
	shndx = MAP_SYM_SHNDX;
6615
      osym->internal_elf_sym.st_shndx = shndx;
7193
      osym->internal_elf_sym.st_shndx = shndx;
6616
    }
7194
    }
Line 6617... Line 7195...
6617
 
7195
 
Line 6620... Line 7198...
6620
 
7198
 
Line 6621... Line 7199...
6621
/* Swap out the symbols.  */
7199
/* Swap out the symbols.  */
6622
 
7200
 
6623
static bfd_boolean
7201
static bfd_boolean
6624
swap_out_syms (bfd *abfd,
7202
swap_out_syms (bfd *abfd,
6625
	       struct bfd_strtab_hash **sttp,
7203
	       struct elf_strtab_hash **sttp,
6626
	       int relocatable_p)
7204
	       int relocatable_p)
6627
{
7205
{
6628
  const struct elf_backend_data *bed;
7206
  const struct elf_backend_data *bed;
6629
  int symcount;
7207
  int symcount;
6630
  asymbol **syms;
7208
  asymbol **syms;
6631
  struct bfd_strtab_hash *stt;
7209
  struct elf_strtab_hash *stt;
6632
  Elf_Internal_Shdr *symtab_hdr;
7210
  Elf_Internal_Shdr *symtab_hdr;
-
 
7211
  Elf_Internal_Shdr *symtab_shndx_hdr;
6633
  Elf_Internal_Shdr *symtab_shndx_hdr;
7212
  Elf_Internal_Shdr *symstrtab_hdr;
6634
  Elf_Internal_Shdr *symstrtab_hdr;
7213
  struct elf_sym_strtab *symstrtab;
-
 
7214
  bfd_byte *outbound_syms;
-
 
7215
  bfd_byte *outbound_shndx;
6635
  bfd_byte *outbound_syms;
7216
  unsigned long outbound_syms_index;
6636
  bfd_byte *outbound_shndx;
7217
  unsigned long outbound_shndx_index;
6637
  int idx;
7218
  int idx;
6638
  unsigned int num_locals;
7219
  unsigned int num_locals;
Line 6639... Line 7220...
6639
  bfd_size_type amt;
7220
  bfd_size_type amt;
6640
  bfd_boolean name_local_sections;
7221
  bfd_boolean name_local_sections;
Line 6641... Line 7222...
6641
 
7222
 
6642
  if (!elf_map_symbols (abfd, &num_locals))
7223
  if (!elf_map_symbols (abfd, &num_locals))
6643
    return FALSE;
7224
    return FALSE;
6644
 
7225
 
Line 6645... Line 7226...
6645
  /* Dump out the symtabs.  */
7226
  /* Dump out the symtabs.  */
6646
  stt = _bfd_elf_stringtab_init ();
7227
  stt = _bfd_elf_strtab_init ();
Line 6657... Line 7238...
6657
  symtab_hdr->sh_addralign = (bfd_vma) 1 << bed->s->log_file_align;
7238
  symtab_hdr->sh_addralign = (bfd_vma) 1 << bed->s->log_file_align;
Line 6658... Line 7239...
6658
 
7239
 
6659
  symstrtab_hdr = &elf_tdata (abfd)->strtab_hdr;
7240
  symstrtab_hdr = &elf_tdata (abfd)->strtab_hdr;
Line -... Line 7241...
-
 
7241
  symstrtab_hdr->sh_type = SHT_STRTAB;
-
 
7242
 
-
 
7243
  /* Allocate buffer to swap out the .strtab section.  */
-
 
7244
  symstrtab = (struct elf_sym_strtab *) bfd_malloc ((symcount + 1)
-
 
7245
						    * sizeof (*symstrtab));
-
 
7246
  if (symstrtab == NULL)
-
 
7247
    {
-
 
7248
      _bfd_elf_strtab_free (stt);
-
 
7249
      return FALSE;
6660
  symstrtab_hdr->sh_type = SHT_STRTAB;
7250
    }
6661
 
7251
 
6662
  outbound_syms = (bfd_byte *) bfd_alloc2 (abfd, 1 + symcount,
7252
  outbound_syms = (bfd_byte *) bfd_alloc2 (abfd, 1 + symcount,
6663
                                           bed->s->sizeof_sym);
7253
                                           bed->s->sizeof_sym);
-
 
7254
  if (outbound_syms == NULL)
6664
  if (outbound_syms == NULL)
7255
    {
-
 
7256
error_return:
6665
    {
7257
      _bfd_elf_strtab_free (stt);
6666
      _bfd_stringtab_free (stt);
7258
      free (symstrtab);
6667
      return FALSE;
7259
      return FALSE;
-
 
7260
    }
Line 6668... Line 7261...
6668
    }
7261
  symtab_hdr->contents = outbound_syms;
-
 
7262
  outbound_syms_index = 0;
-
 
7263
 
-
 
7264
  outbound_shndx = NULL;
-
 
7265
  outbound_shndx_index = 0;
6669
  symtab_hdr->contents = outbound_syms;
7266
 
6670
 
7267
  if (elf_symtab_shndx_list (abfd))
6671
  outbound_shndx = NULL;
7268
    {
6672
  symtab_shndx_hdr = &elf_tdata (abfd)->symtab_shndx_hdr;
7269
      symtab_shndx_hdr = & elf_symtab_shndx_list (abfd)->hdr;
6673
  if (symtab_shndx_hdr->sh_name != 0)
7270
      if (symtab_shndx_hdr->sh_name != 0)
6674
    {
7271
	{
6675
      amt = (bfd_size_type) (1 + symcount) * sizeof (Elf_External_Sym_Shndx);
7272
	  amt = (bfd_size_type) (1 + symcount) * sizeof (Elf_External_Sym_Shndx);
6676
      outbound_shndx =  (bfd_byte *)
-
 
6677
          bfd_zalloc2 (abfd, 1 + symcount, sizeof (Elf_External_Sym_Shndx));
7273
	  outbound_shndx =  (bfd_byte *)
6678
      if (outbound_shndx == NULL)
-
 
6679
	{
-
 
Line 6680... Line 7274...
6680
	  _bfd_stringtab_free (stt);
7274
	    bfd_zalloc2 (abfd, 1 + symcount, sizeof (Elf_External_Sym_Shndx));
6681
	  return FALSE;
7275
	  if (outbound_shndx == NULL)
6682
	}
7276
	    goto error_return;
6683
 
7277
 
6684
      symtab_shndx_hdr->contents = outbound_shndx;
7278
	  symtab_shndx_hdr->contents = outbound_shndx;
6685
      symtab_shndx_hdr->sh_type = SHT_SYMTAB_SHNDX;
7279
	  symtab_shndx_hdr->sh_type = SHT_SYMTAB_SHNDX;
-
 
7280
	  symtab_shndx_hdr->sh_size = amt;
-
 
7281
	  symtab_shndx_hdr->sh_addralign = sizeof (Elf_External_Sym_Shndx);
Line 6686... Line 7282...
6686
      symtab_shndx_hdr->sh_size = amt;
7282
	  symtab_shndx_hdr->sh_entsize = sizeof (Elf_External_Sym_Shndx);
6687
      symtab_shndx_hdr->sh_addralign = sizeof (Elf_External_Sym_Shndx);
7283
	}
6688
      symtab_shndx_hdr->sh_entsize = sizeof (Elf_External_Sym_Shndx);
7284
      /* FIXME: What about any other headers in the list ?  */
6689
    }
7285
    }
Line 6697... Line 7293...
6697
    sym.st_size = 0;
7293
    sym.st_size = 0;
6698
    sym.st_info = 0;
7294
    sym.st_info = 0;
6699
    sym.st_other = 0;
7295
    sym.st_other = 0;
6700
    sym.st_shndx = SHN_UNDEF;
7296
    sym.st_shndx = SHN_UNDEF;
6701
    sym.st_target_internal = 0;
7297
    sym.st_target_internal = 0;
-
 
7298
    symstrtab[0].sym = sym;
6702
    bed->s->swap_symbol_out (abfd, &sym, outbound_syms, outbound_shndx);
7299
    symstrtab[0].dest_index = outbound_syms_index;
-
 
7300
    symstrtab[0].destshndx_index = outbound_shndx_index;
6703
    outbound_syms += bed->s->sizeof_sym;
7301
    outbound_syms_index++;
6704
    if (outbound_shndx != NULL)
7302
    if (outbound_shndx != NULL)
6705
      outbound_shndx += sizeof (Elf_External_Sym_Shndx);
7303
      outbound_shndx_index++;
6706
  }
7304
  }
Line 6707... Line 7305...
6707
 
7305
 
6708
  name_local_sections
7306
  name_local_sections
6709
    = (bed->elf_backend_name_local_section_symbols
7307
    = (bed->elf_backend_name_local_section_symbols
Line 6710... Line 7308...
6710
       && bed->elf_backend_name_local_section_symbols (abfd));
7308
       && bed->elf_backend_name_local_section_symbols (abfd));
6711
 
7309
 
6712
  syms = bfd_get_outsymbols (abfd);
7310
  syms = bfd_get_outsymbols (abfd);
6713
  for (idx = 0; idx < symcount; idx++)
7311
  for (idx = 0; idx < symcount;)
6714
    {
7312
    {
6715
      Elf_Internal_Sym sym;
7313
      Elf_Internal_Sym sym;
6716
      bfd_vma value = syms[idx]->value;
7314
      bfd_vma value = syms[idx]->value;
Line 6720... Line 7318...
6720
 
7318
 
6721
      if (!name_local_sections
7319
      if (!name_local_sections
6722
	  && (flags & (BSF_SECTION_SYM | BSF_GLOBAL)) == BSF_SECTION_SYM)
7320
	  && (flags & (BSF_SECTION_SYM | BSF_GLOBAL)) == BSF_SECTION_SYM)
6723
	{
7321
	{
6724
	  /* Local section symbols have no name.  */
7322
	  /* Local section symbols have no name.  */
6725
	  sym.st_name = 0;
7323
	  sym.st_name = (unsigned long) -1;
6726
	}
7324
	}
6727
      else
7325
      else
6728
	{
7326
	{
-
 
7327
	  /* Call _bfd_elf_strtab_offset after _bfd_elf_strtab_finalize
6729
	  sym.st_name = (unsigned long) _bfd_stringtab_add (stt,
7328
	     to get the final offset for st_name.  */
-
 
7329
	  sym.st_name
6730
							    syms[idx]->name,
7330
	    = (unsigned long) _bfd_elf_strtab_add (stt, syms[idx]->name,
6731
							    TRUE, FALSE);
7331
						   FALSE);
6732
	  if (sym.st_name == (unsigned long) -1)
-
 
6733
	    {
-
 
6734
	      _bfd_stringtab_free (stt);
7332
	  if (sym.st_name == (unsigned long) -1)
6735
	      return FALSE;
-
 
6736
	    }
7333
	    goto error_return;
Line 6737... Line 7334...
6737
	}
7334
	}
Line 6738... Line 7335...
6738
 
7335
 
Line 6791... Line 7388...
6791
		  break;
7388
		  break;
6792
		case MAP_SHSTRTAB:
7389
		case MAP_SHSTRTAB:
6793
		  shndx = elf_shstrtab_sec (abfd);
7390
		  shndx = elf_shstrtab_sec (abfd);
6794
		  break;
7391
		  break;
6795
		case MAP_SYM_SHNDX:
7392
		case MAP_SYM_SHNDX:
-
 
7393
		  if (elf_symtab_shndx_list (abfd))
6796
		  shndx = elf_symtab_shndx (abfd);
7394
		    shndx = elf_symtab_shndx_list (abfd)->ndx;
6797
		  break;
7395
		  break;
6798
		default:
7396
		default:
6799
		  shndx = SHN_ABS;
7397
		  shndx = SHN_ABS;
6800
		  break;
7398
		  break;
6801
		}
7399
		}
Line 6821... Line 7419...
6821
		      _bfd_error_handler (_("\
7419
		      _bfd_error_handler (_("\
6822
Unable to find equivalent output section for symbol '%s' from section '%s'"),
7420
Unable to find equivalent output section for symbol '%s' from section '%s'"),
6823
					  syms[idx]->name ? syms[idx]->name : "",
7421
					  syms[idx]->name ? syms[idx]->name : "",
6824
					  sec->name);
7422
					  sec->name);
6825
		      bfd_set_error (bfd_error_invalid_operation);
7423
		      bfd_set_error (bfd_error_invalid_operation);
6826
		      _bfd_stringtab_free (stt);
-
 
6827
		      return FALSE;
7424
		      goto error_return;
6828
		    }
7425
		    }
Line 6829... Line 7426...
6829
 
7426
 
6830
		  shndx = _bfd_elf_section_from_bfd_section (abfd, sec2);
7427
		  shndx = _bfd_elf_section_from_bfd_section (abfd, sec2);
6831
		  BFD_ASSERT (shndx != SHN_BAD);
7428
		  BFD_ASSERT (shndx != SHN_BAD);
Line 6908... Line 7505...
6908
	{
7505
	{
6909
	  sym.st_other = 0;
7506
	  sym.st_other = 0;
6910
	  sym.st_target_internal = 0;
7507
	  sym.st_target_internal = 0;
6911
	}
7508
	}
Line -... Line 7509...
-
 
7509
 
-
 
7510
      idx++;
6912
 
7511
      symstrtab[idx].sym = sym;
-
 
7512
      symstrtab[idx].dest_index = outbound_syms_index;
-
 
7513
      symstrtab[idx].destshndx_index = outbound_shndx_index;
6913
      bed->s->swap_symbol_out (abfd, &sym, outbound_syms, outbound_shndx);
7514
 
6914
      outbound_syms += bed->s->sizeof_sym;
7515
      outbound_syms_index++;
6915
      if (outbound_shndx != NULL)
7516
      if (outbound_shndx != NULL)
6916
	outbound_shndx += sizeof (Elf_External_Sym_Shndx);
7517
	outbound_shndx_index++;
Line -... Line 7518...
-
 
7518
    }
-
 
7519
 
-
 
7520
  /* Finalize the .strtab section.  */
-
 
7521
  _bfd_elf_strtab_finalize (stt);
-
 
7522
 
-
 
7523
  /* Swap out the .strtab section.  */
-
 
7524
  for (idx = 0; idx <= symcount; idx++)
-
 
7525
    {
-
 
7526
      struct elf_sym_strtab *elfsym = &symstrtab[idx];
-
 
7527
      if (elfsym->sym.st_name == (unsigned long) -1)
-
 
7528
	elfsym->sym.st_name = 0;
-
 
7529
      else
-
 
7530
	elfsym->sym.st_name = _bfd_elf_strtab_offset (stt,
-
 
7531
						      elfsym->sym.st_name);
-
 
7532
      bed->s->swap_symbol_out (abfd, &elfsym->sym,
-
 
7533
			       (outbound_syms
-
 
7534
				+ (elfsym->dest_index
-
 
7535
				   * bed->s->sizeof_sym)),
-
 
7536
			       (outbound_shndx
-
 
7537
				+ (elfsym->destshndx_index
-
 
7538
				   * sizeof (Elf_External_Sym_Shndx))));
-
 
7539
    }
6917
    }
7540
  free (symstrtab);
6918
 
7541
 
6919
  *sttp = stt;
7542
  *sttp = stt;
Line 6920... Line 7543...
6920
  symstrtab_hdr->sh_size = _bfd_stringtab_size (stt);
7543
  symstrtab_hdr->sh_size = _bfd_elf_strtab_size (stt);
6921
  symstrtab_hdr->sh_type = SHT_STRTAB;
7544
  symstrtab_hdr->sh_type = SHT_STRTAB;
6922
 
7545
 
Line 7119... Line 7742...
7119
      unsigned int i;
7742
      unsigned int i;
7120
      bfd_byte *contents_end;
7743
      bfd_byte *contents_end;
Line 7121... Line 7744...
7121
 
7744
 
Line 7122... Line -...
7122
      hdr = &elf_tdata (abfd)->dynverref_hdr;
-
 
7123
 
7745
      hdr = &elf_tdata (abfd)->dynverref_hdr;
7124
      elf_tdata (abfd)->verref = (Elf_Internal_Verneed *)
-
 
7125
          bfd_zalloc2 (abfd, hdr->sh_info, sizeof (Elf_Internal_Verneed));
-
 
7126
      if (elf_tdata (abfd)->verref == NULL)
-
 
7127
	goto error_return;
-
 
7128
 
-
 
7129
      elf_tdata (abfd)->cverrefs = hdr->sh_info;
-
 
7130
 
-
 
7131
      contents = (bfd_byte *) bfd_malloc (hdr->sh_size);
7746
 
-
 
7747
      if (hdr->sh_info == 0 || hdr->sh_size < sizeof (Elf_External_Verneed))
-
 
7748
	{
-
 
7749
error_return_bad_verref:
-
 
7750
	  (*_bfd_error_handler)
7132
      if (contents == NULL)
7751
	    (_("%B: .gnu.version_r invalid entry"), abfd);
7133
	{
7752
	  bfd_set_error (bfd_error_bad_value);
7134
error_return_verref:
7753
error_return_verref:
7135
	  elf_tdata (abfd)->verref = NULL;
7754
	  elf_tdata (abfd)->verref = NULL;
7136
	  elf_tdata (abfd)->cverrefs = 0;
7755
	  elf_tdata (abfd)->cverrefs = 0;
-
 
7756
	  goto error_return;
-
 
7757
	}
-
 
7758
 
-
 
7759
      contents = (bfd_byte *) bfd_malloc (hdr->sh_size);
-
 
7760
      if (contents == NULL)
7137
	  goto error_return;
7761
	goto error_return_verref;
7138
	}
7762
 
7139
      if (bfd_seek (abfd, hdr->sh_offset, SEEK_SET) != 0
7763
      if (bfd_seek (abfd, hdr->sh_offset, SEEK_SET) != 0
Line -... Line 7764...
-
 
7764
	  || bfd_bread (contents, hdr->sh_size, abfd) != hdr->sh_size)
7140
	  || bfd_bread (contents, hdr->sh_size, abfd) != hdr->sh_size)
7765
	goto error_return_verref;
-
 
7766
 
-
 
7767
      elf_tdata (abfd)->verref = (Elf_Internal_Verneed *)
7141
	goto error_return_verref;
7768
	bfd_zalloc2 (abfd, hdr->sh_info, sizeof (Elf_Internal_Verneed));
Line 7142... Line 7769...
7142
 
7769
 
7143
      if (hdr->sh_info && hdr->sh_size < sizeof (Elf_External_Verneed))
7770
      if (elf_tdata (abfd)->verref == NULL)
7144
	goto error_return_verref;
7771
	goto error_return_verref;
Line 7160... Line 7787...
7160
 
7787
 
7161
	  iverneed->vn_filename =
7788
	  iverneed->vn_filename =
7162
	    bfd_elf_string_from_elf_section (abfd, hdr->sh_link,
7789
	    bfd_elf_string_from_elf_section (abfd, hdr->sh_link,
7163
					     iverneed->vn_file);
7790
					     iverneed->vn_file);
7164
	  if (iverneed->vn_filename == NULL)
7791
	  if (iverneed->vn_filename == NULL)
Line 7165... Line 7792...
7165
	    goto error_return_verref;
7792
	    goto error_return_bad_verref;
7166
 
7793
 
7167
	  if (iverneed->vn_cnt == 0)
7794
	  if (iverneed->vn_cnt == 0)
7168
	    iverneed->vn_auxptr = NULL;
7795
	    iverneed->vn_auxptr = NULL;
Line 7175... Line 7802...
7175
		goto error_return_verref;
7802
		goto error_return_verref;
7176
	    }
7803
	    }
Line 7177... Line 7804...
7177
 
7804
 
7178
	  if (iverneed->vn_aux
7805
	  if (iverneed->vn_aux
7179
	      > (size_t) (contents_end - (bfd_byte *) everneed))
7806
	      > (size_t) (contents_end - (bfd_byte *) everneed))
Line 7180... Line 7807...
7180
	    goto error_return_verref;
7807
	    goto error_return_bad_verref;
7181
 
7808
 
7182
	  evernaux = ((Elf_External_Vernaux *)
7809
	  evernaux = ((Elf_External_Vernaux *)
7183
		      ((bfd_byte *) everneed + iverneed->vn_aux));
7810
		      ((bfd_byte *) everneed + iverneed->vn_aux));
Line 7188... Line 7815...
7188
 
7815
 
7189
	      ivernaux->vna_nodename =
7816
	      ivernaux->vna_nodename =
7190
		bfd_elf_string_from_elf_section (abfd, hdr->sh_link,
7817
		bfd_elf_string_from_elf_section (abfd, hdr->sh_link,
7191
						 ivernaux->vna_name);
7818
						 ivernaux->vna_name);
7192
	      if (ivernaux->vna_nodename == NULL)
7819
	      if (ivernaux->vna_nodename == NULL)
-
 
7820
		goto error_return_bad_verref;
-
 
7821
 
-
 
7822
	      if (ivernaux->vna_other > freeidx)
Line -... Line 7823...
-
 
7823
		freeidx = ivernaux->vna_other;
-
 
7824
 
-
 
7825
	      ivernaux->vna_nextptr = NULL;
-
 
7826
	      if (ivernaux->vna_next == 0)
-
 
7827
		{
-
 
7828
		  iverneed->vn_cnt = j + 1;
7193
		goto error_return_verref;
7829
		  break;
7194
 
7830
		}
7195
	      if (j + 1 < iverneed->vn_cnt)
-
 
7196
		ivernaux->vna_nextptr = ivernaux + 1;
-
 
Line 7197... Line 7831...
7197
	      else
7831
	      if (j + 1 < iverneed->vn_cnt)
7198
		ivernaux->vna_nextptr = NULL;
7832
		ivernaux->vna_nextptr = ivernaux + 1;
7199
 
7833
 
Line 7200... Line 7834...
7200
	      if (ivernaux->vna_next
7834
	      if (ivernaux->vna_next
7201
		  > (size_t) (contents_end - (bfd_byte *) evernaux))
7835
		  > (size_t) (contents_end - (bfd_byte *) evernaux))
7202
		goto error_return_verref;
-
 
7203
 
-
 
7204
	      evernaux = ((Elf_External_Vernaux *)
-
 
7205
			  ((bfd_byte *) evernaux + ivernaux->vna_next));
7836
		goto error_return_bad_verref;
Line -... Line 7837...
-
 
7837
 
-
 
7838
	      evernaux = ((Elf_External_Vernaux *)
-
 
7839
			  ((bfd_byte *) evernaux + ivernaux->vna_next));
7206
 
7840
	    }
7207
	      if (ivernaux->vna_other > freeidx)
7841
 
7208
		freeidx = ivernaux->vna_other;
-
 
7209
	    }
-
 
Line 7210... Line 7842...
7210
 
7842
	  iverneed->vn_nextref = NULL;
7211
	  if (i + 1 < hdr->sh_info)
7843
	  if (iverneed->vn_next == 0)
7212
	    iverneed->vn_nextref = iverneed + 1;
7844
	    break;
Line 7213... Line 7845...
7213
	  else
7845
	  if (i + 1 < hdr->sh_info)
7214
	    iverneed->vn_nextref = NULL;
7846
	    iverneed->vn_nextref = iverneed + 1;
7215
 
7847
 
-
 
7848
	  if (iverneed->vn_next
Line 7216... Line 7849...
7216
	  if (iverneed->vn_next
7849
	      > (size_t) (contents_end - (bfd_byte *) everneed))
7217
	      > (size_t) (contents_end - (bfd_byte *) everneed))
7850
	    goto error_return_bad_verref;
7218
	    goto error_return_verref;
7851
 
Line 7236... Line 7869...
7236
      unsigned int maxidx;
7869
      unsigned int maxidx;
7237
      bfd_byte *contents_end_def, *contents_end_aux;
7870
      bfd_byte *contents_end_def, *contents_end_aux;
Line 7238... Line 7871...
7238
 
7871
 
Line -... Line 7872...
-
 
7872
      hdr = &elf_tdata (abfd)->dynverdef_hdr;
-
 
7873
 
-
 
7874
      if (hdr->sh_info == 0 || hdr->sh_size < sizeof (Elf_External_Verdef))
-
 
7875
	{
-
 
7876
	error_return_bad_verdef:
-
 
7877
	  (*_bfd_error_handler)
-
 
7878
	    (_("%B: .gnu.version_d invalid entry"), abfd);
-
 
7879
	  bfd_set_error (bfd_error_bad_value);
-
 
7880
	error_return_verdef:
-
 
7881
	  elf_tdata (abfd)->verdef = NULL;
-
 
7882
	  elf_tdata (abfd)->cverdefs = 0;
-
 
7883
	  goto error_return;
7239
      hdr = &elf_tdata (abfd)->dynverdef_hdr;
7884
	}
7240
 
7885
 
7241
      contents = (bfd_byte *) bfd_malloc (hdr->sh_size);
7886
      contents = (bfd_byte *) bfd_malloc (hdr->sh_size);
7242
      if (contents == NULL)
7887
      if (contents == NULL)
7243
	goto error_return;
7888
	goto error_return_verdef;
7244
      if (bfd_seek (abfd, hdr->sh_offset, SEEK_SET) != 0
-
 
7245
	  || bfd_bread (contents, hdr->sh_size, abfd) != hdr->sh_size)
-
 
7246
	goto error_return;
-
 
7247
 
7889
      if (bfd_seek (abfd, hdr->sh_offset, SEEK_SET) != 0
Line 7248... Line 7890...
7248
      if (hdr->sh_info && hdr->sh_size < sizeof (Elf_External_Verdef))
7890
	  || bfd_bread (contents, hdr->sh_size, abfd) != hdr->sh_size)
7249
	goto error_return;
7891
	goto error_return_verdef;
7250
 
7892
 
7251
      BFD_ASSERT (sizeof (Elf_External_Verdef)
7893
      BFD_ASSERT (sizeof (Elf_External_Verdef)
Line 7262... Line 7904...
7262
      maxidx = 0;
7904
      maxidx = 0;
7263
      for (i = 0; i < hdr->sh_info; ++i)
7905
      for (i = 0; i < hdr->sh_info; ++i)
7264
	{
7906
	{
7265
	  _bfd_elf_swap_verdef_in (abfd, everdef, &iverdefmem);
7907
	  _bfd_elf_swap_verdef_in (abfd, everdef, &iverdefmem);
Line -... Line 7908...
-
 
7908
 
-
 
7909
	  if ((iverdefmem.vd_ndx & ((unsigned) VERSYM_VERSION)) == 0)
7266
 
7910
	    goto error_return_bad_verdef;
7267
	  if ((iverdefmem.vd_ndx & ((unsigned) VERSYM_VERSION)) > maxidx)
7911
	  if ((iverdefmem.vd_ndx & ((unsigned) VERSYM_VERSION)) > maxidx)
Line -... Line 7912...
-
 
7912
	    maxidx = iverdefmem.vd_ndx & ((unsigned) VERSYM_VERSION);
-
 
7913
 
-
 
7914
	  if (iverdefmem.vd_next == 0)
7268
	    maxidx = iverdefmem.vd_ndx & ((unsigned) VERSYM_VERSION);
7915
	    break;
7269
 
7916
 
7270
	  if (iverdefmem.vd_next
7917
	  if (iverdefmem.vd_next
Line 7271... Line 7918...
7271
	      > (size_t) (contents_end_def - (bfd_byte *) everdef))
7918
	      > (size_t) (contents_end_def - (bfd_byte *) everdef))
7272
	    goto error_return;
7919
	    goto error_return_bad_verdef;
7273
 
7920
 
Line 7280... Line 7927...
7280
	  if (freeidx > maxidx)
7927
	  if (freeidx > maxidx)
7281
	    maxidx = ++freeidx;
7928
	    maxidx = ++freeidx;
7282
	  else
7929
	  else
7283
	    freeidx = ++maxidx;
7930
	    freeidx = ++maxidx;
7284
	}
7931
	}
-
 
7932
 
7285
      elf_tdata (abfd)->verdef = (Elf_Internal_Verdef *)
7933
      elf_tdata (abfd)->verdef = (Elf_Internal_Verdef *)
7286
          bfd_zalloc2 (abfd, maxidx, sizeof (Elf_Internal_Verdef));
7934
	bfd_zalloc2 (abfd, maxidx, sizeof (Elf_Internal_Verdef));
7287
      if (elf_tdata (abfd)->verdef == NULL)
7935
      if (elf_tdata (abfd)->verdef == NULL)
7288
	goto error_return;
7936
	goto error_return_verdef;
Line 7289... Line 7937...
7289
 
7937
 
Line 7290... Line 7938...
7290
      elf_tdata (abfd)->cverdefs = maxidx;
7938
      elf_tdata (abfd)->cverdefs = maxidx;
7291
 
7939
 
Line 7298... Line 7946...
7298
	  unsigned int j;
7946
	  unsigned int j;
Line 7299... Line 7947...
7299
 
7947
 
Line 7300... Line 7948...
7300
	  _bfd_elf_swap_verdef_in (abfd, everdef, &iverdefmem);
7948
	  _bfd_elf_swap_verdef_in (abfd, everdef, &iverdefmem);
7301
 
-
 
7302
	  if ((iverdefmem.vd_ndx & VERSYM_VERSION) == 0)
-
 
7303
	    {
-
 
7304
error_return_verdef:
-
 
7305
	      elf_tdata (abfd)->verdef = NULL;
7949
 
7306
	      elf_tdata (abfd)->cverdefs = 0;
-
 
Line 7307... Line 7950...
7307
	      goto error_return;
7950
	  if ((iverdefmem.vd_ndx & VERSYM_VERSION) == 0)
7308
	    }
7951
	    goto error_return_bad_verdef;
Line 7309... Line 7952...
7309
 
7952
 
Line 7310... Line 7953...
7310
	  iverdef = &iverdefarr[(iverdefmem.vd_ndx & VERSYM_VERSION) - 1];
7953
	  iverdef = &iverdefarr[(iverdefmem.vd_ndx & VERSYM_VERSION) - 1];
7311
	  memcpy (iverdef, &iverdefmem, sizeof (Elf_Internal_Verdef));
7954
	  memcpy (iverdef, &iverdefmem, offsetof (Elf_Internal_Verdef, vd_bfd));
Line 7323... Line 7966...
7323
		goto error_return_verdef;
7966
		goto error_return_verdef;
7324
	    }
7967
	    }
Line 7325... Line 7968...
7325
 
7968
 
7326
	  if (iverdef->vd_aux
7969
	  if (iverdef->vd_aux
7327
	      > (size_t) (contents_end_aux - (bfd_byte *) everdef))
7970
	      > (size_t) (contents_end_aux - (bfd_byte *) everdef))
Line 7328... Line 7971...
7328
	    goto error_return_verdef;
7971
	    goto error_return_bad_verdef;
7329
 
7972
 
7330
	  everdaux = ((Elf_External_Verdaux *)
7973
	  everdaux = ((Elf_External_Verdaux *)
7331
		      ((bfd_byte *) everdef + iverdef->vd_aux));
7974
		      ((bfd_byte *) everdef + iverdef->vd_aux));
Line 7336... Line 7979...
7336
 
7979
 
7337
	      iverdaux->vda_nodename =
7980
	      iverdaux->vda_nodename =
7338
		bfd_elf_string_from_elf_section (abfd, hdr->sh_link,
7981
		bfd_elf_string_from_elf_section (abfd, hdr->sh_link,
7339
						 iverdaux->vda_name);
7982
						 iverdaux->vda_name);
7340
	      if (iverdaux->vda_nodename == NULL)
7983
	      if (iverdaux->vda_nodename == NULL)
Line -... Line 7984...
-
 
7984
		goto error_return_bad_verdef;
-
 
7985
 
-
 
7986
	      iverdaux->vda_nextptr = NULL;
-
 
7987
	      if (iverdaux->vda_next == 0)
-
 
7988
		{
-
 
7989
		  iverdef->vd_cnt = j + 1;
7341
		goto error_return_verdef;
7990
		  break;
7342
 
7991
		}
7343
	      if (j + 1 < iverdef->vd_cnt)
-
 
7344
		iverdaux->vda_nextptr = iverdaux + 1;
-
 
Line 7345... Line 7992...
7345
	      else
7992
	      if (j + 1 < iverdef->vd_cnt)
7346
		iverdaux->vda_nextptr = NULL;
7993
		iverdaux->vda_nextptr = iverdaux + 1;
7347
 
7994
 
Line 7348... Line 7995...
7348
	      if (iverdaux->vda_next
7995
	      if (iverdaux->vda_next
7349
		  > (size_t) (contents_end_aux - (bfd_byte *) everdaux))
7996
		  > (size_t) (contents_end_aux - (bfd_byte *) everdaux))
7350
		goto error_return_verdef;
7997
		goto error_return_bad_verdef;
Line -... Line 7998...
-
 
7998
 
7351
 
7999
	      everdaux = ((Elf_External_Verdaux *)
7352
	      everdaux = ((Elf_External_Verdaux *)
8000
			  ((bfd_byte *) everdaux + iverdaux->vda_next));
Line -... Line 8001...
-
 
8001
	    }
-
 
8002
 
-
 
8003
	  iverdef->vd_nodename = NULL;
7353
			  ((bfd_byte *) everdaux + iverdaux->vda_next));
8004
	  if (iverdef->vd_cnt)
7354
	    }
8005
	    iverdef->vd_nodename = iverdef->vd_auxptr->vda_nodename;
7355
 
-
 
7356
	  if (iverdef->vd_cnt)
-
 
Line 7357... Line 8006...
7357
	    iverdef->vd_nodename = iverdef->vd_auxptr->vda_nodename;
8006
 
7358
 
8007
	  iverdef->vd_nextdef = NULL;
7359
	  if ((size_t) (iverdef - iverdefarr) + 1 < maxidx)
8008
	  if (iverdef->vd_next == 0)
Line 7400... Line 8049...
7400
 
8049
 
7401
      iverdef->vd_nodename = bfd_elf_get_dt_soname (abfd);
8050
      iverdef->vd_nodename = bfd_elf_get_dt_soname (abfd);
7402
      if (iverdef->vd_nodename == NULL)
8051
      if (iverdef->vd_nodename == NULL)
7403
	goto error_return_verdef;
8052
	goto error_return_verdef;
7404
      iverdef->vd_nextdef = NULL;
8053
      iverdef->vd_nextdef = NULL;
7405
      iverdef->vd_auxptr = (struct elf_internal_verdaux *)
8054
      iverdef->vd_auxptr = ((struct elf_internal_verdaux *)
7406
          bfd_alloc (abfd, sizeof (Elf_Internal_Verdaux));
8055
			    bfd_zalloc (abfd, sizeof (Elf_Internal_Verdaux)));
7407
      if (iverdef->vd_auxptr == NULL)
8056
      if (iverdef->vd_auxptr == NULL)
Line 7408... Line 8057...
7408
	goto error_return_verdef;
8057
	goto error_return_verdef;
7409
 
8058
 
7410
      iverdaux = iverdef->vd_auxptr;
-
 
7411
      iverdaux->vda_nodename = iverdef->vd_nodename;
8059
      iverdaux = iverdef->vd_auxptr;
Line 7412... Line 8060...
7412
      iverdaux->vda_nextptr = NULL;
8060
      iverdaux->vda_nodename = iverdef->vd_nodename;
Line 7413... Line 8061...
7413
    }
8061
    }
Line 7422... Line 8070...
7422

8070

7423
asymbol *
8071
asymbol *
7424
_bfd_elf_make_empty_symbol (bfd *abfd)
8072
_bfd_elf_make_empty_symbol (bfd *abfd)
7425
{
8073
{
7426
  elf_symbol_type *newsym;
8074
  elf_symbol_type *newsym;
7427
  bfd_size_type amt = sizeof (elf_symbol_type);
-
 
Line 7428... Line 8075...
7428
 
8075
 
7429
  newsym = (elf_symbol_type *) bfd_zalloc (abfd, amt);
8076
  newsym = (elf_symbol_type *) bfd_zalloc (abfd, sizeof * newsym);
7430
  if (!newsym)
8077
  if (!newsym)
7431
    return NULL;
-
 
7432
  else
-
 
7433
    {
8078
    return NULL;
7434
      newsym->symbol.the_bfd = abfd;
8079
  newsym->symbol.the_bfd = abfd;
7435
      return &newsym->symbol;
8080
  return &newsym->symbol;
7436
    }
-
 
Line 7437... Line 8081...
7437
}
8081
}
7438
 
8082
 
7439
void
8083
void
7440
_bfd_elf_get_symbol_info (bfd *abfd ATTRIBUTE_UNUSED,
8084
_bfd_elf_get_symbol_info (bfd *abfd ATTRIBUTE_UNUSED,
Line 7468... Line 8112...
7468
     underscore to be emitted on some ELF targets).  For ease of use,
8112
     underscore to be emitted on some ELF targets).  For ease of use,
7469
     we treat such symbols as local.  */
8113
     we treat such symbols as local.  */
7470
  if (name[0] == '_' && name[1] == '.' && name[2] == 'L' && name[3] == '_')
8114
  if (name[0] == '_' && name[1] == '.' && name[2] == 'L' && name[3] == '_')
7471
    return TRUE;
8115
    return TRUE;
Line -... Line 8116...
-
 
8116
 
-
 
8117
  /* Treat assembler generated fake symbols, dollar local labels and
-
 
8118
     forward-backward labels (aka local labels) as locals.
-
 
8119
     These labels have the form:
-
 
8120
 
-
 
8121
       L0^A.*                                  (fake symbols)
-
 
8122
 
-
 
8123
       [.]?L[0123456789]+{^A|^B}[0123456789]*  (local labels)
-
 
8124
 
-
 
8125
     Versions which start with .L will have already been matched above,
-
 
8126
     so we only need to match the rest.  */
-
 
8127
  if (name[0] == 'L' && ISDIGIT (name[1]))
-
 
8128
    {
-
 
8129
      bfd_boolean ret = FALSE;
-
 
8130
      const char * p;
-
 
8131
      char c;
-
 
8132
 
-
 
8133
      for (p = name + 2; (c = *p); p++)
-
 
8134
	{
-
 
8135
	  if (c == 1 || c == 2)
-
 
8136
	    {
-
 
8137
	      if (c == 1 && p == name + 2)
-
 
8138
		/* A fake symbol.  */
-
 
8139
		return TRUE;
-
 
8140
 
-
 
8141
	      /* FIXME: We are being paranoid here and treating symbols like
-
 
8142
		 L0^Bfoo as if there were non-local, on the grounds that the
-
 
8143
		 assembler will never generate them.  But can any symbol
-
 
8144
		 containing an ASCII value in the range 1-31 ever be anything
-
 
8145
		 other than some kind of local ?  */
-
 
8146
	      ret = TRUE;
-
 
8147
	    }
-
 
8148
 
-
 
8149
	  if (! ISDIGIT (c))
-
 
8150
	    {
-
 
8151
	      ret = FALSE;
-
 
8152
	      break;
-
 
8153
	    }
-
 
8154
	}
-
 
8155
      return ret;
-
 
8156
    }
7472
 
8157
 
7473
  return FALSE;
8158
  return FALSE;
Line 7474... Line 8159...
7474
}
8159
}
7475
 
8160
 
Line 7494... Line 8179...
7494
    return FALSE;
8179
    return FALSE;
Line 7495... Line 8180...
7495
 
8180
 
7496
  return bfd_default_set_arch_mach (abfd, arch, machine);
8181
  return bfd_default_set_arch_mach (abfd, arch, machine);
Line 7497... Line -...
7497
}
-
 
7498
 
-
 
7499
/* Find the function to a particular section and offset,
-
 
7500
   for error reporting.  */
-
 
7501
 
-
 
7502
static bfd_boolean
-
 
7503
elf_find_function (bfd *abfd,
-
 
7504
		   asection *section,
-
 
7505
		   asymbol **symbols,
-
 
7506
		   bfd_vma offset,
-
 
7507
		   const char **filename_ptr,
-
 
7508
		   const char **functionname_ptr)
-
 
7509
{
-
 
7510
  struct elf_find_function_cache
-
 
7511
  {
-
 
7512
    asection *last_section;
-
 
7513
    asymbol *func;
-
 
7514
    const char *filename;
-
 
7515
    bfd_size_type func_size;
-
 
7516
  } *cache;
-
 
7517
 
-
 
7518
  if (symbols == NULL)
-
 
7519
    return FALSE;
-
 
7520
 
-
 
7521
  cache = elf_tdata (abfd)->elf_find_function_cache;
-
 
7522
  if (cache == NULL)
-
 
7523
    {
-
 
7524
      cache = bfd_zalloc (abfd, sizeof (*cache));
-
 
7525
      elf_tdata (abfd)->elf_find_function_cache = cache;
-
 
7526
      if (cache == NULL)
-
 
7527
	return FALSE;
-
 
7528
    }
-
 
7529
  if (cache->last_section != section
-
 
7530
      || cache->func == NULL
-
 
7531
      || offset < cache->func->value
-
 
7532
      || offset >= cache->func->value + cache->func_size)
-
 
7533
    {
-
 
7534
      asymbol *file;
-
 
7535
      bfd_vma low_func;
-
 
7536
      asymbol **p;
-
 
7537
      /* ??? Given multiple file symbols, it is impossible to reliably
-
 
7538
	 choose the right file name for global symbols.  File symbols are
-
 
7539
	 local symbols, and thus all file symbols must sort before any
-
 
7540
	 global symbols.  The ELF spec may be interpreted to say that a
-
 
7541
	 file symbol must sort before other local symbols, but currently
-
 
7542
	 ld -r doesn't do this.  So, for ld -r output, it is possible to
-
 
7543
	 make a better choice of file name for local symbols by ignoring
-
 
7544
	 file symbols appearing after a given local symbol.  */
-
 
7545
      enum { nothing_seen, symbol_seen, file_after_symbol_seen } state;
-
 
7546
      const struct elf_backend_data *bed = get_elf_backend_data (abfd);
-
 
7547
 
-
 
7548
      file = NULL;
-
 
7549
      low_func = 0;
-
 
7550
      state = nothing_seen;
-
 
7551
      cache->filename = NULL;
-
 
7552
      cache->func = NULL;
-
 
7553
      cache->func_size = 0;
-
 
7554
      cache->last_section = section;
-
 
7555
 
-
 
7556
      for (p = symbols; *p != NULL; p++)
-
 
7557
	{
-
 
7558
	  asymbol *sym = *p;
-
 
7559
	  bfd_vma code_off;
-
 
7560
	  bfd_size_type size;
-
 
7561
 
-
 
7562
	  if ((sym->flags & BSF_FILE) != 0)
-
 
7563
	    {
-
 
7564
	      file = sym;
-
 
7565
	      if (state == symbol_seen)
-
 
7566
		state = file_after_symbol_seen;
-
 
7567
	      continue;
-
 
7568
	    }
-
 
7569
 
-
 
7570
	  size = bed->maybe_function_sym (sym, section, &code_off);
-
 
7571
	  if (size != 0
-
 
7572
	      && code_off <= offset
-
 
7573
	      && (code_off > low_func
-
 
7574
		  || (code_off == low_func
-
 
7575
		      && size > cache->func_size)))
-
 
7576
	    {
-
 
7577
	      cache->func = sym;
-
 
7578
	      cache->func_size = size;
-
 
7579
	      cache->filename = NULL;
-
 
7580
	      low_func = code_off;
-
 
7581
	      if (file != NULL
-
 
7582
		  && ((sym->flags & BSF_LOCAL) != 0
-
 
7583
		      || state != file_after_symbol_seen))
-
 
7584
		cache->filename = bfd_asymbol_name (file);
-
 
7585
	    }
-
 
7586
	  if (state == nothing_seen)
-
 
7587
	    state = symbol_seen;
-
 
7588
	}
-
 
7589
    }
-
 
7590
 
-
 
7591
  if (cache->func == NULL)
-
 
7592
    return FALSE;
-
 
7593
 
-
 
7594
  if (filename_ptr)
-
 
7595
    *filename_ptr = cache->filename;
-
 
7596
  if (functionname_ptr)
-
 
7597
    *functionname_ptr = bfd_asymbol_name (cache->func);
-
 
7598
 
-
 
7599
  return TRUE;
-
 
7600
}
8182
}
7601
 
8183
 
Line 7602... Line 8184...
7602
/* Find the nearest line to a particular section and offset,
8184
/* Find the nearest line to a particular section and offset,
7603
   for error reporting.  */
8185
   for error reporting.  */
7604
 
-
 
7605
bfd_boolean
8186
 
7606
_bfd_elf_find_nearest_line (bfd *abfd,
-
 
7607
			    asection *section,
-
 
7608
			    asymbol **symbols,
-
 
7609
			    bfd_vma offset,
-
 
7610
			    const char **filename_ptr,
-
 
7611
			    const char **functionname_ptr,
-
 
7612
			    unsigned int *line_ptr)
-
 
7613
{
-
 
7614
  return _bfd_elf_find_nearest_line_discriminator (abfd, section, symbols,
-
 
7615
                                                   offset, filename_ptr,
-
 
7616
                                                   functionname_ptr,
-
 
7617
                                                   line_ptr,
-
 
7618
                                                   NULL);
-
 
7619
}
-
 
7620
 
8187
bfd_boolean
7621
bfd_boolean
-
 
7622
_bfd_elf_find_nearest_line_discriminator (bfd *abfd,
8188
_bfd_elf_find_nearest_line (bfd *abfd,
7623
                                          asection *section,
8189
			    asymbol **symbols,
7624
                                          asymbol **symbols,
8190
			    asection *section,
7625
                                          bfd_vma offset,
8191
			    bfd_vma offset,
7626
                                          const char **filename_ptr,
8192
			    const char **filename_ptr,
7627
                                          const char **functionname_ptr,
8193
			    const char **functionname_ptr,
7628
                                          unsigned int *line_ptr,
8194
			    unsigned int *line_ptr,
Line 7629... Line 8195...
7629
                                          unsigned int *discriminator_ptr)
8195
			    unsigned int *discriminator_ptr)
7630
{
8196
{
7631
  bfd_boolean found;
8197
  bfd_boolean found;
7632
 
-
 
7633
  if (_bfd_dwarf1_find_nearest_line (abfd, section, symbols, offset,
8198
 
7634
				     filename_ptr, functionname_ptr,
-
 
7635
				     line_ptr))
8199
  if (_bfd_dwarf2_find_nearest_line (abfd, symbols, NULL, section, offset,
7636
    {
-
 
7637
      if (!*functionname_ptr)
-
 
7638
	elf_find_function (abfd, section, symbols, offset,
-
 
7639
			   *filename_ptr ? NULL : filename_ptr,
-
 
7640
			   functionname_ptr);
-
 
7641
 
8200
				     filename_ptr, functionname_ptr,
7642
      return TRUE;
-
 
7643
    }
8201
				     line_ptr, discriminator_ptr,
7644
 
8202
				     dwarf_debug_sections, 0,
7645
  if (_bfd_dwarf2_find_nearest_line (abfd, dwarf_debug_sections,
-
 
7646
                                     section, symbols, offset,
8203
				     &elf_tdata (abfd)->dwarf2_find_line_info)
7647
				     filename_ptr, functionname_ptr,
8204
      || _bfd_dwarf1_find_nearest_line (abfd, symbols, section, offset,
7648
				     line_ptr, discriminator_ptr, 0,
8205
					filename_ptr, functionname_ptr,
7649
				     &elf_tdata (abfd)->dwarf2_find_line_info))
8206
					line_ptr))
7650
    {
8207
    {
7651
      if (!*functionname_ptr)
-
 
7652
	elf_find_function (abfd, section, symbols, offset,
8208
      if (!*functionname_ptr)
7653
			   *filename_ptr ? NULL : filename_ptr,
8209
	_bfd_elf_find_function (abfd, symbols, section, offset,
Line 7654... Line 8210...
7654
			   functionname_ptr);
8210
				*filename_ptr ? NULL : filename_ptr,
7655
 
8211
				functionname_ptr);
Line 7665... Line 8221...
7665
    return TRUE;
8221
    return TRUE;
Line 7666... Line 8222...
7666
 
8222
 
7667
  if (symbols == NULL)
8223
  if (symbols == NULL)
Line 7668... Line 8224...
7668
    return FALSE;
8224
    return FALSE;
7669
 
8225
 
7670
  if (! elf_find_function (abfd, section, symbols, offset,
8226
  if (! _bfd_elf_find_function (abfd, symbols, section, offset,
Line 7671... Line 8227...
7671
			   filename_ptr, functionname_ptr))
8227
				filename_ptr, functionname_ptr))
7672
    return FALSE;
8228
    return FALSE;
Line 7679... Line 8235...
7679
 
8235
 
7680
bfd_boolean
8236
bfd_boolean
7681
_bfd_elf_find_line (bfd *abfd, asymbol **symbols, asymbol *symbol,
8237
_bfd_elf_find_line (bfd *abfd, asymbol **symbols, asymbol *symbol,
7682
		    const char **filename_ptr, unsigned int *line_ptr)
8238
		    const char **filename_ptr, unsigned int *line_ptr)
7683
{
8239
{
7684
  return _bfd_elf_find_line_discriminator (abfd, symbols, symbol,
8240
  return _bfd_dwarf2_find_nearest_line (abfd, symbols, symbol, NULL, 0,
7685
		                           filename_ptr, line_ptr,
-
 
7686
                                           NULL);
-
 
7687
}
-
 
7688
 
-
 
7689
bfd_boolean
-
 
7690
_bfd_elf_find_line_discriminator (bfd *abfd, asymbol **symbols, asymbol *symbol,
-
 
7691
                                  const char **filename_ptr,
-
 
7692
                                  unsigned int *line_ptr,
-
 
7693
                                  unsigned int *discriminator_ptr)
-
 
7694
{
-
 
7695
  return _bfd_dwarf2_find_line (abfd, symbols, symbol,
8241
					filename_ptr, NULL, line_ptr, NULL,
7696
				filename_ptr, line_ptr, discriminator_ptr, 0,
8242
					dwarf_debug_sections, 0,
7697
				&elf_tdata (abfd)->dwarf2_find_line_info);
8243
					&elf_tdata (abfd)->dwarf2_find_line_info);
Line 7698... Line 8244...
7698
}
8244
}
7699
 
8245
 
Line 7720... Line 8266...
7720
_bfd_elf_sizeof_headers (bfd *abfd, struct bfd_link_info *info)
8266
_bfd_elf_sizeof_headers (bfd *abfd, struct bfd_link_info *info)
7721
{
8267
{
7722
  const struct elf_backend_data *bed = get_elf_backend_data (abfd);
8268
  const struct elf_backend_data *bed = get_elf_backend_data (abfd);
7723
  int ret = bed->s->sizeof_ehdr;
8269
  int ret = bed->s->sizeof_ehdr;
Line 7724... Line 8270...
7724
 
8270
 
7725
  if (!info->relocatable)
8271
  if (!bfd_link_relocatable (info))
7726
    {
8272
    {
Line 7727... Line 8273...
7727
      bfd_size_type phdr_size = elf_program_header_size (abfd);
8273
      bfd_size_type phdr_size = elf_program_header_size (abfd);
7728
 
8274
 
Line 7751... Line 8297...
7751
			       const void *location,
8297
			       const void *location,
7752
			       file_ptr offset,
8298
			       file_ptr offset,
7753
			       bfd_size_type count)
8299
			       bfd_size_type count)
7754
{
8300
{
7755
  Elf_Internal_Shdr *hdr;
8301
  Elf_Internal_Shdr *hdr;
7756
  bfd_signed_vma pos;
8302
  file_ptr pos;
Line 7757... Line 8303...
7757
 
8303
 
7758
  if (! abfd->output_has_begun
8304
  if (! abfd->output_has_begun
7759
      && ! _bfd_elf_compute_section_file_positions (abfd, NULL))
8305
      && ! _bfd_elf_compute_section_file_positions (abfd, NULL))
Line -... Line 8306...
-
 
8306
    return FALSE;
-
 
8307
 
-
 
8308
  if (!count)
7760
    return FALSE;
8309
    return TRUE;
-
 
8310
 
-
 
8311
  hdr = &elf_section_data (section)->this_hdr;
-
 
8312
  if (hdr->sh_offset == (file_ptr) -1)
-
 
8313
    {
-
 
8314
      /* We must compress this section.  Write output to the buffer.  */
-
 
8315
      unsigned char *contents = hdr->contents;
-
 
8316
      if ((offset + count) > hdr->sh_size
-
 
8317
	  || (section->flags & SEC_ELF_COMPRESS) == 0
-
 
8318
	  || contents == NULL)
-
 
8319
	abort ();
-
 
8320
      memcpy (contents + offset, location, count);
7761
 
8321
      return TRUE;
7762
  hdr = &elf_section_data (section)->this_hdr;
8322
    }
7763
  pos = hdr->sh_offset + offset;
8323
  pos = hdr->sh_offset + offset;
7764
  if (bfd_seek (abfd, pos, SEEK_SET) != 0
8324
  if (bfd_seek (abfd, pos, SEEK_SET) != 0
Line 8177... Line 8737...
8177
{
8737
{
8178
  return elfcore_make_note_pseudosection (abfd, ".reg-s390-tdb", note);
8738
  return elfcore_make_note_pseudosection (abfd, ".reg-s390-tdb", note);
8179
}
8739
}
Line 8180... Line 8740...
8180
 
8740
 
-
 
8741
static bfd_boolean
-
 
8742
elfcore_grok_s390_vxrs_low (bfd *abfd, Elf_Internal_Note *note)
-
 
8743
{
-
 
8744
  return elfcore_make_note_pseudosection (abfd, ".reg-s390-vxrs-low", note);
-
 
8745
}
-
 
8746
 
-
 
8747
static bfd_boolean
-
 
8748
elfcore_grok_s390_vxrs_high (bfd *abfd, Elf_Internal_Note *note)
-
 
8749
{
-
 
8750
  return elfcore_make_note_pseudosection (abfd, ".reg-s390-vxrs-high", note);
-
 
8751
}
-
 
8752
 
8181
static bfd_boolean
8753
static bfd_boolean
8182
elfcore_grok_arm_vfp (bfd *abfd, Elf_Internal_Note *note)
8754
elfcore_grok_arm_vfp (bfd *abfd, Elf_Internal_Note *note)
8183
{
8755
{
8184
  return elfcore_make_note_pseudosection (abfd, ".reg-arm-vfp", note);
8756
  return elfcore_make_note_pseudosection (abfd, ".reg-arm-vfp", note);
Line 8560... Line 9132...
8560
 
9132
 
8561
    case NT_X86_XSTATE:		/* Linux XSAVE extension */
9133
    case NT_X86_XSTATE:		/* Linux XSAVE extension */
8562
      if (note->namesz == 6
9134
      if (note->namesz == 6
8563
	  && strcmp (note->namedata, "LINUX") == 0)
9135
	  && strcmp (note->namedata, "LINUX") == 0)
-
 
9136
	return elfcore_grok_xstatereg (abfd, note);
-
 
9137
      else if (note->namesz == 8
-
 
9138
	  && strcmp (note->namedata, "FreeBSD") == 0)
8564
	return elfcore_grok_xstatereg (abfd, note);
9139
	return elfcore_grok_xstatereg (abfd, note);
8565
      else
9140
      else
Line 8566... Line 9141...
8566
	return TRUE;
9141
	return TRUE;
8567
 
9142
 
Line 8640... Line 9215...
8640
          && strcmp (note->namedata, "LINUX") == 0)
9215
          && strcmp (note->namedata, "LINUX") == 0)
8641
        return elfcore_grok_s390_tdb (abfd, note);
9216
        return elfcore_grok_s390_tdb (abfd, note);
8642
      else
9217
      else
8643
        return TRUE;
9218
        return TRUE;
Line -... Line 9219...
-
 
9219
 
-
 
9220
    case NT_S390_VXRS_LOW:
-
 
9221
      if (note->namesz == 6
-
 
9222
	  && strcmp (note->namedata, "LINUX") == 0)
-
 
9223
	return elfcore_grok_s390_vxrs_low (abfd, note);
-
 
9224
      else
-
 
9225
	return TRUE;
-
 
9226
 
-
 
9227
    case NT_S390_VXRS_HIGH:
-
 
9228
      if (note->namesz == 6
-
 
9229
	  && strcmp (note->namedata, "LINUX") == 0)
-
 
9230
	return elfcore_grok_s390_vxrs_high (abfd, note);
-
 
9231
      else
-
 
9232
	return TRUE;
8644
 
9233
 
8645
    case NT_ARM_VFP:
9234
    case NT_ARM_VFP:
8646
      if (note->namesz == 6
9235
      if (note->namesz == 6
8647
	  && strcmp (note->namedata, "LINUX") == 0)
9236
	  && strcmp (note->namedata, "LINUX") == 0)
8648
	return elfcore_grok_arm_vfp (abfd, note);
9237
	return elfcore_grok_arm_vfp (abfd, note);
Line 8706... Line 9295...
8706
}
9295
}
Line 8707... Line 9296...
8707
 
9296
 
8708
static bfd_boolean
9297
static bfd_boolean
8709
elfobj_grok_gnu_build_id (bfd *abfd, Elf_Internal_Note *note)
9298
elfobj_grok_gnu_build_id (bfd *abfd, Elf_Internal_Note *note)
8710
{
9299
{
Line 8711... Line 9300...
8711
  struct elf_obj_tdata *t;
9300
  struct bfd_build_id* build_id;
8712
 
9301
 
Line 8713... Line -...
8713
  if (note->descsz == 0)
-
 
8714
    return FALSE;
9302
  if (note->descsz == 0)
8715
 
9303
    return FALSE;
8716
  t = elf_tdata (abfd);
9304
 
Line 8717... Line 9305...
8717
  t->build_id = bfd_alloc (abfd, sizeof (*t->build_id) - 1 + note->descsz);
9305
  build_id = bfd_alloc (abfd, sizeof (struct bfd_build_id) - 1 + note->descsz);
8718
  if (t->build_id == NULL)
9306
  if (build_id == NULL)
-
 
9307
    return FALSE;
Line 8719... Line 9308...
8719
    return FALSE;
9308
 
8720
 
9309
  build_id->size = note->descsz;
Line 8721... Line 9310...
8721
  t->build_id->size = note->descsz;
9310
  memcpy (build_id->data, note->descdata, note->descsz);
Line 9285... Line 9874...
9285
 
9874
 
9286
  memset (&lwpstat, 0, sizeof (lwpstat));
9875
  memset (&lwpstat, 0, sizeof (lwpstat));
9287
  lwpstat.pr_lwpid  = pid >> 16;
9876
  lwpstat.pr_lwpid  = pid >> 16;
9288
  lwpstat.pr_cursig = cursig;
9877
  lwpstat.pr_cursig = cursig;
9289
#if defined (HAVE_LWPSTATUS_T_PR_REG)
9878
#if defined (HAVE_LWPSTATUS_T_PR_REG)
9290
  memcpy (lwpstat.pr_reg, gregs, sizeof (lwpstat.pr_reg));
9879
  memcpy (&lwpstat.pr_reg, gregs, sizeof (lwpstat.pr_reg));
9291
#elif defined (HAVE_LWPSTATUS_T_PR_CONTEXT)
9880
#elif defined (HAVE_LWPSTATUS_T_PR_CONTEXT)
9292
#if !defined(gregs)
9881
#if !defined(gregs)
9293
  memcpy (lwpstat.pr_context.uc_mcontext.gregs,
9882
  memcpy (lwpstat.pr_context.uc_mcontext.gregs,
9294
	  gregs, sizeof (lwpstat.pr_context.uc_mcontext.gregs));
9883
	  gregs, sizeof (lwpstat.pr_context.uc_mcontext.gregs));
Line 9365... Line 9954...
9365
 
9954
 
9366
char *
9955
char *
9367
elfcore_write_xstatereg (bfd *abfd, char *buf, int *bufsiz,
9956
elfcore_write_xstatereg (bfd *abfd, char *buf, int *bufsiz,
9368
			 const void *xfpregs, int size)
9957
			 const void *xfpregs, int size)
-
 
9958
{
-
 
9959
  char *note_name;
-
 
9960
  if (get_elf_backend_data (abfd)->elf_osabi == ELFOSABI_FREEBSD)
-
 
9961
    note_name = "FreeBSD";
9369
{
9962
  else
9370
  char *note_name = "LINUX";
9963
    note_name = "LINUX";
9371
  return elfcore_write_note (abfd, buf, bufsiz,
9964
  return elfcore_write_note (abfd, buf, bufsiz,
9372
			     note_name, NT_X86_XSTATE, xfpregs, size);
9965
			     note_name, NT_X86_XSTATE, xfpregs, size);
Line 9373... Line 9966...
9373
}
9966
}
Line 9506... Line 10099...
9506
  return elfcore_write_note (abfd, buf, bufsiz,
10099
  return elfcore_write_note (abfd, buf, bufsiz,
9507
                             note_name, NT_S390_TDB, s390_tdb, size);
10100
                             note_name, NT_S390_TDB, s390_tdb, size);
9508
}
10101
}
Line 9509... Line 10102...
9509
 
10102
 
-
 
10103
char *
-
 
10104
elfcore_write_s390_vxrs_low (bfd *abfd,
-
 
10105
			     char *buf,
-
 
10106
			     int *bufsiz,
-
 
10107
			     const void *s390_vxrs_low,
-
 
10108
			     int size)
-
 
10109
{
-
 
10110
  char *note_name = "LINUX";
-
 
10111
  return elfcore_write_note (abfd, buf, bufsiz,
-
 
10112
			     note_name, NT_S390_VXRS_LOW, s390_vxrs_low, size);
-
 
10113
}
-
 
10114
 
-
 
10115
char *
-
 
10116
elfcore_write_s390_vxrs_high (bfd *abfd,
-
 
10117
			     char *buf,
-
 
10118
			     int *bufsiz,
-
 
10119
			     const void *s390_vxrs_high,
-
 
10120
			     int size)
-
 
10121
{
-
 
10122
  char *note_name = "LINUX";
-
 
10123
  return elfcore_write_note (abfd, buf, bufsiz,
-
 
10124
			     note_name, NT_S390_VXRS_HIGH,
-
 
10125
			     s390_vxrs_high, size);
-
 
10126
}
-
 
10127
 
9510
char *
10128
char *
9511
elfcore_write_arm_vfp (bfd *abfd,
10129
elfcore_write_arm_vfp (bfd *abfd,
9512
		       char *buf,
10130
		       char *buf,
9513
		       int *bufsiz,
10131
		       int *bufsiz,
9514
		       const void *arm_vfp,
10132
		       const void *arm_vfp,
Line 9589... Line 10207...
9589
    return elfcore_write_s390_last_break (abfd, buf, bufsiz, data, size);
10207
    return elfcore_write_s390_last_break (abfd, buf, bufsiz, data, size);
9590
  if (strcmp (section, ".reg-s390-system-call") == 0)
10208
  if (strcmp (section, ".reg-s390-system-call") == 0)
9591
    return elfcore_write_s390_system_call (abfd, buf, bufsiz, data, size);
10209
    return elfcore_write_s390_system_call (abfd, buf, bufsiz, data, size);
9592
  if (strcmp (section, ".reg-s390-tdb") == 0)
10210
  if (strcmp (section, ".reg-s390-tdb") == 0)
9593
    return elfcore_write_s390_tdb (abfd, buf, bufsiz, data, size);
10211
    return elfcore_write_s390_tdb (abfd, buf, bufsiz, data, size);
-
 
10212
  if (strcmp (section, ".reg-s390-vxrs-low") == 0)
-
 
10213
    return elfcore_write_s390_vxrs_low (abfd, buf, bufsiz, data, size);
-
 
10214
  if (strcmp (section, ".reg-s390-vxrs-high") == 0)
-
 
10215
    return elfcore_write_s390_vxrs_high (abfd, buf, bufsiz, data, size);
9594
  if (strcmp (section, ".reg-arm-vfp") == 0)
10216
  if (strcmp (section, ".reg-arm-vfp") == 0)
9595
    return elfcore_write_arm_vfp (abfd, buf, bufsiz, data, size);
10217
    return elfcore_write_arm_vfp (abfd, buf, bufsiz, data, size);
9596
  if (strcmp (section, ".reg-aarch-tls") == 0)
10218
  if (strcmp (section, ".reg-aarch-tls") == 0)
9597
    return elfcore_write_aarch_tls (abfd, buf, bufsiz, data, size);
10219
    return elfcore_write_aarch_tls (abfd, buf, bufsiz, data, size);
9598
  if (strcmp (section, ".reg-aarch-hw-break") == 0)
10220
  if (strcmp (section, ".reg-aarch-hw-break") == 0)
Line 9636... Line 10258...
9636
        {
10258
        {
9637
	default:
10259
	default:
9638
	  return TRUE;
10260
	  return TRUE;
Line 9639... Line 10261...
9639
 
10261
 
9640
	case bfd_core:
-
 
9641
	  if (CONST_STRNEQ (in.namedata, "NetBSD-CORE"))
10262
	case bfd_core:
9642
	    {
10263
	  {
9643
	      if (! elfcore_grok_netbsd_note (abfd, &in))
-
 
9644
		return FALSE;
10264
#define GROKER_ELEMENT(S,F) {S, sizeof (S) - 1, F}
9645
	    }
-
 
9646
	  else if (CONST_STRNEQ (in.namedata, "OpenBSD"))
10265
	    struct
9647
	    {
10266
	    {
9648
	      if (! elfcore_grok_openbsd_note (abfd, &in))
10267
	      const char * string;
-
 
10268
	      size_t len;
9649
		return FALSE;
10269
	      bfd_boolean (* func)(bfd *, Elf_Internal_Note *);
9650
	    }
10270
	    }
9651
	  else if (CONST_STRNEQ (in.namedata, "QNX"))
10271
	    grokers[] =
-
 
10272
	    {
-
 
10273
	      GROKER_ELEMENT ("", elfcore_grok_note),
-
 
10274
	      GROKER_ELEMENT ("NetBSD-CORE", elfcore_grok_netbsd_note),
9652
	    {
10275
	      GROKER_ELEMENT ( "OpenBSD", elfcore_grok_openbsd_note),
-
 
10276
	      GROKER_ELEMENT ("QNX", elfcore_grok_nto_note),
-
 
10277
	      GROKER_ELEMENT ("SPU/", elfcore_grok_spu_note)
9653
	      if (! elfcore_grok_nto_note (abfd, &in))
10278
	    };
9654
		return FALSE;
10279
#undef GROKER_ELEMENT
-
 
10280
	    int i;
9655
	    }
10281
 
9656
	  else if (CONST_STRNEQ (in.namedata, "SPU/"))
10282
	    for (i = ARRAY_SIZE (grokers); i--;)
-
 
10283
	      {
9657
	    {
10284
		if (in.namesz >= grokers[i].len
9658
	      if (! elfcore_grok_spu_note (abfd, &in))
10285
		    && strncmp (in.namedata, grokers[i].string,
9659
		return FALSE;
-
 
9660
	    }
-
 
9661
	  else
10286
				grokers[i].len) == 0)
9662
	    {
10287
		  {
9663
	      if (! elfcore_grok_note (abfd, &in))
10288
		    if (! grokers[i].func (abfd, & in))
-
 
10289
		      return FALSE;
-
 
10290
		    break;
9664
		return FALSE;
10291
		  }
9665
	    }
10292
	      }
-
 
10293
	    break;
Line 9666... Line 10294...
9666
	  break;
10294
	  }
9667
 
10295
 
9668
	case bfd_object:
10296
	case bfd_object:
9669
	  if (in.namesz == sizeof "GNU" && strcmp (in.namedata, "GNU") == 0)
10297
	  if (in.namesz == sizeof "GNU" && strcmp (in.namedata, "GNU") == 0)
Line 9695... Line 10323...
9695
    return TRUE;
10323
    return TRUE;
Line 9696... Line 10324...
9696
 
10324
 
9697
  if (bfd_seek (abfd, offset, SEEK_SET) != 0)
10325
  if (bfd_seek (abfd, offset, SEEK_SET) != 0)
Line 9698... Line 10326...
9698
    return FALSE;
10326
    return FALSE;
9699
 
10327
 
9700
  buf = (char *) bfd_malloc (size);
10328
  buf = (char *) bfd_malloc (size + 1);
Line -... Line 10329...
-
 
10329
  if (buf == NULL)
-
 
10330
    return FALSE;
-
 
10331
 
-
 
10332
  /* PR 17512: file: ec08f814
9701
  if (buf == NULL)
10333
     0-termintate the buffer so that string searches will not overflow.  */
9702
    return FALSE;
10334
  buf[size] = 0;
9703
 
10335
 
9704
  if (bfd_bread (buf, size, abfd) != size
10336
  if (bfd_bread (buf, size, abfd) != size
9705
      || !elf_parse_notes (abfd, buf, size, offset))
10337
      || !elf_parse_notes (abfd, buf, size, offset))
Line 9859... Line 10491...
9859
 
10491
 
9860
bfd *
10492
bfd *
9861
bfd_elf_bfd_from_remote_memory
10493
bfd_elf_bfd_from_remote_memory
9862
  (bfd *templ,
10494
  (bfd *templ,
-
 
10495
   bfd_vma ehdr_vma,
9863
   bfd_vma ehdr_vma,
10496
   bfd_size_type size,
9864
   bfd_vma *loadbasep,
10497
   bfd_vma *loadbasep,
9865
   int (*target_read_memory) (bfd_vma, bfd_byte *, bfd_size_type))
10498
   int (*target_read_memory) (bfd_vma, bfd_byte *, bfd_size_type))
9866
{
10499
{
9867
  return (*get_elf_backend_data (templ)->elf_backend_bfd_from_remote_memory)
10500
  return (*get_elf_backend_data (templ)->elf_backend_bfd_from_remote_memory)
9868
    (templ, ehdr_vma, loadbasep, target_read_memory);
10501
    (templ, ehdr_vma, size, loadbasep, target_read_memory);
9869
}
10502
}
9870

10503

9871
long
10504
long
9872
_bfd_elf_get_synthetic_symtab (bfd *abfd,
10505
_bfd_elf_get_synthetic_symtab (bfd *abfd,
Line 9989... Line 10622...
9989
asection _bfd_elf_large_com_section
10622
asection _bfd_elf_large_com_section
9990
  = BFD_FAKE_SECTION (_bfd_elf_large_com_section,
10623
  = BFD_FAKE_SECTION (_bfd_elf_large_com_section,
9991
		      SEC_IS_COMMON, NULL, "LARGE_COMMON", 0);
10624
		      SEC_IS_COMMON, NULL, "LARGE_COMMON", 0);
Line 9992... Line 10625...
9992
 
10625
 
9993
void
10626
void
9994
_bfd_elf_set_osabi (bfd * abfd,
10627
_bfd_elf_post_process_headers (bfd * abfd,
9995
		    struct bfd_link_info * link_info ATTRIBUTE_UNUSED)
10628
			       struct bfd_link_info * link_info ATTRIBUTE_UNUSED)
9996
{
10629
{
Line 9997... Line 10630...
9997
  Elf_Internal_Ehdr * i_ehdrp;	/* ELF file header, internal form.  */
10630
  Elf_Internal_Ehdr * i_ehdrp;	/* ELF file header, internal form.  */