}
}
-static void
+static bool
coff_write_auxent_fname (bfd *abfd,
char *str,
union internal_auxent *auxent,
- bfd_size_type *string_size_p)
+ struct bfd_strtab_hash *strtab,
+ bool hash)
{
unsigned int str_length = strlen (str);
unsigned int filnmlen = bfd_coff_filnmlen (abfd);
strncpy (auxent->x_file.x_n.x_fname, str, filnmlen);
else
{
- auxent->x_file.x_n.x_n.x_offset = *string_size_p + STRING_SIZE_SIZE;
+ bfd_size_type indx = _bfd_stringtab_add (strtab, str, hash, false);
+
+ if (indx == (bfd_size_type) -1)
+ return false;
+
+ auxent->x_file.x_n.x_n.x_offset = STRING_SIZE_SIZE + indx;
auxent->x_file.x_n.x_n.x_zeroes = 0;
- *string_size_p += str_length + 1;
}
}
else
if (str_length > filnmlen)
str[filnmlen] = '\0';
}
+
+ return true;
}
-static void
+static bool
coff_fix_symbol_name (bfd *abfd,
asymbol *symbol,
combined_entry_type *native,
- bfd_size_type *string_size_p,
+ struct bfd_strtab_hash *strtab,
+ bool hash,
asection **debug_string_section_p,
bfd_size_type *debug_string_size_p)
{
unsigned int name_length;
char *name = (char *) (symbol->name);
+ bfd_size_type indx;
if (name == NULL)
{
{
if (bfd_coff_force_symnames_in_strings (abfd))
{
- native->u.syment._n._n_n._n_offset =
- (*string_size_p + STRING_SIZE_SIZE);
+ indx = _bfd_stringtab_add (strtab, ".file", hash, false);
+ if (indx == (bfd_size_type) -1)
+ return false;
+
+ native->u.syment._n._n_n._n_offset = STRING_SIZE_SIZE + indx;
native->u.syment._n._n_n._n_zeroes = 0;
- *string_size_p += 6; /* strlen(".file") + 1 */
}
else
strncpy (native->u.syment._n._n_name, ".file", SYMNMLEN);
BFD_ASSERT (! (native + 1)->is_sym);
- coff_write_auxent_fname (abfd, name, &(native + 1)->u.auxent,
- string_size_p);
+ if (!coff_write_auxent_fname (abfd, name, &(native + 1)->u.auxent,
+ strtab, hash))
+ return false;
}
else
{
else if (!bfd_coff_symname_in_debug (abfd, &native->u.syment))
{
- native->u.syment._n._n_n._n_offset = (*string_size_p
- + STRING_SIZE_SIZE);
+ indx = _bfd_stringtab_add (strtab, name, hash, false);
+ if (indx == (bfd_size_type) -1)
+ return false;
+
+ native->u.syment._n._n_n._n_offset = STRING_SIZE_SIZE + indx;
native->u.syment._n._n_n._n_zeroes = 0;
- *string_size_p += name_length + 1;
}
else
{
*debug_string_size_p += name_length + 1 + prefix_len;
}
}
+
+ return true;
}
/* We need to keep track of the symbol index so that when we write out
asymbol *symbol,
combined_entry_type *native,
bfd_vma *written,
- bfd_size_type *string_size_p,
+ struct bfd_strtab_hash *strtab,
+ bool hash,
asection **debug_string_section_p,
bfd_size_type *debug_string_size_p)
{
native->u.syment.n_scnum =
output_section->target_index;
- coff_fix_symbol_name (abfd, symbol, native, string_size_p,
- debug_string_section_p, debug_string_size_p);
+ if (!coff_fix_symbol_name (abfd, symbol, native, strtab, hash,
+ debug_string_section_p, debug_string_size_p))
+ return false;
symesz = bfd_coff_symesz (abfd);
buf = bfd_alloc (abfd, symesz);
if (native->u.syment.n_sclass == C_FILE
&& (native + j + 1)->u.auxent.x_file.x_ftype)
coff_write_auxent_fname (abfd, (char *) (native + j + 1)->extrap,
- &(native + j + 1)->u.auxent, string_size_p);
+ &(native + j + 1)->u.auxent, strtab, hash);
bfd_coff_swap_aux_out (abfd,
&((native + j + 1)->u.auxent),
coff_write_alien_symbol (bfd *abfd,
asymbol *symbol,
struct internal_syment *isym,
- union internal_auxent *iaux,
bfd_vma *written,
- bfd_size_type *string_size_p,
+ struct bfd_strtab_hash *strtab,
+ bool hash,
asection **debug_string_section_p,
bfd_size_type *debug_string_size_p)
{
else
native->u.syment.n_sclass = C_EXT;
- ret = coff_write_symbol (abfd, symbol, native, written, string_size_p,
+ ret = coff_write_symbol (abfd, symbol, native, written, strtab, hash,
debug_string_section_p, debug_string_size_p);
if (isym != NULL)
*isym = native->u.syment;
- if (iaux != NULL && native->u.syment.n_numaux)
- *iaux = native[1].u.auxent;
return ret;
}
coff_write_native_symbol (bfd *abfd,
coff_symbol_type *symbol,
bfd_vma *written,
- bfd_size_type *string_size_p,
+ struct bfd_strtab_hash *strtab,
asection **debug_string_section_p,
bfd_size_type *debug_string_size_p)
{
}
return coff_write_symbol (abfd, &(symbol->symbol), native, written,
- string_size_p, debug_string_section_p,
+ strtab, true, debug_string_section_p,
debug_string_size_p);
}
bool
coff_write_symbols (bfd *abfd)
{
- bfd_size_type string_size;
+ struct bfd_strtab_hash *strtab;
asection *debug_string_section;
bfd_size_type debug_string_size;
unsigned int i;
bfd_vma written = 0;
asymbol **p;
- string_size = 0;
debug_string_section = NULL;
debug_string_size = 0;
+ strtab = _bfd_stringtab_init ();
+ if (strtab == NULL)
+ return false;
+
/* If this target supports long section names, they must be put into
the string table. This is supported by PE. This code must
handle section names just as they are handled in
- coff_write_object_contents. */
+ coff_write_object_contents. This is why we pass hash as FALSE below. */
if (bfd_coff_long_section_names (abfd))
{
asection *o;
for (o = abfd->sections; o != NULL; o = o->next)
- {
- size_t len;
-
- len = strlen (o->name);
- if (len > SCNNMLEN)
- string_size += len + 1;
- }
+ if (strlen (o->name) > SCNNMLEN
+ && _bfd_stringtab_add (strtab, o->name, false, false)
+ == (bfd_size_type) -1)
+ return false;
}
/* Seek to the right place. */
if (c_symbol == (coff_symbol_type *) NULL
|| c_symbol->native == (combined_entry_type *) NULL)
{
- if (!coff_write_alien_symbol (abfd, symbol, NULL, NULL, &written,
- &string_size, &debug_string_section,
+ if (!coff_write_alien_symbol (abfd, symbol, NULL, &written,
+ strtab, true, &debug_string_section,
&debug_string_size))
return false;
}
}
if (!coff_write_native_symbol (abfd, c_symbol, &written,
- &string_size, &debug_string_section,
+ strtab, &debug_string_section,
&debug_string_size))
return false;
}
obj_raw_syment_count (abfd) = written;
- /* Now write out strings. */
- if (string_size != 0)
- {
- unsigned int size = string_size + STRING_SIZE_SIZE;
- bfd_byte buffer[STRING_SIZE_SIZE];
+ /* Now write out strings.
+
+ We would normally not write anything here if there are no strings, but
+ we'll write out 4 so that any stupid coff reader which tries to read the
+ string table even when there isn't one won't croak. */
+ {
+ bfd_byte buffer[STRING_SIZE_SIZE];
#if STRING_SIZE_SIZE == 4
- H_PUT_32 (abfd, size, buffer);
+ H_PUT_32 (abfd, _bfd_stringtab_size (strtab) + STRING_SIZE_SIZE, buffer);
#else
#error Change H_PUT_32
#endif
- if (bfd_bwrite ((void *) buffer, (bfd_size_type) sizeof (buffer), abfd)
- != sizeof (buffer))
- return false;
-
- /* Handle long section names. This code must handle section
- names just as they are handled in coff_write_object_contents. */
- if (bfd_coff_long_section_names (abfd))
- {
- asection *o;
-
- for (o = abfd->sections; o != NULL; o = o->next)
- {
- size_t len;
-
- len = strlen (o->name);
- if (len > SCNNMLEN)
- {
- if (bfd_bwrite (o->name, (bfd_size_type) (len + 1), abfd)
- != len + 1)
- return false;
- }
- }
- }
-
- for (p = abfd->outsymbols, i = 0;
- i < limit;
- i++, p++)
- {
- asymbol *q = *p;
- size_t name_length = strlen (q->name);
- coff_symbol_type *c_symbol = coff_symbol_from (q);
- size_t maxlen;
- bool is_c_file = false;
-
- /* Figure out whether the symbol name should go in the string
- table. Symbol names that are short enough are stored
- directly in the syment structure. File names permit a
- different, longer, length in the syment structure. On
- XCOFF, some symbol names are stored in the .debug section
- rather than in the string table. */
-
- if (c_symbol == NULL
- || c_symbol->native == NULL)
- /* This is not a COFF symbol, so it certainly is not a
- file name, nor does it go in the .debug section. */
- maxlen = bfd_coff_force_symnames_in_strings (abfd) ? 0 : SYMNMLEN;
-
- else if (! c_symbol->native->is_sym)
- maxlen = bfd_coff_force_symnames_in_strings (abfd) ? 0 : SYMNMLEN;
-
- else if (bfd_coff_symname_in_debug (abfd,
- &c_symbol->native->u.syment))
- /* This symbol name is in the XCOFF .debug section.
- Don't write it into the string table. */
- maxlen = name_length;
-
- else if (c_symbol->native->u.syment.n_sclass == C_FILE
- && c_symbol->native->u.syment.n_numaux > 0)
- {
- is_c_file=true;
- if (bfd_coff_force_symnames_in_strings (abfd))
- {
- if (bfd_bwrite (".file", (bfd_size_type) 6, abfd) != 6)
- return false;
- }
- maxlen = bfd_coff_filnmlen (abfd);
- }
- else
- maxlen = bfd_coff_force_symnames_in_strings (abfd) ? 0 : SYMNMLEN;
-
- if (name_length > maxlen)
- {
- if (bfd_bwrite ((void *) (q->name), (bfd_size_type) name_length + 1,
- abfd) != name_length + 1)
- return false;
- }
-
- /* Add strings for C_FILE aux entries. */
- if (is_c_file
- && c_symbol->native->u.syment.n_numaux > 1)
- {
- for (int j = 1; j < c_symbol->native->u.syment.n_numaux; j++)
- {
- char *str;
- size_t str_length;
-
- /* Add strings from aux entries only if this isn't the
- filename auxiliary entry. */
- if (!c_symbol->native[j + 1].u.auxent.x_file.x_ftype)
- continue;
-
- if (c_symbol->native[j + 1].u.auxent.x_file.x_n.x_fname[0] != 0)
- continue;
-
- str = (char *) c_symbol->native[j + 1].extrap;
- str_length = strlen (str);
- if (str_length > maxlen)
- {
- if (bfd_bwrite ((void *) (str), (bfd_size_type) str_length + 1,
- abfd) != str_length + 1)
- return false;
- }
+ if (bfd_bwrite ((void *) buffer, (bfd_size_type) sizeof (buffer), abfd)
+ != sizeof (buffer))
+ return false;
- }
- }
- }
- }
- else
- {
- /* We would normally not write anything here, but we'll write
- out 4 so that any stupid coff reader which tries to read the
- string table even when there isn't one won't croak. */
- unsigned int size = STRING_SIZE_SIZE;
- bfd_byte buffer[STRING_SIZE_SIZE];
+ if (! _bfd_stringtab_emit (abfd, strtab))
+ return false;
+ }
-#if STRING_SIZE_SIZE == 4
- H_PUT_32 (abfd, size, buffer);
-#else
- #error Change H_PUT_32
-#endif
- if (bfd_bwrite ((void *) buffer, (bfd_size_type) STRING_SIZE_SIZE, abfd)
- != STRING_SIZE_SIZE)
- return false;
- }
+ _bfd_stringtab_free (strtab);
/* Make sure the .debug section was created to be the correct size.
We should create it ourselves on the fly, but we don't because
asymbol *sym = bfd_get_outsymbols (sub) [i];
file_ptr pos;
struct internal_syment isym;
- union internal_auxent iaux;
- bfd_size_type string_size = 0, indx;
bfd_vma written = 0;
- bool rewrite = false, hash;
+ bool rewrite = false;
if (! (sym->flags & BSF_LOCAL)
|| (sym->flags & (BSF_SECTION_SYM | BSF_DEBUGGING_RELOC
* symesz;
if (bfd_seek (abfd, pos, SEEK_SET) != 0)
goto error_return;
- if (! coff_write_alien_symbol(abfd, sym, &isym, &iaux, &written,
- &string_size, NULL, NULL))
+ if (! coff_write_alien_symbol(abfd, sym, &isym, &written,
+ flaginfo.strtab,
+ !flaginfo.info->traditional_format,
+ NULL, NULL))
goto error_return;
- hash = !flaginfo.info->traditional_format;
-
- if (string_size >= 6 && isym.n_sclass == C_FILE
- && ! isym._n._n_n._n_zeroes && isym.n_numaux)
- {
- indx = _bfd_stringtab_add (flaginfo.strtab, ".file", hash,
- false);
- if (indx == (bfd_size_type) -1)
- goto error_return;
- isym._n._n_n._n_offset = STRING_SIZE_SIZE + indx;
- bfd_coff_swap_sym_out (abfd, &isym, flaginfo.outsyms);
- if (bfd_seek (abfd, pos, SEEK_SET) != 0
- || bfd_bwrite (flaginfo.outsyms, symesz,
- abfd) != symesz)
- goto error_return;
- string_size -= 6;
- }
-
- if (string_size)
- {
- indx = _bfd_stringtab_add (flaginfo.strtab,
- bfd_asymbol_name (sym), hash,
- false);
- if (indx == (bfd_size_type) -1)
- goto error_return;
- if (isym.n_sclass != C_FILE)
- {
- isym._n._n_n._n_offset = STRING_SIZE_SIZE + indx;
- bfd_coff_swap_sym_out (abfd, &isym, flaginfo.outsyms);
- rewrite = true;
- }
- else
- {
- BFD_ASSERT (isym.n_numaux == 1);
- iaux.x_file.x_n.x_n.x_offset = STRING_SIZE_SIZE + indx;
- bfd_coff_swap_aux_out (abfd, &iaux, isym.n_type, C_FILE,
- 0, 1, flaginfo.outsyms + symesz);
- if (bfd_seek (abfd, pos + symesz, SEEK_SET) != 0
- || bfd_bwrite (flaginfo.outsyms + symesz, symesz,
- abfd) != symesz)
- goto error_return;
- }
- }
-
if (isym.n_sclass == C_FILE)
{
if (flaginfo.last_file_index != -1)