From patchwork Tue Nov 15 19:31:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 1704230 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=Swo9hiev; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NBbt31byVz23mx for ; Wed, 16 Nov 2022 06:32:27 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1F2F538AA27D for ; Tue, 15 Nov 2022 19:32:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1F2F538AA27D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1668540743; bh=c6DWeUh0csKKa0NLudR0UGhZbMe2e9Mx5sXKZKjKM2Q=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=Swo9hievWa5RF7X142MRxBtXrV0nvEDIa6qfQSV7nPIS+hv3y8fbohFm8Xha08dNE PdXria/YkPOkr9dde0TN63yz1fyOEz+QWxd/ju8H9iugl2ux9avEEB9fVZCQShtDoS 29OvuMgiGIoC+iwUp3ExNq6PY5K7WTK2oQZX4VdQ= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oa1-x29.google.com (mail-oa1-x29.google.com [IPv6:2001:4860:4864:20::29]) by sourceware.org (Postfix) with ESMTPS id 6FFA338A90BE for ; Tue, 15 Nov 2022 19:32:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6FFA338A90BE Received: by mail-oa1-x29.google.com with SMTP id 586e51a60fabf-1322d768ba7so17411805fac.5 for ; Tue, 15 Nov 2022 11:32:07 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=c6DWeUh0csKKa0NLudR0UGhZbMe2e9Mx5sXKZKjKM2Q=; b=O0pDwAN1XRH7V56BPIKtcu7Q147PN2Rl2eGOdiGkpwCfrhwDCbDt7o5TKMm39Uzmc6 d2U37Tf6fBed3FKxwTDhgZ8RQWq5395iw7XZxbSA4bNL711gMgDvlOMU/pYGPPQZlOFF 4VvN+VUUiu0tPqoXP4eJWgh5FpMWth+d+NGgCulzuEFWDmzU0va5ZSs2W/OLKB/0aqIA dhvgMm51T+vCzjUA9t3KhaiFwv3k+SBom4kKx6OpoN8LEqbiPEytp45vR8LbCqLadRV9 lwLtQXosUT1M3zN9B3JO349PENLgIP/xuyG9xXgbUTPgd7hWnycJRa6ofUQwe2YPL2lI NTSg== X-Gm-Message-State: ANoB5plxMk5/zy+56XBInv+bP6olieF3s9ElsawuixSm2beDIPoMn4tf zxI2fDspCPhe4Q9ahtUaUOMe8jmEas8ZrXpN X-Google-Smtp-Source: AA0mqf6+nd5gEmI1VqYuKp53x/b4xLC0NPc0F+oh53aqoTFizRmXDh/M+s4Ihs9UbcsY26D+6VsmMw== X-Received: by 2002:a05:6870:cd10:b0:12d:4244:43d0 with SMTP id qk16-20020a056870cd1000b0012d424443d0mr2018453oab.207.1668540726475; Tue, 15 Nov 2022 11:32:06 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c1:1164:573d:c7d8:ae8e:e2eb]) by smtp.gmail.com with ESMTPSA id f7-20020a9d2c07000000b00660e833baddsm5705231otb.29.2022.11.15.11.32.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Nov 2022 11:32:06 -0800 (PST) To: libc-alpha@sourceware.org, Fangrui Song Subject: [PATCH 2/7] elf: Do not assume symbol order on tst-audit25{a,b} Date: Tue, 15 Nov 2022 16:31:54 -0300 Message-Id: <20221115193159.173838-3-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221115193159.173838-1-adhemerval.zanella@linaro.org> References: <20221115193159.173838-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, KAM_STOCKGEN, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" The static linker might impose any order or internal function position, so change the test to check if the audit prints the symbol only once in any order. --- elf/tst-audit25.h | 46 ++++++++++++++++++++++++++++++++++++++++++++++ elf/tst-audit25a.c | 38 ++++++++++++++++++++++++-------------- elf/tst-audit25b.c | 39 +++++++++++++++++++++++++-------------- 3 files changed, 95 insertions(+), 28 deletions(-) create mode 100644 elf/tst-audit25.h diff --git a/elf/tst-audit25.h b/elf/tst-audit25.h new file mode 100644 index 0000000000..9b08c43c32 --- /dev/null +++ b/elf/tst-audit25.h @@ -0,0 +1,46 @@ +/* Check LD_AUDIT and LD_BIND_NOW. Common definitions. + 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 + . */ + +static void +compare_output (void *buffer, size_t length, const char *ref[], size_t reflen) +{ + FILE *in = fmemopen (buffer, length, "r"); + TEST_VERIFY_EXIT (in != NULL); + char *line = NULL; + size_t linelen = 0; + + bool found[reflen]; + for (int i = 0; i < reflen; i++) + found[i] = false; + + while (xgetline (&line, &linelen, in)) + { + for (int i = 0; i < reflen; i++) + if (strcmp (line, ref[i]) == 0) + { + TEST_COMPARE (found[i], false); + found[i] = true; + } + } + + for (int i = 0; i < reflen; i++) + TEST_COMPARE (found[i], true); + + free (line); + fclose (in); +} diff --git a/elf/tst-audit25a.c b/elf/tst-audit25a.c index c2cff8541b..9d2b316576 100644 --- a/elf/tst-audit25a.c +++ b/elf/tst-audit25a.c @@ -29,6 +29,8 @@ #include #include +#include "tst-audit25.h" + static int restart; #define CMDLINE_OPTIONS \ { "restart", no_argument, &restart, 1 }, @@ -82,13 +84,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_audit25mod1_func1 0\n", + "la_symbind: tst_audit25mod1_func2 0\n", + "la_symbind: tst_audit25mod2_func1 0\n", + "la_symbind: tst_audit25mod2_func2 0\n", + "la_symbind: tst_audit25mod3_func1 1\n", + "la_symbind: tst_audit25mod4_func1 0\n", + }; + compare_output (result.err.buffer, result.err.length, + expected, array_length(expected)); support_capture_subprocess_free (&result); } @@ -103,13 +109,17 @@ do_test (int argc, char *argv[]) /* 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"); + const char *expected[] = + { + "la_symbind: tst_audit25mod1_func1 1\n", + "la_symbind: tst_audit25mod1_func2 1\n", + "la_symbind: tst_audit25mod2_func1 1\n", + "la_symbind: tst_audit25mod2_func2 1\n", + "la_symbind: tst_audit25mod3_func1 1\n", + "la_symbind: tst_audit25mod4_func1 1\n", + }; + compare_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..e1422049b1 100644 --- a/elf/tst-audit25b.c +++ b/elf/tst-audit25b.c @@ -16,6 +16,7 @@ License along with the GNU C Library; if not, see . */ +#include #include #include #include @@ -28,6 +29,8 @@ #include #include +#include "tst-audit25.h" + static int restart; #define CMDLINE_OPTIONS \ { "restart", no_argument, &restart, 1 }, @@ -81,13 +84,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", + }; + compare_output (result.err.buffer, result.err.length, + expected, array_length(expected)); support_capture_subprocess_free (&result); } @@ -102,13 +109,17 @@ do_test (int argc, char *argv[]) /* 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"); + 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", + }; + compare_output (result.err.buffer, result.err.length, + expected, array_length(expected)); support_capture_subprocess_free (&result); }