From patchwork Thu Oct 6 09:28:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philipp Tomsich X-Patchwork-Id: 1763 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp218558wrs; Thu, 6 Oct 2022 02:29:51 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4xtYFldKWKXTG2KUIXvIh8SU5KJnet+LGTzV6eSoE1SidNcSEh24lmjKAi56M+BPe88kZN X-Received: by 2002:a05:6402:27c8:b0:458:ecf7:7248 with SMTP id c8-20020a05640227c800b00458ecf77248mr3807451ede.67.1665048591302; Thu, 06 Oct 2022 02:29:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665048591; cv=none; d=google.com; s=arc-20160816; b=WByWmvk5CQdQPtkEaol0THy4d88aPoQgAegyVf0avDtre9Ip7ScvfKIF8kgrDLYx/B SLJe1n+JLtGpDe97iOawMMYEMFxEQ/BErbi0kUyigghQdIAu81IFMUZPjbKFRLSrAJyb PuXBUxyBoLhd5Yplbq4o1cuHntBj7GEnhE8HR1Gi23kcgdJVhU365Ud49Ia/svrun8Nf frEbwL1K0XPM1VKBmmO27PNG38Bzk/66JnCHj3ug//Y0MHWnRfGt4vsGFWqpo0oYO3X+ f9nF/e82vsBRZjXtVfLGNVn4N1ijpdnU/CSB1CmoOtJsq477wE4hwIickg1U/Dk0QJAv SGTQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:to:from:dkim-signature :dmarc-filter:delivered-to; bh=6weKT2dbh9nGjgIMNSP3IUcK0WzpfIybSN8ungtVqdE=; b=lI/GBIeUzsLl+Cpbpg2+cTqQbwab8i9MeE+DqJBgcHnWcnRVzBnrvN6Hl9NBNHGyE7 9BzfAbm4CmPZtYqgdgQi/N8Avl4SNIMX/+2po5M7Q+iviGa+1CMHoA9OVF1F3cS3Sq6G 9iFZN4zpFE816Aom5ofH5JAjIUjPElZpZKPwS+ZimIlCSKBMx8FUw+wTouAVRCKtSaek nKI11pXiQTT49md4880TrFo1qH6BbndaErCBM1Wkzk6ZG4itsF7bVI503Kt0+D1LpZH6 qtV7HgyZdLFGTd9Ug04dv2+kJpEMsblT9AD0uJPLNlmgQ8QX0K6X5uGw57XizJ/QwvOC 2rIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@vrull.eu header.s=google header.b=pgRGMD9g; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id p23-20020a170906615700b0077eca9fa444si14372203ejl.187.2022.10.06.02.29.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Oct 2022 02:29:51 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=fail header.i=@vrull.eu header.s=google header.b=pgRGMD9g; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 16D123885500 for ; Thu, 6 Oct 2022 09:29:16 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by sourceware.org (Postfix) with ESMTPS id 1EA21383FB8B for ; Thu, 6 Oct 2022 09:28:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1EA21383FB8B Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=vrull.eu Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=vrull.eu Received: by mail-wr1-x42b.google.com with SMTP id w18so1757052wro.7 for ; Thu, 06 Oct 2022 02:28:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vrull.eu; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date; bh=6weKT2dbh9nGjgIMNSP3IUcK0WzpfIybSN8ungtVqdE=; b=pgRGMD9gTFN5oI65jr+p5+Ia/2kI+y0GrpdhDCZGk9w5JQGBU0i2JhH0fKcAfhEB+b zK4Ea05XDEWK7OdeyAua/c0ZT4FVkNm/TiUwBQBpgjDzpW55ImrHIqFDSb+taocOOpVC i1I5i9hw2HTGZclDG/kcstwuvNhBTYrEv+HRmA/09gFDg4R/oePrnCfEjLcd4CjL6wva g3ijuG/Zpe3fZj8e/aH2wLSWcZ+B6ZoSOBNX8CQzP41SO6wBfzHgSNRxI+XuTtNIRkUA 4IT/jdVpzwwUsGfwMluzQairzDpLES5aOO6gIQWyvdnFw5dUZ7eaaxWjckEoT8AgWhRP dmYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date; bh=6weKT2dbh9nGjgIMNSP3IUcK0WzpfIybSN8ungtVqdE=; b=GPAW/R3JHBn2AIbFIIPmBQ7mNt6HAIesGtCLIdhQnhC8bSDcV+4YeNkhoFZwXdfHST IoNjjcWjCaJdPRFC2B34mX0Ad6LworYUTgv1bpf2eZszu/G3mhUghTJBI/4kbRqDalQB hoxT87jmyIhrJvJuJLETcTxs2PRvG0tu9i5Y7wRi+njE5DNeudIHDaDzovYgGRyVR3GS KNaR2RXZ0a7a9mUM7GC2J4SCZDp4RuAJPVfJjPF+v385QTEgWv8+PLl5PiLj0Q+HQe53 NZne0TyA5Eahn6lANMCMJD41AIqfODVzUPNrD9TGM3Qm4zjT4BTg33Wh6LSa7Lbio4n8 /oZQ== X-Gm-Message-State: ACrzQf162IGrydhkNFkyY58IpdIJm4KASH48BxdwUIeZzpTw6e1MAT6D NuWoQCMvPmKcW6zRyQr6F0GC5Uvf+0bspQ== X-Received: by 2002:a05:6000:1e03:b0:22e:3bf2:4685 with SMTP id bj3-20020a0560001e0300b0022e3bf24685mr2444685wrb.82.1665048524618; Thu, 06 Oct 2022 02:28:44 -0700 (PDT) Received: from ubuntu-focal.. ([2a01:4f9:3a:1e26::2]) by smtp.gmail.com with ESMTPSA id l18-20020a5d6692000000b0022ac1be009esm17332171wru.16.2022.10.06.02.28.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Oct 2022 02:28:44 -0700 (PDT) From: Philipp Tomsich To: gcc-patches@gcc.gnu.org Subject: [PATCH v2] aarch64: fix off-by-one in reading cpuinfo Date: Thu, 6 Oct 2022 11:28:39 +0200 Message-Id: <20221006092840.607374-1-philipp.tomsich@vrull.eu> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_SHORT, 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: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Richard Sandiford , Philipp Tomsich Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1745929991590455109?= X-GMAIL-MSGID: =?utf-8?q?1745929991590455109?= Fixes: 341573406b39 Don't subtract one from the result of strnlen() when trying to point to the first character after the current string. This issue would cause individual characters (where the 128 byte buffers are stitched together) to be lost. gcc/ChangeLog: * config/aarch64/driver-aarch64.cc (readline): Fix off-by-one. gcc/testsuite/ChangeLog: * gcc.target/aarch64/cpunative/info_18: New test. * gcc.target/aarch64/cpunative/native_cpu_18.c: New test. Signed-off-by: Philipp Tomsich --- Changes in v2: - Add a a regression test (as per review comment). gcc/config/aarch64/driver-aarch64.cc | 4 ++-- .../gcc.target/aarch64/cpunative/info_18 | 8 ++++++++ .../gcc.target/aarch64/cpunative/native_cpu_18.c | 15 +++++++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.target/aarch64/cpunative/info_18 create mode 100644 gcc/testsuite/gcc.target/aarch64/cpunative/native_cpu_18.c diff --git a/gcc/config/aarch64/driver-aarch64.cc b/gcc/config/aarch64/driver-aarch64.cc index 52ff537908e..48250e68034 100644 --- a/gcc/config/aarch64/driver-aarch64.cc +++ b/gcc/config/aarch64/driver-aarch64.cc @@ -203,9 +203,9 @@ readline (FILE *f) return std::string (); /* If we're not at the end of the line then override the \0 added by fgets. */ - last = strnlen (buf, size) - 1; + last = strnlen (buf, size); } - while (!feof (f) && buf[last] != '\n'); + while (!feof (f) && (last > 0 && buf[last - 1] != '\n')); std::string result (buf); free (buf); diff --git a/gcc/testsuite/gcc.target/aarch64/cpunative/info_18 b/gcc/testsuite/gcc.target/aarch64/cpunative/info_18 new file mode 100644 index 00000000000..25061a4abe8 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/cpunative/info_18 @@ -0,0 +1,8 @@ +processor : 0 +BogoMIPS : 2000.00 +Features : fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 asimddp sha512 asimdfhm dit uscat ilrcpc flagm ssbs sb dcpodp flagm2 frint i8mm bf16 rng ecv +CPU implementer : 0xc0 +CPU architecture: 8 +CPU variant : 0x0 +CPU part : 0xac3 +CPU revision : 0 diff --git a/gcc/testsuite/gcc.target/aarch64/cpunative/native_cpu_18.c b/gcc/testsuite/gcc.target/aarch64/cpunative/native_cpu_18.c new file mode 100644 index 00000000000..b5f0a3005f5 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/cpunative/native_cpu_18.c @@ -0,0 +1,15 @@ +/* { dg-do compile { target { { aarch64*-*-linux*} && native } } } */ +/* { dg-set-compiler-env-var GCC_CPUINFO "$srcdir/gcc.target/aarch64/cpunative/info_18" } */ +/* { dg-additional-options "-mcpu=native" } */ + +int main() +{ + return 0; +} + +/* { dg-final { scan-assembler {\.arch armv8.6-a\+crc\+fp16\+aes\+sha3\+rng} } } */ + +/* Test one where the boundary of buffer size would overwrite the last + character read when stitching the fgets-calls together. With the + test data provided, this would truncate the 'sha512' into 'ha512' + (dropping the 'sha3' feature). */