+2017-08-11  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR gas/21667
+       * read.c (pseudo_set): Update error message for alias of common
+       symbol.
+       * write.c (write_object_file): Disallow both local and global
+       aliases of common symbol.
+       * testsuite/gas/elf/common5a.d: New file.
+       * testsuite/gas/elf/common5a.l: Likewise.
+       * testsuite/gas/elf/common5a.s: Likewise.
+       * testsuite/gas/elf/common5b.d: Likewise.
+       * testsuite/gas/elf/common5b.l: Likewise.
+       * testsuite/gas/elf/common5b.s: Likewise.
+       * testsuite/gas/elf/common5c.d: Likewise.
+       * testsuite/gas/elf/common5c.s: Likewise.
+       * testsuite/gas/elf/common5d.d: Likewise.
+       * testsuite/gas/elf/common5d.s: Likewise.
+       * testsuite/gas/elf/elf.exp: Run common5a, common5b, common5c
+       and common5d.
+
 2017-08-10  Nick Clifton  <nickc@redhat.com>
 
        PR gas/21939
 
          symbolS *s = exp.X_add_symbol;
 
          if (S_IS_COMMON (s))
-           as_bad (_("`%s' can't be equated to common symbol '%s'"),
+           as_bad (_("`%s' can't be equated to common symbol `%s'"),
                    S_GET_NAME (symbolP), S_GET_NAME (s));
 
          S_SET_SEGMENT (symbolP, seg);
 
--- /dev/null
+#source: common5a.s
+#as: 
+#error-output: common5a.l
+#not-target: alpha-*-*
+# The Alpha target uses its own .set pseudo-insn.
 
--- /dev/null
+[^:]*: Assembler messages:
+[^:]*: Error: `foo1' can't be equated to common symbol `foo'
 
--- /dev/null
+       .set    foo1,foo
+       .globl  foo1
+       .comm   foo,8,8
 
--- /dev/null
+#source: common5b.s
+#as: 
+#error-output: common5b.l
+#not-target: alpha-*-*
+# The Alpha target uses its own .set pseudo-insn.
 
--- /dev/null
+[^:]*: Assembler messages:
+[^:]*:2: Error: `foo1' can't be equated to common symbol `foo'
 
--- /dev/null
+       .comm   foo,8,8
+       .set    foo1,foo
+       .globl  foo1
 
--- /dev/null
+#source: common5c.s
+#as: 
+#error-output: common5a.l
+#not-target: alpha-*-*
+# The Alpha target uses its own .set pseudo-insn.
 
--- /dev/null
+       .set    foo1,foo
+       .comm   foo,8,8
 
--- /dev/null
+#source: common5d.s
+#as: 
+#error-output: common5b.l
+#not-target: alpha-*-*
+# The Alpha target uses its own .set pseudo-insn.
 
--- /dev/null
+       .comm   foo,8,8
+       .set    foo1,foo
 
        run_dump_test "common3b"
        run_dump_test "common4a"
        run_dump_test "common4b"
+       run_dump_test "common5a"
+       run_dump_test "common5b"
+       run_dump_test "common5c"
+       run_dump_test "common5d"
     }
 
     run_dump_test "strtab"
 
 
              if (S_IS_COMMON (symp)
                  && !TC_FAKE_LABEL (sname)
-                 && !S_IS_WEAKREFR (symp)
-                 && (!S_IS_EXTERNAL (symp) || S_IS_LOCAL (symp)))
+                 && !S_IS_WEAKREFR (symp))
                {
                  expressionS *e = symbol_get_value_expression (symp);
 
-                 as_bad (_("Local symbol `%s' can't be equated to common symbol `%s'"),
+                 as_bad (_("`%s' can't be equated to common symbol `%s'"),
                          sname, S_GET_NAME (e->X_add_symbol));
                }
              if (S_GET_SEGMENT (symp) == reg_section)