Patchwork [3/3] dl-load: test that loaded libraries cannot have duplicated sonames

login
register
mail settings
Submitter Nicolas Viennot
Date Jan. 6, 2020, 3:45 p.m.
Message ID <8fd944a7c6d74ef3868a3fec7aae625e@EXMBDFT10.ad.twosigma.com>
Download mbox | patch
Permalink /patch/37215/
State New
Headers show

Comments

Nicolas Viennot - Jan. 6, 2020, 3:45 p.m.
---
 elf/Makefile                | 14 +++++++++++++-
 elf/tst-dlopen-soname-dup.c | 34 ++++++++++++++++++++++++++++++++++
 elf/tst-soname-mod.c        | 19 +++++++++++++++++++
 3 files changed, 66 insertions(+), 1 deletion(-)
 create mode 100644 elf/tst-dlopen-soname-dup.c
 create mode 100644 elf/tst-soname-mod.c

Patch

diff --git a/elf/Makefile b/elf/Makefile
index f861126b2f..88a7361073 100644
--- a/elf/Makefile
+++ b/elf/Makefile
@@ -199,7 +199,8 @@  tests += restest1 preloadtest loadfail multiload origtest resolvfail \
 	 tst-debug1 tst-main1 tst-absolute-sym tst-absolute-zero tst-big-note \
 	 tst-unwind-ctor tst-unwind-main tst-audit13 \
 	 tst-sonamemove-link tst-sonamemove-dlopen tst-dlopen-tlsmodid \
-	 tst-dlopen-self tst-auditmany tst-initfinilazyfail tst-dlopenfail
+	 tst-dlopen-self tst-auditmany tst-initfinilazyfail tst-dlopenfail \
+	 tst-dlopen-soname-dup
 #	 reldep9
 tests-internal += loadtest unload unload2 circleload1 \
 	 neededtest neededtest2 neededtest3 neededtest4 \
@@ -305,6 +306,7 @@  modules-names = testobj1 testobj2 testobj3 testobj4 testobj5 testobj6 \
 		tst-absolute-zero-lib tst-big-note-lib tst-unwind-ctor-lib \
 		tst-audit13mod1 tst-sonamemove-linkmod1 \
 		tst-sonamemove-runmod1 tst-sonamemove-runmod2 \
+		tst-soname-mod \
 		tst-auditmanymod1 tst-auditmanymod2 tst-auditmanymod3 \
 		tst-auditmanymod4 tst-auditmanymod5 tst-auditmanymod6 \
 		tst-auditmanymod7 tst-auditmanymod8 tst-auditmanymod9 \
@@ -1499,6 +1501,16 @@  $(objpfx)tst-sonamemove-dlopen.out: \
   $(objpfx)tst-sonamemove-runmod1.so \
   $(objpfx)tst-sonamemove-runmod2.so
 
+LDFLAGS-tst-soname-mod.so = -Wl,-soname=dummyname
+
+$(objpfx)tst-soname-mod-copy.so: $(objpfx)tst-soname-mod.so
+	cp $< $@
+
+$(objpfx)tst-dlopen-soname-dup: $(libdl)
+$(objpfx)tst-dlopen-soname-dup.out: \
+  $(objpfx)tst-soname-mod.so \
+  $(objpfx)tst-soname-mod-copy.so
+
 # Override -z defs, so that we can reference an undefined symbol.
 # Force lazy binding for the same reason.
 LDFLAGS-tst-latepthreadmod.so = \
diff --git a/elf/tst-dlopen-soname-dup.c b/elf/tst-dlopen-soname-dup.c
new file mode 100644
index 0000000000..804b259f3f
--- /dev/null
+++ b/elf/tst-dlopen-soname-dup.c
@@ -0,0 +1,34 @@ 
+/* Check that two DSOs with the same soname can only be loaded once
+   Copyright (C) 2019 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+#include <stddef.h>
+#include <support/check.h>
+#include <support/xdlfcn.h>
+
+static int
+do_test (void)
+{
+  void *h1 = xdlopen ("tst-soname-mod.so", RTLD_NOW);
+  void *h2 = xdlopen ("tst-soname-mod-copy.so", RTLD_NOW);
+
+  TEST_VERIFY (h1 == h2);
+
+  return 0;
+}
+
+#include <support/test-driver.c>
diff --git a/elf/tst-soname-mod.c b/elf/tst-soname-mod.c
new file mode 100644
index 0000000000..844438a146
--- /dev/null
+++ b/elf/tst-soname-mod.c
@@ -0,0 +1,19 @@ 
+/* Run-time module with a soname defined
+   Copyright (C) 2019 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+/* left intentionally blank */