This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
[PATCH] PR gas/21661: Check unsupported .symver with common symbol
- From: "H.J. Lu" <hjl dot tools at gmail dot com>
- To: binutils at sourceware dot org
- Date: Fri, 23 Jun 2017 06:52:01 -0700
- Subject: [PATCH] PR gas/21661: Check unsupported .symver with common symbol
- Authentication-results: sourceware.org; auth=none
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'
$
OK for master?
H.J.
---
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/config/obj-elf.c | 18 ++++++++++++++++++
gas/testsuite/gas/elf/elf.exp | 1 +
gas/testsuite/gas/elf/pr21661.d | 2 ++
gas/testsuite/gas/elf/pr21661.l | 3 +++
gas/testsuite/gas/elf/pr21661.s | 4 ++++
5 files changed, 28 insertions(+)
create mode 100644 gas/testsuite/gas/elf/pr21661.d
create mode 100644 gas/testsuite/gas/elf/pr21661.l
create mode 100644 gas/testsuite/gas/elf/pr21661.s
diff --git a/gas/config/obj-elf.c b/gas/config/obj-elf.c
index 3696d5e..94ffb31 100644
--- a/gas/config/obj-elf.c
+++ b/gas/config/obj-elf.c
@@ -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);
@@ -2301,6 +2309,16 @@ elf_frob_symbol (symbolS *symp, int *puntp)
}
}
}
+ else if (S_IS_COMMON (symp))
+ {
+ const char *sname = S_GET_NAME (symp);
+ if (strchr (sname, ELF_VER_CHR))
+ {
+ as_bad (_("symbol `%s' can't be versioned to common symbol"),
+ sname);
+ return;
+ }
+ }
/* Double check weak symbols. */
if (S_IS_WEAK (symp))
diff --git a/gas/testsuite/gas/elf/elf.exp b/gas/testsuite/gas/elf/elf.exp
index ad38d66..6b2b31a 100644
--- a/gas/testsuite/gas/elf/elf.exp
+++ b/gas/testsuite/gas/elf/elf.exp
@@ -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
index 0000000..a16e410
--- /dev/null
+++ b/gas/testsuite/gas/elf/pr21661.d
@@ -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
index 0000000..daf0d36
--- /dev/null
+++ b/gas/testsuite/gas/elf/pr21661.l
@@ -0,0 +1,3 @@
+[^:]*: Assembler messages:
+[^:]*:2: Error: `foo@VERS.1' can't be versioned to common symbol 'foo'
+[^:]*: Error: symbol `bar@VERS.1' can't be versioned to common symbol
diff --git a/gas/testsuite/gas/elf/pr21661.s b/gas/testsuite/gas/elf/pr21661.s
new file mode 100644
index 0000000..5586bfd
--- /dev/null
+++ b/gas/testsuite/gas/elf/pr21661.s
@@ -0,0 +1,4 @@
+ .comm foo,8,8
+ .symver foo,foo@VERS.1
+ .symver bar,bar@VERS.1
+ .comm bar,8,8
--
2.9.4