aboutsummaryrefslogtreecommitdiff
path: root/gas
diff options
context:
space:
mode:
authorIain Sandoe <iain@codesourcery.com>2012-01-09 10:47:50 +0000
committerIain Sandoe <iain@codesourcery.com>2012-01-09 10:47:50 +0000
commitb22161d698a0541ddede4074f85dad037d72af05 (patch)
tree53cf2020927eaf6eb69edecb085e14ae1ed33713 /gas
parent9f2f828a179a3c726c880ab151ffd297c3c966aa (diff)
downloadgdb-b22161d698a0541ddede4074f85dad037d72af05.zip
gdb-b22161d698a0541ddede4074f85dad037d72af05.tar.gz
gdb-b22161d698a0541ddede4074f85dad037d72af05.tar.bz2
add symbol qualifiers for mach-o to bfd/gas
bfd: * mach-o.c (bfd_mach_o_bfd_copy_private_symbol_data): Implement. (bfd_mach_o_write_symtab): Remove handling for indirect syms. (bfd_mach_o_primary_symbol_sort_key): Likewise. (bfd_mach_o_cf_symbols): Likewise. (bfd_mach_o_sort_symbol_table): Remove. (bfd_mach_o_mangle_symbols): Adjust arguments, remove handling for indirect and dysymtab counts. Do the symbol sorting here. (bfd_mach_o_build_dysymtab_command): Count the symbol types here. Make the indirect symbols a TODO. (bfd_mach_o_build_commands): Adjust call to bfd_mach_o_mangle_symbols. (bfd_mach_o_make_empty_symbol): Specifically flag unset symbols with a non-zero value. (bfd_mach_o_read_symtab_symbol): Record the symbol index. (bfd_mach_o_read_symtab_symbol): Adjust recording of global status. * mach-o.h (mach_o_data_struct): Remove indirect and dysymtab entries. (IS_MACHO_INDIRECT): Remove. (SYM_MACHO_FIELDS_UNSET, SYM_MACHO_FIELDS_NOT_VALIDATED): New. gas: * config/obj-macho.c (obj_mach_o_weak): Remove. (obj_mach_o_common_parse): Set symbol qualifiers. (LAZY, REFE): New macros. (obj_mach_o_symbol_type): New enum. (obj_mach_o_set_symbol_qualifier): New. (obj_mach_o_sym_qual): New. (mach_o_pseudo_table): Add symbol qualifiers, set indirect_symbol to a dummy function. (obj_mach_o_type_for_symbol): New. (obj_macho_frob_label): New. (obj_macho_frob_symbol): New. * config/obj-macho.h (S_SET_ALIGN): Amend temorary var name. (obj_frob_label, obj_macho_frob_label): Declare. (obj_frob_symbol, obj_macho_frob_symbol): Declare. gas/testsuite: * gas/mach-o/err-syms-1.s: New. * gas/mach-o/err-syms-2.s: New. * gas/mach-o/err-syms-3.s: New. * gas/mach-o/symbols-2.d: New. * gas/mach-o/symbols-2.s: New. * gas/mach-o/symbols-3.s: New. * gas/mach-o/symbols-4.s: New. * gas/mach-o/symbols-5.d: New. * gas/mach-o/symbols-5.s: New.
Diffstat (limited to 'gas')
-rw-r--r--gas/ChangeLog17
-rw-r--r--gas/config/obj-macho.c371
-rw-r--r--gas/config/obj-macho.h10
-rw-r--r--gas/testsuite/ChangeLog12
-rw-r--r--gas/testsuite/gas/mach-o/err-syms-1.s12
-rw-r--r--gas/testsuite/gas/mach-o/err-syms-2.s15
-rw-r--r--gas/testsuite/gas/mach-o/err-syms-3.s10
-rw-r--r--gas/testsuite/gas/mach-o/symbols-2.d7
-rw-r--r--gas/testsuite/gas/mach-o/symbols-2.s9
-rw-r--r--gas/testsuite/gas/mach-o/symbols-3.s111
-rw-r--r--gas/testsuite/gas/mach-o/symbols-4.s65
-rw-r--r--gas/testsuite/gas/mach-o/symbols-5.d11
-rw-r--r--gas/testsuite/gas/mach-o/symbols-5.s17
13 files changed, 633 insertions, 34 deletions
diff --git a/gas/ChangeLog b/gas/ChangeLog
index c905439..1d72c39 100644
--- a/gas/ChangeLog
+++ b/gas/ChangeLog
@@ -1,3 +1,20 @@
+2012-01-09 Iain Sandoe <idsandoe@googlemail.com>
+
+ * config/obj-macho.c (obj_mach_o_weak): Remove.
+ (obj_mach_o_common_parse): Set symbol qualifiers.
+ (LAZY, REFE): New macros.
+ (obj_mach_o_symbol_type): New enum.
+ (obj_mach_o_set_symbol_qualifier): New.
+ (obj_mach_o_sym_qual): New.
+ (mach_o_pseudo_table): Add symbol qualifiers, set indirect_symbol to
+ a dummy function.
+ (obj_mach_o_type_for_symbol): New.
+ (obj_macho_frob_label): New.
+ (obj_macho_frob_symbol): New.
+ * config/obj-macho.h (S_SET_ALIGN): Amend temorary var name.
+ (obj_frob_label, obj_macho_frob_label): Declare.
+ (obj_frob_symbol, obj_macho_frob_symbol): Declare.
+
2012-01-08 Richard Sandiford <rdsandiford@googlemail.com>
* config/tc-mips.c (s_tls_rel_directive): Call mips_clear_insn_labels.
diff --git a/gas/config/obj-macho.c b/gas/config/obj-macho.c
index b523767..43f4fba 100644
--- a/gas/config/obj-macho.c
+++ b/gas/config/obj-macho.c
@@ -82,33 +82,8 @@ mach_o_begin (void)
/* Remember the subsections_by_symbols state in case we need to reset
the file flags. */
-static int obj_mach_o_subsections_by_symbols;
-static void
-obj_mach_o_weak (int ignore ATTRIBUTE_UNUSED)
-{
- char *name;
- int c;
- symbolS *symbolP;
-
- do
- {
- /* Get symbol name. */
- name = input_line_pointer;
- c = get_symbol_end ();
- symbolP = symbol_find_or_make (name);
- S_SET_WEAK (symbolP);
- *input_line_pointer = c;
- SKIP_WHITESPACE ();
-
- if (c != ',')
- break;
- input_line_pointer++;
- SKIP_WHITESPACE ();
- }
- while (*input_line_pointer != '\n');
- demand_empty_rest_of_line ();
-}
+static int obj_mach_o_subsections_by_symbols;
/* This will put at most 16 characters (terminated by a ',' or newline) from
the input stream into dest. If there are more than 16 chars before the
@@ -901,6 +876,7 @@ obj_mach_o_common_parse (int is_local, symbolS *symbolP,
addressT size)
{
addressT align = 0;
+ bfd_mach_o_asymbol *s;
SKIP_WHITESPACE ();
@@ -920,6 +896,7 @@ obj_mach_o_common_parse (int is_local, symbolS *symbolP,
}
}
+ s = (bfd_mach_o_asymbol *) symbol_get_bfdsym (symbolP);
if (is_local)
{
/* Create the BSS section on demand. */
@@ -929,6 +906,7 @@ obj_mach_o_common_parse (int is_local, symbolS *symbolP,
seg_info (bss_section)->bss = 1;
}
bss_alloc (symbolP, size, align);
+ s->n_type = BFD_MACH_O_N_SECT;
S_CLEAR_EXTERNAL (symbolP);
}
else
@@ -937,9 +915,14 @@ obj_mach_o_common_parse (int is_local, symbolS *symbolP,
S_SET_ALIGN (symbolP, align);
S_SET_EXTERNAL (symbolP);
S_SET_SEGMENT (symbolP, bfd_com_section_ptr);
+ s->n_type = BFD_MACH_O_N_UNDF | BFD_MACH_O_N_EXT;
}
- symbol_get_bfdsym (symbolP)->flags |= BSF_OBJECT;
+ /* This is a data object (whatever we choose that to mean). */
+ s->symbol.flags |= BSF_OBJECT;
+
+ /* We've set symbol qualifiers, so validate if you can. */
+ s->symbol.udata.i = SYM_MACHO_FIELDS_NOT_VALIDATED;
return symbolP;
}
@@ -979,6 +962,175 @@ obj_mach_o_fileprop (int prop)
}
}
+/* Temporary markers for symbol reference data.
+ Lazy will remain in place. */
+#define LAZY 0x01
+#define REFE 0x02
+
+/* We have a bunch of qualifiers that may be applied to symbols.
+ .globl is handled here so that we might make sure that conflicting qualifiers
+ are caught where possible. */
+
+typedef enum obj_mach_o_symbol_type {
+ OBJ_MACH_O_SYM_UNK = 0,
+ OBJ_MACH_O_SYM_LOCAL = 1,
+ OBJ_MACH_O_SYM_GLOBL = 2,
+ OBJ_MACH_O_SYM_REFERENCE = 3,
+ OBJ_MACH_O_SYM_WEAK_REF = 4,
+ OBJ_MACH_O_SYM_LAZY_REF = 5,
+ OBJ_MACH_O_SYM_WEAK_DEF = 6,
+ OBJ_MACH_O_SYM_PRIV_EXT = 7,
+ OBJ_MACH_O_SYM_NO_DEAD_STRIP = 8,
+ OBJ_MACH_O_SYM_WEAK = 9
+} obj_mach_o_symbol_type;
+
+/* Set Mach-O-specific symbol qualifiers. */
+
+static int
+obj_mach_o_set_symbol_qualifier (symbolS *sym, int type)
+{
+ int is_defined;
+ bfd_mach_o_asymbol *s = (bfd_mach_o_asymbol *) symbol_get_bfdsym (sym);
+ bfd_mach_o_section *sec;
+ int sectype = -1;
+ int err = 0;
+
+ /* If the symbol is defined, then we can do more rigorous checking on
+ the validity of the qualifiers. Otherwise, we are stuck with waiting
+ until it's defined - or until write the file.
+
+ In certain cases (e.g. when a symbol qualifier is intended to introduce
+ an undefined symbol in a stubs section) we should check that the current
+ section is appropriate to the qualifier. */
+
+ is_defined = s->symbol.section != bfd_und_section_ptr;
+ if (is_defined)
+ sec = bfd_mach_o_get_mach_o_section (s->symbol.section) ;
+ else
+ sec = bfd_mach_o_get_mach_o_section (now_seg) ;
+
+ if (sec != NULL)
+ sectype = sec->flags & BFD_MACH_O_SECTION_TYPE_MASK;
+
+ switch ((obj_mach_o_symbol_type) type)
+ {
+ case OBJ_MACH_O_SYM_LOCAL:
+ /* This is an extension over the system tools. */
+ if (s->n_type & (BFD_MACH_O_N_PEXT | BFD_MACH_O_N_EXT))
+ {
+ as_bad (_("'%s' previously declared as '%s'."), s->symbol.name,
+ (s->n_type & BFD_MACH_O_N_PEXT) ? "private extern"
+ : "global" );
+ err = 1;
+ }
+ else
+ {
+ s->n_type &= ~BFD_MACH_O_N_EXT;
+ S_CLEAR_EXTERNAL (sym);
+ }
+ break;
+
+ case OBJ_MACH_O_SYM_PRIV_EXT:
+ s->n_type |= BFD_MACH_O_N_PEXT ;
+ /* We follow the system tools in marking PEXT as also global. */
+ /* Fall through. */
+
+ case OBJ_MACH_O_SYM_GLOBL:
+ /* It's not an error to define a symbol and then make it global. */
+ s->n_type |= BFD_MACH_O_N_EXT;
+ S_SET_EXTERNAL (sym);
+ break;
+
+ case OBJ_MACH_O_SYM_REFERENCE:
+ if (is_defined)
+ s->n_desc |= BFD_MACH_O_N_NO_DEAD_STRIP;
+ else
+ s->n_desc |= (REFE | BFD_MACH_O_N_NO_DEAD_STRIP);
+ break;
+
+ case OBJ_MACH_O_SYM_LAZY_REF:
+ if (is_defined)
+ s->n_desc |= BFD_MACH_O_N_NO_DEAD_STRIP;
+ else
+ s->n_desc |= (REFE | LAZY | BFD_MACH_O_N_NO_DEAD_STRIP);
+ break;
+
+ /* Force ld to retain the symbol - even if it appears unused. */
+ case OBJ_MACH_O_SYM_NO_DEAD_STRIP:
+ s->n_desc |= BFD_MACH_O_N_NO_DEAD_STRIP ;
+ break;
+
+ /* Mach-O's idea of weak ... */
+ case OBJ_MACH_O_SYM_WEAK_REF:
+ s->n_desc |= BFD_MACH_O_N_WEAK_REF ;
+ break;
+
+ case OBJ_MACH_O_SYM_WEAK_DEF:
+ if (is_defined && sectype != BFD_MACH_O_S_COALESCED)
+ {
+ as_bad (_("'%s' can't be a weak_definition (currently only"
+ " supported in sections of type coalesced)"),
+ s->symbol.name);
+ err = 1;
+ }
+ else
+ s->n_desc |= BFD_MACH_O_N_WEAK_DEF;
+ break;
+
+ case OBJ_MACH_O_SYM_WEAK:
+ /* A generic 'weak' - we try to figure out what it means at
+ symbol frob time. */
+ S_SET_WEAK (sym);
+ break;
+
+ default:
+ break;
+ }
+
+ /* We've seen some kind of qualifier - check validity if or when the entity
+ is defined. */
+ s->symbol.udata.i = SYM_MACHO_FIELDS_NOT_VALIDATED;
+ return err;
+}
+
+/* Respond to symbol qualifiers.
+ All of the form:
+ .<qualifier> symbol [, symbol]*
+ a list of symbols is an extension over the Darwin system as. */
+
+static void
+obj_mach_o_sym_qual (int ntype)
+{
+ char *name;
+ char c;
+ symbolS *symbolP;
+
+#ifdef md_flush_pending_output
+ md_flush_pending_output ();
+#endif
+
+ do
+ {
+ name = input_line_pointer;
+ c = get_symbol_end ();
+ symbolP = symbol_find_or_make (name);
+ obj_mach_o_set_symbol_qualifier (symbolP, ntype);
+ *input_line_pointer = c;
+ SKIP_WHITESPACE ();
+ c = *input_line_pointer;
+ if (c == ',')
+ {
+ input_line_pointer++;
+ SKIP_WHITESPACE ();
+ if (is_end_of_line[(unsigned char) *input_line_pointer])
+ c = '\n';
+ }
+ }
+ while (c == ',');
+
+ demand_empty_rest_of_line ();
+}
+
/* Dummy function to allow test-code to work while we are working
on things. */
@@ -1068,11 +1220,18 @@ const pseudo_typeS mach_o_pseudo_table[] =
{ "section", obj_mach_o_section, 0},
{ "zerofill", obj_mach_o_zerofill, 0},
- /* Symbol-related. */
- { "indirect_symbol", obj_mach_o_placeholder, 0},
- { "weak_definition", obj_mach_o_placeholder, 0},
- { "private_extern", obj_mach_o_placeholder, 0},
- { "weak", obj_mach_o_weak, 0}, /* extension */
+ /* Symbol qualifiers. */
+ {"local", obj_mach_o_sym_qual, OBJ_MACH_O_SYM_LOCAL},
+ {"globl", obj_mach_o_sym_qual, OBJ_MACH_O_SYM_GLOBL},
+ {"reference", obj_mach_o_sym_qual, OBJ_MACH_O_SYM_REFERENCE},
+ {"weak_reference", obj_mach_o_sym_qual, OBJ_MACH_O_SYM_WEAK_REF},
+ {"lazy_reference", obj_mach_o_sym_qual, OBJ_MACH_O_SYM_LAZY_REF},
+ {"weak_definition", obj_mach_o_sym_qual, OBJ_MACH_O_SYM_WEAK_DEF},
+ {"private_extern", obj_mach_o_sym_qual, OBJ_MACH_O_SYM_PRIV_EXT},
+ {"no_dead_strip", obj_mach_o_sym_qual, OBJ_MACH_O_SYM_NO_DEAD_STRIP},
+ {"weak", obj_mach_o_sym_qual, OBJ_MACH_O_SYM_WEAK}, /* ext */
+
+ {"indirect_symbol", obj_mach_o_placeholder, 0},
/* File flags. */
{ "subsections_via_symbols", obj_mach_o_fileprop,
@@ -1081,6 +1240,154 @@ const pseudo_typeS mach_o_pseudo_table[] =
{NULL, NULL, 0}
};
+/* Determine the default n_type value for a symbol from its section. */
+
+static unsigned
+obj_mach_o_type_for_symbol (bfd_mach_o_asymbol *s)
+{
+ if (s->symbol.section == bfd_abs_section_ptr)
+ return BFD_MACH_O_N_ABS;
+ else if (s->symbol.section == bfd_com_section_ptr
+ || s->symbol.section == bfd_und_section_ptr)
+ return BFD_MACH_O_N_UNDF;
+ else
+ return BFD_MACH_O_N_SECT;
+}
+
+/* We need to check the correspondence between some kinds of symbols and their
+ sections. Common and BSS vars will seen via the obj_macho_comm() function.
+
+ The earlier we can pick up a problem, the better the diagnostics will be.
+
+ However, when symbol type information is attached, the symbol section will
+ quite possibly be unknown. So we are stuck with checking (most of the)
+ validity at the time the file is written (unfortunately, then one doesn't
+ get line number information in the diagnostic). */
+
+/* Here we pick up the case where symbol qualifiers have been applied that
+ are possibly incompatible with the section etc. that the symbol is defined
+ in. */
+
+void obj_macho_frob_label (struct symbol *sp)
+{
+ bfd_mach_o_asymbol *s = (bfd_mach_o_asymbol *) symbol_get_bfdsym (sp);
+ /* This is the base symbol type, that we mask in. */
+ unsigned base_type = obj_mach_o_type_for_symbol (s);
+ bfd_mach_o_section *sec = bfd_mach_o_get_mach_o_section (s->symbol.section);
+ int sectype = -1;
+
+ if ((s->n_type & BFD_MACH_O_N_STAB) != 0)
+ return; /* Leave alone. */
+
+ if (sec != NULL)
+ sectype = sec->flags & BFD_MACH_O_SECTION_TYPE_MASK;
+
+ /* If there is a pre-existing qualifier, we can make some checks about
+ validity now. */
+
+ if(s->symbol.udata.i == SYM_MACHO_FIELDS_NOT_VALIDATED)
+ {
+ if ((s->n_desc & BFD_MACH_O_N_WEAK_DEF)
+ && sectype != BFD_MACH_O_S_COALESCED)
+ as_bad (_("'%s' can't be a weak_definition (currently only supported"
+ " in sections of type coalesced)"), s->symbol.name);
+
+ /* Have we changed from an undefined to defined ref? */
+ s->n_desc &= ~(REFE | LAZY);
+ }
+
+ s->n_type &= ~BFD_MACH_O_N_TYPE;
+ s->n_type |= base_type;
+}
+
+/* This is the fall-back, we come here when we get to the end of the file and
+ the symbol is not defined - or there are combinations of qualifiers required
+ (e.g. global + weak_def). */
+
+int
+obj_macho_frob_symbol (struct symbol *sp)
+{
+ bfd_mach_o_asymbol *s = (bfd_mach_o_asymbol *) symbol_get_bfdsym (sp);
+ unsigned base_type = obj_mach_o_type_for_symbol (s);
+ bfd_mach_o_section *sec = bfd_mach_o_get_mach_o_section (s->symbol.section);
+ int sectype = -1;
+
+ if (sec != NULL)
+ sectype = sec->flags & BFD_MACH_O_SECTION_TYPE_MASK;
+
+ if ((s->n_type & BFD_MACH_O_N_STAB) != 0)
+ return 0; /* Leave alone. */
+ else if (s->symbol.section == bfd_und_section_ptr)
+ {
+ /* ??? Do we really gain much from implementing this as well as the
+ mach-o specific ones? */
+ if (s->symbol.flags & BSF_WEAK)
+ s->n_desc |= BFD_MACH_O_N_WEAK_REF;
+
+ /* Undefined references, become extern. */
+ if (s->n_desc & REFE)
+ {
+ s->n_desc &= ~REFE;
+ s->n_type |= BFD_MACH_O_N_EXT;
+ }
+
+ /* So do undefined 'no_dead_strip's. */
+ if (s->n_desc & BFD_MACH_O_N_NO_DEAD_STRIP)
+ s->n_type |= BFD_MACH_O_N_EXT;
+
+ }
+ else
+ {
+ if ((s->symbol.flags & BSF_WEAK)
+ && (sectype == BFD_MACH_O_S_COALESCED)
+ && (s->n_type & (BFD_MACH_O_N_PEXT | BFD_MACH_O_N_EXT)))
+ s->n_desc |= BFD_MACH_O_N_WEAK_DEF;
+/* ??? we should do this - but then that reveals that the semantics of weak
+ are different from what's supported in mach-o object files.
+ else
+ as_bad (_("'%s' can't be a weak_definition."),
+ s->symbol.name); */
+ }
+
+ if (s->symbol.udata.i == SYM_MACHO_FIELDS_UNSET)
+ {
+ /* Anything here that should be added that is non-standard. */
+ s->n_desc &= ~BFD_MACH_O_REFERENCE_MASK;
+ }
+ else if (s->symbol.udata.i == SYM_MACHO_FIELDS_NOT_VALIDATED)
+ {
+ /* Try to validate any combinations. */
+ if (s->n_desc & BFD_MACH_O_N_WEAK_DEF)
+ {
+ if (s->symbol.section == bfd_und_section_ptr)
+ as_bad (_("'%s' can't be a weak_definition (since it is"
+ " undefined)"), s->symbol.name);
+ else if (sectype != BFD_MACH_O_S_COALESCED)
+ as_bad (_("'%s' can't be a weak_definition (currently only supported"
+ " in sections of type coalesced)"), s->symbol.name);
+ else if (! (s->n_type & (BFD_MACH_O_N_PEXT | BFD_MACH_O_N_EXT)))
+ as_bad (_("Non-global symbol: '%s' can't be a weak_definition."),
+ s->symbol.name);
+ }
+
+ }
+ else
+ as_bad (_("internal error: [%s] unexpected code [%lx] in frob symbol"),
+ s->symbol.name, (unsigned long)s->symbol.udata.i);
+
+ s->n_type &= ~BFD_MACH_O_N_TYPE;
+ s->n_type |= base_type;
+
+ if (s->symbol.flags & BSF_GLOBAL)
+ s->n_type |= BFD_MACH_O_N_EXT;
+
+ /* This cuts both ways - we promote some things to external above. */
+ if (s->n_type & (BFD_MACH_O_N_PEXT | BFD_MACH_O_N_EXT))
+ S_SET_EXTERNAL (sp);
+
+ return 0;
+}
+
/* Support stabs for mach-o. */
void
diff --git a/gas/config/obj-macho.h b/gas/config/obj-macho.h
index b2acd17..cbc3a4f 100644
--- a/gas/config/obj-macho.h
+++ b/gas/config/obj-macho.h
@@ -40,8 +40,8 @@ extern void mach_o_begin (void);
/* Common symbols can carry alignment information. */
#ifndef S_SET_ALIGN
#define S_SET_ALIGN(S,V) do {\
- bfd_mach_o_asymbol *s = (bfd_mach_o_asymbol *) symbol_get_bfdsym (S);\
- s->n_desc = (s->n_desc & 0xf0ff) | (((V) & 0x0f) << 8);\
+ bfd_mach_o_asymbol *___s = (bfd_mach_o_asymbol *) symbol_get_bfdsym (S);\
+ ___s->n_desc = (___s->n_desc & 0xf0ff) | (((V) & 0x0f) << 8);\
} while (0)
#endif
@@ -56,6 +56,12 @@ extern const pseudo_typeS mach_o_pseudo_table[];
#define obj_read_begin_hook() {;}
#define obj_symbol_new_hook(s) {;}
+#define obj_frob_label(s) obj_macho_frob_label(s)
+extern void obj_macho_frob_label (struct symbol *);
+
+#define obj_frob_symbol(s, punt) punt = obj_macho_frob_symbol(s)
+extern int obj_macho_frob_symbol (struct symbol *);
+
#define EMIT_SECTION_SYMBOLS 0
#define OBJ_PROCESS_STAB(SEG,W,S,T,O,D) obj_mach_o_process_stab(W,S,T,O,D)
diff --git a/gas/testsuite/ChangeLog b/gas/testsuite/ChangeLog
index c638cdc..3176c0c 100644
--- a/gas/testsuite/ChangeLog
+++ b/gas/testsuite/ChangeLog
@@ -1,3 +1,15 @@
+2012-01-09 Iain Sandoe <idsandoe@googlemail.com>
+
+ * gas/mach-o/err-syms-1.s: New.
+ * gas/mach-o/err-syms-2.s: New.
+ * gas/mach-o/err-syms-3.s: New.
+ * gas/mach-o/symbols-2.d: New.
+ * gas/mach-o/symbols-2.s: New.
+ * gas/mach-o/symbols-3.s: New.
+ * gas/mach-o/symbols-4.s: New.
+ * gas/mach-o/symbols-5.d: New.
+ * gas/mach-o/symbols-5.s: New.
+
2012-01-08 Richard Sandiford <rdsandiford@googlemail.com>
* gas/mips/tls-relw.s, gas/mips/tls-relw.d: New test.
diff --git a/gas/testsuite/gas/mach-o/err-syms-1.s b/gas/testsuite/gas/mach-o/err-syms-1.s
new file mode 100644
index 0000000..84146c7
--- /dev/null
+++ b/gas/testsuite/gas/mach-o/err-syms-1.s
@@ -0,0 +1,12 @@
+# { dg-do assemble }
+
+ .globl a
+a: .space 1
+ .local a
+
+ .private_extern b
+b: .space 1
+ .local b
+
+# { dg-error ".a. previously declared as .global." "" { target *-*-darwin*} 5 }
+# { dg-error ".b. previously declared as .private extern." "" { target *-*-darwin*} 9 }
diff --git a/gas/testsuite/gas/mach-o/err-syms-2.s b/gas/testsuite/gas/mach-o/err-syms-2.s
new file mode 100644
index 0000000..ad4a692
--- /dev/null
+++ b/gas/testsuite/gas/mach-o/err-syms-2.s
@@ -0,0 +1,15 @@
+# { dg-do assemble }
+
+ .section __weak, __weak, coalesced
+
+a: .space 1
+ .weak_definition a
+
+ .weak_definition b
+b: .space 1
+
+ .weak_definition c
+
+# { dg-error "Non-global symbol: .a. can.t be a weak_definition." "" { target *-*-darwin*} 0 }
+# { dg-error "Non-global symbol: .b. can.t be a weak_definition." "" { target *-*-darwin*} 0 }
+# { dg-error ".c. can.t be a weak_definition .since it is undefined." "" { target *-*-darwin*} 0 }
diff --git a/gas/testsuite/gas/mach-o/err-syms-3.s b/gas/testsuite/gas/mach-o/err-syms-3.s
new file mode 100644
index 0000000..8315d86
--- /dev/null
+++ b/gas/testsuite/gas/mach-o/err-syms-3.s
@@ -0,0 +1,10 @@
+# { dg-do assemble }
+
+ .weak_definition a
+a: .space 1
+
+b: .space 1
+ .weak_definition b
+
+# { dg-error ".a. can.t be a weak_definition .currently only supported in sections of type coalesced." "" { target *-*-darwin*} 4 }
+# { dg-error ".b. can.t be a weak_definition .currently only supported in sections of type coalesced." "" { target *-*-darwin*} 7 }
diff --git a/gas/testsuite/gas/mach-o/symbols-2.d b/gas/testsuite/gas/mach-o/symbols-2.d
new file mode 100644
index 0000000..c4bfcbd
--- /dev/null
+++ b/gas/testsuite/gas/mach-o/symbols-2.d
@@ -0,0 +1,7 @@
+#objdump: -t
+# weak_definitions.
+.*: +file format mach-o.*
+#...
+SYMBOL TABLE:
+(00000000)?00000000 g.*1f SECT.*02 0080 \[__weak.__weak\] a
+(00000000)?00000001 g.*0f SECT.*02 0080 \[__weak.__weak\] b
diff --git a/gas/testsuite/gas/mach-o/symbols-2.s b/gas/testsuite/gas/mach-o/symbols-2.s
new file mode 100644
index 0000000..2ba36d1
--- /dev/null
+++ b/gas/testsuite/gas/mach-o/symbols-2.s
@@ -0,0 +1,9 @@
+ .section __weak, __weak, coalesced
+
+ .private_extern a
+ .weak_definition a
+a: .space 1
+
+ .globl b
+ .weak_definition b
+b: .space 1
diff --git a/gas/testsuite/gas/mach-o/symbols-3.s b/gas/testsuite/gas/mach-o/symbols-3.s
new file mode 100644
index 0000000..054fdf6
--- /dev/null
+++ b/gas/testsuite/gas/mach-o/symbols-3.s
@@ -0,0 +1,111 @@
+# indirect references, stubs and {non,}_lazy_symbol_pointer sections.
+# not applicable to x86_64 mach-o.
+
+ .text
+ .globl c
+ .globl c1
+ .globl c2
+c: nop
+c1: nop
+c2: nop
+
+e: nop
+e1: nop
+e2: nop
+
+ .data
+d: .space 8
+d1: .space 8
+d2: .space 8
+
+ .private_extern f
+ .private_extern f1
+ .private_extern f2
+f: .space 8
+f1: .space 8
+f2: .space 8
+
+ .section __dummy, __dummy, symbol_stubs,strip_static_syms,8
+
+ .indirect_symbol a
+La: .space 8
+
+ .indirect_symbol b
+Lb: .space 8
+
+ .indirect_symbol c
+Lc: .space 8
+
+ .indirect_symbol d
+Ld: .space 8
+
+ .indirect_symbol e
+Le: .space 8
+
+ .indirect_symbol f
+Lf: .space 8
+
+ .private_extern g
+ .indirect_symbol g
+Lg: .space 8
+
+ .lazy_symbol_pointer
+
+ .indirect_symbol a1
+La1: .space 4
+
+ .indirect_symbol b1
+Lb1: .space 4
+
+ .indirect_symbol c1
+Lc1: .space 4
+
+ .indirect_symbol d1
+Ld1: .space 4
+
+ .indirect_symbol e1
+Le1: .space 4
+
+ .indirect_symbol f1
+Lf1: .space 4
+
+ .private_extern g1
+ .indirect_symbol g1
+Lg1: .space 4
+
+ .non_lazy_symbol_pointer
+
+ .indirect_symbol a2
+La2: .space 4
+
+ .indirect_symbol b2
+Lb2: .space 4
+
+ .indirect_symbol c2
+Lc2: .space 4
+
+ .indirect_symbol d2
+Ld2: .space 4
+
+ .indirect_symbol e2
+Le2: .space 4
+
+ .indirect_symbol f2
+Lf2: .space 4
+
+ .private_extern g2
+ .indirect_symbol g2
+Lg2: .space 4
+
+ .indirect_symbol f1
+Lf11: .space 4
+
+ .private_extern g1
+ .indirect_symbol g1
+Lg11: .space 4
+
+ .indirect_symbol a2
+La12: .space 4
+
+ .indirect_symbol b2
+Lb12: .space 4
diff --git a/gas/testsuite/gas/mach-o/symbols-4.s b/gas/testsuite/gas/mach-o/symbols-4.s
new file mode 100644
index 0000000..8800806
--- /dev/null
+++ b/gas/testsuite/gas/mach-o/symbols-4.s
@@ -0,0 +1,65 @@
+# Reference & dead strip permutations.
+
+ .text
+
+ .reference ua
+ .lazy_reference ub
+
+ .reference ua1
+ .private_extern ua1
+
+ .private_extern ub1
+ .lazy_reference ub1
+
+c: .space 1
+ .reference c
+
+d: .space 1
+ .lazy_reference d
+
+ .reference c1
+c1: .space 1
+
+ .lazy_reference d1
+d1: .space 1
+
+ .private_extern e
+ .reference e
+
+ .private_extern f
+ .lazy_reference f
+
+g: .space 1
+ .private_extern g
+ .reference g
+
+h: .space 1
+ .private_extern h
+ .lazy_reference h
+
+ .private_extern g1
+ .reference g1
+g1: .space 1
+
+ .private_extern h1
+ .lazy_reference h1
+h1: .space 1
+
+ .no_dead_strip n
+
+ .globl m
+ .no_dead_strip m
+
+ .private_extern p
+ .no_dead_strip p
+
+n1: .space 1
+ .no_dead_strip n1
+
+m1: .space 1
+ .globl m1
+ .no_dead_strip m1
+
+p1: .space 1
+ .private_extern p1
+ .no_dead_strip p1
diff --git a/gas/testsuite/gas/mach-o/symbols-5.d b/gas/testsuite/gas/mach-o/symbols-5.d
new file mode 100644
index 0000000..7f87e74
--- /dev/null
+++ b/gas/testsuite/gas/mach-o/symbols-5.d
@@ -0,0 +1,11 @@
+#objdump: -t
+# globals and private_externs
+.*: +file format mach-o.*
+#...
+SYMBOL TABLE:
+(00000000)?00000000 g.*1f SECT.*01 0000 \[.text\] a
+(00000000)?00000001 g.*0f SECT.*01 0000 \[.text\] b
+(00000000)?00000002 g.*1f SECT.*01 0000 \[.text\] c
+(00000000)?00000000 g.*11 UND.*00 0000 d
+(00000000)?00000000 g.*01 UND.*00 0000 e
+(00000000)?00000000 g.*11 UND.*00 0000 f
diff --git a/gas/testsuite/gas/mach-o/symbols-5.s b/gas/testsuite/gas/mach-o/symbols-5.s
new file mode 100644
index 0000000..a43266d
--- /dev/null
+++ b/gas/testsuite/gas/mach-o/symbols-5.s
@@ -0,0 +1,17 @@
+
+ .private_extern a
+a: .space 1
+
+ .globl b
+b: .space 1
+
+ .private_extern c
+ .globl c
+c: .space 1
+
+ .private_extern d
+
+ .globl e
+
+ .globl f
+ .private_extern f