public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
* [glibc/azanella/clang] elf: Do not assume relocation ordering to check for output
@ 2022-06-09 13:23 Adhemerval Zanella
0 siblings, 0 replies; 5+ messages in thread
From: Adhemerval Zanella @ 2022-06-09 13:23 UTC (permalink / raw)
To: glibc-cvs
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=1eb5c329a886d87675af865de9dde82e7abefe4d
commit 1eb5c329a886d87675af865de9dde82e7abefe4d
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date: Thu May 12 14:37:36 2022 -0300
elf: Do not assume relocation ordering to check for output
The static linker might not create the PLT relocation in the ordering
expected by the tests. For instance, on x86_64 binutils shows:
$ readelf -aW elf/tst-audit25a | grep tst_audit25mod[12]_func
000000000000b0b0 0000001b00000007 R_X86_64_JUMP_SLOT 0000000000000000 tst_audit25mod1_func1 + 0
000000000000b128 0000002a00000007 R_X86_64_JUMP_SLOT 0000000000000000 tst_audit25mod2_func1 + 0
000000000000b1b8 0000004300000007 R_X86_64_JUMP_SLOT 0000000000000000 tst_audit25mod1_func2 + 0
000000000000b228 0000005200000007 R_X86_64_JUMP_SLOT 0000000000000000 tst_audit25mod2_func2 + 0
[...]
While lld shows:
$ readelf -aW elf/tst-audit25a | grep tst_audit25mod[12]_func
000000000000a488 0000000900000007 R_X86_64_JUMP_SLOT 0000000000000000 tst_audit25mod1_func1 + 0
000000000000a490 0000000a00000007 R_X86_64_JUMP_SLOT 0000000000000000 tst_audit25mod1_func2 + 0
000000000000a498 0000000b00000007 R_X86_64_JUMP_SLOT 0000000000000000 tst_audit25mod2_func1 + 0
000000000000a4a0 0000000c00000007 R_X86_64_JUMP_SLOT 0000000000000000 tst_audit25mod2_func2 + 0
[...]
Instead, check each line against the expected set.
Diff:
---
elf/Makefile | 4 +---
elf/tst-audit25.h | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
elf/tst-audit25a.c | 46 ++++++++++++++++++-------------------
elf/tst-audit25b.c | 48 ++++++++++++++++++++-------------------
4 files changed, 115 insertions(+), 49 deletions(-)
diff --git a/elf/Makefile b/elf/Makefile
index 2d7a21846d..1c90965362 100644
--- a/elf/Makefile
+++ b/elf/Makefile
@@ -2343,9 +2343,7 @@ LDFLAGS-tst-audit24d = -Wl,-z,lazy
$(objpfx)tst-audit25a.out: $(objpfx)tst-auditmod25.so
$(objpfx)tst-audit25a: $(objpfx)tst-audit25mod1.so \
- $(objpfx)tst-audit25mod2.so \
- $(objpfx)tst-audit25mod3.so \
- $(objpfx)tst-audit25mod4.so
+ $(objpfx)tst-audit25mod2.so
LDFLAGS-tst-audit25a = -Wl,-z,lazy
$(objpfx)tst-audit25mod1.so: $(objpfx)tst-audit25mod3.so
LDFLAGS-tst-audit25mod1.so = -Wl,-z,now
diff --git a/elf/tst-audit25.h b/elf/tst-audit25.h
new file mode 100644
index 0000000000..489d0de519
--- /dev/null
+++ b/elf/tst-audit25.h
@@ -0,0 +1,66 @@
+/* Check LD_AUDIT and LD_BIND_NOW.
+ Copyright (C) 2022 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/>. */
+
+#ifndef _TEST_AUDIT25_H
+#define _TEST_AUDIT25_H
+
+#include <string.h>
+#include <support/check.h>
+#include <support/xstdio.h>
+
+/* Check if every line in EXPECTED is presented only once on BUFFER
+ with size of LEN. */
+static void
+check_output (char *buffer, size_t len, const char *expected[],
+ size_t expected_len)
+{
+ FILE *f = fmemopen (buffer, len, "r");
+ TEST_VERIFY (f != NULL);
+
+ bool found[expected_len];
+ for (size_t i = 0; i < expected_len; i++)
+ found[i] = false;
+
+ char *line = NULL;
+ size_t linelen = 0;
+ while (xgetline (&line, &linelen, f))
+ {
+ for (size_t i = 0; i < expected_len; i++)
+ if (strcmp (line, expected[i]) == 0)
+ {
+ if (found[i] != false)
+ {
+ support_record_failure ();
+ printf ("error: duplicated line %s\n", expected[i]);
+ }
+ TEST_COMPARE (found[i], false);
+ found[i] = true;
+ }
+ }
+
+ for (size_t i = 0; i < expected_len; i++)
+ if (found[i] == false)
+ {
+ support_record_failure ();
+ printf ("error: %s not present in output\n", expected[i]);
+ }
+
+ xfclose (f);
+}
+
+#endif
diff --git a/elf/tst-audit25a.c b/elf/tst-audit25a.c
index c2cff8541b..51097b5c9c 100644
--- a/elf/tst-audit25a.c
+++ b/elf/tst-audit25a.c
@@ -17,17 +17,11 @@
<https://www.gnu.org/licenses/>. */
#include <array_length.h>
-#include <errno.h>
#include <getopt.h>
-#include <limits.h>
-#include <inttypes.h>
-#include <string.h>
#include <stdlib.h>
#include <support/capture_subprocess.h>
-#include <support/check.h>
-#include <support/xstdio.h>
#include <support/support.h>
-#include <sys/auxv.h>
+#include <tst-audit25.h>
static int restart;
#define CMDLINE_OPTIONS \
@@ -82,13 +76,17 @@ do_test (int argc, char *argv[])
/* tst-audit25a is build with -Wl,-z,lazy and tst-audit25mod1 with
-Wl,-z,now; so only tst_audit25mod3_func1 should be expected to
have LA_SYMB_NOPLTENTER | LA_SYMB_NOPLTEXIT. */
- TEST_COMPARE_STRING (result.err.buffer,
- "la_symbind: tst_audit25mod3_func1 1\n"
- "la_symbind: tst_audit25mod1_func1 0\n"
- "la_symbind: tst_audit25mod1_func2 0\n"
- "la_symbind: tst_audit25mod2_func1 0\n"
- "la_symbind: tst_audit25mod4_func1 0\n"
- "la_symbind: tst_audit25mod2_func2 0\n");
+ const char *expected[] = {
+ "la_symbind: tst_audit25mod3_func1 1\n",
+ "la_symbind: tst_audit25mod1_func1 0\n",
+ "la_symbind: tst_audit25mod1_func2 0\n",
+ "la_symbind: tst_audit25mod2_func1 0\n",
+ "la_symbind: tst_audit25mod4_func1 0\n",
+ "la_symbind: tst_audit25mod2_func2 0\n"
+ };
+
+ check_output (result.err.buffer, result.err.length,
+ expected, array_length (expected));
support_capture_subprocess_free (&result);
}
@@ -101,15 +99,17 @@ do_test (int argc, char *argv[])
sc_allow_stderr);
/* With LD_BIND_NOW all symbols are expected to have
- LA_SYMB_NOPLTENTER | LA_SYMB_NOPLTEXIT. Also the resolution
- order is done in breadth-first order. */
- TEST_COMPARE_STRING (result.err.buffer,
- "la_symbind: tst_audit25mod4_func1 1\n"
- "la_symbind: tst_audit25mod3_func1 1\n"
- "la_symbind: tst_audit25mod1_func1 1\n"
- "la_symbind: tst_audit25mod2_func1 1\n"
- "la_symbind: tst_audit25mod1_func2 1\n"
- "la_symbind: tst_audit25mod2_func2 1\n");
+ LA_SYMB_NOPLTENTER | LA_SYMB_NOPLTEXIT. */
+ const char *expected[] = {
+ "la_symbind: tst_audit25mod4_func1 1\n",
+ "la_symbind: tst_audit25mod3_func1 1\n",
+ "la_symbind: tst_audit25mod1_func1 1\n",
+ "la_symbind: tst_audit25mod2_func1 1\n",
+ "la_symbind: tst_audit25mod1_func2 1\n",
+ "la_symbind: tst_audit25mod2_func2 1\n"
+ };
+ check_output (result.err.buffer, result.err.length,
+ expected, array_length (expected));
support_capture_subprocess_free (&result);
}
diff --git a/elf/tst-audit25b.c b/elf/tst-audit25b.c
index 46391770fd..807ff53b3e 100644
--- a/elf/tst-audit25b.c
+++ b/elf/tst-audit25b.c
@@ -16,17 +16,12 @@
License along with the GNU C Library; if not, see
<https://www.gnu.org/licenses/>. */
-#include <errno.h>
+#include <array_length.h>
#include <getopt.h>
-#include <limits.h>
-#include <inttypes.h>
-#include <string.h>
#include <stdlib.h>
#include <support/capture_subprocess.h>
-#include <support/check.h>
-#include <support/xstdio.h>
#include <support/support.h>
-#include <sys/auxv.h>
+#include <tst-audit25.h>
static int restart;
#define CMDLINE_OPTIONS \
@@ -81,13 +76,17 @@ do_test (int argc, char *argv[])
tst-audit25mod2 is built with -Wl,-z,lazy. So only
tst_audit25mod4_func1 (called by tst_audit25mod2_func1) should not
have LA_SYMB_NOPLTENTER | LA_SYMB_NOPLTEXIT. */
- TEST_COMPARE_STRING (result.err.buffer,
- "la_symbind: tst_audit25mod3_func1 1\n"
- "la_symbind: tst_audit25mod1_func1 1\n"
- "la_symbind: tst_audit25mod2_func1 1\n"
- "la_symbind: tst_audit25mod1_func2 1\n"
- "la_symbind: tst_audit25mod2_func2 1\n"
- "la_symbind: tst_audit25mod4_func1 0\n");
+ const char *expected[] = {
+ "la_symbind: tst_audit25mod3_func1 1\n",
+ "la_symbind: tst_audit25mod1_func1 1\n",
+ "la_symbind: tst_audit25mod2_func1 1\n",
+ "la_symbind: tst_audit25mod1_func2 1\n",
+ "la_symbind: tst_audit25mod2_func2 1\n",
+ "la_symbind: tst_audit25mod4_func1 0\n"
+ };
+
+ check_output (result.err.buffer, result.err.length,
+ expected, array_length (expected));
support_capture_subprocess_free (&result);
}
@@ -100,15 +99,18 @@ do_test (int argc, char *argv[])
sc_allow_stderr);
/* With LD_BIND_NOW all symbols are expected to have
- LA_SYMB_NOPLTENTER | LA_SYMB_NOPLTEXIT. Also the resolution
- order is done in breadth-first order. */
- TEST_COMPARE_STRING (result.err.buffer,
- "la_symbind: tst_audit25mod4_func1 1\n"
- "la_symbind: tst_audit25mod3_func1 1\n"
- "la_symbind: tst_audit25mod1_func1 1\n"
- "la_symbind: tst_audit25mod2_func1 1\n"
- "la_symbind: tst_audit25mod1_func2 1\n"
- "la_symbind: tst_audit25mod2_func2 1\n");
+ LA_SYMB_NOPLTENTER | LA_SYMB_NOPLTEXIT. */
+ const char *expected[] = {
+ "la_symbind: tst_audit25mod4_func1 1\n",
+ "la_symbind: tst_audit25mod3_func1 1\n",
+ "la_symbind: tst_audit25mod1_func1 1\n",
+ "la_symbind: tst_audit25mod2_func1 1\n",
+ "la_symbind: tst_audit25mod1_func2 1\n",
+ "la_symbind: tst_audit25mod2_func2 1\n"
+ };
+
+ check_output (result.err.buffer, result.err.length,
+ expected, array_length (expected));
support_capture_subprocess_free (&result);
}
^ permalink raw reply [flat|nested] 5+ messages in thread
* [glibc/azanella/clang] elf: Do not assume relocation ordering to check for output
@ 2022-06-09 21:26 Adhemerval Zanella
0 siblings, 0 replies; 5+ messages in thread
From: Adhemerval Zanella @ 2022-06-09 21:26 UTC (permalink / raw)
To: glibc-cvs
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=1eb5c329a886d87675af865de9dde82e7abefe4d
commit 1eb5c329a886d87675af865de9dde82e7abefe4d
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date: Thu May 12 14:37:36 2022 -0300
elf: Do not assume relocation ordering to check for output
The static linker might not create the PLT relocation in the ordering
expected by the tests. For instance, on x86_64 binutils shows:
$ readelf -aW elf/tst-audit25a | grep tst_audit25mod[12]_func
000000000000b0b0 0000001b00000007 R_X86_64_JUMP_SLOT 0000000000000000 tst_audit25mod1_func1 + 0
000000000000b128 0000002a00000007 R_X86_64_JUMP_SLOT 0000000000000000 tst_audit25mod2_func1 + 0
000000000000b1b8 0000004300000007 R_X86_64_JUMP_SLOT 0000000000000000 tst_audit25mod1_func2 + 0
000000000000b228 0000005200000007 R_X86_64_JUMP_SLOT 0000000000000000 tst_audit25mod2_func2 + 0
[...]
While lld shows:
$ readelf -aW elf/tst-audit25a | grep tst_audit25mod[12]_func
000000000000a488 0000000900000007 R_X86_64_JUMP_SLOT 0000000000000000 tst_audit25mod1_func1 + 0
000000000000a490 0000000a00000007 R_X86_64_JUMP_SLOT 0000000000000000 tst_audit25mod1_func2 + 0
000000000000a498 0000000b00000007 R_X86_64_JUMP_SLOT 0000000000000000 tst_audit25mod2_func1 + 0
000000000000a4a0 0000000c00000007 R_X86_64_JUMP_SLOT 0000000000000000 tst_audit25mod2_func2 + 0
[...]
Instead, check each line against the expected set.
Diff:
---
elf/Makefile | 4 +---
elf/tst-audit25.h | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
elf/tst-audit25a.c | 46 ++++++++++++++++++-------------------
elf/tst-audit25b.c | 48 ++++++++++++++++++++-------------------
4 files changed, 115 insertions(+), 49 deletions(-)
diff --git a/elf/Makefile b/elf/Makefile
index 2d7a21846d..1c90965362 100644
--- a/elf/Makefile
+++ b/elf/Makefile
@@ -2343,9 +2343,7 @@ LDFLAGS-tst-audit24d = -Wl,-z,lazy
$(objpfx)tst-audit25a.out: $(objpfx)tst-auditmod25.so
$(objpfx)tst-audit25a: $(objpfx)tst-audit25mod1.so \
- $(objpfx)tst-audit25mod2.so \
- $(objpfx)tst-audit25mod3.so \
- $(objpfx)tst-audit25mod4.so
+ $(objpfx)tst-audit25mod2.so
LDFLAGS-tst-audit25a = -Wl,-z,lazy
$(objpfx)tst-audit25mod1.so: $(objpfx)tst-audit25mod3.so
LDFLAGS-tst-audit25mod1.so = -Wl,-z,now
diff --git a/elf/tst-audit25.h b/elf/tst-audit25.h
new file mode 100644
index 0000000000..489d0de519
--- /dev/null
+++ b/elf/tst-audit25.h
@@ -0,0 +1,66 @@
+/* Check LD_AUDIT and LD_BIND_NOW.
+ Copyright (C) 2022 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/>. */
+
+#ifndef _TEST_AUDIT25_H
+#define _TEST_AUDIT25_H
+
+#include <string.h>
+#include <support/check.h>
+#include <support/xstdio.h>
+
+/* Check if every line in EXPECTED is presented only once on BUFFER
+ with size of LEN. */
+static void
+check_output (char *buffer, size_t len, const char *expected[],
+ size_t expected_len)
+{
+ FILE *f = fmemopen (buffer, len, "r");
+ TEST_VERIFY (f != NULL);
+
+ bool found[expected_len];
+ for (size_t i = 0; i < expected_len; i++)
+ found[i] = false;
+
+ char *line = NULL;
+ size_t linelen = 0;
+ while (xgetline (&line, &linelen, f))
+ {
+ for (size_t i = 0; i < expected_len; i++)
+ if (strcmp (line, expected[i]) == 0)
+ {
+ if (found[i] != false)
+ {
+ support_record_failure ();
+ printf ("error: duplicated line %s\n", expected[i]);
+ }
+ TEST_COMPARE (found[i], false);
+ found[i] = true;
+ }
+ }
+
+ for (size_t i = 0; i < expected_len; i++)
+ if (found[i] == false)
+ {
+ support_record_failure ();
+ printf ("error: %s not present in output\n", expected[i]);
+ }
+
+ xfclose (f);
+}
+
+#endif
diff --git a/elf/tst-audit25a.c b/elf/tst-audit25a.c
index c2cff8541b..51097b5c9c 100644
--- a/elf/tst-audit25a.c
+++ b/elf/tst-audit25a.c
@@ -17,17 +17,11 @@
<https://www.gnu.org/licenses/>. */
#include <array_length.h>
-#include <errno.h>
#include <getopt.h>
-#include <limits.h>
-#include <inttypes.h>
-#include <string.h>
#include <stdlib.h>
#include <support/capture_subprocess.h>
-#include <support/check.h>
-#include <support/xstdio.h>
#include <support/support.h>
-#include <sys/auxv.h>
+#include <tst-audit25.h>
static int restart;
#define CMDLINE_OPTIONS \
@@ -82,13 +76,17 @@ do_test (int argc, char *argv[])
/* tst-audit25a is build with -Wl,-z,lazy and tst-audit25mod1 with
-Wl,-z,now; so only tst_audit25mod3_func1 should be expected to
have LA_SYMB_NOPLTENTER | LA_SYMB_NOPLTEXIT. */
- TEST_COMPARE_STRING (result.err.buffer,
- "la_symbind: tst_audit25mod3_func1 1\n"
- "la_symbind: tst_audit25mod1_func1 0\n"
- "la_symbind: tst_audit25mod1_func2 0\n"
- "la_symbind: tst_audit25mod2_func1 0\n"
- "la_symbind: tst_audit25mod4_func1 0\n"
- "la_symbind: tst_audit25mod2_func2 0\n");
+ const char *expected[] = {
+ "la_symbind: tst_audit25mod3_func1 1\n",
+ "la_symbind: tst_audit25mod1_func1 0\n",
+ "la_symbind: tst_audit25mod1_func2 0\n",
+ "la_symbind: tst_audit25mod2_func1 0\n",
+ "la_symbind: tst_audit25mod4_func1 0\n",
+ "la_symbind: tst_audit25mod2_func2 0\n"
+ };
+
+ check_output (result.err.buffer, result.err.length,
+ expected, array_length (expected));
support_capture_subprocess_free (&result);
}
@@ -101,15 +99,17 @@ do_test (int argc, char *argv[])
sc_allow_stderr);
/* With LD_BIND_NOW all symbols are expected to have
- LA_SYMB_NOPLTENTER | LA_SYMB_NOPLTEXIT. Also the resolution
- order is done in breadth-first order. */
- TEST_COMPARE_STRING (result.err.buffer,
- "la_symbind: tst_audit25mod4_func1 1\n"
- "la_symbind: tst_audit25mod3_func1 1\n"
- "la_symbind: tst_audit25mod1_func1 1\n"
- "la_symbind: tst_audit25mod2_func1 1\n"
- "la_symbind: tst_audit25mod1_func2 1\n"
- "la_symbind: tst_audit25mod2_func2 1\n");
+ LA_SYMB_NOPLTENTER | LA_SYMB_NOPLTEXIT. */
+ const char *expected[] = {
+ "la_symbind: tst_audit25mod4_func1 1\n",
+ "la_symbind: tst_audit25mod3_func1 1\n",
+ "la_symbind: tst_audit25mod1_func1 1\n",
+ "la_symbind: tst_audit25mod2_func1 1\n",
+ "la_symbind: tst_audit25mod1_func2 1\n",
+ "la_symbind: tst_audit25mod2_func2 1\n"
+ };
+ check_output (result.err.buffer, result.err.length,
+ expected, array_length (expected));
support_capture_subprocess_free (&result);
}
diff --git a/elf/tst-audit25b.c b/elf/tst-audit25b.c
index 46391770fd..807ff53b3e 100644
--- a/elf/tst-audit25b.c
+++ b/elf/tst-audit25b.c
@@ -16,17 +16,12 @@
License along with the GNU C Library; if not, see
<https://www.gnu.org/licenses/>. */
-#include <errno.h>
+#include <array_length.h>
#include <getopt.h>
-#include <limits.h>
-#include <inttypes.h>
-#include <string.h>
#include <stdlib.h>
#include <support/capture_subprocess.h>
-#include <support/check.h>
-#include <support/xstdio.h>
#include <support/support.h>
-#include <sys/auxv.h>
+#include <tst-audit25.h>
static int restart;
#define CMDLINE_OPTIONS \
@@ -81,13 +76,17 @@ do_test (int argc, char *argv[])
tst-audit25mod2 is built with -Wl,-z,lazy. So only
tst_audit25mod4_func1 (called by tst_audit25mod2_func1) should not
have LA_SYMB_NOPLTENTER | LA_SYMB_NOPLTEXIT. */
- TEST_COMPARE_STRING (result.err.buffer,
- "la_symbind: tst_audit25mod3_func1 1\n"
- "la_symbind: tst_audit25mod1_func1 1\n"
- "la_symbind: tst_audit25mod2_func1 1\n"
- "la_symbind: tst_audit25mod1_func2 1\n"
- "la_symbind: tst_audit25mod2_func2 1\n"
- "la_symbind: tst_audit25mod4_func1 0\n");
+ const char *expected[] = {
+ "la_symbind: tst_audit25mod3_func1 1\n",
+ "la_symbind: tst_audit25mod1_func1 1\n",
+ "la_symbind: tst_audit25mod2_func1 1\n",
+ "la_symbind: tst_audit25mod1_func2 1\n",
+ "la_symbind: tst_audit25mod2_func2 1\n",
+ "la_symbind: tst_audit25mod4_func1 0\n"
+ };
+
+ check_output (result.err.buffer, result.err.length,
+ expected, array_length (expected));
support_capture_subprocess_free (&result);
}
@@ -100,15 +99,18 @@ do_test (int argc, char *argv[])
sc_allow_stderr);
/* With LD_BIND_NOW all symbols are expected to have
- LA_SYMB_NOPLTENTER | LA_SYMB_NOPLTEXIT. Also the resolution
- order is done in breadth-first order. */
- TEST_COMPARE_STRING (result.err.buffer,
- "la_symbind: tst_audit25mod4_func1 1\n"
- "la_symbind: tst_audit25mod3_func1 1\n"
- "la_symbind: tst_audit25mod1_func1 1\n"
- "la_symbind: tst_audit25mod2_func1 1\n"
- "la_symbind: tst_audit25mod1_func2 1\n"
- "la_symbind: tst_audit25mod2_func2 1\n");
+ LA_SYMB_NOPLTENTER | LA_SYMB_NOPLTEXIT. */
+ const char *expected[] = {
+ "la_symbind: tst_audit25mod4_func1 1\n",
+ "la_symbind: tst_audit25mod3_func1 1\n",
+ "la_symbind: tst_audit25mod1_func1 1\n",
+ "la_symbind: tst_audit25mod2_func1 1\n",
+ "la_symbind: tst_audit25mod1_func2 1\n",
+ "la_symbind: tst_audit25mod2_func2 1\n"
+ };
+
+ check_output (result.err.buffer, result.err.length,
+ expected, array_length (expected));
support_capture_subprocess_free (&result);
}
^ permalink raw reply [flat|nested] 5+ messages in thread
* [glibc/azanella/clang] elf: Do not assume relocation ordering to check for output
@ 2022-06-03 14:12 Adhemerval Zanella
0 siblings, 0 replies; 5+ messages in thread
From: Adhemerval Zanella @ 2022-06-03 14:12 UTC (permalink / raw)
To: glibc-cvs
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=864814901127d04c70e42e864587c8a834d5134d
commit 864814901127d04c70e42e864587c8a834d5134d
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date: Thu May 12 14:37:36 2022 -0300
elf: Do not assume relocation ordering to check for output
The static linker might not create the PLT relocation in the ordering
expected by the tests. For instance, on x86_64 binutils shows:
$ readelf -aW elf/tst-audit25a | grep tst_audit25mod[12]_func
000000000000b0b0 0000001b00000007 R_X86_64_JUMP_SLOT 0000000000000000 tst_audit25mod1_func1 + 0
000000000000b128 0000002a00000007 R_X86_64_JUMP_SLOT 0000000000000000 tst_audit25mod2_func1 + 0
000000000000b1b8 0000004300000007 R_X86_64_JUMP_SLOT 0000000000000000 tst_audit25mod1_func2 + 0
000000000000b228 0000005200000007 R_X86_64_JUMP_SLOT 0000000000000000 tst_audit25mod2_func2 + 0
[...]
While lld shows:
$ readelf -aW elf/tst-audit25a | grep tst_audit25mod[12]_func
000000000000a488 0000000900000007 R_X86_64_JUMP_SLOT 0000000000000000 tst_audit25mod1_func1 + 0
000000000000a490 0000000a00000007 R_X86_64_JUMP_SLOT 0000000000000000 tst_audit25mod1_func2 + 0
000000000000a498 0000000b00000007 R_X86_64_JUMP_SLOT 0000000000000000 tst_audit25mod2_func1 + 0
000000000000a4a0 0000000c00000007 R_X86_64_JUMP_SLOT 0000000000000000 tst_audit25mod2_func2 + 0
[...]
Instead, check each line against the expected set.
Diff:
---
elf/Makefile | 4 +---
elf/tst-audit25.h | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
elf/tst-audit25a.c | 46 ++++++++++++++++++-------------------
elf/tst-audit25b.c | 48 ++++++++++++++++++++-------------------
4 files changed, 115 insertions(+), 49 deletions(-)
diff --git a/elf/Makefile b/elf/Makefile
index 40cc2a19a2..baaffe01ed 100644
--- a/elf/Makefile
+++ b/elf/Makefile
@@ -2343,9 +2343,7 @@ LDFLAGS-tst-audit24d = -Wl,-z,lazy
$(objpfx)tst-audit25a.out: $(objpfx)tst-auditmod25.so
$(objpfx)tst-audit25a: $(objpfx)tst-audit25mod1.so \
- $(objpfx)tst-audit25mod2.so \
- $(objpfx)tst-audit25mod3.so \
- $(objpfx)tst-audit25mod4.so
+ $(objpfx)tst-audit25mod2.so
LDFLAGS-tst-audit25a = -Wl,-z,lazy
$(objpfx)tst-audit25mod1.so: $(objpfx)tst-audit25mod3.so
LDFLAGS-tst-audit25mod1.so = -Wl,-z,now
diff --git a/elf/tst-audit25.h b/elf/tst-audit25.h
new file mode 100644
index 0000000000..489d0de519
--- /dev/null
+++ b/elf/tst-audit25.h
@@ -0,0 +1,66 @@
+/* Check LD_AUDIT and LD_BIND_NOW.
+ Copyright (C) 2022 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/>. */
+
+#ifndef _TEST_AUDIT25_H
+#define _TEST_AUDIT25_H
+
+#include <string.h>
+#include <support/check.h>
+#include <support/xstdio.h>
+
+/* Check if every line in EXPECTED is presented only once on BUFFER
+ with size of LEN. */
+static void
+check_output (char *buffer, size_t len, const char *expected[],
+ size_t expected_len)
+{
+ FILE *f = fmemopen (buffer, len, "r");
+ TEST_VERIFY (f != NULL);
+
+ bool found[expected_len];
+ for (size_t i = 0; i < expected_len; i++)
+ found[i] = false;
+
+ char *line = NULL;
+ size_t linelen = 0;
+ while (xgetline (&line, &linelen, f))
+ {
+ for (size_t i = 0; i < expected_len; i++)
+ if (strcmp (line, expected[i]) == 0)
+ {
+ if (found[i] != false)
+ {
+ support_record_failure ();
+ printf ("error: duplicated line %s\n", expected[i]);
+ }
+ TEST_COMPARE (found[i], false);
+ found[i] = true;
+ }
+ }
+
+ for (size_t i = 0; i < expected_len; i++)
+ if (found[i] == false)
+ {
+ support_record_failure ();
+ printf ("error: %s not present in output\n", expected[i]);
+ }
+
+ xfclose (f);
+}
+
+#endif
diff --git a/elf/tst-audit25a.c b/elf/tst-audit25a.c
index c2cff8541b..51097b5c9c 100644
--- a/elf/tst-audit25a.c
+++ b/elf/tst-audit25a.c
@@ -17,17 +17,11 @@
<https://www.gnu.org/licenses/>. */
#include <array_length.h>
-#include <errno.h>
#include <getopt.h>
-#include <limits.h>
-#include <inttypes.h>
-#include <string.h>
#include <stdlib.h>
#include <support/capture_subprocess.h>
-#include <support/check.h>
-#include <support/xstdio.h>
#include <support/support.h>
-#include <sys/auxv.h>
+#include <tst-audit25.h>
static int restart;
#define CMDLINE_OPTIONS \
@@ -82,13 +76,17 @@ do_test (int argc, char *argv[])
/* tst-audit25a is build with -Wl,-z,lazy and tst-audit25mod1 with
-Wl,-z,now; so only tst_audit25mod3_func1 should be expected to
have LA_SYMB_NOPLTENTER | LA_SYMB_NOPLTEXIT. */
- TEST_COMPARE_STRING (result.err.buffer,
- "la_symbind: tst_audit25mod3_func1 1\n"
- "la_symbind: tst_audit25mod1_func1 0\n"
- "la_symbind: tst_audit25mod1_func2 0\n"
- "la_symbind: tst_audit25mod2_func1 0\n"
- "la_symbind: tst_audit25mod4_func1 0\n"
- "la_symbind: tst_audit25mod2_func2 0\n");
+ const char *expected[] = {
+ "la_symbind: tst_audit25mod3_func1 1\n",
+ "la_symbind: tst_audit25mod1_func1 0\n",
+ "la_symbind: tst_audit25mod1_func2 0\n",
+ "la_symbind: tst_audit25mod2_func1 0\n",
+ "la_symbind: tst_audit25mod4_func1 0\n",
+ "la_symbind: tst_audit25mod2_func2 0\n"
+ };
+
+ check_output (result.err.buffer, result.err.length,
+ expected, array_length (expected));
support_capture_subprocess_free (&result);
}
@@ -101,15 +99,17 @@ do_test (int argc, char *argv[])
sc_allow_stderr);
/* With LD_BIND_NOW all symbols are expected to have
- LA_SYMB_NOPLTENTER | LA_SYMB_NOPLTEXIT. Also the resolution
- order is done in breadth-first order. */
- TEST_COMPARE_STRING (result.err.buffer,
- "la_symbind: tst_audit25mod4_func1 1\n"
- "la_symbind: tst_audit25mod3_func1 1\n"
- "la_symbind: tst_audit25mod1_func1 1\n"
- "la_symbind: tst_audit25mod2_func1 1\n"
- "la_symbind: tst_audit25mod1_func2 1\n"
- "la_symbind: tst_audit25mod2_func2 1\n");
+ LA_SYMB_NOPLTENTER | LA_SYMB_NOPLTEXIT. */
+ const char *expected[] = {
+ "la_symbind: tst_audit25mod4_func1 1\n",
+ "la_symbind: tst_audit25mod3_func1 1\n",
+ "la_symbind: tst_audit25mod1_func1 1\n",
+ "la_symbind: tst_audit25mod2_func1 1\n",
+ "la_symbind: tst_audit25mod1_func2 1\n",
+ "la_symbind: tst_audit25mod2_func2 1\n"
+ };
+ check_output (result.err.buffer, result.err.length,
+ expected, array_length (expected));
support_capture_subprocess_free (&result);
}
diff --git a/elf/tst-audit25b.c b/elf/tst-audit25b.c
index 46391770fd..807ff53b3e 100644
--- a/elf/tst-audit25b.c
+++ b/elf/tst-audit25b.c
@@ -16,17 +16,12 @@
License along with the GNU C Library; if not, see
<https://www.gnu.org/licenses/>. */
-#include <errno.h>
+#include <array_length.h>
#include <getopt.h>
-#include <limits.h>
-#include <inttypes.h>
-#include <string.h>
#include <stdlib.h>
#include <support/capture_subprocess.h>
-#include <support/check.h>
-#include <support/xstdio.h>
#include <support/support.h>
-#include <sys/auxv.h>
+#include <tst-audit25.h>
static int restart;
#define CMDLINE_OPTIONS \
@@ -81,13 +76,17 @@ do_test (int argc, char *argv[])
tst-audit25mod2 is built with -Wl,-z,lazy. So only
tst_audit25mod4_func1 (called by tst_audit25mod2_func1) should not
have LA_SYMB_NOPLTENTER | LA_SYMB_NOPLTEXIT. */
- TEST_COMPARE_STRING (result.err.buffer,
- "la_symbind: tst_audit25mod3_func1 1\n"
- "la_symbind: tst_audit25mod1_func1 1\n"
- "la_symbind: tst_audit25mod2_func1 1\n"
- "la_symbind: tst_audit25mod1_func2 1\n"
- "la_symbind: tst_audit25mod2_func2 1\n"
- "la_symbind: tst_audit25mod4_func1 0\n");
+ const char *expected[] = {
+ "la_symbind: tst_audit25mod3_func1 1\n",
+ "la_symbind: tst_audit25mod1_func1 1\n",
+ "la_symbind: tst_audit25mod2_func1 1\n",
+ "la_symbind: tst_audit25mod1_func2 1\n",
+ "la_symbind: tst_audit25mod2_func2 1\n",
+ "la_symbind: tst_audit25mod4_func1 0\n"
+ };
+
+ check_output (result.err.buffer, result.err.length,
+ expected, array_length (expected));
support_capture_subprocess_free (&result);
}
@@ -100,15 +99,18 @@ do_test (int argc, char *argv[])
sc_allow_stderr);
/* With LD_BIND_NOW all symbols are expected to have
- LA_SYMB_NOPLTENTER | LA_SYMB_NOPLTEXIT. Also the resolution
- order is done in breadth-first order. */
- TEST_COMPARE_STRING (result.err.buffer,
- "la_symbind: tst_audit25mod4_func1 1\n"
- "la_symbind: tst_audit25mod3_func1 1\n"
- "la_symbind: tst_audit25mod1_func1 1\n"
- "la_symbind: tst_audit25mod2_func1 1\n"
- "la_symbind: tst_audit25mod1_func2 1\n"
- "la_symbind: tst_audit25mod2_func2 1\n");
+ LA_SYMB_NOPLTENTER | LA_SYMB_NOPLTEXIT. */
+ const char *expected[] = {
+ "la_symbind: tst_audit25mod4_func1 1\n",
+ "la_symbind: tst_audit25mod3_func1 1\n",
+ "la_symbind: tst_audit25mod1_func1 1\n",
+ "la_symbind: tst_audit25mod2_func1 1\n",
+ "la_symbind: tst_audit25mod1_func2 1\n",
+ "la_symbind: tst_audit25mod2_func2 1\n"
+ };
+
+ check_output (result.err.buffer, result.err.length,
+ expected, array_length (expected));
support_capture_subprocess_free (&result);
}
^ permalink raw reply [flat|nested] 5+ messages in thread
* [glibc/azanella/clang] elf: Do not assume relocation ordering to check for output
@ 2022-05-13 14:26 Adhemerval Zanella
0 siblings, 0 replies; 5+ messages in thread
From: Adhemerval Zanella @ 2022-05-13 14:26 UTC (permalink / raw)
To: glibc-cvs
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=980ed6330848248afd15f822b0130ffb15663512
commit 980ed6330848248afd15f822b0130ffb15663512
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date: Thu May 12 14:37:36 2022 -0300
elf: Do not assume relocation ordering to check for output
The static linker might not create the PLT relocation in the ordering
expected by the tests. For instance, on x86_64 binutils shows:
$ readelf -aW elf/tst-audit25a | grep tst_audit25mod[12]_func
000000000000b0b0 0000001b00000007 R_X86_64_JUMP_SLOT 0000000000000000 tst_audit25mod1_func1 + 0
000000000000b128 0000002a00000007 R_X86_64_JUMP_SLOT 0000000000000000 tst_audit25mod2_func1 + 0
000000000000b1b8 0000004300000007 R_X86_64_JUMP_SLOT 0000000000000000 tst_audit25mod1_func2 + 0
000000000000b228 0000005200000007 R_X86_64_JUMP_SLOT 0000000000000000 tst_audit25mod2_func2 + 0
[...]
While lld shows:
$ readelf -aW elf/tst-audit25a | grep tst_audit25mod[12]_func
000000000000a488 0000000900000007 R_X86_64_JUMP_SLOT 0000000000000000 tst_audit25mod1_func1 + 0
000000000000a490 0000000a00000007 R_X86_64_JUMP_SLOT 0000000000000000 tst_audit25mod1_func2 + 0
000000000000a498 0000000b00000007 R_X86_64_JUMP_SLOT 0000000000000000 tst_audit25mod2_func1 + 0
000000000000a4a0 0000000c00000007 R_X86_64_JUMP_SLOT 0000000000000000 tst_audit25mod2_func2 + 0
[...]
Instead, check each line against the expected set.
Diff:
---
elf/Makefile | 4 +---
elf/tst-audit25.h | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
elf/tst-audit25a.c | 46 ++++++++++++++++++-------------------
elf/tst-audit25b.c | 48 ++++++++++++++++++++-------------------
4 files changed, 115 insertions(+), 49 deletions(-)
diff --git a/elf/Makefile b/elf/Makefile
index 518b1c0233..b15ec1bbb3 100644
--- a/elf/Makefile
+++ b/elf/Makefile
@@ -2328,9 +2328,7 @@ LDFLAGS-tst-audit24d = -Wl,-z,lazy
$(objpfx)tst-audit25a.out: $(objpfx)tst-auditmod25.so
$(objpfx)tst-audit25a: $(objpfx)tst-audit25mod1.so \
- $(objpfx)tst-audit25mod2.so \
- $(objpfx)tst-audit25mod3.so \
- $(objpfx)tst-audit25mod4.so
+ $(objpfx)tst-audit25mod2.so
LDFLAGS-tst-audit25a = -Wl,-z,lazy
$(objpfx)tst-audit25mod1.so: $(objpfx)tst-audit25mod3.so
LDFLAGS-tst-audit25mod1.so = -Wl,-z,now
diff --git a/elf/tst-audit25.h b/elf/tst-audit25.h
new file mode 100644
index 0000000000..489d0de519
--- /dev/null
+++ b/elf/tst-audit25.h
@@ -0,0 +1,66 @@
+/* Check LD_AUDIT and LD_BIND_NOW.
+ Copyright (C) 2022 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/>. */
+
+#ifndef _TEST_AUDIT25_H
+#define _TEST_AUDIT25_H
+
+#include <string.h>
+#include <support/check.h>
+#include <support/xstdio.h>
+
+/* Check if every line in EXPECTED is presented only once on BUFFER
+ with size of LEN. */
+static void
+check_output (char *buffer, size_t len, const char *expected[],
+ size_t expected_len)
+{
+ FILE *f = fmemopen (buffer, len, "r");
+ TEST_VERIFY (f != NULL);
+
+ bool found[expected_len];
+ for (size_t i = 0; i < expected_len; i++)
+ found[i] = false;
+
+ char *line = NULL;
+ size_t linelen = 0;
+ while (xgetline (&line, &linelen, f))
+ {
+ for (size_t i = 0; i < expected_len; i++)
+ if (strcmp (line, expected[i]) == 0)
+ {
+ if (found[i] != false)
+ {
+ support_record_failure ();
+ printf ("error: duplicated line %s\n", expected[i]);
+ }
+ TEST_COMPARE (found[i], false);
+ found[i] = true;
+ }
+ }
+
+ for (size_t i = 0; i < expected_len; i++)
+ if (found[i] == false)
+ {
+ support_record_failure ();
+ printf ("error: %s not present in output\n", expected[i]);
+ }
+
+ xfclose (f);
+}
+
+#endif
diff --git a/elf/tst-audit25a.c b/elf/tst-audit25a.c
index c2cff8541b..51097b5c9c 100644
--- a/elf/tst-audit25a.c
+++ b/elf/tst-audit25a.c
@@ -17,17 +17,11 @@
<https://www.gnu.org/licenses/>. */
#include <array_length.h>
-#include <errno.h>
#include <getopt.h>
-#include <limits.h>
-#include <inttypes.h>
-#include <string.h>
#include <stdlib.h>
#include <support/capture_subprocess.h>
-#include <support/check.h>
-#include <support/xstdio.h>
#include <support/support.h>
-#include <sys/auxv.h>
+#include <tst-audit25.h>
static int restart;
#define CMDLINE_OPTIONS \
@@ -82,13 +76,17 @@ do_test (int argc, char *argv[])
/* tst-audit25a is build with -Wl,-z,lazy and tst-audit25mod1 with
-Wl,-z,now; so only tst_audit25mod3_func1 should be expected to
have LA_SYMB_NOPLTENTER | LA_SYMB_NOPLTEXIT. */
- TEST_COMPARE_STRING (result.err.buffer,
- "la_symbind: tst_audit25mod3_func1 1\n"
- "la_symbind: tst_audit25mod1_func1 0\n"
- "la_symbind: tst_audit25mod1_func2 0\n"
- "la_symbind: tst_audit25mod2_func1 0\n"
- "la_symbind: tst_audit25mod4_func1 0\n"
- "la_symbind: tst_audit25mod2_func2 0\n");
+ const char *expected[] = {
+ "la_symbind: tst_audit25mod3_func1 1\n",
+ "la_symbind: tst_audit25mod1_func1 0\n",
+ "la_symbind: tst_audit25mod1_func2 0\n",
+ "la_symbind: tst_audit25mod2_func1 0\n",
+ "la_symbind: tst_audit25mod4_func1 0\n",
+ "la_symbind: tst_audit25mod2_func2 0\n"
+ };
+
+ check_output (result.err.buffer, result.err.length,
+ expected, array_length (expected));
support_capture_subprocess_free (&result);
}
@@ -101,15 +99,17 @@ do_test (int argc, char *argv[])
sc_allow_stderr);
/* With LD_BIND_NOW all symbols are expected to have
- LA_SYMB_NOPLTENTER | LA_SYMB_NOPLTEXIT. Also the resolution
- order is done in breadth-first order. */
- TEST_COMPARE_STRING (result.err.buffer,
- "la_symbind: tst_audit25mod4_func1 1\n"
- "la_symbind: tst_audit25mod3_func1 1\n"
- "la_symbind: tst_audit25mod1_func1 1\n"
- "la_symbind: tst_audit25mod2_func1 1\n"
- "la_symbind: tst_audit25mod1_func2 1\n"
- "la_symbind: tst_audit25mod2_func2 1\n");
+ LA_SYMB_NOPLTENTER | LA_SYMB_NOPLTEXIT. */
+ const char *expected[] = {
+ "la_symbind: tst_audit25mod4_func1 1\n",
+ "la_symbind: tst_audit25mod3_func1 1\n",
+ "la_symbind: tst_audit25mod1_func1 1\n",
+ "la_symbind: tst_audit25mod2_func1 1\n",
+ "la_symbind: tst_audit25mod1_func2 1\n",
+ "la_symbind: tst_audit25mod2_func2 1\n"
+ };
+ check_output (result.err.buffer, result.err.length,
+ expected, array_length (expected));
support_capture_subprocess_free (&result);
}
diff --git a/elf/tst-audit25b.c b/elf/tst-audit25b.c
index 46391770fd..807ff53b3e 100644
--- a/elf/tst-audit25b.c
+++ b/elf/tst-audit25b.c
@@ -16,17 +16,12 @@
License along with the GNU C Library; if not, see
<https://www.gnu.org/licenses/>. */
-#include <errno.h>
+#include <array_length.h>
#include <getopt.h>
-#include <limits.h>
-#include <inttypes.h>
-#include <string.h>
#include <stdlib.h>
#include <support/capture_subprocess.h>
-#include <support/check.h>
-#include <support/xstdio.h>
#include <support/support.h>
-#include <sys/auxv.h>
+#include <tst-audit25.h>
static int restart;
#define CMDLINE_OPTIONS \
@@ -81,13 +76,17 @@ do_test (int argc, char *argv[])
tst-audit25mod2 is built with -Wl,-z,lazy. So only
tst_audit25mod4_func1 (called by tst_audit25mod2_func1) should not
have LA_SYMB_NOPLTENTER | LA_SYMB_NOPLTEXIT. */
- TEST_COMPARE_STRING (result.err.buffer,
- "la_symbind: tst_audit25mod3_func1 1\n"
- "la_symbind: tst_audit25mod1_func1 1\n"
- "la_symbind: tst_audit25mod2_func1 1\n"
- "la_symbind: tst_audit25mod1_func2 1\n"
- "la_symbind: tst_audit25mod2_func2 1\n"
- "la_symbind: tst_audit25mod4_func1 0\n");
+ const char *expected[] = {
+ "la_symbind: tst_audit25mod3_func1 1\n",
+ "la_symbind: tst_audit25mod1_func1 1\n",
+ "la_symbind: tst_audit25mod2_func1 1\n",
+ "la_symbind: tst_audit25mod1_func2 1\n",
+ "la_symbind: tst_audit25mod2_func2 1\n",
+ "la_symbind: tst_audit25mod4_func1 0\n"
+ };
+
+ check_output (result.err.buffer, result.err.length,
+ expected, array_length (expected));
support_capture_subprocess_free (&result);
}
@@ -100,15 +99,18 @@ do_test (int argc, char *argv[])
sc_allow_stderr);
/* With LD_BIND_NOW all symbols are expected to have
- LA_SYMB_NOPLTENTER | LA_SYMB_NOPLTEXIT. Also the resolution
- order is done in breadth-first order. */
- TEST_COMPARE_STRING (result.err.buffer,
- "la_symbind: tst_audit25mod4_func1 1\n"
- "la_symbind: tst_audit25mod3_func1 1\n"
- "la_symbind: tst_audit25mod1_func1 1\n"
- "la_symbind: tst_audit25mod2_func1 1\n"
- "la_symbind: tst_audit25mod1_func2 1\n"
- "la_symbind: tst_audit25mod2_func2 1\n");
+ LA_SYMB_NOPLTENTER | LA_SYMB_NOPLTEXIT. */
+ const char *expected[] = {
+ "la_symbind: tst_audit25mod4_func1 1\n",
+ "la_symbind: tst_audit25mod3_func1 1\n",
+ "la_symbind: tst_audit25mod1_func1 1\n",
+ "la_symbind: tst_audit25mod2_func1 1\n",
+ "la_symbind: tst_audit25mod1_func2 1\n",
+ "la_symbind: tst_audit25mod2_func2 1\n"
+ };
+
+ check_output (result.err.buffer, result.err.length,
+ expected, array_length (expected));
support_capture_subprocess_free (&result);
}
^ permalink raw reply [flat|nested] 5+ messages in thread
* [glibc/azanella/clang] elf: Do not assume relocation ordering to check for output
@ 2022-05-12 19:40 Adhemerval Zanella
0 siblings, 0 replies; 5+ messages in thread
From: Adhemerval Zanella @ 2022-05-12 19:40 UTC (permalink / raw)
To: glibc-cvs
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=e74f9f0475e1a503bfd21466baeb59c85c3f3f7b
commit e74f9f0475e1a503bfd21466baeb59c85c3f3f7b
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date: Thu May 12 14:37:36 2022 -0300
elf: Do not assume relocation ordering to check for output
The static linker might not create the PLT relocation in the ordering
expected by the tests. For instance, on x86_64 binutils shows:
$ readelf -aW elf/tst-audit25a | grep tst_audit25mod[12]_func
000000000000b0b0 0000001b00000007 R_X86_64_JUMP_SLOT 0000000000000000 tst_audit25mod1_func1 + 0
000000000000b128 0000002a00000007 R_X86_64_JUMP_SLOT 0000000000000000 tst_audit25mod2_func1 + 0
000000000000b1b8 0000004300000007 R_X86_64_JUMP_SLOT 0000000000000000 tst_audit25mod1_func2 + 0
000000000000b228 0000005200000007 R_X86_64_JUMP_SLOT 0000000000000000 tst_audit25mod2_func2 + 0
[...]
While lld shows:
$ readelf -aW elf/tst-audit25a | grep tst_audit25mod[12]_func
000000000000a488 0000000900000007 R_X86_64_JUMP_SLOT 0000000000000000 tst_audit25mod1_func1 + 0
000000000000a490 0000000a00000007 R_X86_64_JUMP_SLOT 0000000000000000 tst_audit25mod1_func2 + 0
000000000000a498 0000000b00000007 R_X86_64_JUMP_SLOT 0000000000000000 tst_audit25mod2_func1 + 0
000000000000a4a0 0000000c00000007 R_X86_64_JUMP_SLOT 0000000000000000 tst_audit25mod2_func2 + 0
[...]
Instead, check each line against the expected set.
Diff:
---
elf/Makefile | 4 +---
elf/tst-audit25.h | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
elf/tst-audit25a.c | 46 ++++++++++++++++++-------------------
elf/tst-audit25b.c | 48 ++++++++++++++++++++-------------------
4 files changed, 115 insertions(+), 49 deletions(-)
diff --git a/elf/Makefile b/elf/Makefile
index 518b1c0233..b15ec1bbb3 100644
--- a/elf/Makefile
+++ b/elf/Makefile
@@ -2328,9 +2328,7 @@ LDFLAGS-tst-audit24d = -Wl,-z,lazy
$(objpfx)tst-audit25a.out: $(objpfx)tst-auditmod25.so
$(objpfx)tst-audit25a: $(objpfx)tst-audit25mod1.so \
- $(objpfx)tst-audit25mod2.so \
- $(objpfx)tst-audit25mod3.so \
- $(objpfx)tst-audit25mod4.so
+ $(objpfx)tst-audit25mod2.so
LDFLAGS-tst-audit25a = -Wl,-z,lazy
$(objpfx)tst-audit25mod1.so: $(objpfx)tst-audit25mod3.so
LDFLAGS-tst-audit25mod1.so = -Wl,-z,now
diff --git a/elf/tst-audit25.h b/elf/tst-audit25.h
new file mode 100644
index 0000000000..489d0de519
--- /dev/null
+++ b/elf/tst-audit25.h
@@ -0,0 +1,66 @@
+/* Check LD_AUDIT and LD_BIND_NOW.
+ Copyright (C) 2022 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/>. */
+
+#ifndef _TEST_AUDIT25_H
+#define _TEST_AUDIT25_H
+
+#include <string.h>
+#include <support/check.h>
+#include <support/xstdio.h>
+
+/* Check if every line in EXPECTED is presented only once on BUFFER
+ with size of LEN. */
+static void
+check_output (char *buffer, size_t len, const char *expected[],
+ size_t expected_len)
+{
+ FILE *f = fmemopen (buffer, len, "r");
+ TEST_VERIFY (f != NULL);
+
+ bool found[expected_len];
+ for (size_t i = 0; i < expected_len; i++)
+ found[i] = false;
+
+ char *line = NULL;
+ size_t linelen = 0;
+ while (xgetline (&line, &linelen, f))
+ {
+ for (size_t i = 0; i < expected_len; i++)
+ if (strcmp (line, expected[i]) == 0)
+ {
+ if (found[i] != false)
+ {
+ support_record_failure ();
+ printf ("error: duplicated line %s\n", expected[i]);
+ }
+ TEST_COMPARE (found[i], false);
+ found[i] = true;
+ }
+ }
+
+ for (size_t i = 0; i < expected_len; i++)
+ if (found[i] == false)
+ {
+ support_record_failure ();
+ printf ("error: %s not present in output\n", expected[i]);
+ }
+
+ xfclose (f);
+}
+
+#endif
diff --git a/elf/tst-audit25a.c b/elf/tst-audit25a.c
index c2cff8541b..51097b5c9c 100644
--- a/elf/tst-audit25a.c
+++ b/elf/tst-audit25a.c
@@ -17,17 +17,11 @@
<https://www.gnu.org/licenses/>. */
#include <array_length.h>
-#include <errno.h>
#include <getopt.h>
-#include <limits.h>
-#include <inttypes.h>
-#include <string.h>
#include <stdlib.h>
#include <support/capture_subprocess.h>
-#include <support/check.h>
-#include <support/xstdio.h>
#include <support/support.h>
-#include <sys/auxv.h>
+#include <tst-audit25.h>
static int restart;
#define CMDLINE_OPTIONS \
@@ -82,13 +76,17 @@ do_test (int argc, char *argv[])
/* tst-audit25a is build with -Wl,-z,lazy and tst-audit25mod1 with
-Wl,-z,now; so only tst_audit25mod3_func1 should be expected to
have LA_SYMB_NOPLTENTER | LA_SYMB_NOPLTEXIT. */
- TEST_COMPARE_STRING (result.err.buffer,
- "la_symbind: tst_audit25mod3_func1 1\n"
- "la_symbind: tst_audit25mod1_func1 0\n"
- "la_symbind: tst_audit25mod1_func2 0\n"
- "la_symbind: tst_audit25mod2_func1 0\n"
- "la_symbind: tst_audit25mod4_func1 0\n"
- "la_symbind: tst_audit25mod2_func2 0\n");
+ const char *expected[] = {
+ "la_symbind: tst_audit25mod3_func1 1\n",
+ "la_symbind: tst_audit25mod1_func1 0\n",
+ "la_symbind: tst_audit25mod1_func2 0\n",
+ "la_symbind: tst_audit25mod2_func1 0\n",
+ "la_symbind: tst_audit25mod4_func1 0\n",
+ "la_symbind: tst_audit25mod2_func2 0\n"
+ };
+
+ check_output (result.err.buffer, result.err.length,
+ expected, array_length (expected));
support_capture_subprocess_free (&result);
}
@@ -101,15 +99,17 @@ do_test (int argc, char *argv[])
sc_allow_stderr);
/* With LD_BIND_NOW all symbols are expected to have
- LA_SYMB_NOPLTENTER | LA_SYMB_NOPLTEXIT. Also the resolution
- order is done in breadth-first order. */
- TEST_COMPARE_STRING (result.err.buffer,
- "la_symbind: tst_audit25mod4_func1 1\n"
- "la_symbind: tst_audit25mod3_func1 1\n"
- "la_symbind: tst_audit25mod1_func1 1\n"
- "la_symbind: tst_audit25mod2_func1 1\n"
- "la_symbind: tst_audit25mod1_func2 1\n"
- "la_symbind: tst_audit25mod2_func2 1\n");
+ LA_SYMB_NOPLTENTER | LA_SYMB_NOPLTEXIT. */
+ const char *expected[] = {
+ "la_symbind: tst_audit25mod4_func1 1\n",
+ "la_symbind: tst_audit25mod3_func1 1\n",
+ "la_symbind: tst_audit25mod1_func1 1\n",
+ "la_symbind: tst_audit25mod2_func1 1\n",
+ "la_symbind: tst_audit25mod1_func2 1\n",
+ "la_symbind: tst_audit25mod2_func2 1\n"
+ };
+ check_output (result.err.buffer, result.err.length,
+ expected, array_length (expected));
support_capture_subprocess_free (&result);
}
diff --git a/elf/tst-audit25b.c b/elf/tst-audit25b.c
index 46391770fd..807ff53b3e 100644
--- a/elf/tst-audit25b.c
+++ b/elf/tst-audit25b.c
@@ -16,17 +16,12 @@
License along with the GNU C Library; if not, see
<https://www.gnu.org/licenses/>. */
-#include <errno.h>
+#include <array_length.h>
#include <getopt.h>
-#include <limits.h>
-#include <inttypes.h>
-#include <string.h>
#include <stdlib.h>
#include <support/capture_subprocess.h>
-#include <support/check.h>
-#include <support/xstdio.h>
#include <support/support.h>
-#include <sys/auxv.h>
+#include <tst-audit25.h>
static int restart;
#define CMDLINE_OPTIONS \
@@ -81,13 +76,17 @@ do_test (int argc, char *argv[])
tst-audit25mod2 is built with -Wl,-z,lazy. So only
tst_audit25mod4_func1 (called by tst_audit25mod2_func1) should not
have LA_SYMB_NOPLTENTER | LA_SYMB_NOPLTEXIT. */
- TEST_COMPARE_STRING (result.err.buffer,
- "la_symbind: tst_audit25mod3_func1 1\n"
- "la_symbind: tst_audit25mod1_func1 1\n"
- "la_symbind: tst_audit25mod2_func1 1\n"
- "la_symbind: tst_audit25mod1_func2 1\n"
- "la_symbind: tst_audit25mod2_func2 1\n"
- "la_symbind: tst_audit25mod4_func1 0\n");
+ const char *expected[] = {
+ "la_symbind: tst_audit25mod3_func1 1\n",
+ "la_symbind: tst_audit25mod1_func1 1\n",
+ "la_symbind: tst_audit25mod2_func1 1\n",
+ "la_symbind: tst_audit25mod1_func2 1\n",
+ "la_symbind: tst_audit25mod2_func2 1\n",
+ "la_symbind: tst_audit25mod4_func1 0\n"
+ };
+
+ check_output (result.err.buffer, result.err.length,
+ expected, array_length (expected));
support_capture_subprocess_free (&result);
}
@@ -100,15 +99,18 @@ do_test (int argc, char *argv[])
sc_allow_stderr);
/* With LD_BIND_NOW all symbols are expected to have
- LA_SYMB_NOPLTENTER | LA_SYMB_NOPLTEXIT. Also the resolution
- order is done in breadth-first order. */
- TEST_COMPARE_STRING (result.err.buffer,
- "la_symbind: tst_audit25mod4_func1 1\n"
- "la_symbind: tst_audit25mod3_func1 1\n"
- "la_symbind: tst_audit25mod1_func1 1\n"
- "la_symbind: tst_audit25mod2_func1 1\n"
- "la_symbind: tst_audit25mod1_func2 1\n"
- "la_symbind: tst_audit25mod2_func2 1\n");
+ LA_SYMB_NOPLTENTER | LA_SYMB_NOPLTEXIT. */
+ const char *expected[] = {
+ "la_symbind: tst_audit25mod4_func1 1\n",
+ "la_symbind: tst_audit25mod3_func1 1\n",
+ "la_symbind: tst_audit25mod1_func1 1\n",
+ "la_symbind: tst_audit25mod2_func1 1\n",
+ "la_symbind: tst_audit25mod1_func2 1\n",
+ "la_symbind: tst_audit25mod2_func2 1\n"
+ };
+
+ check_output (result.err.buffer, result.err.length,
+ expected, array_length (expected));
support_capture_subprocess_free (&result);
}
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-06-09 21:26 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-09 13:23 [glibc/azanella/clang] elf: Do not assume relocation ordering to check for output Adhemerval Zanella
-- strict thread matches above, loose matches on Subject: below --
2022-06-09 21:26 Adhemerval Zanella
2022-06-03 14:12 Adhemerval Zanella
2022-05-13 14:26 Adhemerval Zanella
2022-05-12 19:40 Adhemerval Zanella
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).