?? sunos.c
字號:
} } /* Return pointers to the dynamic asymbol structures. */ for (i = 0; i < info->dynsym_count; i++) *storage++ = (asymbol *) (info->canonical_dynsym + i); *storage = NULL; return info->dynsym_count;}/* Return the amount of memory required for the dynamic relocs. */sunos_get_dynamic_reloc_upper_bound (abfd) bfd *abfd;{ struct sunos_dynamic_info *info; if (! sunos_read_dynamic_info (abfd)) return -1; info = (struct sunos_dynamic_info *) obj_aout_dynamic_info (abfd); if (! info->valid) bfd_set_error (bfd_error_no_symbols); return -1; } return (info->dynrel_count + 1) * sizeof (arelent *);}/* Read in the dynamic relocs. */static longsunos_canonicalize_dynamic_reloc (abfd, storage, syms) bfd *abfd; arelent **storage; asymbol **syms;{ struct sunos_dynamic_info *info; unsigned long i; /* Get the general dynamic information. */ if (obj_aout_dynamic_info (abfd) == (PTR) NULL) { if (! sunos_read_dynamic_info (abfd)) return -1; } info = (struct sunos_dynamic_info *) obj_aout_dynamic_info (abfd); if (! info->valid) { bfd_set_error (bfd_error_no_symbols); return -1; } /* Get the dynamic reloc information. */ if (info->dynrel == NULL) { info->dynrel = (PTR) bfd_alloc (abfd, (info->dynrel_count * obj_reloc_entry_size (abfd))); if (info->dynrel == NULL && info->dynrel_count != 0) return -1; if (bfd_seek (abfd, info->dyninfo.ld_rel, SEEK_SET) != 0 || (bfd_read ((PTR) info->dynrel, info->dynrel_count, obj_reloc_entry_size (abfd), abfd) != info->dynrel_count * obj_reloc_entry_size (abfd))) { if (info->dynrel != NULL) { bfd_release (abfd, info->dynrel); info->dynrel = NULL; } return -1; } } /* Get the arelent structures corresponding to the dynamic reloc information. */ if (info->canonical_dynrel == (arelent *) NULL) { arelent *to; info->canonical_dynrel = ((arelent *) bfd_alloc (abfd, (info->dynrel_count * sizeof (arelent)))); if (info->canonical_dynrel == NULL && info->dynrel_count != 0) return -1; to = info->canonical_dynrel; if (obj_reloc_entry_size (abfd) == RELOC_EXT_SIZE) { register struct reloc_ext_external *p; struct reloc_ext_external *pend; p = (struct reloc_ext_external *) info->dynrel; pend = p + info->dynrel_count; for (; p < pend; p++, to++) NAME(aout,swap_ext_reloc_in) (abfd, p, to, syms, info->dynsym_count); } else { register struct reloc_std_external *p; struct reloc_std_external *pend; p = (struct reloc_std_external *) info->dynrel; pend = p + info->dynrel_count; for (; p < pend; p++, to++) NAME(aout,swap_std_reloc_in) (abfd, p, to, syms, info->dynsym_count); } } /* Return pointers to the dynamic arelent structures. */ for (i = 0; i < info->dynrel_count; i++) *storage++ = info->canonical_dynrel + i; *storage = NULL; return info->dynrel_count;}/* Code to handle linking of SunOS shared libraries. *//* A SPARC procedure linkage table entry is 12 bytes. The first entry in the table is a jump which is filled in by the runtime linker. The remaining entries are branches back to the first entry, followed by an index into the relocation table encoded to look like a sethi of %g0. */#define SPARC_PLT_ENTRY_SIZE (12)static const bfd_byte sparc_plt_first_entry[SPARC_PLT_ENTRY_SIZE] ={ /* sethi %hi(0),%g1; address filled in by runtime linker. */ 0x3, 0, 0, 0, /* jmp %g1; offset filled in by runtime linker. */ 0x81, 0xc0, 0x60, 0, /* nop */ 0x1, 0, 0, 0};/* save %sp, -96, %sp */#define SPARC_PLT_ENTRY_WORD0 0x9de3bfa0/* call; address filled in later. */#define SPARC_PLT_ENTRY_WORD1 0x40000000/* sethi; reloc index filled in later. */#define SPARC_PLT_ENTRY_WORD2 0x01000000/* This sequence is used when for the jump table entry to a defined symbol in a complete executable. It is used when linking PIC compiled code which is not being put into a shared library. *//* sethi <address to be filled in later>, %g1 */#define SPARC_PLT_PIC_WORD0 0x03000000/* jmp %g1 + <address to be filled in later> */#define SPARC_PLT_PIC_WORD1 0x81c06000/* nop */#define SPARC_PLT_PIC_WORD2 0x01000000/* An m68k procedure linkage table entry is 8 bytes. The first entry in the table is a jump which is filled in the by the runtime linker. The remaining entries are branches back to the first entry, followed by a two byte index into the relocation table. */#define M68K_PLT_ENTRY_SIZE (8)static const bfd_byte m68k_plt_first_entry[M68K_PLT_ENTRY_SIZE] ={ /* jmps @# */ 0x4e, 0xf9, /* Filled in by runtime linker with a magic address. */ 0, 0, 0, 0, /* Not used? */ 0, 0};/* bsrl */#define M68K_PLT_ENTRY_WORD0 (0x61ff)/* Remaining words filled in later. *//* An entry in the SunOS linker hash table. */struct sunos_link_hash_entry{ struct aout_link_hash_entry root; /* If this is a dynamic symbol, this is its index into the dynamic symbol table. This is initialized to -1. As the linker looks at the input files, it changes this to -2 if it will be added to the dynamic symbol table. After all the input files have been seen, the linker will know whether to build a dynamic symbol table; if it does build one, this becomes the index into the table. */ long dynindx; /* If this is a dynamic symbol, this is the index of the name in the dynamic symbol string table. */ long dynstr_index; /* The offset into the global offset table used for this symbol. If the symbol does not require a GOT entry, this is 0. */ bfd_vma got_offset; /* The offset into the procedure linkage table used for this symbol. If the symbol does not require a PLT entry, this is 0. */ bfd_vma plt_offset; /* Some linker flags. */ unsigned char flags; /* Symbol is referenced by a regular object. */#define SUNOS_REF_REGULAR 01 /* Symbol is defined by a regular object. */#define SUNOS_DEF_REGULAR 02 /* Symbol is referenced by a dynamic object. */#define SUNOS_REF_DYNAMIC 04 /* Symbol is defined by a dynamic object. */#define SUNOS_DEF_DYNAMIC 010 /* Symbol is a constructor symbol in a regular object. */#define SUNOS_CONSTRUCTOR 020};/* The SunOS linker hash table. */struct sunos_link_hash_table{ struct aout_link_hash_table root; /* The object which holds the dynamic sections. */ bfd *dynobj; /* Whether we have created the dynamic sections. */ boolean dynamic_sections_created; /* Whether we need the dynamic sections. */ boolean dynamic_sections_needed; /* Whether we need the .got table. */ boolean got_needed; /* The number of dynamic symbols. */ size_t dynsymcount; /* The number of buckets in the hash table. */ size_t bucketcount; /* The list of dynamic objects needed by dynamic objects included in the link. */ struct bfd_link_needed_list *needed; /* The offset of __GLOBAL_OFFSET_TABLE_ into the .got section. */ bfd_vma got_base;};/* Routine to create an entry in an SunOS link hash table. */static struct bfd_hash_entry *sunos_link_hash_newfunc (entry, table, string) struct bfd_hash_entry *entry; struct bfd_hash_table *table; const char *string;{ struct sunos_link_hash_entry *ret = (struct sunos_link_hash_entry *) entry; /* Allocate the structure if it has not already been allocated by a subclass. */ if (ret == (struct sunos_link_hash_entry *) NULL) ret = ((struct sunos_link_hash_entry *) bfd_hash_allocate (table, sizeof (struct sunos_link_hash_entry))); if (ret == (struct sunos_link_hash_entry *) NULL) return (struct bfd_hash_entry *) ret; /* Call the allocation method of the superclass. */ ret = ((struct sunos_link_hash_entry *) NAME(aout,link_hash_newfunc) ((struct bfd_hash_entry *) ret, table, string)); if (ret != NULL) { /* Set local fields. */ ret->dynindx = -1; ret->dynstr_index = -1; ret->got_offset = 0; ret->plt_offset = 0; ret->flags = 0; } return (struct bfd_hash_entry *) ret;}/* Create a SunOS link hash table. */static struct bfd_link_hash_table *sunos_link_hash_table_create (abfd) bfd *abfd;{ struct sunos_link_hash_table *ret; ret = ((struct sunos_link_hash_table *) bfd_alloc (abfd, sizeof (struct sunos_link_hash_table))); if (ret == (struct sunos_link_hash_table *) NULL) return (struct bfd_link_hash_table *) NULL; if (! NAME(aout,link_hash_table_init) (&ret->root, abfd, sunos_link_hash_newfunc)) { bfd_release (abfd, ret); return (struct bfd_link_hash_table *) NULL; } ret->dynobj = NULL; ret->dynamic_sections_created = false; ret->dynamic_sections_needed = false; ret->got_needed = false; ret->dynsymcount = 0; ret->bucketcount = 0; ret->needed = NULL; ret->got_base = 0; return &ret->root.root;}/* Look up an entry in an SunOS link hash table. */#define sunos_link_hash_lookup(table, string, create, copy, follow) \ ((struct sunos_link_hash_entry *) \ aout_link_hash_lookup (&(table)->root, (string), (create), (copy),\ (follow)))/* Traverse a SunOS link hash table. */#define sunos_link_hash_traverse(table, func, info) \ (aout_link_hash_traverse \ (&(table)->root, \ (boolean (*) PARAMS ((struct aout_link_hash_entry *, PTR))) (func), \ (info)))/* Get the SunOS link hash table from the info structure. This is just a cast. */#define sunos_hash_table(p) ((struct sunos_link_hash_table *) ((p)->hash))static boolean sunos_scan_dynamic_symbol PARAMS ((struct sunos_link_hash_entry *, PTR));/* Create the dynamic sections needed if we are linking against a dynamic object, or if we are linking PIC compiled code. ABFD is a bfd we can attach the dynamic sections to. The linker script will look for these special sections names and put them in the right place in the output file. See include/aout/sun4.h for more details of the dynamic linking information. */static booleansunos_create_dynamic_sections (abfd, info, needed) bfd *abfd; struct bfd_link_info *info; boolean needed;{ asection *s; if (! sunos_hash_table (info)->dynamic_sections_created) { flagword flags; sunos_hash_table (info)->dynobj = abfd; flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED); /* The .dynamic section holds the basic dynamic information: the sun4_dynamic structure, the dynamic debugger information, and the sun4_dynamic_link structure. */ s = bfd_make_section (abfd, ".dynamic"); if (s == NULL || ! bfd_set_section_flags (abfd, s, flags) || ! bfd_set_section_alignment (abfd, s, 2)) return false; /* The .got section holds the global offset table. The address is put in the ld_got field. */ s = bfd_make_section (abfd, ".got"); if (s == NULL || ! bfd_set_section_flags (abfd, s, flags) || ! bfd_set_section_alignment (abfd, s, 2)) return false; /* The .plt section holds the procedure linkage table. The address is put in the ld_plt field. */ s = bfd_make_section (abfd, ".plt"); if (s == NULL || ! bfd_set_section_flags (abfd, s, flags | SEC_CODE) || ! bfd_set_section_alignment (abfd, s, 2)) return false; /* The .dynrel section holds the dynamic relocs. The address is put in the ld_rel field. */ s = bfd_make_section (abfd, ".dynrel"); if (s == NULL || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY) || ! bfd_set_section_alignment (abfd, s, 2)) return false; /* The .hash section holds the dynamic hash table. The address is put in the ld_hash field. */ s = bfd_make_section (abfd, ".hash"); if (s == NULL || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY) || ! bfd_set_section_alignment (abfd, s, 2)) return false; /* The .dynsym section holds the dynamic symbols. The address is put in the ld_stab field. */ s = bfd_make_section (abfd, ".dynsym"); if (s == NULL || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY) || ! bfd_set_section_alignment (abfd, s, 2)) return false; /* The .dynstr section holds the dynamic symbol string table.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -