summaryrefslogtreecommitdiff
path: root/usr/src/test/elf-tests/tests
diff options
context:
space:
mode:
authorRichard Lowe <richlowe@richlowe.net>2021-04-05 14:06:47 -0500
committerRichard Lowe <richlowe@richlowe.net>2021-04-09 15:48:05 -0500
commit8222814ef8560ee0ba222eca8ca5acffc6cd0e44 (patch)
tree55274c4f702ccf5aa98764391b250a81ba3f1990 /usr/src/test/elf-tests/tests
parent99ea293e719ac006d413e4fde6ac0d5cd4dd6c59 (diff)
downloadillumos-joyent-8222814ef8560ee0ba222eca8ca5acffc6cd0e44.tar.gz
13487 want mapfile-based assertions about symbol properties
Reviewed by: Robert Mustacchi <rm@fingolfin.org> Reviewed by: Jason King <jason.brian.king@gmail.com> Approved by: Dan McDonald <danmcd@joyent.com>
Diffstat (limited to 'usr/src/test/elf-tests/tests')
-rw-r--r--usr/src/test/elf-tests/tests/Makefile1
-rw-r--r--usr/src/test/elf-tests/tests/mapfiles/Makefile18
-rw-r--r--usr/src/test/elf-tests/tests/mapfiles/assert/Makefile67
-rw-r--r--usr/src/test/elf-tests/tests/mapfiles/assert/mapfile.alias-with-others31
-rw-r--r--usr/src/test/elf-tests/tests/mapfiles/assert/mapfile.circalias31
-rw-r--r--usr/src/test/elf-tests/tests/mapfiles/assert/mapfile.guidance43
-rw-r--r--usr/src/test/elf-tests/tests/mapfiles/assert/mapfile.no-extern75
-rw-r--r--usr/src/test/elf-tests/tests/mapfiles/assert/mapfile.no-parent75
-rw-r--r--usr/src/test/elf-tests/tests/mapfiles/assert/mapfile.not-alias69
-rw-r--r--usr/src/test/elf-tests/tests/mapfiles/assert/mapfile.true69
-rw-r--r--usr/src/test/elf-tests/tests/mapfiles/assert/mapfile.unknown-alias31
-rw-r--r--usr/src/test/elf-tests/tests/mapfiles/assert/mapfile.unknown-assert27
-rw-r--r--usr/src/test/elf-tests/tests/mapfiles/assert/mapfile.unknown-bind27
-rw-r--r--usr/src/test/elf-tests/tests/mapfiles/assert/mapfile.unknown-shattr27
-rw-r--r--usr/src/test/elf-tests/tests/mapfiles/assert/mapfile.unknown-type27
-rw-r--r--usr/src/test/elf-tests/tests/mapfiles/assert/mapfile.wrongalias26
-rw-r--r--usr/src/test/elf-tests/tests/mapfiles/assert/mapfile.wrongbits32
-rw-r--r--usr/src/test/elf-tests/tests/mapfiles/assert/mapfile.wrongbits232
-rw-r--r--usr/src/test/elf-tests/tests/mapfiles/assert/mapfile.wrongscope26
-rw-r--r--usr/src/test/elf-tests/tests/mapfiles/assert/mapfile.wrongsize26
-rw-r--r--usr/src/test/elf-tests/tests/mapfiles/assert/mapfile.wrongtype25
-rw-r--r--usr/src/test/elf-tests/tests/mapfiles/assert/mapfile.wrongtype-alias26
-rw-r--r--usr/src/test/elf-tests/tests/mapfiles/assert/mapfile.wrongtype225
-rw-r--r--usr/src/test/elf-tests/tests/mapfiles/assert/object.c31
-rw-r--r--usr/src/test/elf-tests/tests/mapfiles/assert/test-assert.sh144
-rw-r--r--usr/src/test/elf-tests/tests/mapfiles/parser/Makefile56
-rw-r--r--usr/src/test/elf-tests/tests/mapfiles/parser/mapfile.addrsize.good33
-rw-r--r--usr/src/test/elf-tests/tests/mapfiles/parser/mapfile.addrsize.mult26
-rw-r--r--usr/src/test/elf-tests/tests/mapfiles/parser/mapfile.addrsize.substring33
-rw-r--r--usr/src/test/elf-tests/tests/mapfiles/parser/mapfile.addrsize.superstring33
-rw-r--r--usr/src/test/elf-tests/tests/mapfiles/parser/mapfile.addrsize.wrong33
-rw-r--r--usr/src/test/elf-tests/tests/mapfiles/parser/mapfile.sizemult.good38
-rw-r--r--usr/src/test/elf-tests/tests/mapfiles/parser/mapfile.sizemult.noterm33
-rw-r--r--usr/src/test/elf-tests/tests/mapfiles/parser/mapfile.sizemult.overflow33
-rw-r--r--usr/src/test/elf-tests/tests/mapfiles/parser/mapfile.sizemult.twobegin33
-rw-r--r--usr/src/test/elf-tests/tests/mapfiles/parser/mapfile.sizemult.wrong39
-rw-r--r--usr/src/test/elf-tests/tests/mapfiles/parser/object.c18
-rw-r--r--usr/src/test/elf-tests/tests/mapfiles/parser/test-parser.sh108
38 files changed, 1527 insertions, 0 deletions
diff --git a/usr/src/test/elf-tests/tests/Makefile b/usr/src/test/elf-tests/tests/Makefile
index 5da70cc241..060d1c2e3e 100644
--- a/usr/src/test/elf-tests/tests/Makefile
+++ b/usr/src/test/elf-tests/tests/Makefile
@@ -17,6 +17,7 @@
SUBDIRS = \
assert-deflib \
linker-sets \
+ mapfiles \
tls
include $(SRC)/test/Makefile.com
diff --git a/usr/src/test/elf-tests/tests/mapfiles/Makefile b/usr/src/test/elf-tests/tests/mapfiles/Makefile
new file mode 100644
index 0000000000..aebddb4e98
--- /dev/null
+++ b/usr/src/test/elf-tests/tests/mapfiles/Makefile
@@ -0,0 +1,18 @@
+#
+# This file and its contents are supplied under the terms of the
+# Common Development and Distribution License ("CDDL"), version 1.0.
+# You may only use this file in accordance with the terms of version
+# 1.0 of the CDDL.
+#
+# A full copy of the text of the CDDL should have accompanied this
+# source. A copy of the CDDL is also available via the Internet at
+# http://www.illumos.org/license/CDDL.
+#
+
+# Copyright 2019, Richard Lowe.
+
+SUBDIRS = \
+ assert \
+ parser
+
+include $(SRC)/test/Makefile.com
diff --git a/usr/src/test/elf-tests/tests/mapfiles/assert/Makefile b/usr/src/test/elf-tests/tests/mapfiles/assert/Makefile
new file mode 100644
index 0000000000..11e47c2ca7
--- /dev/null
+++ b/usr/src/test/elf-tests/tests/mapfiles/assert/Makefile
@@ -0,0 +1,67 @@
+#
+# This file and its contents are supplied under the terms of the
+# Common Development and Distribution License ("CDDL"), version 1.0.
+# You may only use this file in accordance with the terms of version
+# 1.0 of the CDDL.
+#
+# A full copy of the text of the CDDL should have accompanied this
+# source. A copy of the CDDL is also available via the Internet at
+# http://www.illumos.org/license/CDDL.
+#
+
+# Copyright 2019, Richard Lowe.
+
+include $(SRC)/cmd/Makefile.cmd
+include $(SRC)/test/Makefile.com
+
+PROG = test-assert
+
+DATAFILES= \
+ mapfile.alias-with-others \
+ mapfile.circalias \
+ mapfile.guidance \
+ mapfile.no-extern \
+ mapfile.no-parent \
+ mapfile.not-alias \
+ mapfile.true \
+ mapfile.unknown-alias \
+ mapfile.unknown-assert \
+ mapfile.unknown-bind \
+ mapfile.unknown-shattr \
+ mapfile.unknown-type \
+ mapfile.wrongalias \
+ mapfile.wrongbits \
+ mapfile.wrongbits2 \
+ mapfile.wrongscope \
+ mapfile.wrongsize \
+ mapfile.wrongtype \
+ mapfile.wrongtype-alias \
+ mapfile.wrongtype2 \
+ object.c
+
+ROOTOPTPKG = $(ROOT)/opt/elf-tests
+TESTDIR = $(ROOTOPTPKG)/tests/mapfiles/assert
+
+CMDS = $(PROG:%=$(TESTDIR)/%)
+$(CMDS) := FILEMODE = 0555
+
+DATA = $(DATAFILES:%=$(TESTDIR)/%)
+$(DATA) := FILEMODE = 0444
+
+all: $(PROG)
+
+install: all $(CMDS) $(DATA)
+
+clobber: clean
+ -$(RM) $(PROG)
+
+clean:
+ -$(RM) $(CLEANFILES)
+
+$(CMDS): $(TESTDIR) $(PROG)
+
+$(TESTDIR):
+ $(INS.dir)
+
+$(TESTDIR)/%: %
+ $(INS.file)
diff --git a/usr/src/test/elf-tests/tests/mapfiles/assert/mapfile.alias-with-others b/usr/src/test/elf-tests/tests/mapfiles/assert/mapfile.alias-with-others
new file mode 100644
index 0000000000..48c658ebdb
--- /dev/null
+++ b/usr/src/test/elf-tests/tests/mapfiles/assert/mapfile.alias-with-others
@@ -0,0 +1,31 @@
+#
+# This file and its contents are supplied under the terms of the
+# Common Development and Distribution License ("CDDL"), version 1.0.
+# You may only use this file in accordance with the terms of version
+# 1.0 of the CDDL.
+#
+# A full copy of the text of the CDDL should have accompanied this
+# source. A copy of the CDDL is also available via the Internet at
+# http://www.illumos.org/license/CDDL.
+#
+
+#
+# Copyright 2012, Richard Lowe.
+#
+
+
+$mapfile_version 2
+
+
+SYMBOL_VERSION foo {
+ global:
+ weak_function {
+ ASSERT = {
+ TYPE = FUNCTION;
+ ALIAS = function;
+ };
+ };
+
+ local:
+ *;
+};
diff --git a/usr/src/test/elf-tests/tests/mapfiles/assert/mapfile.circalias b/usr/src/test/elf-tests/tests/mapfiles/assert/mapfile.circalias
new file mode 100644
index 0000000000..9640dec15f
--- /dev/null
+++ b/usr/src/test/elf-tests/tests/mapfiles/assert/mapfile.circalias
@@ -0,0 +1,31 @@
+#
+# This file and its contents are supplied under the terms of the
+# Common Development and Distribution License ("CDDL"), version 1.0.
+# You may only use this file in accordance with the terms of version
+# 1.0 of the CDDL.
+#
+# A full copy of the text of the CDDL should have accompanied this
+# source. A copy of the CDDL is also available via the Internet at
+# http://www.illumos.org/license/CDDL.
+#
+
+#
+# Copyright 2012, Richard Lowe.
+#
+
+
+$mapfile_version 2
+
+
+SYMBOL_VERSION foo {
+ global:
+ weak_function {
+ ASSERT = {
+ BINDING = WEAK;
+ ALIAS = weak_function;
+ };
+ };
+
+ local:
+ *;
+};
diff --git a/usr/src/test/elf-tests/tests/mapfiles/assert/mapfile.guidance b/usr/src/test/elf-tests/tests/mapfiles/assert/mapfile.guidance
new file mode 100644
index 0000000000..c3e0197e22
--- /dev/null
+++ b/usr/src/test/elf-tests/tests/mapfiles/assert/mapfile.guidance
@@ -0,0 +1,43 @@
+#
+# This file and its contents are supplied under the terms of the
+# Common Development and Distribution License ("CDDL"), version 1.0.
+# You may only use this file in accordance with the terms of version
+# 1.0 of the CDDL.
+#
+# A full copy of the text of the CDDL should have accompanied this
+# source. A copy of the CDDL is also available via the Internet at
+# http://www.illumos.org/license/CDDL.
+#
+
+#
+# Copyright 2012, Richard Lowe.
+#
+
+
+$mapfile_version 2
+
+
+SYMBOL_VERSION foo {
+ global:
+ common;
+ data;
+ function {
+ ASSERT = {
+ TYPE = FUNCTION;
+ SH_ATTR = BITS;
+ BINDING = GLOBAL;
+ };
+ };
+ weak_function {
+ ASSERT = {
+ BINDING = WEAK;
+ ALIAS = function;
+ };
+ };
+ weak_data { ASSERT = { BINDING = WEAK; ALIAS = data; }; };
+ tbs;
+ tdata;
+
+ local:
+ *;
+};
diff --git a/usr/src/test/elf-tests/tests/mapfiles/assert/mapfile.no-extern b/usr/src/test/elf-tests/tests/mapfiles/assert/mapfile.no-extern
new file mode 100644
index 0000000000..9704b640a3
--- /dev/null
+++ b/usr/src/test/elf-tests/tests/mapfiles/assert/mapfile.no-extern
@@ -0,0 +1,75 @@
+#
+# This file and its contents are supplied under the terms of the
+# Common Development and Distribution License ("CDDL"), version 1.0.
+# You may only use this file in accordance with the terms of version
+# 1.0 of the CDDL.
+#
+# A full copy of the text of the CDDL should have accompanied this
+# source. A copy of the CDDL is also available via the Internet at
+# http://www.illumos.org/license/CDDL.
+#
+
+#
+# Copyright 2012, Richard Lowe.
+#
+
+
+$mapfile_version 2
+
+
+SYMBOL_VERSION foo {
+ global:
+ common {
+ ASSERT = {
+ TYPE = OBJECT;
+ SIZE = 4;
+ SH_ATTR = NOBITS;
+ BINDING = GLOBAL;
+ };
+ };
+ data {
+ ASSERT = {
+ TYPE = OBJECT;
+ SIZE = 5;
+ SH_ATTR = BITS;
+ BINDING = GLOBAL;
+ };
+ };
+ function {
+ ASSERT = {
+ TYPE = FUNCTION;
+ SH_ATTR = BITS;
+ BINDING = GLOBAL;
+ };
+ };
+ weak_function {
+ ASSERT = {
+ BINDING = WEAK;
+ ALIAS = function;
+ };
+ };
+ weak_data { ASSERT = { BINDING = WEAK; ALIAS = data; }; };
+ tbs {
+ ASSERT = {
+ TYPE = TLS;
+ SH_ATTR = NOBITS;
+ SIZE = 4;
+ };
+ };
+ tdata {
+ ASSERT = {
+ TYPE = TLS;
+ SH_ATTR = BITS;
+ SIZE = 4;
+ };
+ };
+ extern {
+ FLAGS = EXTERN;
+ ASSERT = {
+ TYPE = OBJECT;
+ SIZE = 4;
+ };
+ };
+ local:
+ *;
+};
diff --git a/usr/src/test/elf-tests/tests/mapfiles/assert/mapfile.no-parent b/usr/src/test/elf-tests/tests/mapfiles/assert/mapfile.no-parent
new file mode 100644
index 0000000000..d6954d6e04
--- /dev/null
+++ b/usr/src/test/elf-tests/tests/mapfiles/assert/mapfile.no-parent
@@ -0,0 +1,75 @@
+#
+# This file and its contents are supplied under the terms of the
+# Common Development and Distribution License ("CDDL"), version 1.0.
+# You may only use this file in accordance with the terms of version
+# 1.0 of the CDDL.
+#
+# A full copy of the text of the CDDL should have accompanied this
+# source. A copy of the CDDL is also available via the Internet at
+# http://www.illumos.org/license/CDDL.
+#
+
+#
+# Copyright 2012, Richard Lowe.
+#
+
+
+$mapfile_version 2
+
+
+SYMBOL_VERSION foo {
+ global:
+ common {
+ ASSERT = {
+ TYPE = OBJECT;
+ SIZE = 4;
+ SH_ATTR = NOBITS;
+ BINDING = GLOBAL;
+ };
+ };
+ data {
+ ASSERT = {
+ TYPE = OBJECT;
+ SIZE = 5;
+ SH_ATTR = BITS;
+ BINDING = GLOBAL;
+ };
+ };
+ function {
+ ASSERT = {
+ TYPE = FUNCTION;
+ SH_ATTR = BITS;
+ BINDING = GLOBAL;
+ };
+ };
+ weak_function {
+ ASSERT = {
+ BINDING = WEAK;
+ ALIAS = function;
+ };
+ };
+ weak_data { ASSERT = { BINDING = WEAK; ALIAS = data; }; };
+ tbs {
+ ASSERT = {
+ TYPE = TLS;
+ SH_ATTR = NOBITS;
+ SIZE = 4;
+ };
+ };
+ tdata {
+ ASSERT = {
+ TYPE = TLS;
+ SH_ATTR = BITS;
+ SIZE = 4;
+ };
+ };
+ parent {
+ FLAGS = PARENT;
+ ASSERT = {
+ TYPE = OBJECT;
+ SIZE = 4;
+ };
+ };
+ local:
+ *;
+};
diff --git a/usr/src/test/elf-tests/tests/mapfiles/assert/mapfile.not-alias b/usr/src/test/elf-tests/tests/mapfiles/assert/mapfile.not-alias
new file mode 100644
index 0000000000..0d4b84fb40
--- /dev/null
+++ b/usr/src/test/elf-tests/tests/mapfiles/assert/mapfile.not-alias
@@ -0,0 +1,69 @@
+#
+# This file and its contents are supplied under the terms of the
+# Common Development and Distribution License ("CDDL"), version 1.0.
+# You may only use this file in accordance with the terms of version
+# 1.0 of the CDDL.
+#
+# A full copy of the text of the CDDL should have accompanied this
+# source. A copy of the CDDL is also available via the Internet at
+# http://www.illumos.org/license/CDDL.
+#
+
+#
+# Copyright 2012, Richard Lowe.
+#
+
+
+$mapfile_version 2
+
+
+SYMBOL_VERSION foo {
+ global:
+ common {
+ ASSERT = {
+ TYPE = OBJECT;
+ SIZE = 4;
+ SH_ATTR = NOBITS;
+ BINDING = GLOBAL;
+ };
+ };
+ data {
+ ASSERT = {
+ TYPE = OBJECT;
+ SIZE = 5;
+ SH_ATTR = BITS;
+ BINDING = GLOBAL;
+ };
+ };
+ function {
+ ASSERT = {
+ TYPE = FUNCTION;
+ SH_ATTR = BITS;
+ BINDING = GLOBAL;
+ };
+ };
+ weak_function {
+ ASSERT = {
+ BINDING = WEAK;
+ ALIAS = function;
+ };
+ };
+ weak_data { ASSERT = { BINDING = WEAK; SIZE = 5; }; };
+ tbs {
+ ASSERT = {
+ TYPE = TLS;
+ SH_ATTR = NOBITS;
+ SIZE = 4;
+ };
+ };
+ tdata {
+ ASSERT = {
+ TYPE = TLS;
+ SH_ATTR = BITS;
+ SIZE = 4;
+ };
+ };
+
+ local:
+ *;
+};
diff --git a/usr/src/test/elf-tests/tests/mapfiles/assert/mapfile.true b/usr/src/test/elf-tests/tests/mapfiles/assert/mapfile.true
new file mode 100644
index 0000000000..76008effa4
--- /dev/null
+++ b/usr/src/test/elf-tests/tests/mapfiles/assert/mapfile.true
@@ -0,0 +1,69 @@
+#
+# This file and its contents are supplied under the terms of the
+# Common Development and Distribution License ("CDDL"), version 1.0.
+# You may only use this file in accordance with the terms of version
+# 1.0 of the CDDL.
+#
+# A full copy of the text of the CDDL should have accompanied this
+# source. A copy of the CDDL is also available via the Internet at
+# http://www.illumos.org/license/CDDL.
+#
+
+#
+# Copyright 2012, Richard Lowe.
+#
+
+
+$mapfile_version 2
+
+
+SYMBOL_VERSION foo {
+ global:
+ common {
+ ASSERT = {
+ TYPE = OBJECT;
+ SIZE = addrsize;
+ SH_ATTR = NOBITS;
+ BINDING = GLOBAL;
+ };
+ };
+ data {
+ ASSERT = {
+ TYPE = OBJECT;
+ SIZE = 5;
+ SH_ATTR = BITS;
+ BINDING = GLOBAL;
+ };
+ };
+ function {
+ ASSERT = {
+ TYPE = FUNCTION;
+ SH_ATTR = BITS;
+ BINDING = GLOBAL;
+ };
+ };
+ weak_function {
+ ASSERT = {
+ BINDING = WEAK;
+ ALIAS = function;
+ };
+ };
+ weak_data { ASSERT = { BINDING = WEAK; ALIAS = data; }; };
+ tbs {
+ ASSERT = {
+ TYPE = TLS;
+ SH_ATTR = NOBITS;
+ SIZE = addrsize;
+ };
+ };
+ tdata {
+ ASSERT = {
+ TYPE = TLS;
+ SH_ATTR = BITS;
+ SIZE = addrsize;
+ };
+ };
+
+ local:
+ *;
+};
diff --git a/usr/src/test/elf-tests/tests/mapfiles/assert/mapfile.unknown-alias b/usr/src/test/elf-tests/tests/mapfiles/assert/mapfile.unknown-alias
new file mode 100644
index 0000000000..0668af569c
--- /dev/null
+++ b/usr/src/test/elf-tests/tests/mapfiles/assert/mapfile.unknown-alias
@@ -0,0 +1,31 @@
+#
+# This file and its contents are supplied under the terms of the
+# Common Development and Distribution License ("CDDL"), version 1.0.
+# You may only use this file in accordance with the terms of version
+# 1.0 of the CDDL.
+#
+# A full copy of the text of the CDDL should have accompanied this
+# source. A copy of the CDDL is also available via the Internet at
+# http://www.illumos.org/license/CDDL.
+#
+
+#
+# Copyright 2012, Richard Lowe.
+#
+
+
+$mapfile_version 2
+
+
+SYMBOL_VERSION foo {
+ global:
+ weak_function {
+ ASSERT = {
+ BINDING = WEAK;
+ ALIAS = undefined_symbol;
+ };
+ };
+
+ local:
+ *;
+};
diff --git a/usr/src/test/elf-tests/tests/mapfiles/assert/mapfile.unknown-assert b/usr/src/test/elf-tests/tests/mapfiles/assert/mapfile.unknown-assert
new file mode 100644
index 0000000000..c6f1400fcf
--- /dev/null
+++ b/usr/src/test/elf-tests/tests/mapfiles/assert/mapfile.unknown-assert
@@ -0,0 +1,27 @@
+
+#
+# This file and its contents are supplied under the terms of the
+# Common Development and Distribution License ("CDDL"), version 1.0.
+# You may only use this file in accordance with the terms of version
+# 1.0 of the CDDL.
+#
+# A full copy of the text of the CDDL should have accompanied this
+# source. A copy of the CDDL is also available via the Internet at
+# http://www.illumos.org/license/CDDL.
+#
+
+#
+# Copyright 2012, Richard Lowe.
+#
+
+
+$mapfile_version 2
+
+
+SYMBOL_VERSION foo {
+ global:
+ common { ASSERT = { ICE = COLD; }; };
+
+ local:
+ *;
+};
diff --git a/usr/src/test/elf-tests/tests/mapfiles/assert/mapfile.unknown-bind b/usr/src/test/elf-tests/tests/mapfiles/assert/mapfile.unknown-bind
new file mode 100644
index 0000000000..604fb36588
--- /dev/null
+++ b/usr/src/test/elf-tests/tests/mapfiles/assert/mapfile.unknown-bind
@@ -0,0 +1,27 @@
+
+#
+# This file and its contents are supplied under the terms of the
+# Common Development and Distribution License ("CDDL"), version 1.0.
+# You may only use this file in accordance with the terms of version
+# 1.0 of the CDDL.
+#
+# A full copy of the text of the CDDL should have accompanied this
+# source. A copy of the CDDL is also available via the Internet at
+# http://www.illumos.org/license/CDDL.
+#
+
+#
+# Copyright 2012, Richard Lowe.
+#
+
+
+$mapfile_version 2
+
+
+SYMBOL_VERSION foo {
+ global:
+ common { ASSERT = { BINDING = HEMPEN; }; };
+
+ local:
+ *;
+};
diff --git a/usr/src/test/elf-tests/tests/mapfiles/assert/mapfile.unknown-shattr b/usr/src/test/elf-tests/tests/mapfiles/assert/mapfile.unknown-shattr
new file mode 100644
index 0000000000..470ea5e5f7
--- /dev/null
+++ b/usr/src/test/elf-tests/tests/mapfiles/assert/mapfile.unknown-shattr
@@ -0,0 +1,27 @@
+
+#
+# This file and its contents are supplied under the terms of the
+# Common Development and Distribution License ("CDDL"), version 1.0.
+# You may only use this file in accordance with the terms of version
+# 1.0 of the CDDL.
+#
+# A full copy of the text of the CDDL should have accompanied this
+# source. A copy of the CDDL is also available via the Internet at
+# http://www.illumos.org/license/CDDL.
+#
+
+#
+# Copyright 2012, Richard Lowe.
+#
+
+
+$mapfile_version 2
+
+
+SYMBOL_VERSION foo {
+ global:
+ common { ASSERT = { SH_ATTR = WET; }; };
+
+ local:
+ *;
+};
diff --git a/usr/src/test/elf-tests/tests/mapfiles/assert/mapfile.unknown-type b/usr/src/test/elf-tests/tests/mapfiles/assert/mapfile.unknown-type
new file mode 100644
index 0000000000..55e5b4c695
--- /dev/null
+++ b/usr/src/test/elf-tests/tests/mapfiles/assert/mapfile.unknown-type
@@ -0,0 +1,27 @@
+
+#
+# This file and its contents are supplied under the terms of the
+# Common Development and Distribution License ("CDDL"), version 1.0.
+# You may only use this file in accordance with the terms of version
+# 1.0 of the CDDL.
+#
+# A full copy of the text of the CDDL should have accompanied this
+# source. A copy of the CDDL is also available via the Internet at
+# http://www.illumos.org/license/CDDL.
+#
+
+#
+# Copyright 2012, Richard Lowe.
+#
+
+
+$mapfile_version 2
+
+
+SYMBOL_VERSION foo {
+ global:
+ common { ASSERT = { TYPE = CHEWY; }; };
+
+ local:
+ *;
+};
diff --git a/usr/src/test/elf-tests/tests/mapfiles/assert/mapfile.wrongalias b/usr/src/test/elf-tests/tests/mapfiles/assert/mapfile.wrongalias
new file mode 100644
index 0000000000..8ee5b45daa
--- /dev/null
+++ b/usr/src/test/elf-tests/tests/mapfiles/assert/mapfile.wrongalias
@@ -0,0 +1,26 @@
+#
+# This file and its contents are supplied under the terms of the
+# Common Development and Distribution License ("CDDL"), version 1.0.
+# You may only use this file in accordance with the terms of version
+# 1.0 of the CDDL.
+#
+# A full copy of the text of the CDDL should have accompanied this
+# source. A copy of the CDDL is also available via the Internet at
+# http://www.illumos.org/license/CDDL.
+#
+
+#
+# Copyright 2012, Richard Lowe.
+#
+
+
+$mapfile_version 2
+
+
+SYMBOL_VERSION foo {
+ global:
+ weak_function { ASSERT = { BINDING = WEAK; ALIAS = common; }; };
+
+ local:
+ *;
+};
diff --git a/usr/src/test/elf-tests/tests/mapfiles/assert/mapfile.wrongbits b/usr/src/test/elf-tests/tests/mapfiles/assert/mapfile.wrongbits
new file mode 100644
index 0000000000..668c8167e6
--- /dev/null
+++ b/usr/src/test/elf-tests/tests/mapfiles/assert/mapfile.wrongbits
@@ -0,0 +1,32 @@
+#
+# This file and its contents are supplied under the terms of the
+# Common Development and Distribution License ("CDDL"), version 1.0.
+# You may only use this file in accordance with the terms of version
+# 1.0 of the CDDL.
+#
+# A full copy of the text of the CDDL should have accompanied this
+# source. A copy of the CDDL is also available via the Internet at
+# http://www.illumos.org/license/CDDL.
+#
+
+#
+# Copyright 2012, Richard Lowe.
+#
+
+
+$mapfile_version 2
+
+
+SYMBOL_VERSION foo {
+ global:
+ data {
+ ASSERT = {
+ TYPE = OBJECT;
+ SIZE = 5;
+ SH_ATTR = NOBITS;
+ };
+ };
+
+ local:
+ *;
+};
diff --git a/usr/src/test/elf-tests/tests/mapfiles/assert/mapfile.wrongbits2 b/usr/src/test/elf-tests/tests/mapfiles/assert/mapfile.wrongbits2
new file mode 100644
index 0000000000..8a262b5910
--- /dev/null
+++ b/usr/src/test/elf-tests/tests/mapfiles/assert/mapfile.wrongbits2
@@ -0,0 +1,32 @@
+#
+# This file and its contents are supplied under the terms of the
+# Common Development and Distribution License ("CDDL"), version 1.0.
+# You may only use this file in accordance with the terms of version
+# 1.0 of the CDDL.
+#
+# A full copy of the text of the CDDL should have accompanied this
+# source. A copy of the CDDL is also available via the Internet at
+# http://www.illumos.org/license/CDDL.
+#
+
+#
+# Copyright 2012, Richard Lowe.
+#
+
+
+$mapfile_version 2
+
+
+SYMBOL_VERSION foo {
+ global:
+ common {
+ ASSERT = {
+ TYPE = OBJECT;
+ SIZE = 4;
+ SH_ATTR = BITS;
+ };
+ };
+
+ local:
+ *;
+};
diff --git a/usr/src/test/elf-tests/tests/mapfiles/assert/mapfile.wrongscope b/usr/src/test/elf-tests/tests/mapfiles/assert/mapfile.wrongscope
new file mode 100644
index 0000000000..b6b4188945
--- /dev/null
+++ b/usr/src/test/elf-tests/tests/mapfiles/assert/mapfile.wrongscope
@@ -0,0 +1,26 @@
+#
+# This file and its contents are supplied under the terms of the
+# Common Development and Distribution License ("CDDL"), version 1.0.
+# You may only use this file in accordance with the terms of version
+# 1.0 of the CDDL.
+#
+# A full copy of the text of the CDDL should have accompanied this
+# source. A copy of the CDDL is also available via the Internet at
+# http://www.illumos.org/license/CDDL.
+#
+
+#
+# Copyright 2012, Richard Lowe.
+#
+
+
+$mapfile_version 2
+
+
+SYMBOL_VERSION foo {
+ global:
+ function { ASSERT = { TYPE = FUNC; BINDING = WEAK; }; };
+
+ local:
+ *;
+};
diff --git a/usr/src/test/elf-tests/tests/mapfiles/assert/mapfile.wrongsize b/usr/src/test/elf-tests/tests/mapfiles/assert/mapfile.wrongsize
new file mode 100644
index 0000000000..280352d6a0
--- /dev/null
+++ b/usr/src/test/elf-tests/tests/mapfiles/assert/mapfile.wrongsize
@@ -0,0 +1,26 @@
+#
+# This file and its contents are supplied under the terms of the
+# Common Development and Distribution License ("CDDL"), version 1.0.
+# You may only use this file in accordance with the terms of version
+# 1.0 of the CDDL.
+#
+# A full copy of the text of the CDDL should have accompanied this
+# source. A copy of the CDDL is also available via the Internet at
+# http://www.illumos.org/license/CDDL.
+#
+
+#
+# Copyright 2012, Richard Lowe.
+#
+
+
+$mapfile_version 2
+
+
+SYMBOL_VERSION foo {
+ global:
+ data { ASSERT = { TYPE = OBJECT; SIZE = 8; }; };
+
+ local:
+ *;
+};
diff --git a/usr/src/test/elf-tests/tests/mapfiles/assert/mapfile.wrongtype b/usr/src/test/elf-tests/tests/mapfiles/assert/mapfile.wrongtype
new file mode 100644
index 0000000000..6d6ae24885
--- /dev/null
+++ b/usr/src/test/elf-tests/tests/mapfiles/assert/mapfile.wrongtype
@@ -0,0 +1,25 @@
+#
+# This file and its contents are supplied under the terms of the
+# Common Development and Distribution License ("CDDL"), version 1.0.
+# You may only use this file in accordance with the terms of version
+# 1.0 of the CDDL.
+#
+# A full copy of the text of the CDDL should have accompanied this
+# source. A copy of the CDDL is also available via the Internet at
+# http://www.illumos.org/license/CDDL.
+#
+
+#
+# Copyright 2012, Richard Lowe.
+#
+
+
+$mapfile_version 2
+
+
+SYMBOL_VERSION foo {
+ global:
+ data { ASSERT = { TYPE = FUNCTION; }; };
+ local:
+ *;
+};
diff --git a/usr/src/test/elf-tests/tests/mapfiles/assert/mapfile.wrongtype-alias b/usr/src/test/elf-tests/tests/mapfiles/assert/mapfile.wrongtype-alias
new file mode 100644
index 0000000000..467507bc34
--- /dev/null
+++ b/usr/src/test/elf-tests/tests/mapfiles/assert/mapfile.wrongtype-alias
@@ -0,0 +1,26 @@
+#
+# This file and its contents are supplied under the terms of the
+# Common Development and Distribution License ("CDDL"), version 1.0.
+# You may only use this file in accordance with the terms of version
+# 1.0 of the CDDL.
+#
+# A full copy of the text of the CDDL should have accompanied this
+# source. A copy of the CDDL is also available via the Internet at
+# http://www.illumos.org/license/CDDL.
+#
+
+#
+# Copyright 2012, Richard Lowe.
+#
+
+
+$mapfile_version 2
+
+
+SYMBOL_VERSION foo {
+ global:
+ weak_function { ASSERT = { BINDING = WEAK; ALIAS = 31; }; };
+
+ local:
+ *;
+};
diff --git a/usr/src/test/elf-tests/tests/mapfiles/assert/mapfile.wrongtype2 b/usr/src/test/elf-tests/tests/mapfiles/assert/mapfile.wrongtype2
new file mode 100644
index 0000000000..b90fd24cfd
--- /dev/null
+++ b/usr/src/test/elf-tests/tests/mapfiles/assert/mapfile.wrongtype2
@@ -0,0 +1,25 @@
+#
+# This file and its contents are supplied under the terms of the
+# Common Development and Distribution License ("CDDL"), version 1.0.
+# You may only use this file in accordance with the terms of version
+# 1.0 of the CDDL.
+#
+# A full copy of the text of the CDDL should have accompanied this
+# source. A copy of the CDDL is also available via the Internet at
+# http://www.illumos.org/license/CDDL.
+#
+
+#
+# Copyright 2012, Richard Lowe.
+#
+
+
+$mapfile_version 2
+
+
+SYMBOL_VERSION foo {
+ global:
+ data { ASSERT = { TYPE = COMMON; SIZE = 5; }; };
+ local:
+ *;
+};
diff --git a/usr/src/test/elf-tests/tests/mapfiles/assert/object.c b/usr/src/test/elf-tests/tests/mapfiles/assert/object.c
new file mode 100644
index 0000000000..70ed1921a4
--- /dev/null
+++ b/usr/src/test/elf-tests/tests/mapfiles/assert/object.c
@@ -0,0 +1,31 @@
+
+/*
+ * This file and its contents are supplied under the terms of the
+ * Common Development and Distribution License ("CDDL"), version 1.0.
+ * You may only use this file in accordance with the terms of version
+ * 1.0 of the CDDL.
+ *
+ * A full copy of the text of the CDDL should have accompanied this
+ * source. A copy of the CDDL is also available via the Internet at
+ * http://www.illumos.org/license/CDDL.
+ */
+
+/*
+ * Copyright 2012, Richard Lowe.
+ */
+
+__thread char *tbs;
+__thread char *tdata = "tdata!";
+
+char *common;
+
+const char data[] = "data";
+
+#pragma weak weak_function = function
+#pragma weak weak_data = data
+
+int
+function(void)
+{
+ return (1);
+}
diff --git a/usr/src/test/elf-tests/tests/mapfiles/assert/test-assert.sh b/usr/src/test/elf-tests/tests/mapfiles/assert/test-assert.sh
new file mode 100644
index 0000000000..63447e2e08
--- /dev/null
+++ b/usr/src/test/elf-tests/tests/mapfiles/assert/test-assert.sh
@@ -0,0 +1,144 @@
+#! /usr/bin/sh
+#
+# This file and its contents are supplied under the terms of the
+# Common Development and Distribution License ("CDDL"), version 1.0.
+# You may only use this file in accordance with the terms of version
+# 1.0 of the CDDL.
+#
+# A full copy of the text of the CDDL should have accompanied this
+# source. A copy of the CDDL is also available via the Internet at
+# http://www.illumos.org/license/CDDL.
+#
+
+# Copyright 2012, Richard Lowe.
+
+TESTDIR=$(dirname $0)
+
+tmpdir=/tmp/test.$$
+mkdir $tmpdir
+cd $tmpdir
+
+cleanup() {
+ cd /
+ rm -fr $tmpdir
+}
+
+trap 'cleanup' EXIT
+
+if [[ $PWD != $tmpdir ]]; then
+ print -u2 "Failed to create temporary directory: $tmpdir"
+ exit 1;
+fi
+
+if [[ -n $PROTO ]]; then
+ export LD_ALTEXEC=$PROTO/bin/ld
+fi
+
+LDFLAGS="-Wl,-zguidance -Wl,-zfatal-warnings -Wl,-zdirect -Wl,-zlazyload"
+ret=0
+
+function should_succeed {
+ mapfile=$1
+ msg=$2
+
+ if gcc -m32 -shared $LDFLAGS -Wl,-M,${TESTDIR}/$mapfile \
+ ${TESTDIR}/object.c -o object.so; then
+ echo "pass (32): $msg"
+ else
+ echo "FAIL (32): $msg"
+ ret=1
+ fi
+
+ if gcc -m64 -shared $LDFLAGS -Wl,-M,${TESTDIR}/$mapfile \
+ ${TESTDIR}/object.c -o object.so; then
+ echo "pass (64): $msg"
+ else
+ echo "FAIL (64): $msg"
+ ret=1
+ fi
+}
+
+function should_fail {
+ mapfile=$1
+ msg=$2
+ error=$3
+
+ if gcc -m32 -shared $LDFLAGS -Wl,-M,${TESTDIR}/$mapfile \
+ ${TESTDIR}/object.c -o object.so 2>&1 | \
+ /usr/bin/grep -Eq "$error"; then
+ echo "pass (32): $msg"
+ else
+ echo "FAIL (32): $msg"
+ ret=1
+ fi
+
+ if gcc -m64 -shared $LDFLAGS -Wl,-M,${TESTDIR}/$mapfile \
+ ${TESTDIR}/object.c -o object.so 2>&1 | \
+ /usr/bin/grep -Eq "$error"; then
+ echo "pass (64): $msg"
+ else
+ echo "FAIL (64): $msg"
+ ret=1
+ fi
+}
+
+should_succeed mapfile.true "link with correct mapfile"
+
+should_fail mapfile.guidance "link without sized data" \
+ "guidance:.*size assertion.*data"
+
+should_fail mapfile.wrongtype "link with incorrect type in object (data v. function)" \
+ "ld: fatal: .*mapfile.wrongtype: [0-9]+: assertion failed: type of symbol data should be:"
+
+should_fail mapfile.wrongtype2 "link with incorrect type in object (common v. data)" \
+ "ld: fatal: .*mapfile.wrongtype2: [0-9]+: assertion failed: type of symbol data should be:"
+
+should_fail mapfile.wrongsize "link with incorrect size in object" \
+ "ld: fatal: .*mapfile.wrongsize: [0-9]+: assertion failed: size of symbol data should be:"
+
+should_fail mapfile.wrongscope "link with incorrect scope in object" \
+ "ld: fatal: .*mapfile.wrongscope: [0-9]+: assertion failed: scope of symbol function should be:"
+
+should_fail mapfile.wrongbits "link with incorrect shattr in object (nobits when bits)" \
+ "ld: fatal: .*mapfile.wrongbits: [0-9]+: assertion failed: symbol [^ ]* is not in an SHT_NOBITS section"
+
+should_fail mapfile.wrongbits2 "link with incorrect shattr in object (bits when nobits)" \
+ "ld: fatal: .*mapfile.wrongbits2: [0-9]+: assertion failed: symbol [^ ]* is in an SHT_NOBITS section"
+
+should_fail mapfile.unknown-assert "link with unknown assertion type" \
+ "expected attribute name \([^\)]*\), or terminator \([^\)]*\): ICE"
+
+should_fail mapfile.unknown-type "link with unknown type value" \
+ "expected symbol type \([^\)]*\): CHEWY"
+
+should_fail mapfile.unknown-bind "link with unknown bind value" \
+ "expected binding type \([^\)]*\): HEMPEN"
+
+should_fail mapfile.unknown-shattr "link with unknown shattr value" \
+ "expected section attribute \([^)\]*\): WET"
+
+should_fail mapfile.wrongalias "link with incorrect alias" \
+ "ld: fatal: .*mapfile.wrongalias: [0-9]+: assertion failed: symbol weak_function is not an alias of common"
+
+should_fail mapfile.alias-with-others "link with alias and other assertions" \
+ "ALIAS assertions may only be used with BINDING"
+
+should_fail mapfile.unknown-alias "link with alias to unknown symbol" \
+ "ld: fatal: .*mapfile.unknown-alias: [0-9]+: assertion failed: unknown symbol in ALIAS: undefined_symbol"
+
+should_fail mapfile.wrongtype-alias "link with alias to invalid token" \
+ "expected string valued ALIAS"
+
+should_fail mapfile.not-alias "link with two non-alias of the same value" \
+ "ld: fatal: .*mapfile.not-alias: [0-9]+: weak_data and data (.*mapfile.not-alias: [0-9]+)"
+
+should_fail mapfile.no-extern "link with assertions on an extern symbol" \
+ "ld: fatal: .*mapfile.no-extern: [0-9]+: can't assert attributes of extern/parent symbol: extern"
+
+should_fail mapfile.no-parent "link with assertions on a parent symbol" \
+ "ld: fatal: .*mapfile.no-parent: [0-9]+: can't assert attributes of extern/parent symbol: parent"
+
+should_fail mapfile.circalias "link with alias of alias" \
+ "ld: fatal: .*mapfile.circalias: [0-9]+: weak_function should not be aliased to an alias"
+
+exit $ret
diff --git a/usr/src/test/elf-tests/tests/mapfiles/parser/Makefile b/usr/src/test/elf-tests/tests/mapfiles/parser/Makefile
new file mode 100644
index 0000000000..d527f3a375
--- /dev/null
+++ b/usr/src/test/elf-tests/tests/mapfiles/parser/Makefile
@@ -0,0 +1,56 @@
+#
+# This file and its contents are supplied under the terms of the
+# Common Development and Distribution License ("CDDL"), version 1.0.
+# You may only use this file in accordance with the terms of version
+# 1.0 of the CDDL.
+#
+# A full copy of the text of the CDDL should have accompanied this
+# source. A copy of the CDDL is also available via the Internet at
+# http://www.illumos.org/license/CDDL.
+#
+
+# Copyright 2019, Richard Lowe.
+
+include $(SRC)/cmd/Makefile.cmd
+include $(SRC)/test/Makefile.com
+
+PROG = test-parser
+
+DATAFILES= mapfile.addrsize.good \
+ mapfile.addrsize.mult \
+ mapfile.addrsize.substring \
+ mapfile.addrsize.superstring \
+ mapfile.addrsize.wrong \
+ mapfile.sizemult.good \
+ mapfile.sizemult.noterm \
+ mapfile.sizemult.overflow \
+ mapfile.sizemult.twobegin \
+ mapfile.sizemult.wrong \
+ object.c
+
+ROOTOPTPKG = $(ROOT)/opt/elf-tests
+TESTDIR = $(ROOTOPTPKG)/tests/mapfiles/parser
+
+CMDS = $(PROG:%=$(TESTDIR)/%)
+$(CMDS) := FILEMODE = 0555
+
+DATA = $(DATAFILES:%=$(TESTDIR)/%)
+$(DATA) := FILEMODE = 0444
+
+all: $(PROG)
+
+install: all $(CMDS) $(DATA)
+
+clobber: clean
+ -$(RM) $(PROG)
+
+clean:
+ -$(RM) $(CLEANFILES)
+
+$(CMDS): $(TESTDIR) $(PROG)
+
+$(TESTDIR):
+ $(INS.dir)
+
+$(TESTDIR)/%: %
+ $(INS.file)
diff --git a/usr/src/test/elf-tests/tests/mapfiles/parser/mapfile.addrsize.good b/usr/src/test/elf-tests/tests/mapfiles/parser/mapfile.addrsize.good
new file mode 100644
index 0000000000..932784accd
--- /dev/null
+++ b/usr/src/test/elf-tests/tests/mapfiles/parser/mapfile.addrsize.good
@@ -0,0 +1,33 @@
+#
+# This file and its contents are supplied under the terms of the
+# Common Development and Distribution License ("CDDL"), version 1.0.
+# You may only use this file in accordance with the terms of version
+# 1.0 of the CDDL.
+#
+# A full copy of the text of the CDDL should have accompanied this
+# source. A copy of the CDDL is also available via the Internet at
+# http://www.illumos.org/license/CDDL.
+#
+
+#
+# Copyright 2012, Richard Lowe.
+#
+
+
+$mapfile_version 2
+
+
+SYMBOL_VERSION foo {
+ global:
+ common {
+ ASSERT = {
+ TYPE = OBJECT;
+ SIZE = addrsize;
+ SH_ATTR = NOBITS;
+ BINDING = GLOBAL;
+ };
+ };
+
+ local:
+ *;
+};
diff --git a/usr/src/test/elf-tests/tests/mapfiles/parser/mapfile.addrsize.mult b/usr/src/test/elf-tests/tests/mapfiles/parser/mapfile.addrsize.mult
new file mode 100644
index 0000000000..28486ef1e7
--- /dev/null
+++ b/usr/src/test/elf-tests/tests/mapfiles/parser/mapfile.addrsize.mult
@@ -0,0 +1,26 @@
+#
+# This file and its contents are supplied under the terms of the
+# Common Development and Distribution License ("CDDL"), version 1.0.
+# You may only use this file in accordance with the terms of version
+# 1.0 of the CDDL.
+#
+# A full copy of the text of the CDDL should have accompanied this
+# source. A copy of the CDDL is also available via the Internet at
+# http://www.illumos.org/license/CDDL.
+#
+
+#
+# Copyright 2012, Richard Lowe.
+#
+
+
+$mapfile_version 2
+
+
+SYMBOL_VERSION foo {
+ global:
+ data { ASSERT = { TYPE = OBJECT; SIZE = addrsize[2]; }; };
+
+ local:
+ *;
+};
diff --git a/usr/src/test/elf-tests/tests/mapfiles/parser/mapfile.addrsize.substring b/usr/src/test/elf-tests/tests/mapfiles/parser/mapfile.addrsize.substring
new file mode 100644
index 0000000000..fded002c04
--- /dev/null
+++ b/usr/src/test/elf-tests/tests/mapfiles/parser/mapfile.addrsize.substring
@@ -0,0 +1,33 @@
+#
+# This file and its contents are supplied under the terms of the
+# Common Development and Distribution License ("CDDL"), version 1.0.
+# You may only use this file in accordance with the terms of version
+# 1.0 of the CDDL.
+#
+# A full copy of the text of the CDDL should have accompanied this
+# source. A copy of the CDDL is also available via the Internet at
+# http://www.illumos.org/license/CDDL.
+#
+
+#
+# Copyright 2012, Richard Lowe.
+#
+
+
+$mapfile_version 2
+
+
+SYMBOL_VERSION foo {
+ global:
+ common {
+ ASSERT = {
+ TYPE = OBJECT;
+ SIZE = addrs;
+ SH_ATTR = NOBITS;
+ BINDING = GLOBAL;
+ };
+ };
+
+ local:
+ *;
+};
diff --git a/usr/src/test/elf-tests/tests/mapfiles/parser/mapfile.addrsize.superstring b/usr/src/test/elf-tests/tests/mapfiles/parser/mapfile.addrsize.superstring
new file mode 100644
index 0000000000..74d5f2b01f
--- /dev/null
+++ b/usr/src/test/elf-tests/tests/mapfiles/parser/mapfile.addrsize.superstring
@@ -0,0 +1,33 @@
+#
+# This file and its contents are supplied under the terms of the
+# Common Development and Distribution License ("CDDL"), version 1.0.
+# You may only use this file in accordance with the terms of version
+# 1.0 of the CDDL.
+#
+# A full copy of the text of the CDDL should have accompanied this
+# source. A copy of the CDDL is also available via the Internet at
+# http://www.illumos.org/license/CDDL.
+#
+
+#
+# Copyright 2012, Richard Lowe.
+#
+
+
+$mapfile_version 2
+
+
+SYMBOL_VERSION foo {
+ global:
+ common {
+ ASSERT = {
+ TYPE = OBJECT;
+ SIZE = addrsizes;
+ SH_ATTR = NOBITS;
+ BINDING = GLOBAL;
+ };
+ };
+
+ local:
+ *;
+};
diff --git a/usr/src/test/elf-tests/tests/mapfiles/parser/mapfile.addrsize.wrong b/usr/src/test/elf-tests/tests/mapfiles/parser/mapfile.addrsize.wrong
new file mode 100644
index 0000000000..306c3af6c1
--- /dev/null
+++ b/usr/src/test/elf-tests/tests/mapfiles/parser/mapfile.addrsize.wrong
@@ -0,0 +1,33 @@
+#
+# This file and its contents are supplied under the terms of the
+# Common Development and Distribution License ("CDDL"), version 1.0.
+# You may only use this file in accordance with the terms of version
+# 1.0 of the CDDL.
+#
+# A full copy of the text of the CDDL should have accompanied this
+# source. A copy of the CDDL is also available via the Internet at
+# http://www.illumos.org/license/CDDL.
+#
+
+#
+# Copyright 2012, Richard Lowe.
+#
+
+
+$mapfile_version 2
+
+
+SYMBOL_VERSION foo {
+ global:
+ data {
+ ASSERT = {
+ TYPE = OBJECT;
+ SIZE = addrsize;
+ SH_ATTR = BITS;
+ BINDING = GLOBAL;
+ };
+ };
+
+ local:
+ *;
+};
diff --git a/usr/src/test/elf-tests/tests/mapfiles/parser/mapfile.sizemult.good b/usr/src/test/elf-tests/tests/mapfiles/parser/mapfile.sizemult.good
new file mode 100644
index 0000000000..8f8194ea06
--- /dev/null
+++ b/usr/src/test/elf-tests/tests/mapfiles/parser/mapfile.sizemult.good
@@ -0,0 +1,38 @@
+#
+# This file and its contents are supplied under the terms of the
+# Common Development and Distribution License ("CDDL"), version 1.0.
+# You may only use this file in accordance with the terms of version
+# 1.0 of the CDDL.
+#
+# A full copy of the text of the CDDL should have accompanied this
+# source. A copy of the CDDL is also available via the Internet at
+# http://www.illumos.org/license/CDDL.
+#
+
+#
+# Copyright 2012, Richard Lowe.
+#
+
+$mapfile_version 2
+
+
+SYMBOL_VERSION foo {
+ global:
+ common {
+ ASSERT = {
+ TYPE = OBJECT;
+$if _ELF32
+ SIZE = 2[2];
+$elif _ELF64
+ SIZE = 4[2];
+$else
+$error unknown platform
+$endif
+ SH_ATTR = NOBITS;
+ BINDING = GLOBAL;
+ };
+ };
+
+ local:
+ *;
+};
diff --git a/usr/src/test/elf-tests/tests/mapfiles/parser/mapfile.sizemult.noterm b/usr/src/test/elf-tests/tests/mapfiles/parser/mapfile.sizemult.noterm
new file mode 100644
index 0000000000..dd678b9154
--- /dev/null
+++ b/usr/src/test/elf-tests/tests/mapfiles/parser/mapfile.sizemult.noterm
@@ -0,0 +1,33 @@
+#
+# This file and its contents are supplied under the terms of the
+# Common Development and Distribution License ("CDDL"), version 1.0.
+# You may only use this file in accordance with the terms of version
+# 1.0 of the CDDL.
+#
+# A full copy of the text of the CDDL should have accompanied this
+# source. A copy of the CDDL is also available via the Internet at
+# http://www.illumos.org/license/CDDL.
+#
+
+#
+# Copyright 2012, Richard Lowe.
+#
+
+
+$mapfile_version 2
+
+
+SYMBOL_VERSION foo {
+ global:
+ common {
+ ASSERT = {
+ TYPE = OBJECT;
+ SIZE = 2[4;
+ SH_ATTR = NOBITS;
+ BINDING = GLOBAL;
+ };
+ };
+
+ local:
+ *;
+};
diff --git a/usr/src/test/elf-tests/tests/mapfiles/parser/mapfile.sizemult.overflow b/usr/src/test/elf-tests/tests/mapfiles/parser/mapfile.sizemult.overflow
new file mode 100644
index 0000000000..6cee34e19c
--- /dev/null
+++ b/usr/src/test/elf-tests/tests/mapfiles/parser/mapfile.sizemult.overflow
@@ -0,0 +1,33 @@
+#
+# This file and its contents are supplied under the terms of the
+# Common Development and Distribution License ("CDDL"), version 1.0.
+# You may only use this file in accordance with the terms of version
+# 1.0 of the CDDL.
+#
+# A full copy of the text of the CDDL should have accompanied this
+# source. A copy of the CDDL is also available via the Internet at
+# http://www.illumos.org/license/CDDL.
+#
+
+#
+# Copyright 2012, Richard Lowe.
+#
+
+$mapfile_version 2
+
+SYMBOL_VERSION foo {
+ global:
+ gensym { TYPE = DATA;
+ # Overflow size
+$if _ELF32
+ SIZE = 0xffffffff[0x2];
+$elif _ELF64
+ SIZE = 0xffffffffffffffff[0x2];
+$else
+$error unknown platform
+$endif
+ };
+
+ local:
+ *;
+};
diff --git a/usr/src/test/elf-tests/tests/mapfiles/parser/mapfile.sizemult.twobegin b/usr/src/test/elf-tests/tests/mapfiles/parser/mapfile.sizemult.twobegin
new file mode 100644
index 0000000000..ce782d8dfe
--- /dev/null
+++ b/usr/src/test/elf-tests/tests/mapfiles/parser/mapfile.sizemult.twobegin
@@ -0,0 +1,33 @@
+#
+# This file and its contents are supplied under the terms of the
+# Common Development and Distribution License ("CDDL"), version 1.0.
+# You may only use this file in accordance with the terms of version
+# 1.0 of the CDDL.
+#
+# A full copy of the text of the CDDL should have accompanied this
+# source. A copy of the CDDL is also available via the Internet at
+# http://www.illumos.org/license/CDDL.
+#
+
+#
+# Copyright 2012, Richard Lowe.
+#
+
+
+$mapfile_version 2
+
+
+SYMBOL_VERSION foo {
+ global:
+ common {
+ ASSERT = {
+ TYPE = OBJECT;
+ SIZE = 2[[4];
+ SH_ATTR = NOBITS;
+ BINDING = GLOBAL;
+ };
+ };
+
+ local:
+ *;
+};
diff --git a/usr/src/test/elf-tests/tests/mapfiles/parser/mapfile.sizemult.wrong b/usr/src/test/elf-tests/tests/mapfiles/parser/mapfile.sizemult.wrong
new file mode 100644
index 0000000000..d04b0b4d05
--- /dev/null
+++ b/usr/src/test/elf-tests/tests/mapfiles/parser/mapfile.sizemult.wrong
@@ -0,0 +1,39 @@
+#
+# This file and its contents are supplied under the terms of the
+# Common Development and Distribution License ("CDDL"), version 1.0.
+# You may only use this file in accordance with the terms of version
+# 1.0 of the CDDL.
+#
+# A full copy of the text of the CDDL should have accompanied this
+# source. A copy of the CDDL is also available via the Internet at
+# http://www.illumos.org/license/CDDL.
+#
+
+#
+# Copyright 2012, Richard Lowe.
+#
+
+
+$mapfile_version 2
+
+
+SYMBOL_VERSION foo {
+ global:
+ common {
+ ASSERT = {
+ TYPE = OBJECT;
+$if _ELF32
+ SIZE = 2[4];
+$elif _ELF64
+ SIZE = 4[4];
+$else
+$error unknown platform
+$endif
+ SH_ATTR = NOBITS;
+ BINDING = GLOBAL;
+ };
+ };
+
+ local:
+ *;
+};
diff --git a/usr/src/test/elf-tests/tests/mapfiles/parser/object.c b/usr/src/test/elf-tests/tests/mapfiles/parser/object.c
new file mode 100644
index 0000000000..bac42fe326
--- /dev/null
+++ b/usr/src/test/elf-tests/tests/mapfiles/parser/object.c
@@ -0,0 +1,18 @@
+
+/*
+ * This file and its contents are supplied under the terms of the
+ * Common Development and Distribution License ("CDDL"), version 1.0.
+ * You may only use this file in accordance with the terms of version
+ * 1.0 of the CDDL.
+ *
+ * A full copy of the text of the CDDL should have accompanied this
+ * source. A copy of the CDDL is also available via the Internet at
+ * http://www.illumos.org/license/CDDL.
+ */
+
+/*
+ * Copyright 2012, Richard Lowe.
+ */
+
+char *common;
+const char *data[2];
diff --git a/usr/src/test/elf-tests/tests/mapfiles/parser/test-parser.sh b/usr/src/test/elf-tests/tests/mapfiles/parser/test-parser.sh
new file mode 100644
index 0000000000..1fb8634da9
--- /dev/null
+++ b/usr/src/test/elf-tests/tests/mapfiles/parser/test-parser.sh
@@ -0,0 +1,108 @@
+#! /usr/bin/sh
+#
+# This file and its contents are supplied under the terms of the
+# Common Development and Distribution License ("CDDL"), version 1.0.
+# You may only use this file in accordance with the terms of version
+# 1.0 of the CDDL.
+#
+# A full copy of the text of the CDDL should have accompanied this
+# source. A copy of the CDDL is also available via the Internet at
+# http://www.illumos.org/license/CDDL.
+#
+
+# Copyright 2012, Richard Lowe.
+
+TESTDIR=$(dirname $0)
+
+tmpdir=/tmp/test.$$
+mkdir $tmpdir
+cd $tmpdir
+
+cleanup() {
+ cd /
+ rm -fr $tmpdir
+}
+
+trap 'cleanup' EXIT
+
+if [[ $PWD != $tmpdir ]]; then
+ print -u2 "Failed to create temporary directory: $tmpdir"
+ exit 1;
+fi
+
+if [[ -n $PROTO ]]; then
+ export LD_ALTEXEC=$PROTO/bin/ld
+fi
+
+ret=0
+
+function should_succeed {
+ mapfile=$1
+ msg=$2
+
+ if gcc -m32 -shared -Wl,-M,${TESTDIR}/$mapfile ${TESTDIR}/object.c \
+ -o object.so; then
+ echo "pass (32): $msg"
+ else
+ echo "FAIL (32): $msg"
+ ret=1
+ fi
+
+ if gcc -m64 -shared -Wl,-M,${TESTDIR}/$mapfile ${TESTDIR}/object.c \
+ -o object.so; then
+ echo "pass (64): $msg"
+ else
+ echo "FAIL (64): $msg"
+ ret=1
+ fi
+}
+
+function should_fail {
+ mapfile=$1
+ msg=$2
+ error=$3
+
+ if gcc -m32 -shared -Wl,-M,${TESTDIR}/$mapfile ${TESTDIR}/object.c \
+ -o object.so 2>&1 | /usr/bin/grep -Eq "$error"; then
+ echo "pass (32): $msg"
+ else
+ echo "FAIL (32): $msg"
+ ret=1
+ fi
+
+ if gcc -m64 -shared -Wl,-M,${TESTDIR}/$mapfile ${TESTDIR}/object.c \
+ -o object.so 2>&1 | /usr/bin/grep -Eq "$error"; then
+ echo "pass (64): $msg"
+ else
+ echo "FAIL (64): $msg"
+ ret=1
+ fi
+}
+
+should_succeed mapfile.sizemult.good "link with integer multiplier syntax"
+
+should_fail mapfile.sizemult.wrong "link with integer multiplier syntax with wrong result" \
+ "assertion failed: size of symbol common should be: [0-9]+ is: [0-9]+"
+should_fail mapfile.sizemult.noterm "link with integer multiplier syntax with no terminating ]" \
+ "expected '.' to terminate multiplier of: 2"
+
+should_fail mapfile.sizemult.twobegin "link with integer multiplier with two [s" \
+ "expected integer value following '.': 2..4"
+
+should_fail mapfile.sizemult.overflow "link with integer multiplier that overflows" \
+ "multiplication overflow"
+
+should_succeed mapfile.addrsize.good "link with addrsized symbol"
+
+should_succeed mapfile.addrsize.mult "link with addrsized symbol with multiplier"
+
+should_fail mapfile.addrsize.wrong "link with addrsized symbol with wrong value" \
+ "assertion failed: size of symbol"
+
+should_fail mapfile.addrsize.substring "link with addrsized symbol with substring of valid name" \
+ "expected integer value following SIZE: addrs"
+
+should_fail mapfile.addrsize.superstring "link with addrsized symbol with superstring of valid name" \
+ "expected integer value following SIZE: addrsizes"
+
+exit $ret