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: 58449 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 313703887F45 for ; Thu, 6 Oct 2022 09:29:06 +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-Google-Smtp-Source: AMsMyM4qNn1bP1RcVrHdwRGBsaHmod3iD043mgmNKPdrTOKgceUQz/XfZvhtFf6YqP2iQUPI4OOh1A== 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+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" 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). */