https://gcc.gnu.org/g:2afa7fd8c6d32264d4d3d917318fbac9f7f38508
commit r15-1267-g2afa7fd8c6d32264d4d3d917318fbac9f7f38508 Author: Ronan Desplanques <desplanq...@adacore.com> Date: Wed Apr 24 10:18:13 2024 +0200 ada: Fix incorrect String lower bound in gnatlink 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. Diff: --- 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 1455412ef934..db0fd144a13e 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) :=