]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Check unsupported .symver with common symbol
authorH.J. Lu <hjl.tools@gmail.com>
Mon, 26 Jun 2017 12:11:07 +0000 (05:11 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Mon, 26 Jun 2017 12:11:29 +0000 (05:11 -0700)
The .symver directive on common symbol creates a new common symbol,
which shouldn't be allowed, similar to alias on common symbol:

$ cat y.S
.comm bar,8,8
 .set bar1,bar
$ as -o y.o y.S
y.S: Assembler messages:
y.S:2: Error: `bar1' can't be equated to common symbol 'bar'
$

PR gas/21661
* config/obj-elf.c (obj_elf_symver): Don't allow .symver with
common symbol.
(elf_frob_symbol): Likewise.
* testsuite/gas/elf/elf.exp: Run pr21661.
* testsuite/gas/elf/pr21661.d: New file.
* testsuite/gas/elf/pr21661.s: Likewise.

gas/ChangeLog
gas/config/obj-elf.c
gas/testsuite/gas/elf/elf.exp
gas/testsuite/gas/elf/pr21661.d [new file with mode: 0644]
gas/testsuite/gas/elf/pr21661.l [new file with mode: 0644]
gas/testsuite/gas/elf/pr21661.s [new file with mode: 0644]

index f48280d8fdcc6f1f1ba3b0405c20f5660f069894..6d3281d4f2a8479a63785594d11cf4976fbdff9e 100644 (file)
@@ -1,3 +1,13 @@
+2017-06-26  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR gas/21661
+       * config/obj-elf.c (obj_elf_symver): Don't allow .symver with
+       common symbol.
+       (elf_frob_symbol): Likewise.
+       * testsuite/gas/elf/elf.exp: Run pr21661.
+       * testsuite/gas/elf/pr21661.d: New file.
+       * testsuite/gas/elf/pr21661.s: Likewise.
+
 2017-06-26  Nick Clifton  <nickc@redhat.com>
 
        * config/tc-arm.c (fpu_any): Only define for ELF based targets.
index 3696d5ea5e274bcc8d96594a1b520db090214b02..49d99a459ca1cc7d13731f4a7beea5a33612c5d2 100644 (file)
@@ -1414,6 +1414,14 @@ obj_elf_symver (int ignore ATTRIBUTE_UNUSED)
   c = get_symbol_name (& name);
   lex_type[(unsigned char) '@'] = old_lexat;
 
+  if (S_IS_COMMON (sym))
+    {
+      as_bad (_("`%s' can't be versioned to common symbol '%s'"),
+             name, S_GET_NAME (sym));
+      ignore_rest_of_line ();
+      return;
+    }
+
   if (symbol_get_obj (sym)->versioned_name == NULL)
     {
       symbol_get_obj (sym)->versioned_name = xstrdup (name);
@@ -2277,6 +2285,13 @@ elf_frob_symbol (symbolS *symp, int *puntp)
              symp2 = symbol_find_or_make (sy_obj->versioned_name);
 
              /* Now we act as though we saw symp2 = sym.  */
+             if (S_IS_COMMON (symp))
+               {
+                 as_bad (_("`%s' can't be versioned to common symbol '%s'"),
+                         sy_obj->versioned_name, S_GET_NAME (symp));
+                 *puntp = TRUE;
+                 return;
+               }
 
              S_SET_SEGMENT (symp2, S_GET_SEGMENT (symp));
 
index ad38d6655e76fdd724b777a41b8d006b6ae5afe3..6b2b31a04ef4cde5d3b00f834d04ccebb5b76f9c 100644 (file)
@@ -184,6 +184,7 @@ if { [is_elf_format] } then {
        run_dump_test "symtab"
     }
     run_dump_test "symver"
+    run_dump_test "pr21661"
 
     # No indirect functions on non-GNU targets.
     # The Visium and MSP set the ELF header's OSABI field to ELFOSABI_STANDALONE.
diff --git a/gas/testsuite/gas/elf/pr21661.d b/gas/testsuite/gas/elf/pr21661.d
new file mode 100644 (file)
index 0000000..a16e410
--- /dev/null
@@ -0,0 +1,2 @@
+#name: unsupported .symver with common symbol
+#error-output: pr21661.l
diff --git a/gas/testsuite/gas/elf/pr21661.l b/gas/testsuite/gas/elf/pr21661.l
new file mode 100644 (file)
index 0000000..0565faa
--- /dev/null
@@ -0,0 +1,3 @@
+[^:]*: Assembler messages:
+[^:]*:2: Error: `foo@VERS.1' can't be versioned to common symbol 'foo'
+[^:]*: Error: `bar@VERS.1' can't be versioned to common symbol 'bar'
diff --git a/gas/testsuite/gas/elf/pr21661.s b/gas/testsuite/gas/elf/pr21661.s
new file mode 100644 (file)
index 0000000..5586bfd
--- /dev/null
@@ -0,0 +1,4 @@
+       .comm   foo,8,8
+        .symver foo,foo@VERS.1
+        .symver bar,bar@VERS.1
+       .comm   bar,8,8