|
Lines 240-251
_bfd_elf_link_create_dynamic_sections (b
Link Here
|
| 240 |
if (!_bfd_elf_define_linkage_sym (abfd, info, s, "_DYNAMIC")) |
240 |
if (!_bfd_elf_define_linkage_sym (abfd, info, s, "_DYNAMIC")) |
| 241 |
return FALSE; |
241 |
return FALSE; |
| 242 |
|
242 |
|
| 243 |
s = bfd_make_section_with_flags (abfd, ".hash", |
243 |
if (info->emit_hash) |
| 244 |
flags | SEC_READONLY); |
244 |
{ |
| 245 |
if (s == NULL |
245 |
s = bfd_make_section_with_flags (abfd, ".hash", flags | SEC_READONLY); |
| 246 |
|| ! bfd_set_section_alignment (abfd, s, bed->s->log_file_align)) |
246 |
if (s == NULL |
| 247 |
return FALSE; |
247 |
|| ! bfd_set_section_alignment (abfd, s, bed->s->log_file_align)) |
| 248 |
elf_section_data (s)->this_hdr.sh_entsize = bed->s->sizeof_hash_entry; |
248 |
return FALSE; |
|
|
249 |
elf_section_data (s)->this_hdr.sh_entsize = bed->s->sizeof_hash_entry; |
| 250 |
} |
| 251 |
|
| 252 |
if (info->emit_gnu_hash) |
| 253 |
{ |
| 254 |
s = bfd_make_section_with_flags (abfd, ".gnu.hash", |
| 255 |
flags | SEC_READONLY); |
| 256 |
if (s == NULL |
| 257 |
|| ! bfd_set_section_alignment (abfd, s, bed->s->log_file_align)) |
| 258 |
return FALSE; |
| 259 |
/* For 64-bit ELF, .gnu.hash is a non-uniform entity size section: |
| 260 |
4 32-bit words followed by variable count of 64-bit words, then |
| 261 |
variable count of 32-bit words. */ |
| 262 |
if (bed->s->arch_size == 64) |
| 263 |
elf_section_data (s)->this_hdr.sh_entsize = 0; |
| 264 |
else |
| 265 |
elf_section_data (s)->this_hdr.sh_entsize = 4; |
| 266 |
} |
| 249 |
|
267 |
|
| 250 |
/* Let the backend create the rest of the sections. This lets the |
268 |
/* Let the backend create the rest of the sections. This lets the |
| 251 |
backend set the right flags. The backend will normally create |
269 |
backend set the right flags. The backend will normally create |
|
Lines 4795-4800
elf_collect_hash_codes (struct elf_link_
Link Here
|
| 4795 |
return TRUE; |
4813 |
return TRUE; |
| 4796 |
} |
4814 |
} |
| 4797 |
|
4815 |
|
|
|
4816 |
struct collect_gnu_hash_codes |
| 4817 |
{ |
| 4818 |
bfd *output_bfd; |
| 4819 |
const struct elf_backend_data *bed; |
| 4820 |
unsigned long int nsyms; |
| 4821 |
unsigned long int maskbits; |
| 4822 |
unsigned long int *hashcodes; |
| 4823 |
unsigned long int *hashval; |
| 4824 |
unsigned long int *indx; |
| 4825 |
unsigned long int *counts; |
| 4826 |
bfd_vma *bitmask; |
| 4827 |
bfd_byte *contents; |
| 4828 |
long int min_dynindx; |
| 4829 |
unsigned long int bucketcount; |
| 4830 |
unsigned long int symindx; |
| 4831 |
long int local_indx; |
| 4832 |
long int shift1, shift2; |
| 4833 |
unsigned long int mask; |
| 4834 |
}; |
| 4835 |
|
| 4836 |
/* This function will be called though elf_link_hash_traverse to store |
| 4837 |
all hash value of the exported symbols in an array. */ |
| 4838 |
|
| 4839 |
static bfd_boolean |
| 4840 |
elf_collect_gnu_hash_codes (struct elf_link_hash_entry *h, void *data) |
| 4841 |
{ |
| 4842 |
struct collect_gnu_hash_codes *s = data; |
| 4843 |
const char *name; |
| 4844 |
char *p; |
| 4845 |
unsigned long ha; |
| 4846 |
char *alc = NULL; |
| 4847 |
|
| 4848 |
if (h->root.type == bfd_link_hash_warning) |
| 4849 |
h = (struct elf_link_hash_entry *) h->root.u.i.link; |
| 4850 |
|
| 4851 |
/* Ignore indirect symbols. These are added by the versioning code. */ |
| 4852 |
if (h->dynindx == -1) |
| 4853 |
return TRUE; |
| 4854 |
|
| 4855 |
/* Ignore also local symbols and undefined symbols. */ |
| 4856 |
if (! (*s->bed->elf_hash_symbol) (h)) |
| 4857 |
return TRUE; |
| 4858 |
|
| 4859 |
name = h->root.root.string; |
| 4860 |
p = strchr (name, ELF_VER_CHR); |
| 4861 |
if (p != NULL) |
| 4862 |
{ |
| 4863 |
alc = bfd_malloc (p - name + 1); |
| 4864 |
memcpy (alc, name, p - name); |
| 4865 |
alc[p - name] = '\0'; |
| 4866 |
name = alc; |
| 4867 |
} |
| 4868 |
|
| 4869 |
/* Compute the hash value. */ |
| 4870 |
ha = bfd_elf_gnu_hash (name); |
| 4871 |
|
| 4872 |
/* Store the found hash value in the array for compute_bucket_count, |
| 4873 |
and also for .dynsym reordering purposes. */ |
| 4874 |
s->hashcodes[s->nsyms] = ha; |
| 4875 |
s->hashval[h->dynindx] = ha; |
| 4876 |
++s->nsyms; |
| 4877 |
if (s->min_dynindx < 0 || s->min_dynindx > h->dynindx) |
| 4878 |
s->min_dynindx = h->dynindx; |
| 4879 |
|
| 4880 |
if (alc != NULL) |
| 4881 |
free (alc); |
| 4882 |
|
| 4883 |
return TRUE; |
| 4884 |
} |
| 4885 |
|
| 4886 |
/* This function will be called though elf_link_hash_traverse to do |
| 4887 |
final dynaminc symbol renumbering. */ |
| 4888 |
|
| 4889 |
static bfd_boolean |
| 4890 |
elf_renumber_gnu_hash_syms (struct elf_link_hash_entry *h, void *data) |
| 4891 |
{ |
| 4892 |
struct collect_gnu_hash_codes *s = data; |
| 4893 |
unsigned long int bucket; |
| 4894 |
unsigned long int val; |
| 4895 |
|
| 4896 |
if (h->root.type == bfd_link_hash_warning) |
| 4897 |
h = (struct elf_link_hash_entry *) h->root.u.i.link; |
| 4898 |
|
| 4899 |
/* Ignore indirect symbols. */ |
| 4900 |
if (h->dynindx == -1) |
| 4901 |
return TRUE; |
| 4902 |
|
| 4903 |
/* Ignore also local symbols and undefined symbols. */ |
| 4904 |
if (! (*s->bed->elf_hash_symbol) (h)) |
| 4905 |
{ |
| 4906 |
if (h->dynindx >= s->min_dynindx) |
| 4907 |
h->dynindx = s->local_indx++; |
| 4908 |
return TRUE; |
| 4909 |
} |
| 4910 |
|
| 4911 |
bucket = s->hashval[h->dynindx] % s->bucketcount; |
| 4912 |
val = (s->hashval[h->dynindx] >> s->shift1) |
| 4913 |
& ((s->maskbits >> s->shift1) - 1); |
| 4914 |
s->bitmask[val] |= ((bfd_vma) 1) << (s->hashval[h->dynindx] & s->mask); |
| 4915 |
s->bitmask[val] |
| 4916 |
|= ((bfd_vma) 1) << ((s->hashval[h->dynindx] >> s->shift2) & s->mask); |
| 4917 |
val = s->hashval[h->dynindx] & ~(unsigned long int) 1; |
| 4918 |
if (s->counts[bucket] == 1) |
| 4919 |
/* Last element terminates the chain. */ |
| 4920 |
val |= 1; |
| 4921 |
bfd_put_32 (s->output_bfd, val, |
| 4922 |
s->contents + (s->indx[bucket] - s->symindx) * 4); |
| 4923 |
--s->counts[bucket]; |
| 4924 |
h->dynindx = s->indx[bucket]++; |
| 4925 |
return TRUE; |
| 4926 |
} |
| 4927 |
|
| 4928 |
/* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */ |
| 4929 |
|
| 4930 |
bfd_boolean |
| 4931 |
_bfd_elf_hash_symbol (struct elf_link_hash_entry *h) |
| 4932 |
{ |
| 4933 |
return !(h->forced_local |
| 4934 |
|| h->root.type == bfd_link_hash_undefined |
| 4935 |
|| h->root.type == bfd_link_hash_undefweak |
| 4936 |
|| ((h->root.type == bfd_link_hash_defined |
| 4937 |
|| h->root.type == bfd_link_hash_defweak) |
| 4938 |
&& h->root.u.def.section->output_section == NULL)); |
| 4939 |
} |
| 4940 |
|
| 4798 |
/* Array used to determine the number of hash table buckets to use |
4941 |
/* Array used to determine the number of hash table buckets to use |
| 4799 |
based on the number of symbols there are. If there are fewer than |
4942 |
based on the number of symbols there are. If there are fewer than |
| 4800 |
3 symbols we use 1 bucket, fewer than 17 symbols we use 3 buckets, |
4943 |
3 symbols we use 1 bucket, fewer than 17 symbols we use 3 buckets, |
|
Lines 4816-4857
static const size_t elf_buckets[] =
Link Here
|
| 4816 |
Therefore the result is always a good payoff between few collisions |
4959 |
Therefore the result is always a good payoff between few collisions |
| 4817 |
(= short chain lengths) and table size. */ |
4960 |
(= short chain lengths) and table size. */ |
| 4818 |
static size_t |
4961 |
static size_t |
| 4819 |
compute_bucket_count (struct bfd_link_info *info) |
4962 |
compute_bucket_count (struct bfd_link_info *info, unsigned long int *hashcodes, |
|
|
4963 |
unsigned long int nsyms, int gnu_hash) |
| 4820 |
{ |
4964 |
{ |
| 4821 |
size_t dynsymcount = elf_hash_table (info)->dynsymcount; |
4965 |
size_t dynsymcount = elf_hash_table (info)->dynsymcount; |
| 4822 |
size_t best_size = 0; |
4966 |
size_t best_size = 0; |
| 4823 |
unsigned long int *hashcodes; |
|
|
| 4824 |
unsigned long int *hashcodesp; |
| 4825 |
unsigned long int i; |
4967 |
unsigned long int i; |
| 4826 |
bfd_size_type amt; |
4968 |
bfd_size_type amt; |
| 4827 |
|
4969 |
|
| 4828 |
/* Compute the hash values for all exported symbols. At the same |
|
|
| 4829 |
time store the values in an array so that we could use them for |
| 4830 |
optimizations. */ |
| 4831 |
amt = dynsymcount; |
| 4832 |
amt *= sizeof (unsigned long int); |
| 4833 |
hashcodes = bfd_malloc (amt); |
| 4834 |
if (hashcodes == NULL) |
| 4835 |
return 0; |
| 4836 |
hashcodesp = hashcodes; |
| 4837 |
|
| 4838 |
/* Put all hash values in HASHCODES. */ |
| 4839 |
elf_link_hash_traverse (elf_hash_table (info), |
| 4840 |
elf_collect_hash_codes, &hashcodesp); |
| 4841 |
|
| 4842 |
/* We have a problem here. The following code to optimize the table |
4970 |
/* We have a problem here. The following code to optimize the table |
| 4843 |
size requires an integer type with more the 32 bits. If |
4971 |
size requires an integer type with more the 32 bits. If |
| 4844 |
BFD_HOST_U_64_BIT is set we know about such a type. */ |
4972 |
BFD_HOST_U_64_BIT is set we know about such a type. */ |
| 4845 |
#ifdef BFD_HOST_U_64_BIT |
4973 |
#ifdef BFD_HOST_U_64_BIT |
| 4846 |
if (info->optimize) |
4974 |
if (info->optimize) |
| 4847 |
{ |
4975 |
{ |
| 4848 |
unsigned long int nsyms = hashcodesp - hashcodes; |
|
|
| 4849 |
size_t minsize; |
4976 |
size_t minsize; |
| 4850 |
size_t maxsize; |
4977 |
size_t maxsize; |
| 4851 |
BFD_HOST_U_64_BIT best_chlen = ~((BFD_HOST_U_64_BIT) 0); |
4978 |
BFD_HOST_U_64_BIT best_chlen = ~((BFD_HOST_U_64_BIT) 0); |
| 4852 |
unsigned long int *counts ; |
|
|
| 4853 |
bfd *dynobj = elf_hash_table (info)->dynobj; |
4979 |
bfd *dynobj = elf_hash_table (info)->dynobj; |
| 4854 |
const struct elf_backend_data *bed = get_elf_backend_data (dynobj); |
4980 |
const struct elf_backend_data *bed = get_elf_backend_data (dynobj); |
|
|
4981 |
unsigned long int *counts; |
| 4855 |
|
4982 |
|
| 4856 |
/* Possible optimization parameters: if we have NSYMS symbols we say |
4983 |
/* Possible optimization parameters: if we have NSYMS symbols we say |
| 4857 |
that the hashing table must at least have NSYMS/4 and at most |
4984 |
that the hashing table must at least have NSYMS/4 and at most |
|
Lines 4860-4865
compute_bucket_count (struct bfd_link_in
Link Here
|
| 4860 |
if (minsize == 0) |
4987 |
if (minsize == 0) |
| 4861 |
minsize = 1; |
4988 |
minsize = 1; |
| 4862 |
best_size = maxsize = nsyms * 2; |
4989 |
best_size = maxsize = nsyms * 2; |
|
|
4990 |
if (gnu_hash) |
| 4991 |
{ |
| 4992 |
if (minsize < 2) |
| 4993 |
minsize = 2; |
| 4994 |
if ((best_size & 31) == 0) |
| 4995 |
++best_size; |
| 4996 |
} |
| 4863 |
|
4997 |
|
| 4864 |
/* Create array where we count the collisions in. We must use bfd_malloc |
4998 |
/* Create array where we count the collisions in. We must use bfd_malloc |
| 4865 |
since the size could be large. */ |
4999 |
since the size could be large. */ |
|
Lines 4867-4876
compute_bucket_count (struct bfd_link_in
Link Here
|
| 4867 |
amt *= sizeof (unsigned long int); |
5001 |
amt *= sizeof (unsigned long int); |
| 4868 |
counts = bfd_malloc (amt); |
5002 |
counts = bfd_malloc (amt); |
| 4869 |
if (counts == NULL) |
5003 |
if (counts == NULL) |
| 4870 |
{ |
5004 |
return 0; |
| 4871 |
free (hashcodes); |
|
|
| 4872 |
return 0; |
| 4873 |
} |
| 4874 |
|
5005 |
|
| 4875 |
/* Compute the "optimal" size for the hash table. The criteria is a |
5006 |
/* Compute the "optimal" size for the hash table. The criteria is a |
| 4876 |
minimal chain length. The minor criteria is (of course) the size |
5007 |
minimal chain length. The minor criteria is (of course) the size |
|
Lines 4882-4887
compute_bucket_count (struct bfd_link_in
Link Here
|
| 4882 |
unsigned long int j; |
5013 |
unsigned long int j; |
| 4883 |
unsigned long int fact; |
5014 |
unsigned long int fact; |
| 4884 |
|
5015 |
|
|
|
5016 |
if (gnu_hash && (i & 31) == 0) |
| 5017 |
continue; |
| 5018 |
|
| 4885 |
memset (counts, '\0', i * sizeof (unsigned long int)); |
5019 |
memset (counts, '\0', i * sizeof (unsigned long int)); |
| 4886 |
|
5020 |
|
| 4887 |
/* Determine how often each hash bucket is used. */ |
5021 |
/* Determine how often each hash bucket is used. */ |
|
Lines 4897-4905
compute_bucket_count (struct bfd_link_in
Link Here
|
| 4897 |
# define BFD_TARGET_PAGESIZE (4096) |
5031 |
# define BFD_TARGET_PAGESIZE (4096) |
| 4898 |
# endif |
5032 |
# endif |
| 4899 |
|
5033 |
|
| 4900 |
/* We in any case need 2 + NSYMS entries for the size values and |
5034 |
/* We in any case need 2 + DYNSYMCOUNT entries for the size values |
| 4901 |
the chains. */ |
5035 |
and the chains. */ |
| 4902 |
max = (2 + nsyms) * (bed->s->arch_size / 8); |
5036 |
max = (2 + dynsymcount) * bed->s->sizeof_hash_entry; |
| 4903 |
|
5037 |
|
| 4904 |
# if 1 |
5038 |
# if 1 |
| 4905 |
/* Variant 1: optimize for short chains. We add the squares |
5039 |
/* Variant 1: optimize for short chains. We add the squares |
|
Lines 4909-4915
compute_bucket_count (struct bfd_link_in
Link Here
|
| 4909 |
max += counts[j] * counts[j]; |
5043 |
max += counts[j] * counts[j]; |
| 4910 |
|
5044 |
|
| 4911 |
/* This adds penalties for the overall size of the table. */ |
5045 |
/* This adds penalties for the overall size of the table. */ |
| 4912 |
fact = i / (BFD_TARGET_PAGESIZE / (bed->s->arch_size / 8)) + 1; |
5046 |
fact = i / (BFD_TARGET_PAGESIZE / bed->s->sizeof_hash_entry) + 1; |
| 4913 |
max *= fact * fact; |
5047 |
max *= fact * fact; |
| 4914 |
# else |
5048 |
# else |
| 4915 |
/* Variant 2: Optimize a lot more for small table. Here we |
5049 |
/* Variant 2: Optimize a lot more for small table. Here we |
|
Lines 4920-4926
compute_bucket_count (struct bfd_link_in
Link Here
|
| 4920 |
|
5054 |
|
| 4921 |
/* The overall size of the table is considered, but not as |
5055 |
/* The overall size of the table is considered, but not as |
| 4922 |
strong as in variant 1, where it is squared. */ |
5056 |
strong as in variant 1, where it is squared. */ |
| 4923 |
fact = i / (BFD_TARGET_PAGESIZE / (bed->s->arch_size / 8)) + 1; |
5057 |
fact = i / (BFD_TARGET_PAGESIZE / bed->s->sizeof_hash_entry) + 1; |
| 4924 |
max *= fact; |
5058 |
max *= fact; |
| 4925 |
# endif |
5059 |
# endif |
| 4926 |
|
5060 |
|
|
Lines 4943-4956
compute_bucket_count (struct bfd_link_in
Link Here
|
| 4943 |
for (i = 0; elf_buckets[i] != 0; i++) |
5077 |
for (i = 0; elf_buckets[i] != 0; i++) |
| 4944 |
{ |
5078 |
{ |
| 4945 |
best_size = elf_buckets[i]; |
5079 |
best_size = elf_buckets[i]; |
| 4946 |
if (dynsymcount < elf_buckets[i + 1]) |
5080 |
if (nsyms < elf_buckets[i + 1]) |
| 4947 |
break; |
5081 |
break; |
| 4948 |
} |
5082 |
} |
|
|
5083 |
if (gnu_hash && best_size < 2) |
| 5084 |
best_size = 2; |
| 4949 |
} |
5085 |
} |
| 4950 |
|
5086 |
|
| 4951 |
/* Free the arrays we needed. */ |
|
|
| 4952 |
free (hashcodes); |
| 4953 |
|
| 4954 |
return best_size; |
5087 |
return best_size; |
| 4955 |
} |
5088 |
} |
| 4956 |
|
5089 |
|
|
Lines 5308-5314
bfd_elf_size_dynamic_sections (bfd *outp
Link Here
|
| 5308 |
bfd_size_type strsize; |
5441 |
bfd_size_type strsize; |
| 5309 |
|
5442 |
|
| 5310 |
strsize = _bfd_elf_strtab_size (elf_hash_table (info)->dynstr); |
5443 |
strsize = _bfd_elf_strtab_size (elf_hash_table (info)->dynstr); |
| 5311 |
if (!_bfd_elf_add_dynamic_entry (info, DT_HASH, 0) |
5444 |
if ((info->emit_hash |
|
|
5445 |
&& !_bfd_elf_add_dynamic_entry (info, DT_HASH, 0)) |
| 5446 |
|| (info->emit_gnu_hash |
| 5447 |
&& !_bfd_elf_add_dynamic_entry (info, DT_GNU_HASH, 0)) |
| 5312 |
|| !_bfd_elf_add_dynamic_entry (info, DT_STRTAB, 0) |
5448 |
|| !_bfd_elf_add_dynamic_entry (info, DT_STRTAB, 0) |
| 5313 |
|| !_bfd_elf_add_dynamic_entry (info, DT_SYMTAB, 0) |
5449 |
|| !_bfd_elf_add_dynamic_entry (info, DT_SYMTAB, 0) |
| 5314 |
|| !_bfd_elf_add_dynamic_entry (info, DT_STRSZ, strsize) |
5450 |
|| !_bfd_elf_add_dynamic_entry (info, DT_STRSZ, strsize) |
|
Lines 5710-5717
bfd_elf_size_dynsym_hash_dynstr (bfd *ou
Link Here
|
| 5710 |
asection *s; |
5846 |
asection *s; |
| 5711 |
bfd_size_type dynsymcount; |
5847 |
bfd_size_type dynsymcount; |
| 5712 |
unsigned long section_sym_count; |
5848 |
unsigned long section_sym_count; |
| 5713 |
size_t bucketcount = 0; |
|
|
| 5714 |
size_t hash_entry_size; |
| 5715 |
unsigned int dtagcount; |
5849 |
unsigned int dtagcount; |
| 5716 |
|
5850 |
|
| 5717 |
dynobj = elf_hash_table (info)->dynobj; |
5851 |
dynobj = elf_hash_table (info)->dynobj; |
|
Lines 5762-5784
bfd_elf_size_dynsym_hash_dynstr (bfd *ou
Link Here
|
| 5762 |
memset (s->contents, 0, section_sym_count * bed->s->sizeof_sym); |
5896 |
memset (s->contents, 0, section_sym_count * bed->s->sizeof_sym); |
| 5763 |
} |
5897 |
} |
| 5764 |
|
5898 |
|
|
|
5899 |
elf_hash_table (info)->bucketcount = 0; |
| 5900 |
|
| 5765 |
/* Compute the size of the hashing table. As a side effect this |
5901 |
/* Compute the size of the hashing table. As a side effect this |
| 5766 |
computes the hash values for all the names we export. */ |
5902 |
computes the hash values for all the names we export. */ |
| 5767 |
bucketcount = compute_bucket_count (info); |
5903 |
if (info->emit_hash) |
|
|
5904 |
{ |
| 5905 |
unsigned long int *hashcodes; |
| 5906 |
unsigned long int *hashcodesp; |
| 5907 |
bfd_size_type amt; |
| 5908 |
unsigned long int nsyms; |
| 5909 |
size_t bucketcount; |
| 5910 |
size_t hash_entry_size; |
| 5911 |
|
| 5912 |
/* Compute the hash values for all exported symbols. At the same |
| 5913 |
time store the values in an array so that we could use them for |
| 5914 |
optimizations. */ |
| 5915 |
amt = dynsymcount * sizeof (unsigned long int); |
| 5916 |
hashcodes = bfd_malloc (amt); |
| 5917 |
if (hashcodes == NULL) |
| 5918 |
return FALSE; |
| 5919 |
hashcodesp = hashcodes; |
| 5768 |
|
5920 |
|
| 5769 |
s = bfd_get_section_by_name (dynobj, ".hash"); |
5921 |
/* Put all hash values in HASHCODES. */ |
| 5770 |
BFD_ASSERT (s != NULL); |
5922 |
elf_link_hash_traverse (elf_hash_table (info), |
| 5771 |
hash_entry_size = elf_section_data (s)->this_hdr.sh_entsize; |
5923 |
elf_collect_hash_codes, &hashcodesp); |
| 5772 |
s->size = ((2 + bucketcount + dynsymcount) * hash_entry_size); |
|
|
| 5773 |
s->contents = bfd_zalloc (output_bfd, s->size); |
| 5774 |
if (s->contents == NULL) |
| 5775 |
return FALSE; |
| 5776 |
|
5924 |
|
| 5777 |
bfd_put (8 * hash_entry_size, output_bfd, bucketcount, s->contents); |
5925 |
nsyms = hashcodesp - hashcodes; |
| 5778 |
bfd_put (8 * hash_entry_size, output_bfd, dynsymcount, |
5926 |
bucketcount |
| 5779 |
s->contents + hash_entry_size); |
5927 |
= compute_bucket_count (info, hashcodes, nsyms, 0); |
|
|
5928 |
free (hashcodes); |
| 5780 |
|
5929 |
|
| 5781 |
elf_hash_table (info)->bucketcount = bucketcount; |
5930 |
if (bucketcount == 0) |
|
|
5931 |
return FALSE; |
| 5932 |
|
| 5933 |
elf_hash_table (info)->bucketcount = bucketcount; |
| 5934 |
|
| 5935 |
s = bfd_get_section_by_name (dynobj, ".hash"); |
| 5936 |
BFD_ASSERT (s != NULL); |
| 5937 |
hash_entry_size = elf_section_data (s)->this_hdr.sh_entsize; |
| 5938 |
s->size = ((2 + bucketcount + dynsymcount) * hash_entry_size); |
| 5939 |
s->contents = bfd_zalloc (output_bfd, s->size); |
| 5940 |
if (s->contents == NULL) |
| 5941 |
return FALSE; |
| 5942 |
|
| 5943 |
bfd_put (8 * hash_entry_size, output_bfd, bucketcount, s->contents); |
| 5944 |
bfd_put (8 * hash_entry_size, output_bfd, dynsymcount, |
| 5945 |
s->contents + hash_entry_size); |
| 5946 |
} |
| 5947 |
|
| 5948 |
if (info->emit_gnu_hash) |
| 5949 |
{ |
| 5950 |
size_t i, cnt; |
| 5951 |
unsigned char *contents; |
| 5952 |
struct collect_gnu_hash_codes cinfo; |
| 5953 |
bfd_size_type amt; |
| 5954 |
size_t bucketcount; |
| 5955 |
|
| 5956 |
memset (&cinfo, 0, sizeof (cinfo)); |
| 5957 |
|
| 5958 |
/* Compute the hash values for all exported symbols. At the same |
| 5959 |
time store the values in an array so that we could use them for |
| 5960 |
optimizations. */ |
| 5961 |
amt = dynsymcount * 2 * sizeof (unsigned long int); |
| 5962 |
cinfo.hashcodes = bfd_malloc (amt); |
| 5963 |
if (cinfo.hashcodes == NULL) |
| 5964 |
return FALSE; |
| 5965 |
|
| 5966 |
cinfo.hashval = cinfo.hashcodes + dynsymcount; |
| 5967 |
cinfo.min_dynindx = -1; |
| 5968 |
cinfo.output_bfd = output_bfd; |
| 5969 |
cinfo.bed = bed; |
| 5970 |
|
| 5971 |
/* Put all hash values in HASHCODES. */ |
| 5972 |
elf_link_hash_traverse (elf_hash_table (info), |
| 5973 |
elf_collect_gnu_hash_codes, &cinfo); |
| 5974 |
|
| 5975 |
bucketcount |
| 5976 |
= compute_bucket_count (info, cinfo.hashcodes, cinfo.nsyms, 1); |
| 5977 |
|
| 5978 |
if (bucketcount == 0) |
| 5979 |
{ |
| 5980 |
free (cinfo.hashcodes); |
| 5981 |
return FALSE; |
| 5982 |
} |
| 5983 |
|
| 5984 |
s = bfd_get_section_by_name (dynobj, ".gnu.hash"); |
| 5985 |
BFD_ASSERT (s != NULL); |
| 5986 |
|
| 5987 |
if (cinfo.nsyms == 0) |
| 5988 |
{ |
| 5989 |
/* Empty .gnu.hash section is special. */ |
| 5990 |
BFD_ASSERT (cinfo.min_dynindx == -1); |
| 5991 |
free (cinfo.hashcodes); |
| 5992 |
s->size = 5 * 4 + bed->s->arch_size / 8; |
| 5993 |
contents = bfd_zalloc (output_bfd, s->size); |
| 5994 |
if (contents == NULL) |
| 5995 |
return FALSE; |
| 5996 |
s->contents = contents; |
| 5997 |
/* 1 empty bucket. */ |
| 5998 |
bfd_put_32 (output_bfd, 1, contents); |
| 5999 |
/* SYMIDX above the special symbol 0. */ |
| 6000 |
bfd_put_32 (output_bfd, 1, contents + 4); |
| 6001 |
/* Just one word for bitmask. */ |
| 6002 |
bfd_put_32 (output_bfd, 1, contents + 8); |
| 6003 |
/* Only hash fn bloom filter. */ |
| 6004 |
bfd_put_32 (output_bfd, 0, contents + 12); |
| 6005 |
/* No hashes are valid - empty bitmask. */ |
| 6006 |
bfd_put (bed->s->arch_size, output_bfd, 0, contents + 16); |
| 6007 |
/* No hashes in the only bucket. */ |
| 6008 |
bfd_put_32 (output_bfd, 0, |
| 6009 |
contents + 16 + bed->s->arch_size / 8); |
| 6010 |
} |
| 6011 |
else |
| 6012 |
{ |
| 6013 |
BFD_ASSERT (cinfo.min_dynindx != -1); |
| 6014 |
unsigned long int maskwords, maskbitslog2; |
| 6015 |
|
| 6016 |
maskbitslog2 = bfd_log2 (cinfo.nsyms) + 1; |
| 6017 |
if (maskbitslog2 < 3) |
| 6018 |
maskbitslog2 = 5; |
| 6019 |
else if ((1 << (maskbitslog2 - 2)) & cinfo.nsyms) |
| 6020 |
maskbitslog2 = maskbitslog2 + 3; |
| 6021 |
else |
| 6022 |
maskbitslog2 = maskbitslog2 + 2; |
| 6023 |
if (bed->s->arch_size == 64) |
| 6024 |
{ |
| 6025 |
if (maskbitslog2 == 5) |
| 6026 |
maskbitslog2 = 6; |
| 6027 |
cinfo.shift1 = 6; |
| 6028 |
} |
| 6029 |
else |
| 6030 |
cinfo.shift1 = 5; |
| 6031 |
cinfo.mask = (1 << cinfo.shift1) - 1; |
| 6032 |
cinfo.shift2 = maskbitslog2 + cinfo.shift1; |
| 6033 |
cinfo.maskbits = 1 << maskbitslog2; |
| 6034 |
maskwords = 1 << (maskbitslog2 - cinfo.shift1); |
| 6035 |
amt = bucketcount * sizeof (unsigned long int) * 2; |
| 6036 |
amt += maskwords * sizeof (bfd_vma); |
| 6037 |
cinfo.bitmask = bfd_malloc (amt); |
| 6038 |
if (cinfo.bitmask == NULL) |
| 6039 |
{ |
| 6040 |
free (cinfo.hashcodes); |
| 6041 |
return FALSE; |
| 6042 |
} |
| 6043 |
|
| 6044 |
cinfo.counts = (void *) (cinfo.bitmask + maskwords); |
| 6045 |
cinfo.indx = cinfo.counts + bucketcount; |
| 6046 |
cinfo.symindx = dynsymcount - cinfo.nsyms; |
| 6047 |
memset (cinfo.bitmask, 0, maskwords * sizeof (bfd_vma)); |
| 6048 |
|
| 6049 |
/* Determine how often each hash bucket is used. */ |
| 6050 |
memset (cinfo.counts, 0, bucketcount * sizeof (cinfo.counts[0])); |
| 6051 |
for (i = 0; i < cinfo.nsyms; ++i) |
| 6052 |
++cinfo.counts[cinfo.hashcodes[i] % bucketcount]; |
| 6053 |
|
| 6054 |
for (i = 0, cnt = cinfo.symindx; i < bucketcount; ++i) |
| 6055 |
if (cinfo.counts[i] != 0) |
| 6056 |
{ |
| 6057 |
cinfo.indx[i] = cnt; |
| 6058 |
cnt += cinfo.counts[i]; |
| 6059 |
} |
| 6060 |
BFD_ASSERT (cnt == dynsymcount); |
| 6061 |
cinfo.bucketcount = bucketcount; |
| 6062 |
cinfo.local_indx = cinfo.min_dynindx; |
| 6063 |
|
| 6064 |
s->size = (4 + bucketcount + cinfo.nsyms) * 4; |
| 6065 |
s->size += cinfo.maskbits / 8; |
| 6066 |
contents = bfd_zalloc (output_bfd, s->size); |
| 6067 |
if (contents == NULL) |
| 6068 |
{ |
| 6069 |
free (cinfo.bitmask); |
| 6070 |
free (cinfo.hashcodes); |
| 6071 |
return FALSE; |
| 6072 |
} |
| 6073 |
|
| 6074 |
s->contents = contents; |
| 6075 |
bfd_put_32 (output_bfd, bucketcount, contents); |
| 6076 |
bfd_put_32 (output_bfd, cinfo.symindx, contents + 4); |
| 6077 |
bfd_put_32 (output_bfd, maskwords, contents + 8); |
| 6078 |
bfd_put_32 (output_bfd, cinfo.shift2, contents + 12); |
| 6079 |
contents += 16 + cinfo.maskbits / 8; |
| 6080 |
|
| 6081 |
for (i = 0; i < bucketcount; ++i) |
| 6082 |
{ |
| 6083 |
if (cinfo.counts[i] == 0) |
| 6084 |
bfd_put_32 (output_bfd, 0, contents); |
| 6085 |
else |
| 6086 |
bfd_put_32 (output_bfd, cinfo.indx[i], contents); |
| 6087 |
contents += 4; |
| 6088 |
} |
| 6089 |
|
| 6090 |
cinfo.contents = contents; |
| 6091 |
|
| 6092 |
/* Renumber dynamic symbols, populate .gnu.hash section. */ |
| 6093 |
elf_link_hash_traverse (elf_hash_table (info), |
| 6094 |
elf_renumber_gnu_hash_syms, &cinfo); |
| 6095 |
|
| 6096 |
contents = s->contents + 16; |
| 6097 |
for (i = 0; i < maskwords; ++i) |
| 6098 |
{ |
| 6099 |
bfd_put (bed->s->arch_size, output_bfd, cinfo.bitmask[i], |
| 6100 |
contents); |
| 6101 |
contents += bed->s->arch_size / 8; |
| 6102 |
} |
| 6103 |
|
| 6104 |
free (cinfo.bitmask); |
| 6105 |
free (cinfo.hashcodes); |
| 6106 |
} |
| 6107 |
} |
| 5782 |
|
6108 |
|
| 5783 |
s = bfd_get_section_by_name (dynobj, ".dynstr"); |
6109 |
s = bfd_get_section_by_name (dynobj, ".dynstr"); |
| 5784 |
BFD_ASSERT (s != NULL); |
6110 |
BFD_ASSERT (s != NULL); |
|
Lines 6647-6655
elf_link_output_extsym (struct elf_link_
Link Here
|
| 6647 |
{ |
6973 |
{ |
| 6648 |
size_t bucketcount; |
6974 |
size_t bucketcount; |
| 6649 |
size_t bucket; |
6975 |
size_t bucket; |
| 6650 |
size_t hash_entry_size; |
|
|
| 6651 |
bfd_byte *bucketpos; |
| 6652 |
bfd_vma chain; |
| 6653 |
bfd_byte *esym; |
6976 |
bfd_byte *esym; |
| 6654 |
|
6977 |
|
| 6655 |
sym.st_name = h->dynstr_index; |
6978 |
sym.st_name = h->dynstr_index; |
|
Lines 6663-6677
elf_link_output_extsym (struct elf_link_
Link Here
|
| 6663 |
|
6986 |
|
| 6664 |
bucketcount = elf_hash_table (finfo->info)->bucketcount; |
6987 |
bucketcount = elf_hash_table (finfo->info)->bucketcount; |
| 6665 |
bucket = h->u.elf_hash_value % bucketcount; |
6988 |
bucket = h->u.elf_hash_value % bucketcount; |
| 6666 |
hash_entry_size |
6989 |
|
| 6667 |
= elf_section_data (finfo->hash_sec)->this_hdr.sh_entsize; |
6990 |
if (finfo->hash_sec != NULL) |
| 6668 |
bucketpos = ((bfd_byte *) finfo->hash_sec->contents |
6991 |
{ |
| 6669 |
+ (bucket + 2) * hash_entry_size); |
6992 |
size_t hash_entry_size; |
| 6670 |
chain = bfd_get (8 * hash_entry_size, finfo->output_bfd, bucketpos); |
6993 |
bfd_byte *bucketpos; |
| 6671 |
bfd_put (8 * hash_entry_size, finfo->output_bfd, h->dynindx, bucketpos); |
6994 |
bfd_vma chain; |
| 6672 |
bfd_put (8 * hash_entry_size, finfo->output_bfd, chain, |
6995 |
|
| 6673 |
((bfd_byte *) finfo->hash_sec->contents |
6996 |
hash_entry_size |
| 6674 |
+ (bucketcount + 2 + h->dynindx) * hash_entry_size)); |
6997 |
= elf_section_data (finfo->hash_sec)->this_hdr.sh_entsize; |
|
|
6998 |
bucketpos = ((bfd_byte *) finfo->hash_sec->contents |
| 6999 |
+ (bucket + 2) * hash_entry_size); |
| 7000 |
chain = bfd_get (8 * hash_entry_size, finfo->output_bfd, bucketpos); |
| 7001 |
bfd_put (8 * hash_entry_size, finfo->output_bfd, h->dynindx, bucketpos); |
| 7002 |
bfd_put (8 * hash_entry_size, finfo->output_bfd, chain, |
| 7003 |
((bfd_byte *) finfo->hash_sec->contents |
| 7004 |
+ (bucketcount + 2 + h->dynindx) * hash_entry_size)); |
| 7005 |
} |
| 6675 |
|
7006 |
|
| 6676 |
if (finfo->symver_sec != NULL && finfo->symver_sec->contents != NULL) |
7007 |
if (finfo->symver_sec != NULL && finfo->symver_sec->contents != NULL) |
| 6677 |
{ |
7008 |
{ |
|
Lines 7845-7851
bfd_elf_final_link (bfd *abfd, struct bf
Link Here
|
| 7845 |
{ |
8176 |
{ |
| 7846 |
finfo.dynsym_sec = bfd_get_section_by_name (dynobj, ".dynsym"); |
8177 |
finfo.dynsym_sec = bfd_get_section_by_name (dynobj, ".dynsym"); |
| 7847 |
finfo.hash_sec = bfd_get_section_by_name (dynobj, ".hash"); |
8178 |
finfo.hash_sec = bfd_get_section_by_name (dynobj, ".hash"); |
| 7848 |
BFD_ASSERT (finfo.dynsym_sec != NULL && finfo.hash_sec != NULL); |
8179 |
BFD_ASSERT (finfo.dynsym_sec != NULL); |
| 7849 |
finfo.symver_sec = bfd_get_section_by_name (dynobj, ".gnu.version"); |
8180 |
finfo.symver_sec = bfd_get_section_by_name (dynobj, ".gnu.version"); |
| 7850 |
/* Note that it is OK if symver_sec is NULL. */ |
8181 |
/* Note that it is OK if symver_sec is NULL. */ |
| 7851 |
} |
8182 |
} |
|
Lines 8591-8596
bfd_elf_final_link (bfd *abfd, struct bf
Link Here
|
| 8591 |
case DT_HASH: |
8922 |
case DT_HASH: |
| 8592 |
name = ".hash"; |
8923 |
name = ".hash"; |
| 8593 |
goto get_vma; |
8924 |
goto get_vma; |
|
|
8925 |
case DT_GNU_HASH: |
| 8926 |
name = ".gnu.hash"; |
| 8927 |
goto get_vma; |
| 8594 |
case DT_STRTAB: |
8928 |
case DT_STRTAB: |
| 8595 |
name = ".dynstr"; |
8929 |
name = ".dynstr"; |
| 8596 |
goto get_vma; |
8930 |
goto get_vma; |