aboutsummaryrefslogtreecommitdiff
path: root/gas
diff options
context:
space:
mode:
authorNick Clifton <nickc@redhat.com>2015-04-30 11:17:55 +0100
committerNick Clifton <nickc@redhat.com>2015-04-30 11:17:55 +0100
commit8b2d793ce5ee03336d6c1d1f30b8d296cbe443de (patch)
tree7583cf0babfe49436be56b4759c7f703bfd59ec3 /gas
parent7ce98c164ed42df085c1b3e08c5261e02320149b (diff)
downloadgdb-8b2d793ce5ee03336d6c1d1f30b8d296cbe443de.zip
gdb-8b2d793ce5ee03336d6c1d1f30b8d296cbe443de.tar.gz
gdb-8b2d793ce5ee03336d6c1d1f30b8d296cbe443de.tar.bz2
GAS ARM: Warn if the user creates a symbol with the same name as an instruction.
PR gas/18347 gas * config/tc-arm.c (md_undefined_symbol): Issue a warning message (if enabled) when the user creates a symbol with the same name as an ARM instruction. (flag_warn_syms): New static variable. (arm_opts): Add mwarn-syms and mno-warn-syms. * doc/c-arm.texi (ARM Options): Document the -m[no-]warn-syms options. tests * gas/arm/pr18347.s: New file: Test case. * gas/arm/pr18347.l: New file: Expected assembler output. * gas/arm/pr18347.d: New file: Test driver.
Diffstat (limited to 'gas')
-rw-r--r--gas/ChangeLog9
-rw-r--r--gas/config/tc-arm.c52
-rw-r--r--gas/doc/c-arm.texi6
-rw-r--r--gas/testsuite/ChangeLog7
-rw-r--r--gas/testsuite/gas/arm/pr18347.d3
-rw-r--r--gas/testsuite/gas/arm/pr18347.l2
-rw-r--r--gas/testsuite/gas/arm/pr18347.s3
7 files changed, 82 insertions, 0 deletions
diff --git a/gas/ChangeLog b/gas/ChangeLog
index 062e13d..9764a24 100644
--- a/gas/ChangeLog
+++ b/gas/ChangeLog
@@ -1,5 +1,14 @@
2015-04-30 Nick Clifton <nickc@redhat.com>
+ PR gas/18347
+ * config/tc-arm.c (md_undefined_symbol): Issue a warning message
+ (if enabled) when the user creates a symbol with the same name as
+ an ARM instruction.
+ (flag_warn_syms): New static variable.
+ (arm_opts): Add mwarn-syms and mno-warn-syms.
+ * doc/c-arm.texi (ARM Options): Document the -m[no-]warn-syms
+ options.
+
PR gas/18353
* doc/as.texinfo (Zero): Add documentation of the .zero pseudo-op.
diff --git a/gas/config/tc-arm.c b/gas/config/tc-arm.c
index bc8f775..2f6fea6 100644
--- a/gas/config/tc-arm.c
+++ b/gas/config/tc-arm.c
@@ -21623,6 +21623,8 @@ md_pcrel_from_section (fixS * fixP, segT seg)
}
}
+static bfd_boolean flag_warn_syms = TRUE;
+
/* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
Otherwise we have no need to default values of symbols. */
@@ -21646,6 +21648,52 @@ md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
}
#endif
+ /* PR 18347 - Warn if the user attempts to create a symbol with the same
+ name as an ARM instruction. Whilst strictly speaking it is allowed, it
+ does mean that the resulting code might be very confusing to the reader.
+ Also this warning can be triggered if the user omits an operand before
+ an immediate address, eg:
+
+ LDR =foo
+
+ GAS treats this as an assignment of the value of the symbol foo to a
+ symbol LDR, and so (without this code) it will not issue any kind of
+ warning or error message.
+
+ Note - ARM instructions are case-insensitive but the strings in the hash
+ table are all stored in lower case, so we must first ensure that name is
+ lower case too.
+
+ Some names are problematical. Several gas tests for example use:
+
+ b:
+
+ as a label, but of course this matches the branch instruction. For now
+ we punt and only check names longer than 1.
+
+ FIXME: Should this be made into generic code for all targets ? */
+ if (flag_warn_syms && arm_ops_hsh && strlen (name) > 1)
+ {
+ char * nbuf = strdup (name);
+ char * p;
+
+ for (p = nbuf; *p; p++)
+ *p = TOLOWER (*p);
+ if (hash_find (arm_ops_hsh, nbuf) != NULL)
+ {
+ static struct hash_control * already_warned = NULL;
+
+ if (already_warned == NULL)
+ already_warned = hash_new ();
+ /* Only warn about the symbol once. To keep the code
+ simple we let hash_insert do the lookup for us. */
+ if (hash_insert (already_warned, name, NULL) == NULL)
+ as_warn (_("[-mwarn-syms]: Symbol '%s' matches an ARM instruction - is this intentional ?"), name);
+ }
+ else
+ free (nbuf);
+ }
+
return NULL;
}
@@ -24116,6 +24164,7 @@ md_begin (void)
-mthumb-interwork Code supports ARM/Thumb interworking
-m[no-]warn-deprecated Warn about deprecated features
+ -m[no-]warn-syms Warn when symbols match instructions
For now we will also provide support for:
@@ -24184,6 +24233,7 @@ struct option md_longopts[] =
{NULL, no_argument, NULL, 0}
};
+
size_t md_longopts_size = sizeof (md_longopts);
struct arm_option_table
@@ -24218,6 +24268,8 @@ struct arm_option_table arm_opts[] =
{"mwarn-deprecated", NULL, &warn_on_deprecated, 1, NULL},
{"mno-warn-deprecated", N_("do not warn on use of deprecated feature"),
&warn_on_deprecated, 0, NULL},
+ {"mwarn-syms", N_("warn about symbols that match instruction names [default]"), (int *) (& flag_warn_syms), TRUE, NULL},
+ {"mno-warn-syms", N_("disable warnings about symobls that match instructions"), (int *) (& flag_warn_syms), FALSE, NULL},
{NULL, NULL, NULL, 0, NULL}
};
diff --git a/gas/doc/c-arm.texi b/gas/doc/c-arm.texi
index f07aa62..d31ba02 100644
--- a/gas/doc/c-arm.texi
+++ b/gas/doc/c-arm.texi
@@ -394,6 +394,12 @@ features. The default is to warn.
@item -mccs
Turns on CodeComposer Studio assembly syntax compatibility mode.
+@cindex @code{-mwarn-syms} command line option, ARM
+@item -mwarn-syms
+@itemx -mno-warn-syms
+Enable or disable warnings about symbols that match the names of ARM
+instructions. The default is to warn.
+
@end table
diff --git a/gas/testsuite/ChangeLog b/gas/testsuite/ChangeLog
index aed518a..6608a80 100644
--- a/gas/testsuite/ChangeLog
+++ b/gas/testsuite/ChangeLog
@@ -1,3 +1,10 @@
+2015-04-30 Nick Clifton <nickc@redhat.com>
+
+ PR gas/18347
+ * gas/arm/pr18347.s: New file: Test case.
+ * gas/arm/pr18347.l: New file: Expected assembler output.
+ * gas/arm/pr18347.d: New file: Test driver.
+
2015-04-29 Nick Clifton <nickc@redhat.com>
PR gas/18265
diff --git a/gas/testsuite/gas/arm/pr18347.d b/gas/testsuite/gas/arm/pr18347.d
new file mode 100644
index 0000000..b9f042a
--- /dev/null
+++ b/gas/testsuite/gas/arm/pr18347.d
@@ -0,0 +1,3 @@
+# name: PR18347 - GAS silently ignores a misconstructed LDR instruction
+#as:
+#error-output: pr18347.l
diff --git a/gas/testsuite/gas/arm/pr18347.l b/gas/testsuite/gas/arm/pr18347.l
new file mode 100644
index 0000000..12e223d
--- /dev/null
+++ b/gas/testsuite/gas/arm/pr18347.l
@@ -0,0 +1,2 @@
+[^:]*: Assembler messages:
+[^:]*:2: Warning: \[-mwarn-syms\]: Symbol 'LDR' matches an ARM instruction - is this intentional \?
diff --git a/gas/testsuite/gas/arm/pr18347.s b/gas/testsuite/gas/arm/pr18347.s
new file mode 100644
index 0000000..ac22b45
--- /dev/null
+++ b/gas/testsuite/gas/arm/pr18347.s
@@ -0,0 +1,3 @@
+ MOV r1, r0
+ LDR =garbage // no destination register
+ MOV r2, r3