summaryrefslogtreecommitdiff
path: root/usr/src/test/elf-tests
diff options
context:
space:
mode:
authorRob Johnston <rob.johnston@joyent.com>2019-03-29 00:41:51 +0000
committerRob Johnston <rob.johnston@joyent.com>2019-03-29 00:41:51 +0000
commit001fcdd9e24e10f0f713d66ade5b578899a617b8 (patch)
tree8a1970e5a081da4fa90c4405f886131a81479e89 /usr/src/test/elf-tests
parentaafbeec1fd0d7a80544a087b4a08e199e08cdf90 (diff)
parent451d765fb45021fb191507bcbe46a507f1ec89d9 (diff)
downloadillumos-joyent-001fcdd9e24e10f0f713d66ade5b578899a617b8.tar.gz
Merge remote-tracking branch 'origin/master' into uefi
Diffstat (limited to 'usr/src/test/elf-tests')
-rw-r--r--usr/src/test/elf-tests/Makefile20
-rw-r--r--usr/src/test/elf-tests/cmd/Makefile38
-rw-r--r--usr/src/test/elf-tests/cmd/elftest.ksh49
-rw-r--r--usr/src/test/elf-tests/doc/Makefile36
-rw-r--r--usr/src/test/elf-tests/doc/README59
-rw-r--r--usr/src/test/elf-tests/runfiles/Makefile40
-rw-r--r--usr/src/test/elf-tests/runfiles/default.run37
-rw-r--r--usr/src/test/elf-tests/tests/Makefile21
-rw-r--r--usr/src/test/elf-tests/tests/assert-deflib/Makefile48
-rw-r--r--usr/src/test/elf-tests/tests/assert-deflib/link.c23
-rw-r--r--usr/src/test/elf-tests/tests/assert-deflib/test-deflib.sh136
-rw-r--r--usr/src/test/elf-tests/tests/tls/Makefile19
-rw-r--r--usr/src/test/elf-tests/tests/tls/amd64/Makefile19
-rw-r--r--usr/src/test/elf-tests/tests/tls/amd64/ie/Makefile58
-rw-r--r--usr/src/test/elf-tests/tests/tls/amd64/ie/Makefile.test79
-rw-r--r--usr/src/test/elf-tests/tests/tls/amd64/ie/README5
-rw-r--r--usr/src/test/elf-tests/tests/tls/amd64/ie/amd64-ie-test.sh64
-rw-r--r--usr/src/test/elf-tests/tests/tls/amd64/ie/orig/style1-func.c24
-rw-r--r--usr/src/test/elf-tests/tests/tls/amd64/ie/orig/style1-main.c29
-rw-r--r--usr/src/test/elf-tests/tests/tls/amd64/ie/orig/style2.c25
-rw-r--r--usr/src/test/elf-tests/tests/tls/amd64/ie/style1-func-with-r12.s39
-rw-r--r--usr/src/test/elf-tests/tests/tls/amd64/ie/style1-func-with-r13.s38
-rw-r--r--usr/src/test/elf-tests/tests/tls/amd64/ie/style1-func.s38
-rw-r--r--usr/src/test/elf-tests/tests/tls/amd64/ie/style1-main.s60
-rw-r--r--usr/src/test/elf-tests/tests/tls/amd64/ie/style2-with-badness.s47
-rw-r--r--usr/src/test/elf-tests/tests/tls/amd64/ie/style2-with-r12.s49
-rw-r--r--usr/src/test/elf-tests/tests/tls/amd64/ie/style2-with-r13.s48
-rw-r--r--usr/src/test/elf-tests/tests/tls/amd64/ie/style2.s47
-rw-r--r--usr/src/test/elf-tests/tests/tls/amd64/ld/Makefile51
-rw-r--r--usr/src/test/elf-tests/tests/tls/amd64/ld/Makefile.test38
-rw-r--r--usr/src/test/elf-tests/tests/tls/amd64/ld/amd64-ld-test.sh46
-rw-r--r--usr/src/test/elf-tests/tests/tls/amd64/ld/ld-with-addend.s43
-rw-r--r--usr/src/test/elf-tests/tests/tls/i386/Makefile19
-rw-r--r--usr/src/test/elf-tests/tests/tls/i386/ld/Makefile51
-rw-r--r--usr/src/test/elf-tests/tests/tls/i386/ld/Makefile.test38
-rw-r--r--usr/src/test/elf-tests/tests/tls/i386/ld/half-ldm.s49
-rw-r--r--usr/src/test/elf-tests/tests/tls/i386/ld/i386-ld-test.sh43
37 files changed, 1573 insertions, 0 deletions
diff --git a/usr/src/test/elf-tests/Makefile b/usr/src/test/elf-tests/Makefile
new file mode 100644
index 0000000000..6669972e13
--- /dev/null
+++ b/usr/src/test/elf-tests/Makefile
@@ -0,0 +1,20 @@
+#
+# 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 2015 Nexenta Systems, Inc. All rights reserved.
+#
+
+.PARALLEL: $(SUBDIRS)
+
+SUBDIRS = cmd doc runfiles tests
+
+include $(SRC)/test/Makefile.com
diff --git a/usr/src/test/elf-tests/cmd/Makefile b/usr/src/test/elf-tests/cmd/Makefile
new file mode 100644
index 0000000000..ccda4af74e
--- /dev/null
+++ b/usr/src/test/elf-tests/cmd/Makefile
@@ -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 (c) 2012 by Delphix. All rights reserved.
+# Copyright 2015 Nexenta Systems, Inc. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+include $(SRC)/test/Makefile.com
+
+ROOTOPTPKG = $(ROOT)/opt/elf-tests
+ROOTBIN = $(ROOTOPTPKG)/bin
+
+PROGS = elftest
+
+CMDS = $(PROGS:%=$(ROOTBIN)/%)
+$(CMDS) := FILEMODE = 0555
+
+all lint clean clobber:
+
+install: $(CMDS)
+
+$(CMDS): $(ROOTBIN)
+
+$(ROOTBIN):
+ $(INS.dir)
+
+$(ROOTBIN)/%: %.ksh
+ $(INS.rename)
diff --git a/usr/src/test/elf-tests/cmd/elftest.ksh b/usr/src/test/elf-tests/cmd/elftest.ksh
new file mode 100644
index 0000000000..b5a0d9b52f
--- /dev/null
+++ b/usr/src/test/elf-tests/cmd/elftest.ksh
@@ -0,0 +1,49 @@
+#!/usr/bin/ksh
+
+#
+# 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 2015 Nexenta Systems, Inc. All rights reserved.
+#
+
+ELF_TESTS="/opt/elf-tests"
+runner="/opt/test-runner/bin/run"
+
+function fail
+{
+ echo $1
+ exit ${2:-1}
+}
+
+function find_runfile
+{
+ typeset distro=default
+
+ [[ -n $distro ]] && echo $ELF_TESTS/runfiles/$distro.run
+}
+
+while getopts c: c; do
+ case $c in
+ 'c')
+ runfile=$OPTARG
+ [[ -f $runfile ]] || fail "Cannot read file: $runfile"
+ ;;
+ esac
+done
+shift $((OPTIND - 1))
+
+[[ -z $runfile ]] && runfile=$(find_runfile)
+[[ -z $runfile ]] && fail "Couldn't determine distro"
+
+$runner -c $runfile
+
+exit $?
diff --git a/usr/src/test/elf-tests/doc/Makefile b/usr/src/test/elf-tests/doc/Makefile
new file mode 100644
index 0000000000..b2d50b7b93
--- /dev/null
+++ b/usr/src/test/elf-tests/doc/Makefile
@@ -0,0 +1,36 @@
+#
+# 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 (c) 2012 by Delphix. All rights reserved.
+# Copyright 2015 Nexenta Systems, Inc. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+READMES = README
+
+ROOTOPTPKG = $(ROOT)/opt/elf-tests
+
+FILES = $(READMES:%=$(ROOTOPTPKG)/%)
+$(FILES) := FILEMODE = 0444
+
+all: $(READMES)
+
+install: $(ROOTOPTPKG) $(FILES)
+
+clean lint clobber:
+
+$(ROOTOPTPKG):
+ $(INS.dir)
+
+$(ROOTOPTPKG)/%: %
+ $(INS.file)
diff --git a/usr/src/test/elf-tests/doc/README b/usr/src/test/elf-tests/doc/README
new file mode 100644
index 0000000000..ef8ecda914
--- /dev/null
+++ b/usr/src/test/elf-tests/doc/README
@@ -0,0 +1,59 @@
+#
+# 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 (c) 2012 by Delphix. All rights reserved.
+# Copyright 2015 Nexenta Systems, Inc. All rights reserved.
+#
+
+ELF Software Generation Utilities Unit Test Suite README
+
+1. Building and installing the ELF/SGS Unit Test Suite
+2. Running the ELF/SGS Unit Test Suite
+3. Test results
+
+--------------------------------------------------------------------------------
+
+1. Building and installing the ELF/SGS Unit Test Suite
+
+The ELF/SGS Unit Test Suite runs under the testrunner framework (which can be
+installed as pkg:/system/test/testrunner). To build both the ELF/SGS Unit Test Suite
+and the testrunner without running a full nightly:
+
+ build_machine$ bldenv [-d] <your_env_file>
+ build_machine$ cd $SRC/test
+ build_machine$ dmake install
+ build_machine$ cd $SRC/pkg
+ build_machine$ dmake install
+
+Then set the publisher on the test machine to point to your repository and
+install the ELF/SGS Unit Test Suite.
+
+ test_machine# pkg install pkg:/system/test/elftest
+
+Note, the framework will be installed automatically, as the ELF/SGS Unit Test Suite
+depends on it.
+
+2. Running the ELF/SGS Unit Test Suite
+
+The pre-requisites for running the ELF/SGS Unit Test Suite are:
+ None
+
+Once the pre-requisites are satisfied, simply run the elftest script:
+
+ test_machine$ /opt/elf-tests/bin/elftest
+
+3. Test results
+
+While the ELF/SGS Unit Test Suite is running, one informational line is printed at
+the end of each test, and a results summary is printed at the end of the run.
+The results summary includes the location of the complete logs, which is of the
+form /var/tmp/test_results/<ISO 8601 date>.
diff --git a/usr/src/test/elf-tests/runfiles/Makefile b/usr/src/test/elf-tests/runfiles/Makefile
new file mode 100644
index 0000000000..cf1ac703d7
--- /dev/null
+++ b/usr/src/test/elf-tests/runfiles/Makefile
@@ -0,0 +1,40 @@
+#
+# 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 (c) 2012 by Delphix. All rights reserved.
+# Copyright 2014, OmniTI Computer Consulting, Inc. All rights reserved.
+# Copyright 2014 Garrett D'Amore <garrett@damore.org>
+#
+
+include $(SRC)/Makefile.master
+
+SRCS = default.run
+
+ROOTOPTPKG = $(ROOT)/opt/elf-tests
+RUNFILES = $(ROOTOPTPKG)/runfiles
+
+CMDS = $(SRCS:%=$(RUNFILES)/%)
+$(CMDS) := FILEMODE = 0444
+
+all: $(SRCS)
+
+install: $(CMDS)
+
+clean lint clobber:
+
+$(CMDS): $(RUNFILES) $(SRCS)
+
+$(RUNFILES):
+ $(INS.dir)
+
+$(RUNFILES)/%: %
+ $(INS.file)
diff --git a/usr/src/test/elf-tests/runfiles/default.run b/usr/src/test/elf-tests/runfiles/default.run
new file mode 100644
index 0000000000..f1b0c8980a
--- /dev/null
+++ b/usr/src/test/elf-tests/runfiles/default.run
@@ -0,0 +1,37 @@
+
+#
+# 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 2018, Richard Lowe.
+
+[DEFAULT]
+pre =
+verbose = False
+quiet = False
+timeout = 60
+post =
+outputdir = /var/tmp/test_results
+
+[/opt/elf-tests/tests/assert-deflib]
+tests = ['test-deflib']
+
+
+[/opt/elf-tests/tests/tls/amd64/ie]
+arch = i86pc
+tests = ['amd64-ie-test']
+
+[/opt/elf-tests/tests/tls/i386/ld]
+arch = i86pc
+tests = ['i386-ld-test']
+
+[/opt/elf-tests/tests/tls/amd64/ld]
+arch = i86pc
+tests = ['amd64-ld-test']
diff --git a/usr/src/test/elf-tests/tests/Makefile b/usr/src/test/elf-tests/tests/Makefile
new file mode 100644
index 0000000000..e3894ac07d
--- /dev/null
+++ b/usr/src/test/elf-tests/tests/Makefile
@@ -0,0 +1,21 @@
+#
+# 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 (c) 2012, 2016 by Delphix. All rights reserved.
+# Copyright 2018 Joyent, Inc.
+#
+
+SUBDIRS = \
+ assert-deflib \
+ tls
+
+include $(SRC)/test/Makefile.com
diff --git a/usr/src/test/elf-tests/tests/assert-deflib/Makefile b/usr/src/test/elf-tests/tests/assert-deflib/Makefile
new file mode 100644
index 0000000000..768182efbc
--- /dev/null
+++ b/usr/src/test/elf-tests/tests/assert-deflib/Makefile
@@ -0,0 +1,48 @@
+#
+# 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 2018, Richard Lowe.
+
+include $(SRC)/cmd/Makefile.cmd
+include $(SRC)/test/Makefile.com
+
+PROG = test-deflib
+
+DATAFILES = link.c
+
+ROOTOPTPKG = $(ROOT)/opt/elf-tests
+TESTDIR = $(ROOTOPTPKG)/tests/assert-deflib
+
+CMDS = $(PROG:%=$(TESTDIR)/%)
+$(CMDS) := FILEMODE = 0555
+
+DATA = $(DATAFILES:%=$(TESTDIR)/%)
+$(DATA) := FILEMODE = 0444
+
+all: $(PROG)
+
+install: all $(CMDS) $(DATA)
+
+lint:
+
+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/assert-deflib/link.c b/usr/src/test/elf-tests/tests/assert-deflib/link.c
new file mode 100644
index 0000000000..823c7a3785
--- /dev/null
+++ b/usr/src/test/elf-tests/tests/assert-deflib/link.c
@@ -0,0 +1,23 @@
+/*
+ * 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 (c) 2012, Joyent, Inc.
+ */
+
+#include <stdio.h>
+
+int
+main(void)
+{
+ (void) printf("Hello, world!\n");
+ return (0);
+}
diff --git a/usr/src/test/elf-tests/tests/assert-deflib/test-deflib.sh b/usr/src/test/elf-tests/tests/assert-deflib/test-deflib.sh
new file mode 100644
index 0000000000..f2f710e0c1
--- /dev/null
+++ b/usr/src/test/elf-tests/tests/assert-deflib/test-deflib.sh
@@ -0,0 +1,136 @@
+#!/bin/bash
+#
+# 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 (c) 2012, Joyent, Inc.
+#
+
+#
+# This test validates that the -zassert-deflib option of ld(1) works correctly.
+# It requires that some cc is in your path and that you have passed in the path
+# to the proto area with the new version of libld.so.4. One thing that we have
+# to do is be careful with using LD_LIBRARY_PATH. Setting LD_LIBRARY_PATH does
+# not change the default search path so we want to make sure that we use a
+# different ISA (e.g. 32-bit vs 64-bit) from the binary we're generating.
+#
+unalias -a
+
+TESTDIR=$(dirname $0)
+
+sh_path=
+sh_lib="lib"
+sh_lib64="$sh_lib/64"
+sh_soname="libld.so.4"
+sh_cc="gcc"
+sh_cflags="-m32"
+sh_file="${TESTDIR}/link.c"
+sh_arg0=$(basename $0)
+
+function fatal
+{
+ local msg="$*"
+ [[ -z "$msg" ]] && msg="failed"
+ echo "$sh_arg0: $msg" >&2
+ exit 1
+}
+
+
+#
+# Validate that everything we need is in our path. That includes having cc
+# and the proto area libld.
+#
+function validate
+{
+ [[ -f $sh_path/$sh_lib/$sh_soname ]] || fatal "missing 32-bit $sh_soname"
+ [[ -f $sh_path/$sh_lib64/$sh_soname ]] ||
+ fatal "missing 64-bit $sh_soname"
+ which $sh_cc >/dev/null || fatal "cc not in path"
+}
+
+#
+# $1 is a series of flags to append
+# $2 is expected exit status
+# $3 is pre-test message
+# $4 is the failure message
+#
+function run
+{
+ local ret
+
+ echo $3
+ LD_LIBRARY_PATH_64="$sh_path/$sh_lib64" $sh_cc $sh_cflags $sh_file $1
+ if [[ $? -eq $2 ]]; then
+ printf "success\n\n"
+ else
+ fatal $4
+ fi
+}
+
+sh_path=${1:-/}
+validate
+
+run "-Wl,-zassert-deflib" 0 \
+ "Testing basic compilation succeeds with warnings..." \
+ "failed to compile with warnings"
+
+run "-Wl,-zassert-deflib -Wl,-zfatal-warnings" 1 \
+ "Testing basic compilation fails if warning are fatal..." \
+ "linking succeeeded, expected failure"
+
+run "-Wl,-zassert-deflib=libc.so -Wl,-zfatal-warnings" 0 \
+ "Testing basic exception with fatal warnings..." \
+ "linking failed despite exception"
+
+run "-Wl,-zassert-deflib=libc.so -Wl,-zfatal-warnings" 0 \
+ "Testing basic exception with fatal warnings..." \
+ "linking failed despite exception"
+
+
+run "-Wl,-zassert-deflib=lib.so -Wl,-zfatal-warnings" 1 \
+ "Testing invalid library name..." \
+ "ld should not allow invalid library name"
+
+run "-Wl,-zassert-deflib=libf -Wl,-zfatal-warnings" 1 \
+ "Testing invalid library name..." \
+ "ld should not allow invalid library name"
+
+run "-Wl,-zassert-deflib=libf.s -Wl,-zfatal-warnings" 1 \
+ "Testing invalid library name..." \
+ "ld should not allow invalid library name"
+
+run "-Wl,-zassert-deflib=libc.so -Wl,-zfatal-warnings -lelf" 1 \
+ "Errors even if one library is under exception path..." \
+ "one exception shouldn't stop another"
+
+args="-Wl,-zassert-deflib=libc.so -Wl,-zassert-deflib=libelf.so"
+args="$args -Wl,-zfatal-warnings -lelf"
+
+run "$args" 0 \
+ "Multiple exceptions work..." \
+ "multiple exceptions don't work"
+
+args="-Wl,-zassert-deflib=libc.so -Wl,-zassert-deflib=libelfe.so"
+args="$args -Wl,-zfatal-warnings -lelf"
+
+run "$args" 1 \
+ "Exceptions only catch the specific library" \
+ "exceptions caught the wrong library"
+
+args="-Wl,-zassert-deflib=libc.so -Wl,-zassert-deflib=libel.so"
+args="$args -Wl,-zfatal-warnings -lelf"
+
+run "$args" 1 \
+ "Exceptions only catch the specific library" \
+ "exceptions caught the wrong library"
+
+echo "Tests passed."
+exit 0
diff --git a/usr/src/test/elf-tests/tests/tls/Makefile b/usr/src/test/elf-tests/tests/tls/Makefile
new file mode 100644
index 0000000000..d0dc53a033
--- /dev/null
+++ b/usr/src/test/elf-tests/tests/tls/Makefile
@@ -0,0 +1,19 @@
+#
+# 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 (c) 2012, 2016 by Delphix. All rights reserved.
+# Copyright 2018 Joyent, Inc.
+#
+
+SUBDIRS = amd64 i386
+
+include $(SRC)/test/Makefile.com
diff --git a/usr/src/test/elf-tests/tests/tls/amd64/Makefile b/usr/src/test/elf-tests/tests/tls/amd64/Makefile
new file mode 100644
index 0000000000..c7755dcb5b
--- /dev/null
+++ b/usr/src/test/elf-tests/tests/tls/amd64/Makefile
@@ -0,0 +1,19 @@
+#
+# 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 (c) 2012, 2016 by Delphix. All rights reserved.
+# Copyright 2018 Joyent, Inc.
+#
+
+SUBDIRS = ie ld
+
+include $(SRC)/test/Makefile.com
diff --git a/usr/src/test/elf-tests/tests/tls/amd64/ie/Makefile b/usr/src/test/elf-tests/tests/tls/amd64/ie/Makefile
new file mode 100644
index 0000000000..7ffb91e837
--- /dev/null
+++ b/usr/src/test/elf-tests/tests/tls/amd64/ie/Makefile
@@ -0,0 +1,58 @@
+#
+# 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 2018, Richard Lowe.
+
+include $(SRC)/cmd/Makefile.cmd
+include $(SRC)/test/Makefile.com
+
+PROG = amd64-ie-test
+
+DATAFILES = \
+ Makefile.test \
+ style1-func-with-r12.s \
+ style1-func-with-r13.s \
+ style1-func.s \
+ style1-main.s \
+ style2-with-badness.s \
+ style2-with-r12.s \
+ style2-with-r13.s \
+ style2.s
+
+ROOTOPTPKG = $(ROOT)/opt/elf-tests
+TESTDIR = $(ROOTOPTPKG)/tests/tls/amd64/ie
+
+CMDS = $(PROG:%=$(TESTDIR)/%)
+$(CMDS) := FILEMODE = 0555
+
+
+DATA = $(DATAFILES:%=$(TESTDIR)/%)
+$(DATA) := FILEMODE = 0444
+
+all: $(PROG)
+
+install: all $(CMDS) $(DATA)
+
+lint:
+
+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/tls/amd64/ie/Makefile.test b/usr/src/test/elf-tests/tests/tls/amd64/ie/Makefile.test
new file mode 100644
index 0000000000..7f08ba0538
--- /dev/null
+++ b/usr/src/test/elf-tests/tests/tls/amd64/ie/Makefile.test
@@ -0,0 +1,79 @@
+#
+# 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.
+
+CC = gcc
+CFLAGS = -O1 -m64
+
+LINK.c = $(CC) $(CFLAGS) -o $@ $^
+COMPILE.s = $(CC) $(CFLAGS) -c -o $@ $^
+
+.KEEP_STATE:
+
+install default: all
+
+%.o: $(TESTDIR)/%.s
+ $(COMPILE.s)
+
+# A basic use of TLS that uses the movq m/r --> movq i/r variant
+PROGS += style2
+STYLE2OBJS = style2.o
+style2: $(STYLE2OBJS)
+ $(LINK.c)
+
+# A copy of style2 that uses %r13 in the TLS sequence, and thus excercises the
+# REX transitions of the movq mem,reg -> movq imm,reg variant.
+PROGS += style2-with-r13
+STYLE2R13OBJS = style2-with-r13.o
+style2-with-r13: $(STYLE2R13OBJS)
+ $(LINK.c)
+
+# A copy of style2 that uses %r12 in the TLS sequence, so we can verify that
+# it is _not_ special to this variant
+PROGS += style2-with-r12
+STYLE2R12OBJS = style2-with-r12.o
+style2-with-r12: $(STYLE2R12OBJS)
+ $(LINK.c)
+
+# A copy of style2 that has a R_AMD64_GOTTPOFF relocation with a bad insn sequence
+STYLE2BADNESSOBJS = style2-with-badness.o
+style2-with-badness: $(STYLE2BADNESSOBJS)
+ -$(LINK.c)
+
+# A basic use of TLS that uses the addq mem/reg --> leaq mem,reg variant
+PROGS += style1
+STYLE1OBJS = style1-main.o style1-func.o
+style1: $(STYLE1OBJS)
+ $(LINK.c)
+
+# A copy of style1-func that uses %r13 in the TLS sequence and thus excercises
+# the REX transitions. of the addq mem,reg --> leaq mem,reg variant
+PROGS += style1-with-r13
+STYLE1R13OBJS = style1-main.o style1-func-with-r13.o
+style1-with-r13: $(STYLE1R13OBJS)
+ $(LINK.c)
+
+# A copy of style1-func that uses %r12 to test the addq mem,reg --> addq imm,reg variant
+PROGS += style1-with-r12
+STYLE1R12OBJS = style1-main.o style1-func-with-r12.o
+style1-with-r12: $(STYLE1R12OBJS)
+ $(LINK.c)
+
+all: $(PROGS)
+
+clobber clean:
+ rm -f $(PROGS) $(STYLE1OBJS) $(STYLE1R13OBJS) $(STYLE1R12OBJS) \
+ $(STYLE2OBJS) $(STYLE2R13OBJS) $(STYLE2R12OBJS) $(STYLE2BADNESSOBJS)
+
+fail: style2-with-badness FRC
+
+FRC:
diff --git a/usr/src/test/elf-tests/tests/tls/amd64/ie/README b/usr/src/test/elf-tests/tests/tls/amd64/ie/README
new file mode 100644
index 0000000000..cdbf6a4b20
--- /dev/null
+++ b/usr/src/test/elf-tests/tests/tls/amd64/ie/README
@@ -0,0 +1,5 @@
+This tests the amd64 link-editor's handling of Initial Executable TLS sequences.
+
+The original C source files are in orig/ but unused, since we need to avoid
+any changes to the compiler influencing our tests.
+
diff --git a/usr/src/test/elf-tests/tests/tls/amd64/ie/amd64-ie-test.sh b/usr/src/test/elf-tests/tests/tls/amd64/ie/amd64-ie-test.sh
new file mode 100644
index 0000000000..4b9c9cd2d6
--- /dev/null
+++ b/usr/src/test/elf-tests/tests/tls/amd64/ie/amd64-ie-test.sh
@@ -0,0 +1,64 @@
+#!/bin/ksh
+#
+# 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.
+
+function grep_test {
+ name=$1
+ pattern=$2
+
+ if /usr/bin/fgrep -q "${pattern}"; then
+ print -u2 "pass: $name"
+ else
+ print -u2 "FAIL: $name"
+ exit 1
+ fi
+}
+
+function dis_test {
+ name=${1}
+ func=${2}
+ file=${3}
+ pattern=${4}
+
+ dis -F${func} ${file} | grep_test "${name}" "${pattern}"
+}
+
+TESTDIR=$(dirname $0)
+make -f ${TESTDIR}/Makefile.test TESTDIR=${TESTDIR}
+
+dis_test "addq-->leaq 1" func style1 \
+ 'func+0x10: 48 8d 92 f8 ff ff leaq -0x8(%rdx),%rdx'
+dis_test "addq-->leaq 2" func style1 \
+ 'func+0x17: 48 8d b6 f0 ff ff leaq -0x10(%rsi),%rsi'
+
+dis_test "addq-->leaq w/REX 1" func style1-with-r13 \
+ 'func+0x10: 48 8d 92 f8 ff ff leaq -0x8(%rdx),%rdx'
+dis_test "addq-->leaq w/REX 2" func style1-with-r13 \
+ 'func+0x17: 4d 8d ad f0 ff ff leaq -0x10(%r13),%r13'
+
+dis_test "addq-->addq for SIB 1" func style1-with-r12 \
+ 'func+0x10: 48 8d 92 f8 ff ff leaq -0x8(%rdx),%rdx'
+dis_test "addq-->addq for SIB 2" func style1-with-r12 \
+ 'func+0x17: 49 81 c4 f0 ff ff addq $-0x10,%r12 <0xfffffffffffffff0>'
+
+dis_test "movq-->movq" main style2 \
+ 'main+0x4: 48 c7 c6 f0 ff ff movq $-0x10,%rsi <0xfffffffffffffff0>'
+
+dis_test "movq-->movq w/REX" main style2-with-r13 \
+ 'main+0x4: 49 c7 c5 f0 ff ff movq $-0x10,%r13 <0xfffffffffffffff0>'
+
+dis_test "movq-->movq incase of SIB" main style2-with-r12 \
+ 'main+0x4: 49 c7 c4 f0 ff ff movq $-0x10,%r12 <0xfffffffffffffff0>'
+
+make -f ${TESTDIR}/Makefile.test fail TESTDIR=${TESTDIR} 2>&1 | grep_test "bad insn sequence" \
+ 'ld: fatal: relocation error: R_AMD64_TPOFF32: file style2-with-badness.o: symbol foo: section .text: offset 0x7, relocation against unknown TLS instruction sequence'
diff --git a/usr/src/test/elf-tests/tests/tls/amd64/ie/orig/style1-func.c b/usr/src/test/elf-tests/tests/tls/amd64/ie/orig/style1-func.c
new file mode 100644
index 0000000000..ed06493f66
--- /dev/null
+++ b/usr/src/test/elf-tests/tests/tls/amd64/ie/orig/style1-func.c
@@ -0,0 +1,24 @@
+/*
+ * 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.
+ */
+
+#include <stdio.h>
+
+extern __thread char *foo, *bar;
+
+void
+func()
+{
+ printf("foo: %p bar: %p\n", &foo, &bar);
+}
diff --git a/usr/src/test/elf-tests/tests/tls/amd64/ie/orig/style1-main.c b/usr/src/test/elf-tests/tests/tls/amd64/ie/orig/style1-main.c
new file mode 100644
index 0000000000..ac95fe9a58
--- /dev/null
+++ b/usr/src/test/elf-tests/tests/tls/amd64/ie/orig/style1-main.c
@@ -0,0 +1,29 @@
+/*
+ * 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.
+ */
+
+#include <stdio.h>
+
+extern void func();
+
+__thread char *foo = "foo";
+__thread char *bar = "bar";
+
+int
+main(void)
+{
+ printf("foo: %p bar: %p\n", &foo, &bar);
+ func();
+ return (0);
+}
diff --git a/usr/src/test/elf-tests/tests/tls/amd64/ie/orig/style2.c b/usr/src/test/elf-tests/tests/tls/amd64/ie/orig/style2.c
new file mode 100644
index 0000000000..c8b9ae407c
--- /dev/null
+++ b/usr/src/test/elf-tests/tests/tls/amd64/ie/orig/style2.c
@@ -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.
+ */
+
+#include <stdio.h>
+
+__thread char *foo __attribute__((tls_model("initial-exec"))) = "foo";
+
+int
+main(void)
+{
+ printf("foo: %p\n", &foo);
+ return (0);
+}
diff --git a/usr/src/test/elf-tests/tests/tls/amd64/ie/style1-func-with-r12.s b/usr/src/test/elf-tests/tests/tls/amd64/ie/style1-func-with-r12.s
new file mode 100644
index 0000000000..7d7821bed5
--- /dev/null
+++ b/usr/src/test/elf-tests/tests/tls/amd64/ie/style1-func-with-r12.s
@@ -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.
+ */
+
+ .section .rodata.str1.1,"aMS",@progbits,1
+.LC0:
+ .string "foo: %p bar: %p\n"
+ .text
+.globl func
+ .type func, @function
+func:
+.LFB0:
+ pushq %rbp
+.LCFI0:
+ movq %rsp, %rbp
+.LCFI1:
+ movq %fs:0, %r12
+ movq %r12, %rdx
+ addq bar@GOTTPOFF(%rip), %rdx
+ addq foo@GOTTPOFF(%rip), %r12
+ movq %r12, %rsi
+ movl $.LC0, %edi
+ movl $0, %eax
+ call printf
+ leave
+ ret
+.LFE0:
+ .size func, .-func
diff --git a/usr/src/test/elf-tests/tests/tls/amd64/ie/style1-func-with-r13.s b/usr/src/test/elf-tests/tests/tls/amd64/ie/style1-func-with-r13.s
new file mode 100644
index 0000000000..97908bd720
--- /dev/null
+++ b/usr/src/test/elf-tests/tests/tls/amd64/ie/style1-func-with-r13.s
@@ -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.
+ */
+ .section .rodata.str1.1,"aMS",@progbits,1
+.LC0:
+ .string "foo: %p bar: %p\n"
+ .text
+.globl func
+ .type func, @function
+func:
+.LFB0:
+ pushq %rbp
+.LCFI0:
+ movq %rsp, %rbp
+.LCFI1:
+ movq %fs:0, %r13
+ movq %r13, %rdx
+ addq bar@GOTTPOFF(%rip), %rdx
+ addq foo@GOTTPOFF(%rip), %r13
+ movq %r13, %rsi
+ movl $.LC0, %edi
+ movl $0, %eax
+ call printf
+ leave
+ ret
+.LFE0:
+ .size func, .-func
diff --git a/usr/src/test/elf-tests/tests/tls/amd64/ie/style1-func.s b/usr/src/test/elf-tests/tests/tls/amd64/ie/style1-func.s
new file mode 100644
index 0000000000..ae03161880
--- /dev/null
+++ b/usr/src/test/elf-tests/tests/tls/amd64/ie/style1-func.s
@@ -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.
+ */
+
+ .section .rodata.str1.1,"aMS",@progbits,1
+.LC0:
+ .string "foo: %p bar: %p\n"
+ .text
+.globl func
+ .type func, @function
+func:
+.LFB0:
+ pushq %rbp
+.LCFI0:
+ movq %rsp, %rbp
+.LCFI1:
+ movq %fs:0, %rsi
+ movq %rsi, %rdx
+ addq bar@GOTTPOFF(%rip), %rdx
+ addq foo@GOTTPOFF(%rip), %rsi
+ movl $.LC0, %edi
+ movl $0, %eax
+ call printf
+ leave
+ ret
+.LFE0:
+ .size func, .-func
diff --git a/usr/src/test/elf-tests/tests/tls/amd64/ie/style1-main.s b/usr/src/test/elf-tests/tests/tls/amd64/ie/style1-main.s
new file mode 100644
index 0000000000..08362f3c93
--- /dev/null
+++ b/usr/src/test/elf-tests/tests/tls/amd64/ie/style1-main.s
@@ -0,0 +1,60 @@
+/*
+ * 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.
+ */
+
+ .section .rodata.str1.1,"aMS",@progbits,1
+.LC0:
+ .string "foo: %p bar: %p\n"
+ .text
+.globl main
+ .type main, @function
+main:
+.LFB0:
+ pushq %rbp
+.LCFI0:
+ movq %rsp, %rbp
+.LCFI1:
+ movq %fs:0, %rsi
+ leaq bar@TPOFF(%rsi), %rdx
+ addq $foo@TPOFF, %rsi
+ movl $.LC0, %edi
+ movl $0, %eax
+ call printf
+ movl $0, %eax
+ call func
+ movl $0, %eax
+ leave
+ ret
+.LFE0:
+ .size main, .-main
+.globl foo
+ .section .rodata.str1.1
+.LC1:
+ .string "foo"
+ .section .tdata,"awT",@progbits
+ .align 8
+ .type foo, @object
+ .size foo, 8
+foo:
+ .quad .LC1
+.globl bar
+ .section .rodata.str1.1
+.LC2:
+ .string "bar"
+ .section .tdata
+ .align 8
+ .type bar, @object
+ .size bar, 8
+bar:
+ .quad .LC2
diff --git a/usr/src/test/elf-tests/tests/tls/amd64/ie/style2-with-badness.s b/usr/src/test/elf-tests/tests/tls/amd64/ie/style2-with-badness.s
new file mode 100644
index 0000000000..74534f8dd3
--- /dev/null
+++ b/usr/src/test/elf-tests/tests/tls/amd64/ie/style2-with-badness.s
@@ -0,0 +1,47 @@
+/*
+ * 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.
+ */
+
+ .section .rodata.str1.1,"aMS",@progbits,1
+.LC0:
+ .string "foo: %p\n"
+ .text
+.globl main
+ .type main, @function
+main:
+.LFB0:
+ pushq %rbp
+.LCFI0:
+ movq %rsp, %rbp
+.LCFI1:
+ leaq foo@GOTTPOFF(%rip), %rsi
+ addq %fs:0, %rsi
+ movl $.LC0, %edi
+ movl $0, %eax
+ call printf
+ movl $0, %eax
+ leave
+ ret
+.LFE0:
+ .size main, .-main
+.globl foo
+ .section .rodata.str1.1
+.LC1:
+ .string "foo"
+ .section .tdata,"awT",@progbits
+ .align 8
+ .type foo, @object
+ .size foo, 8
+foo:
+ .quad .LC1
diff --git a/usr/src/test/elf-tests/tests/tls/amd64/ie/style2-with-r12.s b/usr/src/test/elf-tests/tests/tls/amd64/ie/style2-with-r12.s
new file mode 100644
index 0000000000..d446982d90
--- /dev/null
+++ b/usr/src/test/elf-tests/tests/tls/amd64/ie/style2-with-r12.s
@@ -0,0 +1,49 @@
+/*
+ * 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.
+ */
+
+ .section .rodata.str1.1,"aMS",@progbits,1
+.LC0:
+ .string "foo: %p\n"
+ .text
+.globl main
+ .type main, @function
+main:
+.LFB0:
+ pushq %rbp
+.LCFI0:
+ movq %rsp, %rbp
+.LCFI1:
+ movq foo@GOTTPOFF(%rip), %r12
+ addq %fs:0, %r12
+ movq %r12, %rsi
+ movl $.LC0, %edi
+ movl $0, %eax
+ call printf
+ movl $0, %eax
+ leave
+ ret
+.LFE0:
+ .size main, .-main
+.globl foo
+ .section .rodata.str1.1
+.LC1:
+ .string "foo"
+
+ .section .tdata,"awT",@progbits
+ .align 8
+ .type foo, @object
+ .size foo, 8
+foo:
+ .quad .LC1
diff --git a/usr/src/test/elf-tests/tests/tls/amd64/ie/style2-with-r13.s b/usr/src/test/elf-tests/tests/tls/amd64/ie/style2-with-r13.s
new file mode 100644
index 0000000000..cc740903da
--- /dev/null
+++ b/usr/src/test/elf-tests/tests/tls/amd64/ie/style2-with-r13.s
@@ -0,0 +1,48 @@
+/*
+ * 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.
+ */
+
+ .section .rodata.str1.1,"aMS",@progbits,1
+.LC0:
+ .string "foo: %p\n"
+ .text
+.globl main
+ .type main, @function
+main:
+.LFB0:
+ pushq %rbp
+.LCFI0:
+ movq %rsp, %rbp
+.LCFI1:
+ movq foo@GOTTPOFF(%rip), %r13
+ addq %fs:0, %r13
+ movq %r13, %rsi
+ movl $.LC0, %edi
+ movl $0, %eax
+ call printf
+ movl $0, %eax
+ leave
+ ret
+.LFE0:
+ .size main, .-main
+.globl foo
+ .section .rodata.str1.1
+.LC1:
+ .string "foo"
+ .section .tdata,"awT",@progbits
+ .align 8
+ .type foo, @object
+ .size foo, 8
+foo:
+ .quad .LC1
diff --git a/usr/src/test/elf-tests/tests/tls/amd64/ie/style2.s b/usr/src/test/elf-tests/tests/tls/amd64/ie/style2.s
new file mode 100644
index 0000000000..8ab6cc9d40
--- /dev/null
+++ b/usr/src/test/elf-tests/tests/tls/amd64/ie/style2.s
@@ -0,0 +1,47 @@
+/*
+ * 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.
+ */
+
+ .section .rodata.str1.1,"aMS",@progbits,1
+.LC0:
+ .string "foo: %p\n"
+ .text
+.globl main
+ .type main, @function
+main:
+.LFB0:
+ pushq %rbp
+.LCFI0:
+ movq %rsp, %rbp
+.LCFI1:
+ movq foo@GOTTPOFF(%rip), %rsi
+ addq %fs:0, %rsi
+ movl $.LC0, %edi
+ movl $0, %eax
+ call printf
+ movl $0, %eax
+ leave
+ ret
+.LFE0:
+ .size main, .-main
+.globl foo
+ .section .rodata.str1.1
+.LC1:
+ .string "foo"
+ .section .tdata,"awT",@progbits
+ .align 8
+ .type foo, @object
+ .size foo, 8
+foo:
+ .quad .LC1
diff --git a/usr/src/test/elf-tests/tests/tls/amd64/ld/Makefile b/usr/src/test/elf-tests/tests/tls/amd64/ld/Makefile
new file mode 100644
index 0000000000..29bf217170
--- /dev/null
+++ b/usr/src/test/elf-tests/tests/tls/amd64/ld/Makefile
@@ -0,0 +1,51 @@
+#
+# 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 2018, Richard Lowe.
+
+include $(SRC)/cmd/Makefile.cmd
+include $(SRC)/test/Makefile.com
+
+PROG = amd64-ld-test
+
+DATAFILES = \
+ Makefile.test \
+ ld-with-addend.s \
+
+ROOTOPTPKG = $(ROOT)/opt/elf-tests
+TESTDIR = $(ROOTOPTPKG)/tests/tls/amd64/ld
+
+CMDS = $(PROG:%=$(TESTDIR)/%)
+$(CMDS) := FILEMODE = 0555
+
+
+DATA = $(DATAFILES:%=$(TESTDIR)/%)
+$(DATA) := FILEMODE = 0444
+
+all: $(PROG)
+
+install: all $(CMDS) $(DATA)
+
+lint:
+
+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/tls/amd64/ld/Makefile.test b/usr/src/test/elf-tests/tests/tls/amd64/ld/Makefile.test
new file mode 100644
index 0000000000..026b70b6d5
--- /dev/null
+++ b/usr/src/test/elf-tests/tests/tls/amd64/ld/Makefile.test
@@ -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.
+
+CC = gcc
+CFLAGS = -O1 -m64
+
+LINK.c = $(CC) $(CFLAGS) -o $@ $^
+COMPILE.s = $(CC) $(CFLAGS) -c -o $@ $^
+
+.KEEP_STATE:
+
+install default: all
+
+%.o: $(TESTDIR)/%.s
+ $(COMPILE.s)
+
+# an R_AMD64_DTPOFF32 with an addend, which must be preserved
+PROGS += ld-with-addend
+
+ld-with-addend: ld-with-addend.o
+ $(LINK.c)
+
+all: $(PROGS)
+
+clobber clean:
+ rm -f $(PROGS) ld-with-addend.o
+
+FRC:
diff --git a/usr/src/test/elf-tests/tests/tls/amd64/ld/amd64-ld-test.sh b/usr/src/test/elf-tests/tests/tls/amd64/ld/amd64-ld-test.sh
new file mode 100644
index 0000000000..08eb00be54
--- /dev/null
+++ b/usr/src/test/elf-tests/tests/tls/amd64/ld/amd64-ld-test.sh
@@ -0,0 +1,46 @@
+#!/bin/ksh
+#
+# 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.
+
+function grep_test {
+ name=$1
+ pattern=$2
+
+ if /usr/bin/grep -q "${pattern}"; then
+ print -u2 "pass: $name"
+ else
+ print -u2 "FAIL: $name"
+ exit 1
+ fi
+}
+
+function dis_test {
+ name=${1}
+ func=${2}
+ file=${3}
+ pattern=${4}
+
+ dis -F${func} ${file} | grep_test "${name}" "${pattern}"
+}
+
+TESTDIR=$(dirname $0)
+
+make -f ${TESTDIR}/Makefile.test TESTDIR=${TESTDIR}
+
+# if we fail, the addend won't be applied, the leaq with be -0x10(%rax)
+dis_test "addend is preserved" main ld-with-addend \
+ 'main+0x10: 48 8d b0 f2 ff ff leaq -0xe(%rax),%rsi'
+
+# We have an addend of 2, a failure will print 'incorrect'
+./ld-with-addend | grep_test 'ld-with-addend execution' \
+ '^foo: correct ([a-f0-9]*)$'
diff --git a/usr/src/test/elf-tests/tests/tls/amd64/ld/ld-with-addend.s b/usr/src/test/elf-tests/tests/tls/amd64/ld/ld-with-addend.s
new file mode 100644
index 0000000000..1c919462f3
--- /dev/null
+++ b/usr/src/test/elf-tests/tests/tls/amd64/ld/ld-with-addend.s
@@ -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.
+ */
+
+ .section .rodata.str1.1,"aMS",@progbits,1
+.LC0:
+ .string "foo: %s (%p)\n"
+ .text
+ .section .tdata,"awT",@progbits
+foo:
+ .string "incorrect"
+ .text
+.globl main
+ .type main, @function
+main:
+.LFB0:
+ pushq %rbp
+.LCFI0:
+ movq %rsp, %rbp
+ .LCFI1:
+ leaq foo@tlsld(%rip), %rdi
+ call __tls_get_addr@plt
+ leaq 2+foo@dtpoff(%rax), %rsi
+ movq %rsi, %rdx
+ movq %rsi, %rsi
+ movl $.LC0, %edi
+ movl $0, %eax
+ call printf
+ movl $0, %eax
+ leave
+ ret
+ .size main, .-main
diff --git a/usr/src/test/elf-tests/tests/tls/i386/Makefile b/usr/src/test/elf-tests/tests/tls/i386/Makefile
new file mode 100644
index 0000000000..51053ae31b
--- /dev/null
+++ b/usr/src/test/elf-tests/tests/tls/i386/Makefile
@@ -0,0 +1,19 @@
+#
+# 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 (c) 2012, 2016 by Delphix. All rights reserved.
+# Copyright 2018 Joyent, Inc.
+#
+
+SUBDIRS = ld
+
+include $(SRC)/test/Makefile.com
diff --git a/usr/src/test/elf-tests/tests/tls/i386/ld/Makefile b/usr/src/test/elf-tests/tests/tls/i386/ld/Makefile
new file mode 100644
index 0000000000..2550e1c457
--- /dev/null
+++ b/usr/src/test/elf-tests/tests/tls/i386/ld/Makefile
@@ -0,0 +1,51 @@
+#
+# 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 2018, Richard Lowe.
+
+include $(SRC)/cmd/Makefile.cmd
+include $(SRC)/test/Makefile.com
+
+PROG = i386-ld-test
+
+DATAFILES = \
+ Makefile.test \
+ half-ldm.s \
+
+ROOTOPTPKG = $(ROOT)/opt/elf-tests
+TESTDIR = $(ROOTOPTPKG)/tests/tls/i386/ld
+
+CMDS = $(PROG:%=$(TESTDIR)/%)
+$(CMDS) := FILEMODE = 0555
+
+
+DATA = $(DATAFILES:%=$(TESTDIR)/%)
+$(DATA) := FILEMODE = 0444
+
+all: $(PROG)
+
+install: all $(CMDS) $(DATA)
+
+lint:
+
+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/tls/i386/ld/Makefile.test b/usr/src/test/elf-tests/tests/tls/i386/ld/Makefile.test
new file mode 100644
index 0000000000..f6e9413310
--- /dev/null
+++ b/usr/src/test/elf-tests/tests/tls/i386/ld/Makefile.test
@@ -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.
+
+CC = gcc
+CFLAGS = -O1 -m32
+
+LINK.c = $(CC) $(CFLAGS) -o $@ $^
+COMPILE.s = $(CC) $(CFLAGS) -c -o $@ $^
+
+.KEEP_STATE:
+
+install default: all
+
+%.o: $(TESTDIR)/%.s
+ $(COMPILE.s)
+
+# an R_386_TLS_LDM with a regular R_386_PLT32 not a R_386_TLS_LDM_PLT
+PROGS += half-ldm
+
+half-ldm: half-ldm.o
+ $(LINK.c)
+
+all: $(PROGS)
+
+clobber clean:
+ rm -f $(PROGS) half-ldm.o
+
+FRC:
diff --git a/usr/src/test/elf-tests/tests/tls/i386/ld/half-ldm.s b/usr/src/test/elf-tests/tests/tls/i386/ld/half-ldm.s
new file mode 100644
index 0000000000..f8e6dbc528
--- /dev/null
+++ b/usr/src/test/elf-tests/tests/tls/i386/ld/half-ldm.s
@@ -0,0 +1,49 @@
+/*
+ * 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.u
+ */
+
+/*
+ * Copyright 2019, Richard Lowe.
+ */
+
+ .section .rodata.str1.1,"aMS",@progbits,1
+.LC0:
+ .string "foo: %s (%p)\n"
+ .section .tdata,"awT",@progbits
+ .align 4
+ .type foo, @object
+ .size foo,4
+.local foo
+foo:
+ .string "foo"
+ .text
+.globl main
+ .type main, @function
+main:
+ pushl %ebp
+ movl %esp, %ebp
+ /*
+ * an R_386_TLS_LDM relocation without a following
+ * followed by an R_386_PLT32 relocation, rather than an
+ * R_386_TLS_LDM_PLT the call should be removed, and _not_
+ * left alone unrelocated as it was prior to:
+ * 10267 ld and GCC disagree about i386 local dynamic TLS
+ */
+ leal foo@TLSLDM(%ebx), %eax
+ call ___tls_get_addr@PLT
+ leal foo@DTPOFF(%eax), %edx
+ pushl %edx
+ pushl %edx
+ pushl $.LC0
+ call printf@PLT
+ movl $0x0,%eax
+ leave
+ ret
+ .size main, .-main
diff --git a/usr/src/test/elf-tests/tests/tls/i386/ld/i386-ld-test.sh b/usr/src/test/elf-tests/tests/tls/i386/ld/i386-ld-test.sh
new file mode 100644
index 0000000000..a86cc5a717
--- /dev/null
+++ b/usr/src/test/elf-tests/tests/tls/i386/ld/i386-ld-test.sh
@@ -0,0 +1,43 @@
+#!/bin/ksh
+#
+# 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.
+
+function grep_test {
+ name=$1
+ pattern=$2
+
+ if /usr/bin/grep -q "${pattern}"; then
+ print -u2 "pass: $name"
+ else
+ print -u2 "FAIL: $name"
+ exit 1
+ fi
+}
+
+function dis_test {
+ name=${1}
+ func=${2}
+ file=${3}
+ pattern=${4}
+
+ dis -F${func} ${file} | grep_test "${name}" "${pattern}"
+}
+
+TESTDIR=$(dirname $0)
+make -f ${TESTDIR}/Makefile.test TESTDIR=${TESTDIR}
+
+dis_test "call-->nop" main half-ldm \
+ 'main\+0x9: 0f 1f 44 00 00 nopl 0x0(%eax,%eax)'
+
+./half-ldm | grep_test 'half-ldm execution' \
+ '^foo: foo ([a-f0-9]*)$'