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