5f7b84
From 0d3905b110000463775b3fb189213833acaebf81 Mon Sep 17 00:00:00 2001
5f7b84
From: "H.J. Lu" <hjl.tools@gmail.com>
5f7b84
Date: Mon, 1 Jul 2019 12:23:10 -0700
5f7b84
Subject: Call _dl_open_check after relocation [BZ #24259]
5f7b84
5f7b84
This is a workaround for [BZ #20839] which doesn't remove the NODELETE
5f7b84
object when _dl_open_check throws an exception.  Move it after relocation
5f7b84
in dl_open_worker to avoid leaving the NODELETE object mapped without
5f7b84
relocation.
5f7b84
5f7b84
	[BZ #24259]
5f7b84
	* elf/dl-open.c (dl_open_worker): Call _dl_open_check after
5f7b84
	relocation.
5f7b84
	* sysdeps/x86/Makefile (tests): Add tst-cet-legacy-5a,
5f7b84
	tst-cet-legacy-5b, tst-cet-legacy-6a and tst-cet-legacy-6b.
5f7b84
	(modules-names): Add tst-cet-legacy-mod-5a, tst-cet-legacy-mod-5b,
5f7b84
	tst-cet-legacy-mod-5c, tst-cet-legacy-mod-6a, tst-cet-legacy-mod-6b
5f7b84
	and tst-cet-legacy-mod-6c.
5f7b84
	(CFLAGS-tst-cet-legacy-5a.c): New.
5f7b84
	(CFLAGS-tst-cet-legacy-5b.c): Likewise.
5f7b84
	(CFLAGS-tst-cet-legacy-mod-5a.c): Likewise.
5f7b84
	(CFLAGS-tst-cet-legacy-mod-5b.c): Likewise.
5f7b84
	(CFLAGS-tst-cet-legacy-mod-5c.c): Likewise.
5f7b84
	(CFLAGS-tst-cet-legacy-6a.c): Likewise.
5f7b84
	(CFLAGS-tst-cet-legacy-6b.c): Likewise.
5f7b84
	(CFLAGS-tst-cet-legacy-mod-6a.c): Likewise.
5f7b84
	(CFLAGS-tst-cet-legacy-mod-6b.c): Likewise.
5f7b84
	(CFLAGS-tst-cet-legacy-mod-6c.c): Likewise.
5f7b84
	($(objpfx)tst-cet-legacy-5a): Likewise.
5f7b84
	($(objpfx)tst-cet-legacy-5a.out): Likewise.
5f7b84
	($(objpfx)tst-cet-legacy-mod-5a.so): Likewise.
5f7b84
	($(objpfx)tst-cet-legacy-mod-5b.so): Likewise.
5f7b84
	($(objpfx)tst-cet-legacy-5b): Likewise.
5f7b84
	($(objpfx)tst-cet-legacy-5b.out): Likewise.
5f7b84
	(tst-cet-legacy-5b-ENV): Likewise.
5f7b84
	($(objpfx)tst-cet-legacy-6a): Likewise.
5f7b84
	($(objpfx)tst-cet-legacy-6a.out): Likewise.
5f7b84
	($(objpfx)tst-cet-legacy-mod-6a.so): Likewise.
5f7b84
	($(objpfx)tst-cet-legacy-mod-6b.so): Likewise.
5f7b84
	($(objpfx)tst-cet-legacy-6b): Likewise.
5f7b84
	($(objpfx)tst-cet-legacy-6b.out): Likewise.
5f7b84
	(tst-cet-legacy-6b-ENV): Likewise.
5f7b84
	* sysdeps/x86/tst-cet-legacy-5.c: New file.
5f7b84
	* sysdeps/x86/tst-cet-legacy-5a.c: Likewise.
5f7b84
	* sysdeps/x86/tst-cet-legacy-5b.c: Likewise.
5f7b84
	* sysdeps/x86/tst-cet-legacy-6.c: Likewise.
5f7b84
	* sysdeps/x86/tst-cet-legacy-6a.c: Likewise.
5f7b84
	* sysdeps/x86/tst-cet-legacy-6b.c: Likewise.
5f7b84
	* sysdeps/x86/tst-cet-legacy-mod-5.c: Likewise.
5f7b84
	* sysdeps/x86/tst-cet-legacy-mod-5a.c: Likewise.
5f7b84
	* sysdeps/x86/tst-cet-legacy-mod-5b.c: Likewise.
5f7b84
	* sysdeps/x86/tst-cet-legacy-mod-5c.c: Likewise.
5f7b84
	* sysdeps/x86/tst-cet-legacy-mod-6.c: Likewise.
5f7b84
	* sysdeps/x86/tst-cet-legacy-mod-6a.c: Likewise.
5f7b84
	* sysdeps/x86/tst-cet-legacy-mod-6b.c: Likewise.
5f7b84
	* sysdeps/x86/tst-cet-legacy-mod-6c.c: Likewise.
5f7b84
5f7b84
(cherry picked from commit d0093c5cefb7f7a4143f3bb03743633823229cc6)
5f7b84
5f7b84
diff --git a/elf/dl-open.c b/elf/dl-open.c
5f7b84
index f6c8ef1043..518a6cad69 100644
5f7b84
--- a/elf/dl-open.c
5f7b84
+++ b/elf/dl-open.c
5f7b84
@@ -292,8 +292,6 @@ dl_open_worker (void *a)
5f7b84
   _dl_debug_state ();
5f7b84
   LIBC_PROBE (map_complete, 3, args->nsid, r, new);
5f7b84
 
5f7b84
-  _dl_open_check (new);
5f7b84
-
5f7b84
   /* Print scope information.  */
5f7b84
   if (__glibc_unlikely (GLRO(dl_debug_mask) & DL_DEBUG_SCOPES))
5f7b84
     _dl_show_scope (new, 0);
5f7b84
@@ -366,6 +364,12 @@ dl_open_worker (void *a)
5f7b84
 	_dl_relocate_object (l, l->l_scope, reloc_mode, 0);
5f7b84
     }
5f7b84
 
5f7b84
+  /* NB: Workaround for [BZ #20839] which doesn't remove the NODELETE
5f7b84
+     object when _dl_open_check throws an exception.  Move it after
5f7b84
+     relocation to avoid leaving the NODELETE object mapped without
5f7b84
+     relocation.  */
5f7b84
+  _dl_open_check (new);
5f7b84
+
5f7b84
   /* If the file is not loaded now as a dependency, add the search
5f7b84
      list of the newly loaded object to the scope.  */
5f7b84
   bool any_tls = false;
5f7b84
diff --git a/sysdeps/x86/Makefile b/sysdeps/x86/Makefile
5f7b84
index 337b0b63dc..43ad4a79ff 100644
5f7b84
--- a/sysdeps/x86/Makefile
5f7b84
+++ b/sysdeps/x86/Makefile
5f7b84
@@ -19,12 +19,17 @@ ifeq ($(subdir),elf)
5f7b84
 sysdep-dl-routines += dl-cet
5f7b84
 
5f7b84
 tests += tst-cet-legacy-1 tst-cet-legacy-2 tst-cet-legacy-2a \
5f7b84
-	 tst-cet-legacy-3 tst-cet-legacy-4
5f7b84
+	 tst-cet-legacy-3 tst-cet-legacy-4 \
5f7b84
+	 tst-cet-legacy-5a tst-cet-legacy-6a
5f7b84
 ifneq (no,$(have-tunables))
5f7b84
-tests += tst-cet-legacy-4a tst-cet-legacy-4b tst-cet-legacy-4c
5f7b84
+tests += tst-cet-legacy-4a tst-cet-legacy-4b tst-cet-legacy-4c \
5f7b84
+	 tst-cet-legacy-5b tst-cet-legacy-6b
5f7b84
 endif
5f7b84
 modules-names += tst-cet-legacy-mod-1 tst-cet-legacy-mod-2 \
5f7b84
-		 tst-cet-legacy-mod-4
5f7b84
+		 tst-cet-legacy-mod-4 tst-cet-legacy-mod-5a \
5f7b84
+		 tst-cet-legacy-mod-5b tst-cet-legacy-mod-5c \
5f7b84
+		 tst-cet-legacy-mod-6a tst-cet-legacy-mod-6b \
5f7b84
+		 tst-cet-legacy-mod-6c
5f7b84
 
5f7b84
 CFLAGS-tst-cet-legacy-2.c += -fcf-protection=branch
5f7b84
 CFLAGS-tst-cet-legacy-2a.c += -fcf-protection
5f7b84
@@ -35,6 +40,16 @@ CFLAGS-tst-cet-legacy-4.c += -fcf-protection=branch
5f7b84
 CFLAGS-tst-cet-legacy-4a.c += -fcf-protection
5f7b84
 CFLAGS-tst-cet-legacy-4b.c += -fcf-protection
5f7b84
 CFLAGS-tst-cet-legacy-mod-4.c += -fcf-protection=none
5f7b84
+CFLAGS-tst-cet-legacy-5a.c += -fcf-protection
5f7b84
+CFLAGS-tst-cet-legacy-5b.c += -fcf-protection
5f7b84
+CFLAGS-tst-cet-legacy-mod-5a.c += -fcf-protection=none
5f7b84
+CFLAGS-tst-cet-legacy-mod-5b.c += -fcf-protection
5f7b84
+CFLAGS-tst-cet-legacy-mod-5c.c += -fcf-protection
5f7b84
+CFLAGS-tst-cet-legacy-6a.c += -fcf-protection
5f7b84
+CFLAGS-tst-cet-legacy-6b.c += -fcf-protection
5f7b84
+CFLAGS-tst-cet-legacy-mod-6a.c += -fcf-protection=none
5f7b84
+CFLAGS-tst-cet-legacy-mod-6b.c += -fcf-protection
5f7b84
+CFLAGS-tst-cet-legacy-mod-6c.c += -fcf-protection
5f7b84
 
5f7b84
 $(objpfx)tst-cet-legacy-1: $(objpfx)tst-cet-legacy-mod-1.so \
5f7b84
 		       $(objpfx)tst-cet-legacy-mod-2.so
5f7b84
@@ -44,6 +59,17 @@ $(objpfx)tst-cet-legacy-2a: $(objpfx)tst-cet-legacy-mod-2.so $(libdl)
5f7b84
 $(objpfx)tst-cet-legacy-2a.out: $(objpfx)tst-cet-legacy-mod-1.so
5f7b84
 $(objpfx)tst-cet-legacy-4: $(libdl)
5f7b84
 $(objpfx)tst-cet-legacy-4.out: $(objpfx)tst-cet-legacy-mod-4.so
5f7b84
+$(objpfx)tst-cet-legacy-5a: $(libdl)
5f7b84
+$(objpfx)tst-cet-legacy-5a.out: $(objpfx)tst-cet-legacy-mod-5a.so \
5f7b84
+				$(objpfx)tst-cet-legacy-mod-5b.so
5f7b84
+$(objpfx)tst-cet-legacy-mod-5a.so: $(objpfx)tst-cet-legacy-mod-5c.so
5f7b84
+$(objpfx)tst-cet-legacy-mod-5b.so: $(objpfx)tst-cet-legacy-mod-5c.so
5f7b84
+$(objpfx)tst-cet-legacy-6a: $(libdl)
5f7b84
+$(objpfx)tst-cet-legacy-6a.out: $(objpfx)tst-cet-legacy-mod-6a.so \
5f7b84
+				$(objpfx)tst-cet-legacy-mod-6b.so
5f7b84
+$(objpfx)tst-cet-legacy-mod-6a.so: $(objpfx)tst-cet-legacy-mod-6c.so
5f7b84
+$(objpfx)tst-cet-legacy-mod-6b.so: $(objpfx)tst-cet-legacy-mod-6c.so
5f7b84
+LDFLAGS-tst-cet-legacy-mod-6c.so = -Wl,--enable-new-dtags,-z,nodelete
5f7b84
 ifneq (no,$(have-tunables))
5f7b84
 $(objpfx)tst-cet-legacy-4a: $(libdl)
5f7b84
 $(objpfx)tst-cet-legacy-4a.out: $(objpfx)tst-cet-legacy-mod-4.so
5f7b84
@@ -54,6 +80,14 @@ tst-cet-legacy-4b-ENV = GLIBC_TUNABLES=glibc.tune.x86_shstk=on
5f7b84
 $(objpfx)tst-cet-legacy-4c: $(libdl)
5f7b84
 $(objpfx)tst-cet-legacy-4c.out: $(objpfx)tst-cet-legacy-mod-4.so
5f7b84
 tst-cet-legacy-4c-ENV = GLIBC_TUNABLES=glibc.tune.x86_shstk=off
5f7b84
+$(objpfx)tst-cet-legacy-5b: $(libdl)
5f7b84
+$(objpfx)tst-cet-legacy-5b.out: $(objpfx)tst-cet-legacy-mod-5a.so \
5f7b84
+				$(objpfx)tst-cet-legacy-mod-5b.so
5f7b84
+tst-cet-legacy-5b-ENV = GLIBC_TUNABLES=glibc.tune.x86_ibt=off:glibc.tune.x86_shstk=off
5f7b84
+$(objpfx)tst-cet-legacy-6b: $(libdl)
5f7b84
+$(objpfx)tst-cet-legacy-6b.out: $(objpfx)tst-cet-legacy-mod-6a.so \
5f7b84
+				$(objpfx)tst-cet-legacy-mod-6b.so
5f7b84
+tst-cet-legacy-6b-ENV = GLIBC_TUNABLES=glibc.tune.x86_ibt=off:glibc.tune.x86_shstk=off
5f7b84
 endif
5f7b84
 endif
5f7b84
 
5f7b84
diff --git a/sysdeps/x86/tst-cet-legacy-5.c b/sysdeps/x86/tst-cet-legacy-5.c
5f7b84
new file mode 100644
5f7b84
index 0000000000..fbf640f664
5f7b84
--- /dev/null
5f7b84
+++ b/sysdeps/x86/tst-cet-legacy-5.c
5f7b84
@@ -0,0 +1,76 @@
5f7b84
+/* Check compatibility of CET-enabled executable with dlopened legacy
5f7b84
+   shared object.
5f7b84
+   Copyright (C) 2019 Free Software Foundation, Inc.
5f7b84
+   This file is part of the GNU C Library.
5f7b84
+
5f7b84
+   The GNU C Library is free software; you can redistribute it and/or
5f7b84
+   modify it under the terms of the GNU Lesser General Public
5f7b84
+   License as published by the Free Software Foundation; either
5f7b84
+   version 2.1 of the License, or (at your option) any later version.
5f7b84
+
5f7b84
+   The GNU C Library is distributed in the hope that it will be useful,
5f7b84
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
5f7b84
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
5f7b84
+   Lesser General Public License for more details.
5f7b84
+
5f7b84
+   You should have received a copy of the GNU Lesser General Public
5f7b84
+   License along with the GNU C Library; if not, see
5f7b84
+   <http://www.gnu.org/licenses/>.  */
5f7b84
+
5f7b84
+#include <dlfcn.h>
5f7b84
+#include <stdio.h>
5f7b84
+#include <stdlib.h>
5f7b84
+#include <stdbool.h>
5f7b84
+#include <string.h>
5f7b84
+
5f7b84
+static void
5f7b84
+do_test_1 (const char *modname, bool fail)
5f7b84
+{
5f7b84
+  int (*fp) (void);
5f7b84
+  void *h;
5f7b84
+
5f7b84
+  h = dlopen (modname, RTLD_LAZY);
5f7b84
+  if (h == NULL)
5f7b84
+    {
5f7b84
+      if (fail)
5f7b84
+	{
5f7b84
+	  const char *err = dlerror ();
5f7b84
+	  if (strstr (err, "shadow stack isn't enabled") == NULL)
5f7b84
+	    {
5f7b84
+	      printf ("incorrect dlopen '%s' error: %s\n", modname,
5f7b84
+		      dlerror ());
5f7b84
+	      exit (1);
5f7b84
+	    }
5f7b84
+
5f7b84
+	  return;
5f7b84
+	}
5f7b84
+
5f7b84
+      printf ("cannot open '%s': %s\n", modname, dlerror ());
5f7b84
+      exit (1);
5f7b84
+    }
5f7b84
+
5f7b84
+  fp = dlsym (h, "test");
5f7b84
+  if (fp == NULL)
5f7b84
+    {
5f7b84
+      printf ("cannot get symbol 'test': %s\n", dlerror ());
5f7b84
+      exit (1);
5f7b84
+    }
5f7b84
+
5f7b84
+  if (fp () != 0)
5f7b84
+    {
5f7b84
+      puts ("test () != 0");
5f7b84
+      exit (1);
5f7b84
+    }
5f7b84
+
5f7b84
+  dlclose (h);
5f7b84
+}
5f7b84
+
5f7b84
+static int
5f7b84
+do_test (void)
5f7b84
+{
5f7b84
+  do_test_1 ("tst-cet-legacy-mod-5a.so", true);
5f7b84
+  do_test_1 ("tst-cet-legacy-mod-5b.so", false);
5f7b84
+  return 0;
5f7b84
+}
5f7b84
+
5f7b84
+#include <support/test-driver.c>
5f7b84
diff --git a/sysdeps/x86/tst-cet-legacy-5a.c b/sysdeps/x86/tst-cet-legacy-5a.c
5f7b84
new file mode 100644
5f7b84
index 0000000000..fc5a609dff
5f7b84
--- /dev/null
5f7b84
+++ b/sysdeps/x86/tst-cet-legacy-5a.c
5f7b84
@@ -0,0 +1 @@
5f7b84
+#include "tst-cet-legacy-5.c"
5f7b84
diff --git a/sysdeps/x86/tst-cet-legacy-5b.c b/sysdeps/x86/tst-cet-legacy-5b.c
5f7b84
new file mode 100644
5f7b84
index 0000000000..fc5a609dff
5f7b84
--- /dev/null
5f7b84
+++ b/sysdeps/x86/tst-cet-legacy-5b.c
5f7b84
@@ -0,0 +1 @@
5f7b84
+#include "tst-cet-legacy-5.c"
5f7b84
diff --git a/sysdeps/x86/tst-cet-legacy-6.c b/sysdeps/x86/tst-cet-legacy-6.c
5f7b84
new file mode 100644
5f7b84
index 0000000000..9151225264
5f7b84
--- /dev/null
5f7b84
+++ b/sysdeps/x86/tst-cet-legacy-6.c
5f7b84
@@ -0,0 +1,76 @@
5f7b84
+/* Check compatibility of CET-enabled executable with dlopened legacy
5f7b84
+   shared object.
5f7b84
+   Copyright (C) 2019 Free Software Foundation, Inc.
5f7b84
+   This file is part of the GNU C Library.
5f7b84
+
5f7b84
+   The GNU C Library is free software; you can redistribute it and/or
5f7b84
+   modify it under the terms of the GNU Lesser General Public
5f7b84
+   License as published by the Free Software Foundation; either
5f7b84
+   version 2.1 of the License, or (at your option) any later version.
5f7b84
+
5f7b84
+   The GNU C Library is distributed in the hope that it will be useful,
5f7b84
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
5f7b84
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
5f7b84
+   Lesser General Public License for more details.
5f7b84
+
5f7b84
+   You should have received a copy of the GNU Lesser General Public
5f7b84
+   License along with the GNU C Library; if not, see
5f7b84
+   <http://www.gnu.org/licenses/>.  */
5f7b84
+
5f7b84
+#include <dlfcn.h>
5f7b84
+#include <stdio.h>
5f7b84
+#include <stdlib.h>
5f7b84
+#include <stdbool.h>
5f7b84
+#include <string.h>
5f7b84
+
5f7b84
+static void
5f7b84
+do_test_1 (const char *modname, bool fail)
5f7b84
+{
5f7b84
+  int (*fp) (void);
5f7b84
+  void *h;
5f7b84
+
5f7b84
+  h = dlopen (modname, RTLD_LAZY);
5f7b84
+  if (h == NULL)
5f7b84
+    {
5f7b84
+      if (fail)
5f7b84
+	{
5f7b84
+	  const char *err = dlerror ();
5f7b84
+	  if (strstr (err, "shadow stack isn't enabled") == NULL)
5f7b84
+	    {
5f7b84
+	      printf ("incorrect dlopen '%s' error: %s\n", modname,
5f7b84
+		      dlerror ());
5f7b84
+	      exit (1);
5f7b84
+	    }
5f7b84
+
5f7b84
+	  return;
5f7b84
+	}
5f7b84
+
5f7b84
+      printf ("cannot open '%s': %s\n", modname, dlerror ());
5f7b84
+      exit (1);
5f7b84
+    }
5f7b84
+
5f7b84
+  fp = dlsym (h, "test");
5f7b84
+  if (fp == NULL)
5f7b84
+    {
5f7b84
+      printf ("cannot get symbol 'test': %s\n", dlerror ());
5f7b84
+      exit (1);
5f7b84
+    }
5f7b84
+
5f7b84
+  if (fp () != 0)
5f7b84
+    {
5f7b84
+      puts ("test () != 0");
5f7b84
+      exit (1);
5f7b84
+    }
5f7b84
+
5f7b84
+  dlclose (h);
5f7b84
+}
5f7b84
+
5f7b84
+static int
5f7b84
+do_test (void)
5f7b84
+{
5f7b84
+  do_test_1 ("tst-cet-legacy-mod-6a.so", true);
5f7b84
+  do_test_1 ("tst-cet-legacy-mod-6b.so", false);
5f7b84
+  return 0;
5f7b84
+}
5f7b84
+
5f7b84
+#include <support/test-driver.c>
5f7b84
diff --git a/sysdeps/x86/tst-cet-legacy-6a.c b/sysdeps/x86/tst-cet-legacy-6a.c
5f7b84
new file mode 100644
5f7b84
index 0000000000..2d1546d36b
5f7b84
--- /dev/null
5f7b84
+++ b/sysdeps/x86/tst-cet-legacy-6a.c
5f7b84
@@ -0,0 +1 @@
5f7b84
+#include "tst-cet-legacy-6.c"
5f7b84
diff --git a/sysdeps/x86/tst-cet-legacy-6b.c b/sysdeps/x86/tst-cet-legacy-6b.c
5f7b84
new file mode 100644
5f7b84
index 0000000000..2d1546d36b
5f7b84
--- /dev/null
5f7b84
+++ b/sysdeps/x86/tst-cet-legacy-6b.c
5f7b84
@@ -0,0 +1 @@
5f7b84
+#include "tst-cet-legacy-6.c"
5f7b84
diff --git a/sysdeps/x86/tst-cet-legacy-mod-5.c b/sysdeps/x86/tst-cet-legacy-mod-5.c
5f7b84
new file mode 100644
5f7b84
index 0000000000..3c1071c2ef
5f7b84
--- /dev/null
5f7b84
+++ b/sysdeps/x86/tst-cet-legacy-mod-5.c
5f7b84
@@ -0,0 +1,31 @@
5f7b84
+/* Check compatibility of CET-enabled executable with dlopened legacy
5f7b84
+   shared object.
5f7b84
+   Copyright (C) 2019 Free Software Foundation, Inc.
5f7b84
+   This file is part of the GNU C Library.
5f7b84
+
5f7b84
+   The GNU C Library is free software; you can redistribute it and/or
5f7b84
+   modify it under the terms of the GNU Lesser General Public
5f7b84
+   License as published by the Free Software Foundation; either
5f7b84
+   version 2.1 of the License, or (at your option) any later version.
5f7b84
+
5f7b84
+   The GNU C Library is distributed in the hope that it will be useful,
5f7b84
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
5f7b84
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
5f7b84
+   Lesser General Public License for more details.
5f7b84
+
5f7b84
+   You should have received a copy of the GNU Lesser General Public
5f7b84
+   License along with the GNU C Library; if not, see
5f7b84
+   <http://www.gnu.org/licenses/>.  */
5f7b84
+
5f7b84
+#include <error.h>
5f7b84
+#include <stdio.h>
5f7b84
+#include <stdlib.h>
5f7b84
+
5f7b84
+extern void foo (void);
5f7b84
+
5f7b84
+int
5f7b84
+test (void)
5f7b84
+{
5f7b84
+  foo ();
5f7b84
+  return 0;
5f7b84
+}
5f7b84
diff --git a/sysdeps/x86/tst-cet-legacy-mod-5a.c b/sysdeps/x86/tst-cet-legacy-mod-5a.c
5f7b84
new file mode 100644
5f7b84
index 0000000000..daa43e4e8d
5f7b84
--- /dev/null
5f7b84
+++ b/sysdeps/x86/tst-cet-legacy-mod-5a.c
5f7b84
@@ -0,0 +1 @@
5f7b84
+#include "tst-cet-legacy-mod-5.c"
5f7b84
diff --git a/sysdeps/x86/tst-cet-legacy-mod-5b.c b/sysdeps/x86/tst-cet-legacy-mod-5b.c
5f7b84
new file mode 100644
5f7b84
index 0000000000..daa43e4e8d
5f7b84
--- /dev/null
5f7b84
+++ b/sysdeps/x86/tst-cet-legacy-mod-5b.c
5f7b84
@@ -0,0 +1 @@
5f7b84
+#include "tst-cet-legacy-mod-5.c"
5f7b84
diff --git a/sysdeps/x86/tst-cet-legacy-mod-5c.c b/sysdeps/x86/tst-cet-legacy-mod-5c.c
5f7b84
new file mode 100644
5f7b84
index 0000000000..e529a42ac0
5f7b84
--- /dev/null
5f7b84
+++ b/sysdeps/x86/tst-cet-legacy-mod-5c.c
5f7b84
@@ -0,0 +1,36 @@
5f7b84
+/* Check compatibility of CET-enabled executable with dlopened legacy
5f7b84
+   shared object.
5f7b84
+   Copyright (C) 2019 Free Software Foundation, Inc.
5f7b84
+   This file is part of the GNU C Library.
5f7b84
+
5f7b84
+   The GNU C Library is free software; you can redistribute it and/or
5f7b84
+   modify it under the terms of the GNU Lesser General Public
5f7b84
+   License as published by the Free Software Foundation; either
5f7b84
+   version 2.1 of the License, or (at your option) any later version.
5f7b84
+
5f7b84
+   The GNU C Library is distributed in the hope that it will be useful,
5f7b84
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
5f7b84
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
5f7b84
+   Lesser General Public License for more details.
5f7b84
+
5f7b84
+   You should have received a copy of the GNU Lesser General Public
5f7b84
+   License along with the GNU C Library; if not, see
5f7b84
+   <http://www.gnu.org/licenses/>.  */
5f7b84
+
5f7b84
+#include <stdlib.h>
5f7b84
+
5f7b84
+static int called = 0;
5f7b84
+
5f7b84
+static void
5f7b84
+__attribute__ ((constructor))
5f7b84
+init (void)
5f7b84
+{
5f7b84
+  called = 1;
5f7b84
+}
5f7b84
+
5f7b84
+void
5f7b84
+foo (void)
5f7b84
+{
5f7b84
+  if (!called)
5f7b84
+    abort ();
5f7b84
+}
5f7b84
diff --git a/sysdeps/x86/tst-cet-legacy-mod-6.c b/sysdeps/x86/tst-cet-legacy-mod-6.c
5f7b84
new file mode 100644
5f7b84
index 0000000000..3c1071c2ef
5f7b84
--- /dev/null
5f7b84
+++ b/sysdeps/x86/tst-cet-legacy-mod-6.c
5f7b84
@@ -0,0 +1,31 @@
5f7b84
+/* Check compatibility of CET-enabled executable with dlopened legacy
5f7b84
+   shared object.
5f7b84
+   Copyright (C) 2019 Free Software Foundation, Inc.
5f7b84
+   This file is part of the GNU C Library.
5f7b84
+
5f7b84
+   The GNU C Library is free software; you can redistribute it and/or
5f7b84
+   modify it under the terms of the GNU Lesser General Public
5f7b84
+   License as published by the Free Software Foundation; either
5f7b84
+   version 2.1 of the License, or (at your option) any later version.
5f7b84
+
5f7b84
+   The GNU C Library is distributed in the hope that it will be useful,
5f7b84
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
5f7b84
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
5f7b84
+   Lesser General Public License for more details.
5f7b84
+
5f7b84
+   You should have received a copy of the GNU Lesser General Public
5f7b84
+   License along with the GNU C Library; if not, see
5f7b84
+   <http://www.gnu.org/licenses/>.  */
5f7b84
+
5f7b84
+#include <error.h>
5f7b84
+#include <stdio.h>
5f7b84
+#include <stdlib.h>
5f7b84
+
5f7b84
+extern void foo (void);
5f7b84
+
5f7b84
+int
5f7b84
+test (void)
5f7b84
+{
5f7b84
+  foo ();
5f7b84
+  return 0;
5f7b84
+}
5f7b84
diff --git a/sysdeps/x86/tst-cet-legacy-mod-6a.c b/sysdeps/x86/tst-cet-legacy-mod-6a.c
5f7b84
new file mode 100644
5f7b84
index 0000000000..c89b8fe8ff
5f7b84
--- /dev/null
5f7b84
+++ b/sysdeps/x86/tst-cet-legacy-mod-6a.c
5f7b84
@@ -0,0 +1 @@
5f7b84
+#include "tst-cet-legacy-mod-6.c"
5f7b84
diff --git a/sysdeps/x86/tst-cet-legacy-mod-6b.c b/sysdeps/x86/tst-cet-legacy-mod-6b.c
5f7b84
new file mode 100644
5f7b84
index 0000000000..c89b8fe8ff
5f7b84
--- /dev/null
5f7b84
+++ b/sysdeps/x86/tst-cet-legacy-mod-6b.c
5f7b84
@@ -0,0 +1 @@
5f7b84
+#include "tst-cet-legacy-mod-6.c"
5f7b84
diff --git a/sysdeps/x86/tst-cet-legacy-mod-6c.c b/sysdeps/x86/tst-cet-legacy-mod-6c.c
5f7b84
new file mode 100644
5f7b84
index 0000000000..e529a42ac0
5f7b84
--- /dev/null
5f7b84
+++ b/sysdeps/x86/tst-cet-legacy-mod-6c.c
5f7b84
@@ -0,0 +1,36 @@
5f7b84
+/* Check compatibility of CET-enabled executable with dlopened legacy
5f7b84
+   shared object.
5f7b84
+   Copyright (C) 2019 Free Software Foundation, Inc.
5f7b84
+   This file is part of the GNU C Library.
5f7b84
+
5f7b84
+   The GNU C Library is free software; you can redistribute it and/or
5f7b84
+   modify it under the terms of the GNU Lesser General Public
5f7b84
+   License as published by the Free Software Foundation; either
5f7b84
+   version 2.1 of the License, or (at your option) any later version.
5f7b84
+
5f7b84
+   The GNU C Library is distributed in the hope that it will be useful,
5f7b84
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
5f7b84
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
5f7b84
+   Lesser General Public License for more details.
5f7b84
+
5f7b84
+   You should have received a copy of the GNU Lesser General Public
5f7b84
+   License along with the GNU C Library; if not, see
5f7b84
+   <http://www.gnu.org/licenses/>.  */
5f7b84
+
5f7b84
+#include <stdlib.h>
5f7b84
+
5f7b84
+static int called = 0;
5f7b84
+
5f7b84
+static void
5f7b84
+__attribute__ ((constructor))
5f7b84
+init (void)
5f7b84
+{
5f7b84
+  called = 1;
5f7b84
+}
5f7b84
+
5f7b84
+void
5f7b84
+foo (void)
5f7b84
+{
5f7b84
+  if (!called)
5f7b84
+    abort ();
5f7b84
+}
5f7b84
diff --git a/sysdeps/x86/tst-cet-legacy-mod-6d.c b/sysdeps/x86/tst-cet-legacy-mod-6d.c
5f7b84
new file mode 100644
5f7b84
index 0000000000..eb233a1d10
5f7b84
--- /dev/null
5f7b84
+++ b/sysdeps/x86/tst-cet-legacy-mod-6d.c
5f7b84
@@ -0,0 +1 @@
5f7b84
+#include "tst-cet-legacy-mod-6c.c"