- /* Invent a section name from the first five chars of the base
- section name and a digit suffix. */
- strncpy (templ, name, sizeof (templ) - 1);
- templ[sizeof (templ) - 1] = '\0';
- if ((sname = bfd_get_unique_section_name (abfd, templ, count)) == NULL
+ /* Invent a section name from the section name and a dotted numeric
+ suffix. */
+ len = strlen (name);
+ tname = (char *) xmalloc (len + 1);
+ memcpy (tname, name, len + 1);
+ /* Remove a dotted number suffix, from a previous split link. */
+ while (len && ISDIGIT (tname[len-1]))
+ len--;
+ if (len > 1 && tname[len-1] == '.')
+ /* It was a dotted number. */
+ tname[len-1] = 0;
+
+ /* We want to use the whole of the original section name for the
+ split name, but coff can be restricted to 8 character names. */
+ if (bfd_family_coff (abfd) && strlen (tname) > 5)
+ {
+ /* Some section names cannot be truncated, as the name is
+ used to locate some other section. */
+ if (CONST_STRNEQ (name, ".stab")
+ || strcmp (name, "$GDB_SYMBOLS$") == 0)
+ {
+ einfo (_ ("%F%P: cannot create split section name for %s\n"), name);
+ /* Silence gcc warnings. einfo exits, so we never reach here. */
+ return NULL;
+ }
+ tname[5] = 0;
+ }
+
+ if ((sname = bfd_get_unique_section_name (abfd, tname, count)) == NULL