~ubuntu-branches/ubuntu/hoary/binutils/hoary

« back to all changes in this revision

Viewing changes to bfd/elf32-i386.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2005-03-18 13:07:52 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20050318130752-j4i37zgqclj53b94
Tags: 2.15-5ubuntu2
debian/rules: Call pkgstriptranslations if present (the package does not
use debhelper, thus it does not happen automatically).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* Intel 80386/80486-specific support for 32-bit ELF
2
 
   Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
3
 
   Free Software Foundation, Inc.
 
2
   Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
 
3
   2003, 2004 Free Software Foundation, Inc.
4
4
 
5
5
   This file is part of BFD, the Binary File Descriptor library.
6
6
 
346
346
}
347
347
 
348
348
/* Support for core dump NOTE sections.  */
 
349
 
349
350
static bfd_boolean
350
351
elf_i386_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
351
352
{
352
353
  int offset;
353
354
  size_t raw_size;
354
355
 
355
 
  switch (note->descsz)
356
 
    {
357
 
      default:
358
 
        return FALSE;
359
 
 
360
 
      case 144:         /* Linux/i386 */
361
 
        /* pr_cursig */
362
 
        elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12);
363
 
 
364
 
        /* pr_pid */
365
 
        elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 24);
366
 
 
367
 
        /* pr_reg */
368
 
        offset = 72;
369
 
        raw_size = 68;
370
 
 
371
 
        break;
 
356
  if (note->namesz == 8 && strcmp (note->namedata, "FreeBSD") == 0)
 
357
    {
 
358
      int pr_version = bfd_get_32 (abfd, note->descdata);
 
359
 
 
360
      if (pr_version != 1)
 
361
        return FALSE;
 
362
 
 
363
      /* pr_cursig */
 
364
      elf_tdata (abfd)->core_signal = bfd_get_32 (abfd, note->descdata + 20);
 
365
 
 
366
      /* pr_pid */
 
367
      elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 24);
 
368
 
 
369
      /* pr_reg */
 
370
      offset = 28;
 
371
      raw_size = bfd_get_32 (abfd, note->descdata + 8);
 
372
    }
 
373
  else
 
374
    {
 
375
      switch (note->descsz)
 
376
        {
 
377
        default:
 
378
          return FALSE;
 
379
 
 
380
        case 144:               /* Linux/i386 */
 
381
          /* pr_cursig */
 
382
          elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12);
 
383
 
 
384
          /* pr_pid */
 
385
          elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 24);
 
386
 
 
387
          /* pr_reg */
 
388
          offset = 72;
 
389
          raw_size = 68;
 
390
 
 
391
          break;
 
392
        }
372
393
    }
373
394
 
374
395
  /* Make a ".reg/999" section.  */
379
400
static bfd_boolean
380
401
elf_i386_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
381
402
{
382
 
  switch (note->descsz)
 
403
  if (note->namesz == 8 && strcmp (note->namedata, "FreeBSD") == 0)
383
404
    {
384
 
      default:
 
405
      int pr_version = bfd_get_32 (abfd, note->descdata);
 
406
 
 
407
      if (pr_version != 1)
385
408
        return FALSE;
386
409
 
387
 
      case 124:         /* Linux/i386 elf_prpsinfo */
388
 
        elf_tdata (abfd)->core_program
389
 
          = _bfd_elfcore_strndup (abfd, note->descdata + 28, 16);
390
 
        elf_tdata (abfd)->core_command
391
 
          = _bfd_elfcore_strndup (abfd, note->descdata + 44, 80);
 
410
      elf_tdata (abfd)->core_program
 
411
        = _bfd_elfcore_strndup (abfd, note->descdata + 8, 17);
 
412
      elf_tdata (abfd)->core_command
 
413
        = _bfd_elfcore_strndup (abfd, note->descdata + 25, 81);
 
414
    }
 
415
  else
 
416
    {
 
417
      switch (note->descsz)
 
418
        {
 
419
        default:
 
420
          return FALSE;
 
421
 
 
422
        case 124:               /* Linux/i386 elf_prpsinfo.  */
 
423
          elf_tdata (abfd)->core_program
 
424
            = _bfd_elfcore_strndup (abfd, note->descdata + 28, 16);
 
425
          elf_tdata (abfd)->core_command
 
426
            = _bfd_elfcore_strndup (abfd, note->descdata + 44, 80);
 
427
        }
392
428
    }
393
429
 
394
430
  /* Note that for some reason, a spurious space is tacked
395
431
     onto the end of the args in some (at least one anyway)
396
432
     implementations, so strip it off if it exists.  */
397
 
 
398
433
  {
399
434
    char *command = elf_tdata (abfd)->core_command;
400
435
    int n = strlen (command);
546
581
  return TRUE;
547
582
}
548
583
 
549
 
static bfd_boolean
550
 
elf_i386_object_p (bfd *abfd)
551
 
{
552
 
  /* Allocate our special target data.  */
553
 
  struct elf_i386_obj_tdata *new_tdata;
554
 
  bfd_size_type amt = sizeof (struct elf_i386_obj_tdata);
555
 
  new_tdata = bfd_zalloc (abfd, amt);
556
 
  if (new_tdata == NULL)
557
 
    return FALSE;
558
 
  new_tdata->root = *abfd->tdata.elf_obj_data;
559
 
  abfd->tdata.any = new_tdata;
560
 
  return TRUE;
561
 
}
562
 
 
563
584
/* i386 ELF linker hash table.  */
564
585
 
565
586
struct elf_i386_link_hash_table
770
791
    dir->elf_link_hash_flags |=
771
792
      (ind->elf_link_hash_flags & (ELF_LINK_HASH_REF_DYNAMIC
772
793
                                   | ELF_LINK_HASH_REF_REGULAR
773
 
                                   | ELF_LINK_HASH_REF_REGULAR_NONWEAK));
 
794
                                   | ELF_LINK_HASH_REF_REGULAR_NONWEAK
 
795
                                   | ELF_LINK_HASH_NEEDS_PLT
 
796
                                   | ELF_LINK_POINTER_EQUALITY_NEEDED));
774
797
  else
775
798
    _bfd_elf_link_hash_copy_indirect (bed, dir, ind);
776
799
}
1000
1023
              /* We may need a .plt entry if the function this reloc
1001
1024
                 refers to is in a shared lib.  */
1002
1025
              h->plt.refcount += 1;
 
1026
              if (r_type != R_386_PC32)
 
1027
                h->elf_link_hash_flags |= ELF_LINK_POINTER_EQUALITY_NEEDED;
1003
1028
            }
1004
1029
 
1005
1030
          /* If we are creating a shared library, and this is a reloc
1132
1157
          /* This relocation describes the C++ object vtable hierarchy.
1133
1158
             Reconstruct it for later use during GC.  */
1134
1159
        case R_386_GNU_VTINHERIT:
1135
 
          if (!_bfd_elf32_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
 
1160
          if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
1136
1161
            return FALSE;
1137
1162
          break;
1138
1163
 
1139
1164
          /* This relocation describes which C++ vtable entries are actually
1140
1165
             used.  Record for later use during GC.  */
1141
1166
        case R_386_GNU_VTENTRY:
1142
 
          if (!_bfd_elf32_gc_record_vtentry (abfd, sec, h, rel->r_offset))
 
1167
          if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_offset))
1143
1168
            return FALSE;
1144
1169
          break;
1145
1170
 
1433
1458
  return TRUE;
1434
1459
}
1435
1460
 
1436
 
/* This is the condition under which elf_i386_finish_dynamic_symbol
1437
 
   will be called from elflink.h.  If elflink.h doesn't call our
1438
 
   finish_dynamic_symbol routine, we'll need to do something about
1439
 
   initializing any .plt and .got entries in elf_i386_relocate_section.  */
1440
 
#define WILL_CALL_FINISH_DYNAMIC_SYMBOL(DYN, SHARED, H) \
1441
 
  ((DYN)                                                                \
1442
 
   && ((SHARED)                                                         \
1443
 
       || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)      \
1444
 
   && ((H)->dynindx != -1                                               \
1445
 
       || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0))
1446
 
 
1447
1461
/* Allocate space in .plt, .got and associated reloc sections for
1448
1462
   dynamic relocs.  */
1449
1463
 
1475
1489
      if (h->dynindx == -1
1476
1490
          && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)
1477
1491
        {
1478
 
          if (! bfd_elf32_link_record_dynamic_symbol (info, h))
 
1492
          if (! bfd_elf_link_record_dynamic_symbol (info, h))
1479
1493
            return FALSE;
1480
1494
        }
1481
1495
 
1543
1557
      if (h->dynindx == -1
1544
1558
          && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)
1545
1559
        {
1546
 
          if (! bfd_elf32_link_record_dynamic_symbol (info, h))
 
1560
          if (! bfd_elf_link_record_dynamic_symbol (info, h))
1547
1561
            return FALSE;
1548
1562
        }
1549
1563
 
1632
1646
          if (h->dynindx == -1
1633
1647
              && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)
1634
1648
            {
1635
 
              if (! bfd_elf32_link_record_dynamic_symbol (info, h))
 
1649
              if (! bfd_elf_link_record_dynamic_symbol (info, h))
1636
1650
                return FALSE;
1637
1651
            }
1638
1652
 
1870
1884
         the .dynamic section.  The DT_DEBUG entry is filled in by the
1871
1885
         dynamic linker and used by the debugger.  */
1872
1886
#define add_dynamic_entry(TAG, VAL) \
1873
 
  bfd_elf32_add_dynamic_entry (info, (TAG), (VAL))
 
1887
  _bfd_elf_add_dynamic_entry (info, TAG, VAL)
1874
1888
 
1875
1889
      if (info->executable)
1876
1890
        {
1953
1967
static bfd_vma
1954
1968
dtpoff_base (struct bfd_link_info *info)
1955
1969
{
1956
 
  /* If tls_segment is NULL, we should have signalled an error already.  */
1957
 
  if (elf_hash_table (info)->tls_segment == NULL)
 
1970
  /* If tls_sec is NULL, we should have signalled an error already.  */
 
1971
  if (elf_hash_table (info)->tls_sec == NULL)
1958
1972
    return 0;
1959
 
  return elf_hash_table (info)->tls_segment->start;
 
1973
  return elf_hash_table (info)->tls_sec->vma;
1960
1974
}
1961
1975
 
1962
1976
/* Return the relocation value for @tpoff relocation
1965
1979
static bfd_vma
1966
1980
tpoff (struct bfd_link_info *info, bfd_vma address)
1967
1981
{
1968
 
  struct elf_link_tls_segment *tls_segment
1969
 
    = elf_hash_table (info)->tls_segment;
 
1982
  struct elf_link_hash_table *htab = elf_hash_table (info);
1970
1983
 
1971
 
  /* If tls_segment is NULL, we should have signalled an error already.  */
1972
 
  if (tls_segment == NULL)
 
1984
  /* If tls_sec is NULL, we should have signalled an error already.  */
 
1985
  if (htab->tls_sec == NULL)
1973
1986
    return 0;
1974
 
  return (align_power (tls_segment->size, tls_segment->align)
1975
 
          + tls_segment->start - address);
 
1987
  return htab->tls_size + htab->tls_sec->vma - address;
1976
1988
}
1977
1989
 
1978
1990
/* Relocate an i386 ELF section.  */
2156
2168
        {
2157
2169
          bfd_boolean warned;
2158
2170
 
2159
 
          RELOC_FOR_GLOBAL_SYMBOL (h, sym_hashes, r_symndx, symtab_hdr, relocation, sec, unresolved_reloc, info, warned);
 
2171
          RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
 
2172
                                   r_symndx, symtab_hdr, sym_hashes,
 
2173
                                   h, sec, relocation,
 
2174
                                   unresolved_reloc, warned);
2160
2175
        }
2161
2176
 
2162
2177
      switch (r_type)
3005
3020
      if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
3006
3021
        {
3007
3022
          /* Mark the symbol as undefined, rather than as defined in
3008
 
             the .plt section.  Leave the value alone.  This is a clue
 
3023
             the .plt section.  Leave the value if there were any
 
3024
             relocations where pointer equality matters (this is a clue
3009
3025
             for the dynamic linker, to make function pointer
3010
3026
             comparisons work between an application and shared
3011
 
             library.  */
 
3027
             library), otherwise set it to zero.  If a function is only
 
3028
             called from a binary, there is no need to slow down
 
3029
             shared libraries because of that.  */
3012
3030
          sym->st_shndx = SHN_UNDEF;
 
3031
          if ((h->elf_link_hash_flags & ELF_LINK_POINTER_EQUALITY_NEEDED) == 0)
 
3032
            sym->st_value = 0;
3013
3033
        }
3014
3034
    }
3015
3035
 
3240
3260
#define elf_backend_plt_readonly        1
3241
3261
#define elf_backend_want_plt_sym        0
3242
3262
#define elf_backend_got_header_size     12
3243
 
#define elf_backend_plt_header_size     PLT_ENTRY_SIZE
3244
3263
 
3245
3264
/* Support RELA for objdump of prelink objects.  */
3246
3265
#define elf_info_to_howto                     elf_i386_info_to_howto_rel
3247
3266
#define elf_info_to_howto_rel                 elf_i386_info_to_howto_rel
3248
3267
 
3249
3268
#define bfd_elf32_mkobject                    elf_i386_mkobject
3250
 
#define elf_backend_object_p                  elf_i386_object_p
3251
3269
 
3252
3270
#define bfd_elf32_bfd_is_local_label_name     elf_i386_is_local_label_name
3253
3271
#define bfd_elf32_bfd_link_hash_table_create  elf_i386_link_hash_table_create