From patchwork Fri Aug 30 07:33:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Deepthi.Hemraj@windriver.com X-Patchwork-Id: 1978777 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; 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 [IPv6:2620:52:3:1:0:246e:9693:128c]) (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 4Ww8zm12CVz1ydy for ; Fri, 30 Aug 2024 17:34:28 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id ED6303858435 for ; Fri, 30 Aug 2024 07:34:25 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-0064b401.pphosted.com (mx0b-0064b401.pphosted.com [205.220.178.238]) by sourceware.org (Postfix) with ESMTPS id 4ADCD3858D20 for ; Fri, 30 Aug 2024 07:34:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4ADCD3858D20 Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=windriver.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=windriver.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 4ADCD3858D20 Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=205.220.178.238 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1725003247; cv=pass; b=eiZAILAt6DH6r4nEh1r7sKaGtacp8tXaSJdVRvRaKwydIlKe/8AG1clDweK6VHvFrwqZ5AUAfcS4+HcXY51GAfTEVUjT6ER3WqtGXiK7Oq7lZEUgZthK+sUBmc2CorsKjnwM5tb3fnPGl4Pzo+D21YLyc/ciAP6YRRjuRR71Ru4= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1725003247; c=relaxed/simple; bh=FdYaK9pctRmZd3oR0y+dKMIQN9gUiI/161sviiKy/Lg=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=eiZ0H2rl1XszCqagZYjcuPgADb09kuEA4RqBTQpwaqfuhernHOLC4ND2MbPKpUyPo1rwaC8+mhQZmNQ1axAzES9QSSAk5zMvSCfA/7RPlMG1oeVUzrUKhFro0kIHSMn6qbNL1NCdEBs6KiEOQVL0Q0HJ0TMwRR8KOg63/7EG7sI= ARC-Authentication-Results: i=2; server2.sourceware.org Received: from pps.filterd (m0250811.ppops.net [127.0.0.1]) by mx0a-0064b401.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 47U6WpR4007763; Fri, 30 Aug 2024 07:34:02 GMT Received: from nam11-dm6-obe.outbound.protection.outlook.com (mail-dm6nam11lp2174.outbound.protection.outlook.com [104.47.57.174]) by mx0a-0064b401.pphosted.com (PPS) with ESMTPS id 419pw2k35c-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 30 Aug 2024 07:34:02 +0000 (GMT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ujP1EGyV9NTzoDP5edl+ORuPydjIlb4ljwaf1uCDTOFdbPuClbp09p+o47O+0dN1lW2wWNw/CQUCfyjqV6IdMVIt2JbRmzxAF5c4Naj5+PXgUktS8tgPqXzCpUBwEl5KddusCOmIIEALR+m5A/2h+QczmbJvBFOfSjz2D2xjBc0gMu3kStAlQIfwYGPIIrk06nL42LUjBM8IBkmwvje09gydDeKdr+sOCwa1/rHXXCcGugKgMJPTZRgNFdRlrKd9XeSRJ4RE6sDexm4bWpQRvXTkzwwmewX3amj/atkXdMbyxhJgvTsL0Yga+Zv3+xB1IauxkhHfDdHjgKDmB0gtRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=7+oft+QrJhIiJOQpywe5ZPJIM6qyxU7qysqozDdPt58=; b=oyULYwBZj8zIn4Mt82a+6loO4GXtNjOv6YikEwwj21Bjf8Px5mf+mtSGLwORGiu2SKLo84JBYD6c4IboR/mHqm3OCF+mgNgz16nfhHMrlBImkuD4KsLUpQUF7B5mbyT6qf6lNfNmbtgtAcmr1uZ7J5XEVzmjdHjLKBhbiEQO4nVnVD0A1i09dpJcmn44YR/mLz2R1GDmo+U3ODes7FS6MVpOmlXkwAHMPB7jHqnQJj4gw9OFmbFrYbZla2Bo7AbGESAPc4tO5N0FV20WbhGgL1o55g+wuEJQbFJsmBxUuWUoWsqZyXhIF89ulTrPUDrA/VgJ842Sb3fAf1AysRpXew== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=windriver.com; dmarc=pass action=none header.from=windriver.com; dkim=pass header.d=windriver.com; arc=none Received: from LV3PR11MB8602.namprd11.prod.outlook.com (2603:10b6:408:1b3::11) by LV3PR11MB8693.namprd11.prod.outlook.com (2603:10b6:408:215::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7897.26; Fri, 30 Aug 2024 07:33:59 +0000 Received: from LV3PR11MB8602.namprd11.prod.outlook.com ([fe80::5e20:4508:a523:df39]) by LV3PR11MB8602.namprd11.prod.outlook.com ([fe80::5e20:4508:a523:df39%6]) with mapi id 15.20.7918.019; Fri, 30 Aug 2024 07:33:59 +0000 From: Deepthi.Hemraj@windriver.com To: gcc-patches@gcc.gnu.org Cc: pinskia@gmail.com, rguenther@suse.de, jeffreyalaw@gmail.com, josmyers@redhat.com, Randy.MacLeod@windriver.com, Naveen.Gowda@windriver.com, sunilkumar.dora@windriver.com Subject: [PATCH v2] GCC Driver : Enable very long gcc command-line option Date: Fri, 30 Aug 2024 00:33:41 -0700 Message-ID: <20240830073341.572756-1-Deepthi.Hemraj@windriver.com> X-Mailer: git-send-email 2.43.0 X-ClientProxiedBy: SJ0PR13CA0155.namprd13.prod.outlook.com (2603:10b6:a03:2c7::10) To LV3PR11MB8602.namprd11.prod.outlook.com (2603:10b6:408:1b3::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV3PR11MB8602:EE_|LV3PR11MB8693:EE_ X-MS-Office365-Filtering-Correlation-Id: 7d59ecce-a135-4626-f328-08dcc8c61caa X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|366016|1800799024|376014|52116014|38350700014; X-Microsoft-Antispam-Message-Info: BC8fIBhmvbo0MultYRxp6s6Ox7nbANuvrMa401xsbiG2pnXAq9jaqv5rWwwZzTsAUND28BQ6JT3jaVOWkym4je7SgRMk+7ITEUpqsypzzjpns70KMbIq62+X7BNo8rHtabR2eeq7M9QuaeQUKZ96qKw+X54wAX2KiTcEUtvrqgDSlOzxNsR1nK7Rdz5LCMQywHr31Df4OMBQIRMzXn6/YMhhFE969UgeCC7og3V2tTTBts2vi0qsGVAjHOY9pyhS63vnMvMyf7DyXdzKhXBAhs6CkzkfJndQoZ5afQ97BMgzst8Hvm9SPA6SYnKfbap+dcTsSH2+laKoXNqDC6oBd5RZF6FOhX90rw4bTlkW94MrMO0+mCuD79SeUtDAPE9mk+gueIbs0om8S48yxvzJYm6OuTkPxNO327srw5gvMWNfYvVl5bZQOHbDWd2WMHxGFBYaIEp07be7I3tSl0R6arhehlFxeeY/VKWKinxsi1FFC920JbWanC5WRw3FWlR+mnyclnG4y3xpSp8WOB9IfEgaNcyNC388n0HjMeGZC+x+uLrWaxaBi6eOCZ1UhGnZvn4jxuQgpATvihTLNnQov/vXbAMb85/FDEoh9IxycgqzD8LRSgxQafbL069YVHhQk1vT/ti7nNvKBMkmccWi55cioceRDeb1onS5l2r1Rq1bgSbbhbTF1PTZn0yjJ08EfCBY/TSmMgUoblUC3x+ULTqj5unOVlIUjklkXn5K4FT6c87zWCuifDKGYSRr1lpVui/+4FGKo0OH+y71o3WC/2324UFJnPzmOXzedO0XC1XX1aVDj9+VKxC2cbD14+UPCTdRA9zRNVPY8domR8+4DY9IhCfU5A0pPTtttEwbU/g67PJDkrg+2Z9+bSI4Yj6dnG+pywQY87cTIsWp+5H5O5l+FLp8DkFGAR2c8Cvr6e7VQDsDQbgqDMLEf8g3U7k0YteNIXEvAf+l0xbSZ/ycCdmt/9Zs9awuB3N2HeqnzrPjAssWlDhplgf6VlDQaGoj5PCtjwbcI3yuH7GHxCMRjhQIUFaFLgWJApqq4fqUyb/O6evJCoa/JO27APUeM9eAjjllOPUgR4ab01YWxI/tJUau79FZPgGFbUV4HjCLMftfeqKJTZSYy58ejHGA3qVSy3nuFyXDNT1LVkdRbnSX75Z8OOjk76W9pCrN8qgyjzlTiLXmt8ZFvl4yxkvq9QRDtEb0/PxpKJH0sw/gRnojpaxERnmL8ykQSdGBdVtlHBrehyOd3uQsnkWiEMFqNezyGX2FuiwxO3eWEt/hCtj7D5iwno/LsqTfZL9xjkb74YIHI88eHoUxPwiiGrWjZhG4k7piFOXdkO96tPkyZVyaRkWOMLFQt2Gky22PE6xrJHFbRko25fJjsTKOjJFKmiG3rDgsGkqRQfy2oV+0p6697A== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:LV3PR11MB8602.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(366016)(1800799024)(376014)(52116014)(38350700014); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: xHfW+SsME1Rx75s74qY5YFn7hAiSbAeZqqpakhOruRb17ck/oMmXum4YgIziLvzNlbJOo6iVqXGUNtJZX4Ru4wkHKFyPMNN1SGHWlgQRdPIzhM8+EW1/lzVsO/Xbiv62hZO9wMCKT0WXS4wzJM8YS3/f4+gvwLO9W53E8YF4JG8AsIqOPDjTbx0BXSNE/XgVnGuFCO1rWlKyMPB16SvtJZZQDzRtfUq6mwsbJxUb/yKQqtlGZ9Jp9/SvQE25fDMi4B88bi5r/HnElgLh29n4mbnqS3q4DUhJi8I3vBNnysWLPLj9zbdeCE58zTXQqX4MqRKzbQyJgj9aPf/338fm+8kIbM/zk9JGtNNTJ1b3H4Uf6B+nxrZuW2ge3fk1PXo1PyOHnxWBGz1rHD/JHx0kOaak+gNVJ9vFcTd89KJEmMLHPqi9dpk0Cdn6mA8x3y3evX69wSxoH+a2q+T9uj+WBFX4qfGraLrJpYQAmEn0Q57W0jxTbmINOnmKQ3SbJqi7+4L1wS5Dg3cgnDCk11aa2cAHVqBWAioM9VOCn7g4cUYb/zI8WBpvCpb3Q1WJt4yF1WhAtiRS5GsJY2We/jm450pTj+3ZlxxRPh/LzkWtBcZsvYGteQ5ZCwtReyNKVxraDJ98A5/H0ZGkGHLoYzT6YB2fwGW7fmL55mC2aIdMkfIM+9gN3c9QxdFa2QR43BeF7dmJvdOlkCszXAcOa6kh+NQPRhsbz5X5VwdAyjFAi5XSm2zHTZlDNi/9T/HG8WEfQUTC+LHLH4WlFCuZw3NzXhqSNdHfTaLZQ0REaj6mP1nvXMYg0p9X/t2HJPkfGUmpGaePQvrhl4+Q6s83IOp+O1JTJJ15sTDSdaB0U/N/USmkafNR5RIOpod3Z8y+Jalg+QdfiW6X/mhH7r3em0tUCJ5bzXoZVvaobiOn3BNGmt5cdrxTxqy9vWjVyqjNVEIY0l2gzeM873Nk/fyUs0ej4Y7udVoJBwSShRHf2a6BVqPBvW7a1ORDm7L9gqOt79ilN3OCjhstBIljpNnCZa7o7wyikSv90Hl5yBcXbh5tzm2ZwO6zgXVipgUt0aYF1pN1to5FicURQRowEmOqVDebfsNmi3WpgKLpjk/+al9gi9NLtrmv3hLMCEaKPYz8kPuur2HlkRLjEOqFlchiyB596hKBZsR1lfPqB7syTh352wZnfBlmh+LGJnunzbHssPImeVXu3LKAujhbi90FY0dn/R6EkdQJ0lAYDye5ICKUtse1h2cIPQRKC4O2TVYzhct34XO7nAvHj5JwGHUjgKob5e6znF/OwBat8EyNCIB9L4n7uGaC/UGQTn6HC4XB8JJzb7AXDd1X6ZRQEStSLMrsZaiTGyDRhzb0ooD6XH0u4A/UnH1ye8gf4yBh5r3ZQn7Q+v+3QY51Q0OMqYnTnwFLEnl1c8tWrJYTAjaQcFLxPaQ87bvwdxwq2f4gu6GSxTKoLq/EQzGBVnkjS+ic1B/7k4QTr/i5kexJz+3vkhZ6h2w2yJyNJthbesvZW25Ov65w/y8zBwh9Vuczxyk2QvVPaBJ2CYPkP1E0q+180twHblYBPb8108QANwXzZ6G4/Ipq5kaAGoEaEg9a0VdpnH9saQ== X-OriginatorOrg: windriver.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7d59ecce-a135-4626-f328-08dcc8c61caa X-MS-Exchange-CrossTenant-AuthSource: LV3PR11MB8602.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Aug 2024 07:33:59.1491 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 8ddb2873-a1ad-4a18-ae4e-4644631433be X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Z46oP0HKMEHi6WBw/Tkpinu/ZA6OZKrpvjiD70HI4jA2HxBi3krLmLxju2qNqXGKhUFwIRd/jUJo+6ObpXmNX8SCDoC88l5H4kiAGtxt9p8= X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV3PR11MB8693 X-Proofpoint-ORIG-GUID: 0td-N_vJOIFvMCGeyXFQ1g3R2GgKXAZM X-Authority-Analysis: v=2.4 cv=Kucf2nWN c=1 sm=1 tr=0 ts=66d175ea cx=c_pps a=dIBsZBmI1wyUZqnlzmwqRg==:117 a=Ol13hO9ccFRV9qXi2t6ftBPywas=:19 a=xqWC_Br6kY4A:10 a=yoJbH4e0A30A:10 a=bRTqI5nwn0kA:10 a=t7CeM3EgAAAA:8 a=mDV3o1hIAAAA:8 a=9qxNCY_qAAAA:8 a=5XxngPURnMwgJoPhwwsA:9 a=3ZKOabzyN94A:10 a=FdTzh2GWekK77mhwV6Dw:22 X-Proofpoint-GUID: 0td-N_vJOIFvMCGeyXFQ1g3R2GgKXAZM X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-08-30_03,2024-08-29_02,2024-05-17_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 clxscore=1011 malwarescore=0 phishscore=0 lowpriorityscore=0 priorityscore=1501 bulkscore=0 impostorscore=0 mlxlogscore=999 spamscore=0 adultscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.21.0-2407110000 definitions=main-2408300055 X-Spam-Status: No, score=-13.5 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, 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: Deepthi Hemraj For excessively long environment variables i.e >128KB Store the arguments in a temporary file and collect them back together in collect2. This commit patches for COLLECT_GCC_OPTIONS issue: GCC should not limit the length of command line passed to collect2. https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111527 The Linux kernel has the following limits on shell commands: I. Total number of bytes used to specify arguments must be under 128KB. II. Each environment variable passed to an executable must be under 128 KiB In order to circumvent these limitations, many build tools support response-files, i.e. files that contain the arguments for the executed command. These are typically passed using @ syntax. Gcc uses the COLLECT_GCC_OPTIONS environment variable to transfer the expanded command line to collect2. With many options, this exceeds the limit II. GCC : Added Testcase for PR111527 TC1 : If the command line argument less than 128kb, gcc should use COLLECT_GCC_OPTION to communicate and compile fine. TC2 : If the command line argument in the range of 128kb to 2mb, gcc should copy arguments in a file and use FILE_GCC_OPTIONS to communicate and compile fine. TC3 : If the command line argument greater thean 2mb, gcc shuld fail the compile and report error. (Expected FAIL) Signed-off-by: sunil dora Signed-off-by: Topi Kuutela Signed-off-by: Deepthi Hemraj --- gcc/collect2.cc | 39 ++++++++++++++++++-- gcc/gcc.cc | 37 +++++++++++++++++-- gcc/testsuite/gcc.dg/longcmd/longcmd.exp | 16 +++++++++ gcc/testsuite/gcc.dg/longcmd/pr111527-1.c | 44 +++++++++++++++++++++++ gcc/testsuite/gcc.dg/longcmd/pr111527-2.c | 9 +++++ gcc/testsuite/gcc.dg/longcmd/pr111527-3.c | 10 ++++++ gcc/testsuite/gcc.dg/longcmd/pr111527-4.c | 10 ++++++ 7 files changed, 159 insertions(+), 6 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/longcmd/longcmd.exp create mode 100644 gcc/testsuite/gcc.dg/longcmd/pr111527-1.c create mode 100644 gcc/testsuite/gcc.dg/longcmd/pr111527-2.c create mode 100644 gcc/testsuite/gcc.dg/longcmd/pr111527-3.c create mode 100644 gcc/testsuite/gcc.dg/longcmd/pr111527-4.c diff --git a/gcc/collect2.cc b/gcc/collect2.cc index 902014a9cc1..1f56963b1ce 100644 --- a/gcc/collect2.cc +++ b/gcc/collect2.cc @@ -376,6 +376,39 @@ typedef int scanfilter; static void scan_prog_file (const char *, scanpass, scanfilter); +char* getenv_extended (const char* var_name) +{ + int file_size; + char* buf = NULL; + const char* prefix = "/tmp"; + + char* string = getenv (var_name); + if (strncmp (var_name, prefix, strlen(prefix)) == 0) + { + FILE *fptr; + fptr = fopen (string, "r"); + if (fptr == NULL) + return (0); + /* Copy contents from temporary file to buffer */ + if (fseek (fptr, 0, SEEK_END) == -1) + return (0); + file_size = ftell (fptr); + rewind (fptr); + buf = (char *) xmalloc (file_size + 1); + if (buf == NULL) + return (0); + if (fread ((void *) buf, file_size, 1, fptr) <= 0) + { + free (buf); + fatal_error (input_location, "fread failed"); + return (0); + } + buf[file_size] = '\0'; + return buf; + } + return string; +} + /* Delete tempfiles and exit function. */ @@ -1004,7 +1037,7 @@ main (int argc, char **argv) /* Now pick up any flags we want early from COLLECT_GCC_OPTIONS The LTO options are passed here as are other options that might be unsuitable for ld (e.g. -save-temps). */ - p = getenv ("COLLECT_GCC_OPTIONS"); + p = getenv_extended ("COLLECT_GCC_OPTIONS"); while (p && *p) { const char *q = extract_string (&p); @@ -1200,7 +1233,7 @@ main (int argc, char **argv) AIX support needs to know if -shared has been specified before parsing commandline arguments. */ - p = getenv ("COLLECT_GCC_OPTIONS"); + p = getenv_extended ("COLLECT_GCC_OPTIONS"); while (p && *p) { const char *q = extract_string (&p); @@ -1594,7 +1627,7 @@ main (int argc, char **argv) fprintf (stderr, "o_file = %s\n", (o_file ? o_file : "not found")); - ptr = getenv ("COLLECT_GCC_OPTIONS"); + ptr = getenv_extended ("COLLECT_GCC_OPTIONS"); if (ptr) fprintf (stderr, "COLLECT_GCC_OPTIONS = %s\n", ptr); diff --git a/gcc/gcc.cc b/gcc/gcc.cc index d07a8e172a4..3d7fd8dff5b 100644 --- a/gcc/gcc.cc +++ b/gcc/gcc.cc @@ -2953,12 +2953,43 @@ add_to_obstack (char *path, void *data) return NULL; } -/* Add or change the value of an environment variable, outputting the - change to standard error if in verbose mode. */ +/* Add or change the value of an environment variable, + * outputting the change to standard error if in verbose mode. */ static void xputenv (const char *string) { - env.xput (string); + static const size_t MAX_ENV_VAR_LEN = 128*1024; + const char *prefix = "COLLECT_GCC_OPTIONS="; + size_t prefix_len = strlen (prefix); + FILE *fptr; + + const size_t string_length = strlen (string); + if ( string_length < MAX_ENV_VAR_LEN ) + { + env.xput (string); + return; + } + /* For excessively long environment variables i.e >128KB + Store the arguments in a temporary file and collect + them back together in collect2 */ + if (strncmp (string, prefix, prefix_len) == 0) + { + const char *data_to_write = string + prefix_len; + char *temp_file = make_at_file (); + fptr = fopen (temp_file, "w"); + if (fptr == NULL) + { + fatal_error (input_location, "Cannot open temporary file"); + return; + } + /* Copy contents into temporary file */ + fwrite (data_to_write, sizeof(char), strlen(data_to_write), fptr); + char *env_val = (char *) xmalloc (strlen (temp_file) + 21); + sprintf (env_val, "COLLECT_GCC_OPTIONS=%s", temp_file); + env.xput (env_val); + record_temp_file (temp_file, !save_temps_flag, !save_temps_flag); + fclose (fptr); + } } /* Build a list of search directories from PATHS. diff --git a/gcc/testsuite/gcc.dg/longcmd/longcmd.exp b/gcc/testsuite/gcc.dg/longcmd/longcmd.exp new file mode 100644 index 00000000000..bac8b6d6fff --- /dev/null +++ b/gcc/testsuite/gcc.dg/longcmd/longcmd.exp @@ -0,0 +1,16 @@ +# GCC testsuite that uses the `dg.exp' driver. +# Load support procs. +load_lib gcc-dg.exp + +# If a testcase doesn't have special options, use these. +global DEFAULT_CFLAGS +if ![info exists DEFAULT_CFLAGS] then { + set DEFAULT_CFLAGS "" +} + +dg-init + +dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.\[cS\]]] \ + "" $DEFAULT_CFLAGS + +dg-finish diff --git a/gcc/testsuite/gcc.dg/longcmd/pr111527-1.c b/gcc/testsuite/gcc.dg/longcmd/pr111527-1.c new file mode 100644 index 00000000000..a5373f57790 --- /dev/null +++ b/gcc/testsuite/gcc.dg/longcmd/pr111527-1.c @@ -0,0 +1,44 @@ +/* { dg-do run } */ + +#include +#include +#include +#include + +#define ARGV_LIMIT_SIZE 128 * 1024 +#define SYSTEM_LIMIT_SIZE 2 * 1024 * 1024 +#define STR_TO_WRITE "-DTEST " +void create_large_response_file () +{ + FILE *fp1, *fp2; + char buffer[1024]; + + strcpy (buffer, STR_TO_WRITE); + + fp1 = fopen ("options_128kb_to_2mb.txt", "wb"); + if (fp1 == NULL) + { + abort (); + } + while (ftell (fp1) < (ARGV_LIMIT_SIZE + 10)) + { + fwrite (buffer, strlen (buffer), 1, fp1); + } + fclose (fp1); + + fp2 = fopen ("options_greater_then_2mb.txt", "wb"); + if (fp2 == NULL) + { + abort (); + } + while (ftell (fp2) < (SYSTEM_LIMIT_SIZE +10)) + { + fwrite (buffer, strlen (buffer), 1, fp2); + } + fclose (fp2); +} + +int main() +{ + create_large_response_file (); +} diff --git a/gcc/testsuite/gcc.dg/longcmd/pr111527-2.c b/gcc/testsuite/gcc.dg/longcmd/pr111527-2.c new file mode 100644 index 00000000000..397d70f7b03 --- /dev/null +++ b/gcc/testsuite/gcc.dg/longcmd/pr111527-2.c @@ -0,0 +1,9 @@ +/* { dg-do run } */ + +#include + +int main() +{ + printf("Hello World\n"); +} +/* { dg-final { output-exists { target *-*-* } } } */ diff --git a/gcc/testsuite/gcc.dg/longcmd/pr111527-3.c b/gcc/testsuite/gcc.dg/longcmd/pr111527-3.c new file mode 100644 index 00000000000..394e54b1074 --- /dev/null +++ b/gcc/testsuite/gcc.dg/longcmd/pr111527-3.c @@ -0,0 +1,10 @@ +/* { dg-do run } */ +/* { dg-options "@options_128kb_to_2mb.txt" } */ + +#include + +int main() +{ + printf("Hello world\n"); +} +/* { dg-final { output-exists { target *-*-* } } } */ diff --git a/gcc/testsuite/gcc.dg/longcmd/pr111527-4.c b/gcc/testsuite/gcc.dg/longcmd/pr111527-4.c new file mode 100644 index 00000000000..eaa427f24a4 --- /dev/null +++ b/gcc/testsuite/gcc.dg/longcmd/pr111527-4.c @@ -0,0 +1,10 @@ +/* { dg-do compile } */ +/* { dg-options "@options_greater_then_2mb.txt" } */ +/* { dg-excess-errors "warnings about argument list too long" } */ + +#include + +int main() +{ + /* { xfail *-*-* } */ +}