{"id":2231740,"url":"http://patchwork.ozlabs.org/api/1.1/patches/2231740/?format=json","web_url":"http://patchwork.ozlabs.org/project/gcc/patch/2409132.ElGaqSPkdT@fomalhaut/","project":{"id":17,"url":"http://patchwork.ozlabs.org/api/1.1/projects/17/?format=json","name":"GNU Compiler Collection","link_name":"gcc","list_id":"gcc-patches.gcc.gnu.org","list_email":"gcc-patches@gcc.gnu.org","web_url":null,"scm_url":null,"webscm_url":null},"msgid":"<2409132.ElGaqSPkdT@fomalhaut>","date":"2026-05-01T11:12:35","name":"[Ada] Link with PIC static Ada runtime when -pie is specified","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"be35cf171b9ca1fdfc8832429bbb80401829f6c9","submitter":{"id":78832,"url":"http://patchwork.ozlabs.org/api/1.1/people/78832/?format=json","name":"Eric Botcazou","email":"botcazou@adacore.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/gcc/patch/2409132.ElGaqSPkdT@fomalhaut/mbox/","series":[{"id":502441,"url":"http://patchwork.ozlabs.org/api/1.1/series/502441/?format=json","web_url":"http://patchwork.ozlabs.org/project/gcc/list/?series=502441","date":"2026-05-01T11:12:35","name":"[Ada] Link with PIC static Ada runtime when -pie is specified","version":1,"mbox":"http://patchwork.ozlabs.org/series/502441/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2231740/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2231740/checks/","tags":{},"headers":{"Return-Path":"<gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org>","X-Original-To":["incoming@patchwork.ozlabs.org","gcc-patches@gcc.gnu.org"],"Delivered-To":["patchwork-incoming@legolas.ozlabs.org","gcc-patches@gcc.gnu.org"],"Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256\n header.s=google header.b=SS0RUyTW;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org\n (client-ip=2620:52:6:3111::32; helo=vm01.sourceware.org;\n envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org;\n receiver=patchwork.ozlabs.org)","sourceware.org;\n\tdkim=pass (2048-bit key,\n secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256\n header.s=google header.b=SS0RUyTW","sourceware.org; dmarc=pass (p=quarantine dis=none)\n header.from=adacore.com","sourceware.org; spf=pass smtp.mailfrom=adacore.com","server2.sourceware.org;\n arc=none smtp.remote-ip=209.85.221.45"],"Received":["from vm01.sourceware.org (vm01.sourceware.org\n [IPv6:2620:52:6:3111::32])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4g6T162hdlz1y04\n\tfor <incoming@patchwork.ozlabs.org>; Fri, 01 May 2026 21:13:12 +1000 (AEST)","from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id 46CB8437423A\n\tfor <incoming@patchwork.ozlabs.org>; Fri,  1 May 2026 11:13:09 +0000 (GMT)","from mail-wr1-f45.google.com (mail-wr1-f45.google.com\n [209.85.221.45])\n by sourceware.org (Postfix) with ESMTPS id A7D16437423F\n for <gcc-patches@gcc.gnu.org>; Fri,  1 May 2026 11:12:39 +0000 (GMT)","by mail-wr1-f45.google.com with SMTP id\n ffacd0b85a97d-448528f4e69so1106381f8f.3\n for <gcc-patches@gcc.gnu.org>; Fri, 01 May 2026 04:12:39 -0700 (PDT)","from fomalhaut.localnet ([2a01:e0a:107c:2f10:e654:e8ff:fe8f:2ce6])\n by smtp.gmail.com with ESMTPSA id\n ffacd0b85a97d-44a8ea7cf97sm4633965f8f.6.2026.05.01.04.12.37\n for <gcc-patches@gcc.gnu.org>\n (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n Fri, 01 May 2026 04:12:37 -0700 (PDT)"],"DKIM-Filter":["OpenDKIM Filter v2.11.0 sourceware.org 46CB8437423A","OpenDKIM Filter v2.11.0 sourceware.org A7D16437423F"],"DMARC-Filter":"OpenDMARC Filter v1.4.2 sourceware.org A7D16437423F","ARC-Filter":"OpenARC Filter v1.0.0 sourceware.org A7D16437423F","ARC-Seal":"i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1777633959; cv=none;\n b=KDs4LvDbCtH5RBceGUpHHrIiMyrpF/2zzyCkPO42RtbGePGsmQ27mod2QbyiDtDlno87m0GAkpoOoXp23DJ8DlUO+gHuYRba/9L60DA9BawE4/9wexVPtrg9YIy+g7Z+RmTdPRSguyYAU+0UviKVkZLvcco8Qe5e5l8td1OFVOY=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=sourceware.org; s=key;\n t=1777633959; c=relaxed/simple;\n bh=52HobyznDVSJFb27LiCIIT5odxUWODs6iKv/t5XFYMM=;\n h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version;\n b=CFqjrQUWbSRud8zh9O7At3eToUFaojxC+elBculFW3D4RB+38jna7jPY3p+J+26v2BeiTAmFfsh1GPcFxcTnqW0wYyiyJadAYvVqaM144fZcoESBQmBXGcIM8IDL+5nzXpNzaGXadnJC0zdZ2irwGAYfaFVKEinZYyS9tDF80K4=","ARC-Authentication-Results":"i=1; server2.sourceware.org","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=adacore.com; s=google; t=1777633958; x=1778238758; darn=gcc.gnu.org;\n h=content-transfer-encoding:mime-version:message-id:date:subject:to\n :from:from:to:cc:subject:date:message-id:reply-to;\n bh=Z1TLrZyWWrgnyWYAnmq4NvZnKrjSsTDzCNYvxro3b6k=;\n b=SS0RUyTW61sNpl0NDX6gencoKY6XGbQM+imA8cDcwfPndKZQk2/rZxA5BWGM+Z2GFP\n uYJW8Mbnqy3Z9hV4LvA3N5OR4qqALFH+UF8+xQLBVY3mZi3cQ851SIb4pGA33xO3QG2+\n gzHnN2sj4DeZ5to4a5K6lJXIJ6a0Xy41zuJbO3XsLaE1XzjxUOW06C0sg+g20zRKyTGT\n 6dXaFV4jdjq1fyLIY0pGdR5xFPRRwkpMCn00q6ZwnBeGDeOwn7VXqra98IzF4Utlm4zf\n +KD7Z8hYmEYfkdyfemxLp47N4DsYYHOgE5FtWGOd/mne3vGSYXoyDaIR2jZtmXzIC58b\n v7yg==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1777633958; x=1778238758;\n h=content-transfer-encoding:mime-version:message-id:date:subject:to\n :from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id\n :reply-to;\n bh=Z1TLrZyWWrgnyWYAnmq4NvZnKrjSsTDzCNYvxro3b6k=;\n b=ngOjvlv0L2pmXfW/hTMvB7K7yxkG2e4cIWYr2K19gXR2INWFVwzp4UngHLmkNmba25\n VSAjPUa7ZXPRcmiSu6nbJGa6ypTiEVfItrIOmhFGczLzwdejm+grJJ+4lnrqOvu6rW7L\n zsHKtXTK1+dzkp/twGNPpFKhMHft6v5n1gyTr8oZODvb+qZ0qBbG1UQCwxPJ9noRo7eX\n 13wm1DjiYghP6RMUEiXLvBWrIq9Wt8HYO96BFrROIoiws+MzMyndsMfGt1vlnFqlb0KP\n 3HYB2I+0pCeVsIA68iepZqnB6ExzT+FtEDJtWxsjDCi3qKXq1LaXXA3ojQC6XHrUAx2T\n TF6g==","X-Gm-Message-State":"AOJu0YzvCTkw8uVubRWrIicJMkqTvMtwti0dUjAdhFhuj6fRVwBP65OG\n AYav2kcpYw2zJI5OvZQji/gvbXoDwX2VbpXp/fLDYBnO8hi75L4MEjdYL/IywKAHjZCTKWNfSYm\n v0v4=","X-Gm-Gg":"AeBDiesx/wEzTWiT0OR1jzS/huFQzvpxKP1EPIeth8pRHwNi8INxRUjRG+JWfyuCi6b\n DHANN8Z06AyA8oT4oxaB5mZ65gmA7MvelPdzbAohgIp2Ah5OUyf3CnS3GC4qrX2O22lQL0Cr1i6\n 7Y3SjCXeSFCdQSnmzvFO9cVhf13qsW9jXOYz2faz4BsDn5n1kbSBgv/qHLp9rPtZltctxP9jUB/\n O70SSs4tUJ5xi5Xvj1iuZ/wdinuEYzQ88iMlcHqdVqfcV+A3BN0YZs3FARvl+6xuyO4l3l4qnr7\n 13YxLFvnlhwFx7DMdah8Hhf4UVnTM7JhQoWedm+cpvwF9/UCLO/uq0Msr3zCdt4AZokNnxzEVUx\n 8QU2LsHtTyxm4elBPyZwf8+zb0CTht8c/vF+fp5ZcwzIwCFYCDCw+chhEZcQkxET+31RtdvFPve\n BQYkRcO28hr/8wR8iGCEkZlV5+fpZnXqiTsULqUK0qJQUYPNg=","X-Received":"by 2002:a05:6000:24c5:b0:43d:71f4:7ed5 with SMTP id\n ffacd0b85a97d-4493cc3fdffmr11657400f8f.17.1777633957923;\n Fri, 01 May 2026 04:12:37 -0700 (PDT)","From":"Eric Botcazou <botcazou@adacore.com>","X-Google-Original-From":"Eric Botcazou <ebotcazou@adacore.com>","To":"gcc-patches@gcc.gnu.org","Subject":"[Ada] Link with PIC static Ada runtime when -pie is specified","Date":"Fri, 01 May 2026 13:12:35 +0200","Message-ID":"<2409132.ElGaqSPkdT@fomalhaut>","MIME-Version":"1.0","Content-Type":"multipart/mixed; boundary=\"nextPart5068158.GXAFRqVoOG\"","Content-Transfer-Encoding":"7Bit","X-BeenThere":"gcc-patches@gcc.gnu.org","X-Mailman-Version":"2.1.30","Precedence":"list","List-Id":"Gcc-patches mailing list <gcc-patches.gcc.gnu.org>","List-Unsubscribe":"<https://gcc.gnu.org/mailman/options/gcc-patches>,\n <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe>","List-Archive":"<https://gcc.gnu.org/pipermail/gcc-patches/>","List-Post":"<mailto:gcc-patches@gcc.gnu.org>","List-Help":"<mailto:gcc-patches-request@gcc.gnu.org?subject=help>","List-Subscribe":"<https://gcc.gnu.org/mailman/listinfo/gcc-patches>,\n <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe>","Errors-To":"gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org"},"content":"This changes gnatlink to append _pic to the name of the static Ada runtime \nwhen -pie is passed on the command line.\n\nTested on x86-64/Linux, applied on the mainline.\n\n\n2026-05-01  Eric Botcazou  <ebotcazou@adacore.com>\n\n\tPR ada/87936\n\t* gnatlink.adb (Gnatlink): Rename local variable and add Output_PIE\n\tlocal variable; when it is set, compile the binder file with -fPIE.\n\t(Process_Args): Set Output_PIE upon seeing -pie.\n\t(Process_Binder_File): Append \"_pic\" to the name of the static Ada\n\truntime if Output_PIE is set.\n\n\n2026-05-01  Eric Botcazou  <ebotcazou@adacore.com>\n\n\t* gnat.dg/pie1.adb: New file.","diff":"diff --git a/gcc/ada/gnatlink.adb b/gcc/ada/gnatlink.adb\nindex 6a53d550470..85517bf3318 100644\n--- a/gcc/ada/gnatlink.adb\n+++ b/gcc/ada/gnatlink.adb\n@@ -166,8 +166,6 @@ procedure Gnatlink is\n    Verbose_Mode       : Boolean := False;\n    Very_Verbose_Mode  : Boolean := False;\n \n-   Standard_Gcc : Boolean := True;\n-\n    Compile_Bind_File : Boolean := True;\n    --  Set to False if bind file is not to be compiled\n \n@@ -175,6 +173,12 @@ procedure Gnatlink is\n    --  Set to True by switch -M. The map file name is derived from\n    --  the ALI file name (mainprog.ali => mainprog.map).\n \n+   Output_PIE : Boolean := False;\n+   --  Set to True if -pie is specified on the command line\n+\n+   Standard_GCC : Boolean := True;\n+   --  Set to False if --GCC is specified on the command line\n+\n    Object_List_File_Supported : Boolean;\n    for Object_List_File_Supported'Size use Character'Size;\n    pragma Import\n@@ -568,6 +572,13 @@ procedure Gnatlink is\n                   Binder_Options.Table (Binder_Options.Last) :=\n                     Linker_Options.Table (Linker_Options.Last);\n \n+               elsif Arg'Length = 4 and then Arg (2 .. 4) = \"pie\" then\n+                  Output_PIE := True;\n+\n+                  Linker_Options.Increment_Last;\n+                  Linker_Options.Table (Linker_Options.Last) :=\n+                    new String'(Arg);\n+\n                elsif Arg'Length >= 7 and then Arg (1 .. 7) = \"--LINK=\" then\n                   if Arg'Length = 7 then\n                      Exit_With_Error (\"Missing argument for --LINK=\");\n@@ -615,7 +626,7 @@ procedure Gnatlink is\n                   begin\n                      if Program_Args.all (1).all /= Gcc.all then\n                         Gcc := new String'(Program_Args.all (1).all);\n-                        Standard_Gcc := False;\n+                        Standard_GCC := False;\n                      end if;\n \n                      --  Set appropriate flags for switches passed\n@@ -1114,10 +1125,28 @@ procedure Gnatlink is\n \n                elsif Next_Line (Nfirst .. Nlast) = \"-lgnarl\"\n                  or else Next_Line (Nfirst .. Nlast) = \"-lgnat\"\n-                 or else\n-                   Next_Line\n-                     (1 .. Natural'Min (Nlast, 8 + Library_Version'Length)) =\n-                       Shared_Lib (\"gnarl\")\n+               then\n+                  if Output_PIE and then GNAT_Static then\n+                     Search_Library_Path\n+                       (Next_Line   => Next_Line (Nfirst .. Nlast) & \"_pic\",\n+                        Nfirst      => Nfirst,\n+                        Nlast       => Nlast + 4,\n+                        Last        => Nlast + 4,\n+                        GNAT_Static => True,\n+                        GNAT_Shared => GNAT_Shared);\n+                  else\n+                     Search_Library_Path\n+                       (Next_Line   => Next_Line,\n+                        Nfirst      => Nfirst,\n+                        Nlast       => Nlast,\n+                        Last        => Nlast,\n+                        GNAT_Static => GNAT_Static,\n+                        GNAT_Shared => GNAT_Shared);\n+                  end if;\n+\n+               elsif Next_Line\n+                       (1 .. Natural'Min (Nlast, 8 + Library_Version'Length)) =\n+                         Shared_Lib (\"gnarl\")\n                  or else\n                    Next_Line\n                      (1 .. Natural'Min (Nlast, 7 + Library_Version'Length)) =\n@@ -1518,7 +1547,7 @@ begin\n    --  back end switches from this ALI file and use these switches to compile\n    --  the binder generated file\n \n-   if Compile_Bind_File and then Standard_Gcc then\n+   if Compile_Bind_File and then Standard_GCC then\n       Initialize_ALI;\n       Name_Len := Ali_File_Name'Length;\n       Name_Buffer (1 .. Name_Len) := Ali_File_Name.all;\n@@ -1621,8 +1650,6 @@ begin\n    --             because bindgen uses brackets encoding for all upper\n    --             half and wide characters in identifier names.\n \n-   --  In addition, in CodePeer mode compile with -x adascil -gnatcC\n-\n    Binder_Options_From_ALI.Increment_Last;\n    Binder_Options_From_ALI.Table (Binder_Options_From_ALI.Last) :=\n         new String'(\"-gnatA\");\n@@ -1633,6 +1660,8 @@ begin\n    Binder_Options_From_ALI.Table (Binder_Options_From_ALI.Last) :=\n         new String'(\"-gnatiw\");\n \n+   --  In addition, in CodePeer mode compile with -x adascil -gnatcC\n+\n    if Opt.CodePeer_Mode then\n       Binder_Options_From_ALI.Increment_Last;\n       Binder_Options_From_ALI.Table (Binder_Options_From_ALI.Last) :=\n@@ -1645,6 +1674,14 @@ begin\n         new String'(\"-gnatcC\");\n    end if;\n \n+   --  Moreover, if -pie is specified, make sure that -fPIE is passed\n+\n+   if Output_PIE then\n+      Binder_Options_From_ALI.Increment_Last;\n+      Binder_Options_From_ALI.Table (Binder_Options_From_ALI.Last) :=\n+        new String'(\"-fPIE\");\n+   end if;\n+\n    --  Locate all the necessary programs and verify required files are present\n \n    Gcc_Path := System.OS_Lib.Locate_Exec_On_Path (Gcc.all);\n","prefixes":["Ada"]}