Adjust the ${ISODIR}/.didbootstrap logic a little, add needed licenses.
[dragonfly.git] / contrib / binutils-2.17 / bfd / merge.c
blobc1795d29112f71c5c8748636919cd71cc9ea33c0
1 /* SEC_MERGE support.
2 Copyright 2001, 2002, 2003, 2004, 2005, 2006
3 Free Software Foundation, Inc.
4 Written by Jakub Jelinek <jakub@redhat.com>.
6 This file is part of BFD, the Binary File Descriptor library.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
22 /* This file contains support for merging duplicate entities within sections,
23 as used in ELF SHF_MERGE. */
25 #include "bfd.h"
26 #include "sysdep.h"
27 #include "libbfd.h"
28 #include "hashtab.h"
29 #include "libiberty.h"
31 struct sec_merge_sec_info;
33 /* An entry in the section merge hash table. */
35 struct sec_merge_hash_entry
37 struct bfd_hash_entry root;
38 /* Length of this entry. This includes the zero terminator. */
39 unsigned int len;
40 /* Start of this string needs to be aligned to
41 alignment octets (not 1 << align). */
42 unsigned int alignment;
43 union
45 /* Index within the merged section. */
46 bfd_size_type index;
47 /* Entry this is a suffix of (if alignment is 0). */
48 struct sec_merge_hash_entry *suffix;
49 } u;
50 /* Which section is it in. */
51 struct sec_merge_sec_info *secinfo;
52 /* Next entity in the hash table. */
53 struct sec_merge_hash_entry *next;
56 /* The section merge hash table. */
58 struct sec_merge_hash
60 struct bfd_hash_table table;
61 /* Next available index. */
62 bfd_size_type size;
63 /* First entity in the SEC_MERGE sections of this type. */
64 struct sec_merge_hash_entry *first;
65 /* Last entity in the SEC_MERGE sections of this type. */
66 struct sec_merge_hash_entry *last;
67 /* Entity size. */
68 unsigned int entsize;
69 /* Are entries fixed size or zero terminated strings? */
70 bfd_boolean strings;
73 struct sec_merge_info
75 /* Chain of sec_merge_infos. */
76 struct sec_merge_info *next;
77 /* Chain of sec_merge_sec_infos. */
78 struct sec_merge_sec_info *chain;
79 /* A hash table used to hold section content. */
80 struct sec_merge_hash *htab;
83 struct sec_merge_sec_info
85 /* Chain of sec_merge_sec_infos. */
86 struct sec_merge_sec_info *next;
87 /* The corresponding section. */
88 asection *sec;
89 /* Pointer to merge_info pointing to us. */
90 void **psecinfo;
91 /* A hash table used to hold section content. */
92 struct sec_merge_hash *htab;
93 /* First string in this section. */
94 struct sec_merge_hash_entry *first_str;
95 /* Original section content. */
96 unsigned char contents[1];
100 /* Routine to create an entry in a section merge hashtab. */
102 static struct bfd_hash_entry *
103 sec_merge_hash_newfunc (struct bfd_hash_entry *entry,
104 struct bfd_hash_table *table, const char *string)
106 /* Allocate the structure if it has not already been allocated by a
107 subclass. */
108 if (entry == NULL)
109 entry = bfd_hash_allocate (table, sizeof (struct sec_merge_hash_entry));
110 if (entry == NULL)
111 return NULL;
113 /* Call the allocation method of the superclass. */
114 entry = bfd_hash_newfunc (entry, table, string);
116 if (entry != NULL)
118 /* Initialize the local fields. */
119 struct sec_merge_hash_entry *ret = (struct sec_merge_hash_entry *) entry;
121 ret->u.suffix = NULL;
122 ret->alignment = 0;
123 ret->secinfo = NULL;
124 ret->next = NULL;
127 return entry;
130 /* Look up an entry in a section merge hash table. */
132 static struct sec_merge_hash_entry *
133 sec_merge_hash_lookup (struct sec_merge_hash *table, const char *string,
134 unsigned int alignment, bfd_boolean create)
136 register const unsigned char *s;
137 register unsigned long hash;
138 register unsigned int c;
139 struct sec_merge_hash_entry *hashp;
140 unsigned int len, i;
141 unsigned int index;
143 hash = 0;
144 len = 0;
145 s = (const unsigned char *) string;
146 if (table->strings)
148 if (table->entsize == 1)
150 while ((c = *s++) != '\0')
152 hash += c + (c << 17);
153 hash ^= hash >> 2;
154 ++len;
156 hash += len + (len << 17);
158 else
160 for (;;)
162 for (i = 0; i < table->entsize; ++i)
163 if (s[i] != '\0')
164 break;
165 if (i == table->entsize)
166 break;
167 for (i = 0; i < table->entsize; ++i)
169 c = *s++;
170 hash += c + (c << 17);
171 hash ^= hash >> 2;
173 ++len;
175 hash += len + (len << 17);
176 len *= table->entsize;
178 hash ^= hash >> 2;
179 len += table->entsize;
181 else
183 for (i = 0; i < table->entsize; ++i)
185 c = *s++;
186 hash += c + (c << 17);
187 hash ^= hash >> 2;
189 len = table->entsize;
192 index = hash % table->table.size;
193 for (hashp = (struct sec_merge_hash_entry *) table->table.table[index];
194 hashp != NULL;
195 hashp = (struct sec_merge_hash_entry *) hashp->root.next)
197 if (hashp->root.hash == hash
198 && len == hashp->len
199 && memcmp (hashp->root.string, string, len) == 0)
201 /* If the string we found does not have at least the required
202 alignment, we need to insert another copy. */
203 if (hashp->alignment < alignment)
205 if (create)
207 /* Mark the less aligned copy as deleted. */
208 hashp->len = 0;
209 hashp->alignment = 0;
211 break;
213 return hashp;
217 if (! create)
218 return NULL;
220 hashp = ((struct sec_merge_hash_entry *)
221 sec_merge_hash_newfunc (NULL, &table->table, string));
222 if (hashp == NULL)
223 return NULL;
224 hashp->root.string = string;
225 hashp->root.hash = hash;
226 hashp->len = len;
227 hashp->alignment = alignment;
228 hashp->root.next = table->table.table[index];
229 table->table.table[index] = (struct bfd_hash_entry *) hashp;
231 return hashp;
234 /* Create a new hash table. */
236 static struct sec_merge_hash *
237 sec_merge_init (unsigned int entsize, bfd_boolean strings)
239 struct sec_merge_hash *table;
241 table = bfd_malloc (sizeof (struct sec_merge_hash));
242 if (table == NULL)
243 return NULL;
245 if (! bfd_hash_table_init_n (&table->table, sec_merge_hash_newfunc,
246 sizeof (struct sec_merge_hash_entry), 16699))
248 free (table);
249 return NULL;
252 table->size = 0;
253 table->first = NULL;
254 table->last = NULL;
255 table->entsize = entsize;
256 table->strings = strings;
258 return table;
261 /* Get the index of an entity in a hash table, adding it if it is not
262 already present. */
264 static struct sec_merge_hash_entry *
265 sec_merge_add (struct sec_merge_hash *tab, const char *str,
266 unsigned int alignment, struct sec_merge_sec_info *secinfo)
268 register struct sec_merge_hash_entry *entry;
270 entry = sec_merge_hash_lookup (tab, str, alignment, TRUE);
271 if (entry == NULL)
272 return NULL;
274 if (entry->secinfo == NULL)
276 tab->size++;
277 entry->secinfo = secinfo;
278 if (tab->first == NULL)
279 tab->first = entry;
280 else
281 tab->last->next = entry;
282 tab->last = entry;
285 return entry;
288 static bfd_boolean
289 sec_merge_emit (bfd *abfd, struct sec_merge_hash_entry *entry)
291 struct sec_merge_sec_info *secinfo = entry->secinfo;
292 asection *sec = secinfo->sec;
293 char *pad = NULL;
294 bfd_size_type off = 0;
295 int alignment_power = sec->output_section->alignment_power;
297 if (alignment_power)
299 pad = bfd_zmalloc ((bfd_size_type) 1 << alignment_power);
300 if (pad == NULL)
301 return FALSE;
304 for (; entry != NULL && entry->secinfo == secinfo; entry = entry->next)
306 const char *str;
307 bfd_size_type len;
309 len = -off & (entry->alignment - 1);
310 if (len != 0)
312 if (bfd_bwrite (pad, len, abfd) != len)
313 goto err;
314 off += len;
317 str = entry->root.string;
318 len = entry->len;
320 if (bfd_bwrite (str, len, abfd) != len)
321 goto err;
323 off += len;
326 /* Trailing alignment needed? */
327 off = sec->size - off;
328 if (off != 0
329 && bfd_bwrite (pad, off, abfd) != off)
330 goto err;
332 if (pad != NULL)
333 free (pad);
334 return TRUE;
336 err:
337 if (pad != NULL)
338 free (pad);
339 return FALSE;
342 /* Register a SEC_MERGE section as a candidate for merging.
343 This function is called for all non-dynamic SEC_MERGE input sections. */
345 bfd_boolean
346 _bfd_add_merge_section (bfd *abfd, void **psinfo, asection *sec,
347 void **psecinfo)
349 struct sec_merge_info *sinfo;
350 struct sec_merge_sec_info *secinfo;
351 unsigned int align;
352 bfd_size_type amt;
354 if ((abfd->flags & DYNAMIC) != 0
355 || (sec->flags & SEC_MERGE) == 0)
356 abort ();
358 if (sec->size == 0
359 || (sec->flags & SEC_EXCLUDE) != 0
360 || sec->entsize == 0)
361 return TRUE;
363 if ((sec->flags & SEC_RELOC) != 0)
365 /* We aren't prepared to handle relocations in merged sections. */
366 return TRUE;
369 align = sec->alignment_power;
370 if ((sec->entsize < (unsigned) 1 << align
371 && ((sec->entsize & (sec->entsize - 1))
372 || !(sec->flags & SEC_STRINGS)))
373 || (sec->entsize > (unsigned) 1 << align
374 && (sec->entsize & (((unsigned) 1 << align) - 1))))
376 /* Sanity check. If string character size is smaller than
377 alignment, then we require character size to be a power
378 of 2, otherwise character size must be integer multiple
379 of alignment. For non-string constants, alignment must
380 be smaller than or equal to entity size and entity size
381 must be integer multiple of alignment. */
382 return TRUE;
385 for (sinfo = (struct sec_merge_info *) *psinfo; sinfo; sinfo = sinfo->next)
386 if ((secinfo = sinfo->chain)
387 && ! ((secinfo->sec->flags ^ sec->flags) & (SEC_MERGE | SEC_STRINGS))
388 && secinfo->sec->entsize == sec->entsize
389 && secinfo->sec->alignment_power == sec->alignment_power
390 && secinfo->sec->output_section == sec->output_section)
391 break;
393 if (sinfo == NULL)
395 /* Initialize the information we need to keep track of. */
396 sinfo = bfd_alloc (abfd, sizeof (struct sec_merge_info));
397 if (sinfo == NULL)
398 goto error_return;
399 sinfo->next = (struct sec_merge_info *) *psinfo;
400 sinfo->chain = NULL;
401 *psinfo = sinfo;
402 sinfo->htab = sec_merge_init (sec->entsize, (sec->flags & SEC_STRINGS));
403 if (sinfo->htab == NULL)
404 goto error_return;
407 /* Read the section from abfd. */
409 amt = sizeof (struct sec_merge_sec_info) + sec->size - 1;
410 *psecinfo = bfd_alloc (abfd, amt);
411 if (*psecinfo == NULL)
412 goto error_return;
414 secinfo = (struct sec_merge_sec_info *) *psecinfo;
415 if (sinfo->chain)
417 secinfo->next = sinfo->chain->next;
418 sinfo->chain->next = secinfo;
420 else
421 secinfo->next = secinfo;
422 sinfo->chain = secinfo;
423 secinfo->sec = sec;
424 secinfo->psecinfo = psecinfo;
425 secinfo->htab = sinfo->htab;
426 secinfo->first_str = NULL;
428 sec->rawsize = sec->size;
429 if (! bfd_get_section_contents (sec->owner, sec, secinfo->contents,
430 0, sec->size))
431 goto error_return;
433 return TRUE;
435 error_return:
436 *psecinfo = NULL;
437 return FALSE;
440 /* Record one section into the hash table. */
441 static bfd_boolean
442 record_section (struct sec_merge_info *sinfo,
443 struct sec_merge_sec_info *secinfo)
445 asection *sec = secinfo->sec;
446 struct sec_merge_hash_entry *entry;
447 bfd_boolean nul;
448 unsigned char *p, *end;
449 bfd_vma mask, eltalign;
450 unsigned int align, i;
452 align = sec->alignment_power;
453 end = secinfo->contents + sec->size;
454 nul = FALSE;
455 mask = ((bfd_vma) 1 << align) - 1;
456 if (sec->flags & SEC_STRINGS)
458 for (p = secinfo->contents; p < end; )
460 eltalign = p - secinfo->contents;
461 eltalign = ((eltalign ^ (eltalign - 1)) + 1) >> 1;
462 if (!eltalign || eltalign > mask)
463 eltalign = mask + 1;
464 entry = sec_merge_add (sinfo->htab, (char *) p, (unsigned) eltalign,
465 secinfo);
466 if (! entry)
467 goto error_return;
468 p += entry->len;
469 if (sec->entsize == 1)
471 while (p < end && *p == 0)
473 if (!nul && !((p - secinfo->contents) & mask))
475 nul = TRUE;
476 entry = sec_merge_add (sinfo->htab, "",
477 (unsigned) mask + 1, secinfo);
478 if (! entry)
479 goto error_return;
481 p++;
484 else
486 while (p < end)
488 for (i = 0; i < sec->entsize; i++)
489 if (p[i] != '\0')
490 break;
491 if (i != sec->entsize)
492 break;
493 if (!nul && !((p - secinfo->contents) & mask))
495 nul = TRUE;
496 entry = sec_merge_add (sinfo->htab, (char *) p,
497 (unsigned) mask + 1, secinfo);
498 if (! entry)
499 goto error_return;
501 p += sec->entsize;
506 else
508 for (p = secinfo->contents; p < end; p += sec->entsize)
510 entry = sec_merge_add (sinfo->htab, (char *) p, 1, secinfo);
511 if (! entry)
512 goto error_return;
516 return TRUE;
518 error_return:
519 for (secinfo = sinfo->chain; secinfo; secinfo = secinfo->next)
520 *secinfo->psecinfo = NULL;
521 return FALSE;
524 static int
525 strrevcmp (const void *a, const void *b)
527 struct sec_merge_hash_entry *A = *(struct sec_merge_hash_entry **) a;
528 struct sec_merge_hash_entry *B = *(struct sec_merge_hash_entry **) b;
529 unsigned int lenA = A->len;
530 unsigned int lenB = B->len;
531 const unsigned char *s = (const unsigned char *) A->root.string + lenA - 1;
532 const unsigned char *t = (const unsigned char *) B->root.string + lenB - 1;
533 int l = lenA < lenB ? lenA : lenB;
535 while (l)
537 if (*s != *t)
538 return (int) *s - (int) *t;
539 s--;
540 t--;
541 l--;
543 return lenA - lenB;
546 /* Like strrevcmp, but for the case where all strings have the same
547 alignment > entsize. */
549 static int
550 strrevcmp_align (const void *a, const void *b)
552 struct sec_merge_hash_entry *A = *(struct sec_merge_hash_entry **) a;
553 struct sec_merge_hash_entry *B = *(struct sec_merge_hash_entry **) b;
554 unsigned int lenA = A->len;
555 unsigned int lenB = B->len;
556 const unsigned char *s = (const unsigned char *) A->root.string + lenA - 1;
557 const unsigned char *t = (const unsigned char *) B->root.string + lenB - 1;
558 int l = lenA < lenB ? lenA : lenB;
559 int tail_align = (lenA & (A->alignment - 1)) - (lenB & (A->alignment - 1));
561 if (tail_align != 0)
562 return tail_align;
564 while (l)
566 if (*s != *t)
567 return (int) *s - (int) *t;
568 s--;
569 t--;
570 l--;
572 return lenA - lenB;
575 static inline int
576 is_suffix (const struct sec_merge_hash_entry *A,
577 const struct sec_merge_hash_entry *B)
579 if (A->len <= B->len)
580 /* B cannot be a suffix of A unless A is equal to B, which is guaranteed
581 not to be equal by the hash table. */
582 return 0;
584 return memcmp (A->root.string + (A->len - B->len),
585 B->root.string, B->len) == 0;
588 /* This is a helper function for _bfd_merge_sections. It attempts to
589 merge strings matching suffixes of longer strings. */
590 static void
591 merge_strings (struct sec_merge_info *sinfo)
593 struct sec_merge_hash_entry **array, **a, *e;
594 struct sec_merge_sec_info *secinfo;
595 bfd_size_type size, amt;
596 unsigned int alignment = 0;
598 /* Now sort the strings */
599 amt = sinfo->htab->size * sizeof (struct sec_merge_hash_entry *);
600 array = bfd_malloc (amt);
601 if (array == NULL)
602 goto alloc_failure;
604 for (e = sinfo->htab->first, a = array; e; e = e->next)
605 if (e->alignment)
607 *a++ = e;
608 /* Adjust the length to not include the zero terminator. */
609 e->len -= sinfo->htab->entsize;
610 if (alignment != e->alignment)
612 if (alignment == 0)
613 alignment = e->alignment;
614 else
615 alignment = (unsigned) -1;
619 sinfo->htab->size = a - array;
620 if (sinfo->htab->size != 0)
622 qsort (array, (size_t) sinfo->htab->size,
623 sizeof (struct sec_merge_hash_entry *),
624 (alignment != (unsigned) -1 && alignment > sinfo->htab->entsize
625 ? strrevcmp_align : strrevcmp));
627 /* Loop over the sorted array and merge suffixes */
628 e = *--a;
629 e->len += sinfo->htab->entsize;
630 while (--a >= array)
632 struct sec_merge_hash_entry *cmp = *a;
634 cmp->len += sinfo->htab->entsize;
635 if (e->alignment >= cmp->alignment
636 && !((e->len - cmp->len) & (cmp->alignment - 1))
637 && is_suffix (e, cmp))
639 cmp->u.suffix = e;
640 cmp->alignment = 0;
642 else
643 e = cmp;
647 alloc_failure:
648 if (array)
649 free (array);
651 /* Now assign positions to the strings we want to keep. */
652 size = 0;
653 secinfo = sinfo->htab->first->secinfo;
654 for (e = sinfo->htab->first; e; e = e->next)
656 if (e->secinfo != secinfo)
658 secinfo->sec->size = size;
659 secinfo = e->secinfo;
661 if (e->alignment)
663 if (e->secinfo->first_str == NULL)
665 e->secinfo->first_str = e;
666 size = 0;
668 size = (size + e->alignment - 1) & ~((bfd_vma) e->alignment - 1);
669 e->u.index = size;
670 size += e->len;
673 secinfo->sec->size = size;
674 if (secinfo->sec->alignment_power != 0)
676 bfd_size_type align = (bfd_size_type) 1 << secinfo->sec->alignment_power;
677 secinfo->sec->size = (secinfo->sec->size + align - 1) & -align;
680 /* And now adjust the rest, removing them from the chain (but not hashtable)
681 at the same time. */
682 for (a = &sinfo->htab->first, e = *a; e; e = e->next)
683 if (e->alignment)
684 a = &e->next;
685 else
687 *a = e->next;
688 if (e->len)
690 e->secinfo = e->u.suffix->secinfo;
691 e->alignment = e->u.suffix->alignment;
692 e->u.index = e->u.suffix->u.index + (e->u.suffix->len - e->len);
697 /* This function is called once after all SEC_MERGE sections are registered
698 with _bfd_merge_section. */
700 bfd_boolean
701 _bfd_merge_sections (bfd *abfd ATTRIBUTE_UNUSED,
702 struct bfd_link_info *info ATTRIBUTE_UNUSED,
703 void *xsinfo,
704 void (*remove_hook) (bfd *, asection *))
706 struct sec_merge_info *sinfo;
708 for (sinfo = (struct sec_merge_info *) xsinfo; sinfo; sinfo = sinfo->next)
710 struct sec_merge_sec_info * secinfo;
712 if (! sinfo->chain)
713 continue;
715 /* Move sinfo->chain to head of the chain, terminate it. */
716 secinfo = sinfo->chain;
717 sinfo->chain = secinfo->next;
718 secinfo->next = NULL;
720 /* Record the sections into the hash table. */
721 for (secinfo = sinfo->chain; secinfo; secinfo = secinfo->next)
722 if (secinfo->sec->flags & SEC_EXCLUDE)
724 *secinfo->psecinfo = NULL;
725 if (remove_hook)
726 (*remove_hook) (abfd, secinfo->sec);
728 else if (! record_section (sinfo, secinfo))
729 break;
731 if (secinfo)
732 continue;
734 if (sinfo->htab->first == NULL)
735 continue;
737 if (sinfo->htab->strings)
738 merge_strings (sinfo);
739 else
741 struct sec_merge_hash_entry *e;
742 bfd_size_type size = 0;
744 /* Things are much simpler for non-strings.
745 Just assign them slots in the section. */
746 secinfo = NULL;
747 for (e = sinfo->htab->first; e; e = e->next)
749 if (e->secinfo->first_str == NULL)
751 if (secinfo)
752 secinfo->sec->size = size;
753 e->secinfo->first_str = e;
754 size = 0;
756 size = (size + e->alignment - 1)
757 & ~((bfd_vma) e->alignment - 1);
758 e->u.index = size;
759 size += e->len;
760 secinfo = e->secinfo;
762 secinfo->sec->size = size;
765 /* Finally remove all input sections which have not made it into
766 the hash table at all. */
767 for (secinfo = sinfo->chain; secinfo; secinfo = secinfo->next)
768 if (secinfo->first_str == NULL)
769 secinfo->sec->flags |= SEC_EXCLUDE;
772 return TRUE;
775 /* Write out the merged section. */
777 bfd_boolean
778 _bfd_write_merged_section (bfd *output_bfd, asection *sec, void *psecinfo)
780 struct sec_merge_sec_info *secinfo;
781 file_ptr pos;
783 secinfo = (struct sec_merge_sec_info *) psecinfo;
785 if (secinfo->first_str == NULL)
786 return TRUE;
788 pos = sec->output_section->filepos + sec->output_offset;
789 if (bfd_seek (output_bfd, pos, SEEK_SET) != 0)
790 return FALSE;
792 if (! sec_merge_emit (output_bfd, secinfo->first_str))
793 return FALSE;
795 return TRUE;
798 /* Adjust an address in the SEC_MERGE section. Given OFFSET within
799 *PSEC, this returns the new offset in the adjusted SEC_MERGE
800 section and writes the new section back into *PSEC. */
802 bfd_vma
803 _bfd_merged_section_offset (bfd *output_bfd ATTRIBUTE_UNUSED, asection **psec,
804 void *psecinfo, bfd_vma offset)
806 struct sec_merge_sec_info *secinfo;
807 struct sec_merge_hash_entry *entry;
808 unsigned char *p;
809 asection *sec = *psec;
811 secinfo = (struct sec_merge_sec_info *) psecinfo;
813 if (offset >= sec->rawsize)
815 if (offset > sec->rawsize)
817 (*_bfd_error_handler)
818 (_("%s: access beyond end of merged section (%ld)"),
819 bfd_get_filename (sec->owner), (long) offset);
821 return secinfo->first_str ? sec->size : 0;
824 if (secinfo->htab->strings)
826 if (sec->entsize == 1)
828 p = secinfo->contents + offset - 1;
829 while (p >= secinfo->contents && *p)
830 --p;
831 ++p;
833 else
835 p = secinfo->contents + (offset / sec->entsize) * sec->entsize;
836 p -= sec->entsize;
837 while (p >= secinfo->contents)
839 unsigned int i;
841 for (i = 0; i < sec->entsize; ++i)
842 if (p[i] != '\0')
843 break;
844 if (i == sec->entsize)
845 break;
846 p -= sec->entsize;
848 p += sec->entsize;
851 else
853 p = secinfo->contents + (offset / sec->entsize) * sec->entsize;
855 entry = sec_merge_hash_lookup (secinfo->htab, (char *) p, 0, FALSE);
856 if (!entry)
858 if (! secinfo->htab->strings)
859 abort ();
860 /* This should only happen if somebody points into the padding
861 after a NUL character but before next entity. */
862 if (*p)
863 abort ();
864 if (! secinfo->htab->first)
865 abort ();
866 entry = secinfo->htab->first;
867 p = (secinfo->contents + (offset / sec->entsize + 1) * sec->entsize
868 - entry->len);
871 *psec = entry->secinfo->sec;
872 return entry->u.index + (secinfo->contents + offset - p);