+ symbolS *symbolP;
+ bfd_mach_o_asymbol *s;
+
+ switch (what)
+ {
+ case 'd':
+ symbolP = symbol_new ("", now_seg, frag_now_fix (), frag_now);
+ /* Special stabd NULL name indicator. */
+ S_SET_NAME (symbolP, NULL);
+ break;
+
+ case 'n':
+ case 's':
+ symbolP = symbol_new (string, undefined_section, (valueT) 0,
+ &zero_address_frag);
+ pseudo_set (symbolP);
+ break;
+
+ default:
+ as_bad(_("unrecognized stab type '%c'"), (char)what);
+ abort ();
+ break;
+ }
+
+ s = (bfd_mach_o_asymbol *) symbol_get_bfdsym (symbolP);
+ s->n_type = type;
+ s->n_desc = desc;
+ /* For stabd, this will eventually get overwritten by the section number. */
+ s->n_sect = other;
+
+ /* It's a debug symbol. */
+ s->symbol.flags |= BSF_DEBUGGING;
+}
+
+/* Here we count up frags in each subsection (where a sub-section is defined
+ as starting with a non-local symbol).
+ Note that, if there are no non-local symbols in a section, all the frags will
+ be attached as one anonymous subsection. */
+
+static void
+obj_mach_o_set_subsections (bfd *abfd ATTRIBUTE_UNUSED,
+ asection *sec,
+ void *unused ATTRIBUTE_UNUSED)
+{
+ segment_info_type *seginfo = seg_info (sec);
+ symbolS *cur_subsection = NULL;
+ struct obj_mach_o_symbol_data *cur_subsection_data = NULL;
+ fragS *frag;
+ frchainS *chain;
+
+ /* Protect against sections not created by gas. */
+ if (seginfo == NULL)
+ return;
+
+ /* Attach every frag to a subsection. */
+ for (chain = seginfo->frchainP; chain != NULL; chain = chain->frch_next)
+ for (frag = chain->frch_root; frag != NULL; frag = frag->fr_next)
+ {
+ if (frag->obj_frag_data.subsection == NULL)
+ frag->obj_frag_data.subsection = cur_subsection;
+ else
+ {
+ cur_subsection = frag->obj_frag_data.subsection;
+ cur_subsection_data = symbol_get_obj (cur_subsection);
+ cur_subsection_data->subsection_size = 0;
+ }
+ if (cur_subsection_data != NULL)
+ {
+ /* Update subsection size. */
+ cur_subsection_data->subsection_size += frag->fr_fix;
+ }
+ }
+}
+
+/* Handle mach-o subsections-via-symbols counting up frags belonging to each
+ sub-section. */
+
+void
+obj_mach_o_pre_relax_hook (void)
+{
+ bfd_map_over_sections (stdoutput, obj_mach_o_set_subsections, (char *) 0);