add test for correct calculation of dl_phdr_info.dlpi_subs

Message ID 20160801122008.GO2502@scylladb.com
State New, archived
Headers

Commit Message

Gleb Natapov Aug. 1, 2016, 12:20 p.m. UTC
  --
			Gleb.
  

Comments

Mike Frysinger Aug. 2, 2016, 4:07 p.m. UTC | #1
On 01 Aug 2016 15:20, Gleb Natapov wrote:
> --- /dev/null
> +++ b/elf/tst-dlpi_subs.c
> @@ -0,0 +1,33 @@
> +#include <dlfcn.h>
> +#include <stdio.h>

please put a proper comment block at the top (copyright/license) and a
short blurb explaining what the test does.

> +static int fail = false;

"false" is for bool types, not int types
-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..bea0110
--- /dev/null
+++ b/elf/tst-dlpi_subs.c
@@ -0,0 +1,33 @@ 
+#include <dlfcn.h>
+#include <stdio.h>
+
+static int fail = false;
+
+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 = true;
+  }
+  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"