From patchwork Thu Jun 13 13:33:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Marc_Poulhi=C3=A8s?= X-Patchwork-Id: 1947402 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=WUpnkVvY; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4W0Njq1mw1z1ydW for ; Thu, 13 Jun 2024 23:36:47 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8F15B388215A for ; Thu, 13 Jun 2024 13:36:45 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by sourceware.org (Postfix) with ESMTPS id 24B5F3882120 for ; Thu, 13 Jun 2024 13:33:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 24B5F3882120 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 24B5F3882120 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::333 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718285640; cv=none; b=DAEcHTBDXbXKYuay2lHe5XC4cJ7ey/RLnBDOFTIBB/ZQwaELNKoiH5Dqse4IOPHJg/q+WTya/aMjEpUCShLCofqCmoGtpKP0XpaNJD5n3bmbZ8AKEy70/AdSsaTP9JGwQeuhITZbS0EjwOMOdIGudwQ4hzi1EMWxHOgjRBIeGMc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718285640; c=relaxed/simple; bh=CoTeJLkxIx+dCRRv/tLB/+e8o29kmTrJIavkyYzYH/I=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=q2tjV7sV7+Rh0q4l+vmLJUBALsBT/jYIK1Svi6PxKszQ2QENZSWfxBpWHz9QV0REzc3F2ELbk40nRqfbrFZNqEL9A+HHPrc0XHd11pTnYdv0hkJ0acJdbS8LPq6WTLGMlE2pePmkmXaZlKapYcPHIeen2mZ+OaoMpVvc5fceQUs= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-4218008c613so8503695e9.2 for ; Thu, 13 Jun 2024 06:33:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1718285637; x=1718890437; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=x+/4TC3xkD187P2hi3A4mkNB1p07SPmemPelxkIGFvE=; b=WUpnkVvYjPVrkr95oZjchxhC3JNSmV8oqxRBJfS9HwELI+VnZHz1XQpDrDLXBH7ZaL k1BhekoCwoTL5fTnnx/rnmUupVm+Z6VLpBxRiRQ5mDBXgjZvvKxJ3Re6E/rWYO6qqjyW VW44iZcw23lpzMaDTtby4iMp/NalEmD4EYni43Sm2VAaB9gW8U3Iu8cfgTx7lNGr0s5P ygEvNUL49tEJAe1G6QFomuWBxmKSfr5d4Sm1KbYumfV3syy2jOKyIsgU9TKpVW0CVf0w nKdevRBYV5SQ7Q6VR12xjSzOsL4aHgqnM3eqmZin5CTKvBAYxiDKq92XUs913MnW5NH7 O+2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718285637; x=1718890437; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=x+/4TC3xkD187P2hi3A4mkNB1p07SPmemPelxkIGFvE=; b=tHipaQVMIcPh7bG5dEgzkXYflj1u75qCQcKUfKoEHR1w2vSd0ShwJiA6dGPXXAm0Ub NMhYI46aN34v2eG44H6IbgSUIhY2zI6kb7BeKXUHtBwCkpWR9Mpa1Tk8KuLeT3nUPsxS 78QFubdeyGmpEMuvMAQThcOqmizxgd3SeTWYTvjrRDgMN+2CvCjp8dBgADXtoMv10cjN q1+uLG20F1hWxBOt+bSzBbcok9/FZXynwZDH7Ea9HbLA/XNvxee5fetfxvPD46YgU583 stmKNo6Yo6044s5LKUk02If8Y5z3tQqE/uPfc46WSpkNdVsRnR2ArUmS/vJoZJn4wjCw Cf2Q== X-Gm-Message-State: AOJu0YwWfq/22G3zpovR6OKA7f0VJu/IJK3eMSL+BtghRLq0eoziqWC0 +1ZZ7AHybqggqj/pRLYhTZWjDvriM4g598QwSyJT3JXlyFrDNoV2fMG330avpee9e+3A3a+vi08 = X-Google-Smtp-Source: AGHT+IHcYvLr/hwnotHjf7QP6t0Oo+FZ0xx/kmr4YWt+QxdCZm4WeEDRDIi+1aYRvbi7TgkaXhCMlg== X-Received: by 2002:a05:600c:34ca:b0:421:7d30:717e with SMTP id 5b1f17b1804b1-422862a7326mr39823115e9.15.1718285637008; Thu, 13 Jun 2024 06:33:57 -0700 (PDT) Received: from poulhies-Precision-5550.telnowedge.local (lmontsouris-659-1-24-67.w81-250.abo.wanadoo.fr. [81.250.175.67]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-422870e9145sm62391955e9.22.2024.06.13.06.33.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jun 2024 06:33:56 -0700 (PDT) From: =?utf-8?q?Marc_Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: Ronan Desplanques Subject: [COMMITTED 09/30] ada: Fix incorrect String lower bound in gnatlink Date: Thu, 13 Jun 2024 15:33:15 +0200 Message-ID: <20240613133338.1809385-9-poulhies@adacore.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240613133338.1809385-1-poulhies@adacore.com> References: <20240613133338.1809385-1-poulhies@adacore.com> MIME-Version: 1.0 X-Spam-Status: No, score=-13.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org From: Ronan Desplanques This patch fixes code in gnatlink that incorrectly assumed that the lower bound of a particular string was always 1. gcc/ada/ * gnatlink.adb (Gnatlink): Fix incorrect lower bound assumption. (Is_Prefix): New function. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/gnatlink.adb | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/gcc/ada/gnatlink.adb b/gcc/ada/gnatlink.adb index 1455412ef93..db0fd144a13 100644 --- a/gcc/ada/gnatlink.adb +++ b/gcc/ada/gnatlink.adb @@ -1885,6 +1885,24 @@ begin Shared_Libgcc_Seen : Boolean := False; Static_Libgcc_Seen : Boolean := False; + function Is_Prefix + (Complete_String : String; Prefix : String) return Boolean; + -- Returns whether Prefix is a prefix of Complete_String + + --------------- + -- Is_Prefix -- + --------------- + + function Is_Prefix + (Complete_String : String; Prefix : String) return Boolean + is + S : String renames Complete_String; + P : String renames Prefix; + begin + return P'Length <= S'Length + and then S (S'First .. S'First + P'Length - 1) = P; + end Is_Prefix; + begin J := Linker_Options.First; while J <= Linker_Options.Last loop @@ -1936,13 +1954,12 @@ begin -- Here we just check for a canonical form that matches the -- pragma Linker_Options set in the NT runtime. - if (Linker_Options.Table (J)'Length > 17 - and then Linker_Options.Table (J) (1 .. 17) = - "-Xlinker --stack=") - or else - (Linker_Options.Table (J)'Length > 12 - and then Linker_Options.Table (J) (1 .. 12) = - "-Wl,--stack=") + if Is_Prefix + (Complete_String => Linker_Options.Table (J).all, + Prefix => "-Xlinker --stack=") + or else Is_Prefix + (Complete_String => Linker_Options.Table (J).all, + Prefix => "-Wl,--stack=") then if Stack_Op then Linker_Options.Table (J .. Linker_Options.Last - 1) :=