From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1791) id 2D44C3850856; Fri, 3 Jun 2022 14:12:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2D44C3850856 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Adhemerval Zanella To: glibc-cvs@sourceware.org Subject: [glibc/azanella/clang] elf: Do not assume relocation ordering to check for output X-Act-Checkin: glibc X-Git-Author: Adhemerval Zanella X-Git-Refname: refs/heads/azanella/clang X-Git-Oldrev: 82657cbbb103cdbd3d480cf7b33918182859cff1 X-Git-Newrev: 864814901127d04c70e42e864587c8a834d5134d Message-Id: <20220603141242.2D44C3850856@sourceware.org> Date: Fri, 3 Jun 2022 14:12:42 +0000 (GMT) X-BeenThere: glibc-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Glibc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 03 Jun 2022 14:12:42 -0000 https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=864814901127d04c70e42e864587c8a834d5134d commit 864814901127d04c70e42e864587c8a834d5134d Author: Adhemerval Zanella 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 + . */ + +#ifndef _TEST_AUDIT25_H +#define _TEST_AUDIT25_H + +#include +#include +#include + +/* 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 @@ . */ #include -#include #include -#include -#include -#include #include #include -#include -#include #include -#include +#include 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 . */ -#include +#include #include -#include -#include -#include #include #include -#include -#include #include -#include +#include 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); }