[v2,2/2] add test for correct calculation of dl_phdr_info.dlpi_subs

Message ID 1470232359-18696-3-git-send-email-gleb@scylladb.com
State New, archived
Headers

Commit Message

Gleb Natapov Aug. 3, 2016, 1:52 p.m. UTC
  ---
 elf/Makefile        |  5 ++++-
 elf/tst-dlpi_subs.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 58 insertions(+), 1 deletion(-)
 create mode 100644 elf/tst-dlpi_subs.c
  

Comments

Mike Frysinger Aug. 5, 2016, 3:32 a.m. UTC | #1
On 03 Aug 2016 16:52, Gleb Natapov wrote:
> --- /dev/null
> +++ b/elf/tst-dlpi_subs.c
> @@ -0,0 +1,54 @@
> +

trim blank lines at the start

> +/* Test error reporting for dlsym, dlvsym failures.
...
> +/* Test checks that dlpi_subs is calculated correctly when dlmopen is used */

looks like the first line is a copy & paste error
-mike
  

Patch

diff --git a/elf/Makefile b/elf/Makefile
index 593403c..d64b281 100644
--- a/elf/Makefile
+++ b/elf/Makefile
@@ -149,7 +149,7 @@  tests += loadtest restest1 preloadtest loadfail multiload origtest resolvfail \
 	 tst-nodelete) \
 	 tst-initorder tst-initorder2 tst-relsort1 tst-null-argv \
 	 tst-ptrguard1 tst-tlsalign tst-tlsalign-extern tst-nodelete-opened \
-	 tst-nodelete2 tst-audit11 tst-audit12 tst-dlsym-error
+	 tst-nodelete2 tst-audit11 tst-audit12 tst-dlsym-error tst-dlpi_subs
 #	 reldep9
 ifeq ($(build-hardcoded-path-in-tests),yes)
 tests += tst-dlopen-aout
@@ -1005,6 +1005,9 @@  generated += check-execstack.out
 $(objpfx)tst-dlmodcount: $(libdl)
 $(objpfx)tst-dlmodcount.out: $(test-modules)
 
+$(objpfx)tst-dlpi_subs: $(libdl)
+$(objpfx)tst-dlpi_subs.out: $(test-modules)
+
 $(all-built-dso:=.jmprel): %.jmprel: % Makefile
 	@rm -f $@T
 	LC_ALL=C $(READELF) -W -S -d -r $< > $@T
diff --git a/elf/tst-dlpi_subs.c b/elf/tst-dlpi_subs.c
new file mode 100644
index 0000000..79ee761
--- /dev/null
+++ b/elf/tst-dlpi_subs.c
@@ -0,0 +1,54 @@ 
+
+/* Test error reporting for dlsym, dlvsym failures.
+   Copyright (C) 2016 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
+   <http://www.gnu.org/licenses/>.  */
+
+/* Test checks that dlpi_subs is calculated correctly when dlmopen is used */
+
+#include <dlfcn.h>
+#include <stdio.h>
+
+static int fail = 0;
+
+static int
+callback (struct dl_phdr_info *info, size_t size, void *data)
+{
+  if (info->dlpi_subs != 0) {
+    printf ("dlpi_subs == %llu instead of 0\n", info->dlpi_subs);
+    fail = 1;
+  }
+  return 0;
+}
+
+
+static int
+do_test (void)
+{
+  void *h = dlmopen (LM_ID_NEWLM, "$ORIGIN/tst-deep1mod2.so", RTLD_LAZY);
+  if (h == NULL)
+    {
+      printf ("cannot get handle for %s: %s\n",
+	      "tst-deep1mod2.so", dlerror ());
+      return 1;
+    }
+  dl_iterate_phdr (callback, NULL);
+
+  return fail;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"