Subversion Repositories Kolibri OS

Rev

Rev 5197 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5197 Rev 6324
Line 1... Line 1...
1
/* SEC_MERGE support.
1
/* SEC_MERGE support.
2
   Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
-
 
3
   Free Software Foundation, Inc.
2
   Copyright (C) 2001-2015 Free Software Foundation, Inc.
4
   Written by Jakub Jelinek .
3
   Written by Jakub Jelinek .
Line 5... Line 4...
5
 
4
 
Line 6... Line 5...
6
   This file is part of BFD, the Binary File Descriptor library.
5
   This file is part of BFD, the Binary File Descriptor library.
Line 24... Line 23...
24
/* This file contains support for merging duplicate entities within sections,
23
/* This file contains support for merging duplicate entities within sections,
25
   as used in ELF SHF_MERGE.  */
24
   as used in ELF SHF_MERGE.  */
Line 26... Line 25...
26
 
25
 
27
#include "sysdep.h"
26
#include "sysdep.h"
-
 
27
#include "bfd.h"
28
#include "bfd.h"
28
#include "elf-bfd.h"
29
#include "libbfd.h"
29
#include "libbfd.h"
30
#include "hashtab.h"
30
#include "hashtab.h"
Line 31... Line 31...
31
#include "libiberty.h"
31
#include "libiberty.h"
Line 282... Line 282...
282
 
282
 
283
  return entry;
283
  return entry;
Line 284... Line 284...
284
}
284
}
285
 
285
 
-
 
286
static bfd_boolean
286
static bfd_boolean
287
sec_merge_emit (bfd *abfd, struct sec_merge_hash_entry *entry,
287
sec_merge_emit (bfd *abfd, struct sec_merge_hash_entry *entry)
288
		unsigned char *contents, file_ptr offset)
288
{
289
{
289
  struct sec_merge_sec_info *secinfo = entry->secinfo;
290
  struct sec_merge_sec_info *secinfo = entry->secinfo;
290
  asection *sec = secinfo->sec;
291
  asection *sec = secinfo->sec;
Line 305... Line 306...
305
      bfd_size_type len;
306
      bfd_size_type len;
Line 306... Line 307...
306
 
307
 
307
      len = -off & (entry->alignment - 1);
308
      len = -off & (entry->alignment - 1);
308
      if (len != 0)
309
      if (len != 0)
-
 
310
	{
-
 
311
	  if (contents)
-
 
312
	    {
-
 
313
	      memcpy (contents + offset, pad, len);
-
 
314
	      offset += len;
309
	{
315
	    }
310
	  if (bfd_bwrite (pad, len, abfd) != len)
316
	  else if (bfd_bwrite (pad, len, abfd) != len)
311
	    goto err;
317
	    goto err;
312
	  off += len;
318
	  off += len;
Line 313... Line 319...
313
	}
319
	}
314
 
320
 
Line -... Line 321...
-
 
321
      str = entry->root.string;
-
 
322
      len = entry->len;
-
 
323
 
-
 
324
      if (contents)
-
 
325
	{
315
      str = entry->root.string;
326
	  memcpy (contents + offset, str, len);
316
      len = entry->len;
327
	  offset += len;
Line 317... Line 328...
317
 
328
	}
318
      if (bfd_bwrite (str, len, abfd) != len)
329
      else if (bfd_bwrite (str, len, abfd) != len)
Line 319... Line 330...
319
	goto err;
330
	goto err;
320
 
331
 
321
      off += len;
332
      off += len;
-
 
333
    }
-
 
334
 
-
 
335
  /* Trailing alignment needed?  */
322
    }
336
  off = sec->size - off;
323
 
337
  if (off != 0)
-
 
338
    {
Line 324... Line 339...
324
  /* Trailing alignment needed?  */
339
      if (contents)
325
  off = sec->size - off;
340
	memcpy (contents + offset, pad, off);
326
  if (off != 0
341
      else if (bfd_bwrite (pad, off, abfd) != off)
Line 784... Line 799...
784
bfd_boolean
799
bfd_boolean
785
_bfd_write_merged_section (bfd *output_bfd, asection *sec, void *psecinfo)
800
_bfd_write_merged_section (bfd *output_bfd, asection *sec, void *psecinfo)
786
{
801
{
787
  struct sec_merge_sec_info *secinfo;
802
  struct sec_merge_sec_info *secinfo;
788
  file_ptr pos;
803
  file_ptr pos;
-
 
804
  unsigned char *contents;
-
 
805
  Elf_Internal_Shdr *hdr;
Line 789... Line 806...
789
 
806
 
Line 790... Line 807...
790
  secinfo = (struct sec_merge_sec_info *) psecinfo;
807
  secinfo = (struct sec_merge_sec_info *) psecinfo;
791
 
808
 
Line 792... Line 809...
792
  if (!secinfo)
809
  if (!secinfo)
793
    return FALSE;
810
    return FALSE;
Line 794... Line 811...
794
 
811
 
-
 
812
  if (secinfo->first_str == NULL)
-
 
813
    return TRUE;
-
 
814
 
-
 
815
  /* FIXME: octets_per_byte.  */
-
 
816
  hdr = &elf_section_data (sec->output_section)->this_hdr;
-
 
817
  if (hdr->sh_offset == (file_ptr) -1)
-
 
818
    {
-
 
819
      /* We must compress this section.  Write output to the
-
 
820
	 buffer.  */
-
 
821
      contents = hdr->contents;
-
 
822
      if ((sec->output_section->flags & SEC_ELF_COMPRESS) == 0
-
 
823
	  || contents == NULL)
-
 
824
	abort ();
795
  if (secinfo->first_str == NULL)
825
    }
796
    return TRUE;
826
  else
797
 
827
    {
-
 
828
      contents = NULL;
Line 798... Line 829...
798
  /* FIXME: octets_per_byte.  */
829
  pos = sec->output_section->filepos + sec->output_offset;
-
 
830
  if (bfd_seek (output_bfd, pos, SEEK_SET) != 0)
799
  pos = sec->output_section->filepos + sec->output_offset;
831
    return FALSE;
Line 800... Line 832...
800
  if (bfd_seek (output_bfd, pos, SEEK_SET) != 0)
832
    }
801
    return FALSE;
833