From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) by sourceware.org (Postfix) with ESMTPS id 68ECD3858D33 for ; Thu, 1 Feb 2024 12:40:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 68ECD3858D33 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=intel.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 68ECD3858D33 Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=198.175.65.16 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1706791212; cv=pass; b=fWlbWQ+fM78P7ogmrM6fh9be8LdzbifxX4WWBd+EtH48DsKw8YkateFV4/i/HK5M4yF3qmK6/WHS4UUm5v4p/NMW7hs3CmjqyX1cY3aI2eLLoF7cq9NpomEBQzgFFUEWvc8kwQwEvhL8CBrZmYnQ2vosyImfgXvFcw1sOan5Szo= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1706791212; c=relaxed/simple; bh=PAW2Tq93sXuZ+bE/8nblKufn1xAOWjpiYw36HnJGdEg=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Kkz9nW1JbEmz4jWTzXz1FfNZBxzeb3GIcG4/AsdAE2orW0jLFEIhFDQagbJdSZgvyzZigKZdCvRGBISynQjNDfveRSWwxGHGD0JQO4nI6gwqnDQ5H5EemM+7z1XllJToIXaFZ4G1RzI9hvk2a8dETwdRQV6+UAwEgkRQNr02SWw= ARC-Authentication-Results: i=2; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1706791209; x=1738327209; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=PAW2Tq93sXuZ+bE/8nblKufn1xAOWjpiYw36HnJGdEg=; b=YX6OdyzwSpT9zkfVWUfiGeZe8W0Krn1XX/EVZx4gsSGn7avvgstm13VD jnOzF9ERXWsA83CpgA2wu39oseOQxBZoUdBeZ2gPsdpxDBk2jqDV4K+uy A3z3iOdFyg3q1MRpdY52dnuD/3XwmOaK5dKpvSZyQh9i09rjSy3rsCjqi HhS+IgnnQVAA2UHzlbwL2eWfqI4icqGEbWlnKGKyf14eF0ZBtPsEHfxUS DYB0QMQ9Jtr8L0mGWqlmEwryRNiVYHC4ZDRXrH5Q6aolBFGx2TSNm1/4U 7CI/ww3D7//x0QmpO28kQyOT0mwZif3DIeYYTcK+ts2dU3iSZkAi3NBnu Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10969"; a="83236" X-IronPort-AV: E=Sophos;i="6.05,234,1701158400"; d="scan'208";a="83236" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Feb 2024 04:40:08 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,234,1701158400"; d="scan'208";a="69154" Received: from orsmsx603.amr.corp.intel.com ([10.22.229.16]) by orviesa008.jf.intel.com with ESMTP/TLS/AES256-GCM-SHA384; 01 Feb 2024 04:40:08 -0800 Received: from orsmsx610.amr.corp.intel.com (10.22.229.23) by ORSMSX603.amr.corp.intel.com (10.22.229.16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Thu, 1 Feb 2024 04:40:06 -0800 Received: from orsedg603.ED.cps.intel.com (10.7.248.4) by orsmsx610.amr.corp.intel.com (10.22.229.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35 via Frontend Transport; Thu, 1 Feb 2024 04:40:06 -0800 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (104.47.55.168) by edgegateway.intel.com (134.134.137.100) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.35; Thu, 1 Feb 2024 04:40:06 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GE+Dt1/m3EvxpJT/ycdu4x6KO2HzkhlgRYbY5dYLPzQQ3M7b+5huWkU5pYXeBA3HKcD5xLYaNjqL//P9P0zZO7ALYwnSLtq06FMAXKRP5DK/jhuptiwGwNsF1M8R/4zNtGfArfEqwRZvnV9vri9/XApHWBwbR05xmYkMjGmkBt3vWlIr3rfdA3Xj0QPa1t52DnCKF95DBCObbS1l9FB2/pUJu0O1pFdut2mzXGCVOye6in5i+27/URv4Msly5TxH/2ryfsj6Avm4R6ydqT0GRbmeLGOruAjtRKSYHahCKYybHoiLq5yRwAJDNLSSvnxMTKAg6HGyNiIf2pweNGDPrg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=RtrP3NcdXdehErlY7SlkT0q7UcKe2jRPf+fHgp+4kpE=; b=h3uLqEiXpSPBx7XjXHrgvG6sJi1S5tXZFqg0Nei5UrlaOrUFY81ePEjy1snNzcjVrH4P2ZKhWGVXBS3ZYF+EAFI2Arzsy4tojrpoubtM2z5rPbDqZtsdSp16uol4h1U086BPz+FY4CoTKmebH6df7J68DmL+y3UpvfDmryHqKAdiCn2MuQp78LVithpVzUOx3jjtRxAOALpiyRX7/dwU2Qz4B95JFvUermW8M61z2e3RjEY4IykEkJXxT/t+6WIJE8yP95u4NWEt0UqQDPsb3DAPb1bePX8KBSQKPE6ZFdVjKOXdYjBJCNFOxGtcN4yv4PoNh4iskGKKg2zN5Do6nA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Received: from IA1PR11MB6466.namprd11.prod.outlook.com (2603:10b6:208:3a6::21) by DS0PR11MB7850.namprd11.prod.outlook.com (2603:10b6:8:fe::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7249.26; Thu, 1 Feb 2024 12:39:58 +0000 Received: from IA1PR11MB6466.namprd11.prod.outlook.com ([fe80::cc66:6d5a:3de2:847e]) by IA1PR11MB6466.namprd11.prod.outlook.com ([fe80::cc66:6d5a:3de2:847e%7]) with mapi id 15.20.7249.024; Thu, 1 Feb 2024 12:39:58 +0000 From: "Wang, Yanzhang" To: Andreas Schwab CC: "libc-alpha@sourceware.org" , "adhemerval.zanella@linaro.org" Subject: RE: [PATCH v3] RISC-V: Enable static-pie. Thread-Topic: [PATCH v3] RISC-V: Enable static-pie. Thread-Index: AQHaPWoju9JbbEn/ckyGHb3x2oB2B7Dw54EugASfnIA= Date: Thu, 1 Feb 2024 12:39:58 +0000 Message-ID: References: <20230810233348.1214955-1-yanzhang.wang@intel.com> <20240102105415.516313-1-yanzhang.wang@intel.com> In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: IA1PR11MB6466:EE_|DS0PR11MB7850:EE_ x-ms-office365-filtering-correlation-id: 9cb4c6a8-213d-4bac-c1d7-08dc2322e6af x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: GYEgf1vNrQFFQxuQbHQ9LBSfPDxswStIM35qd0zxHPk191ZBH977x9GHIyfHNY72VrDbjQP8THSX+2B2sga/2rRBxIplCEzobyqn1AegaalRQZuknH9I9YdZCP9CqxMSGXebNpcu5RVesotXHRqyxTAQvMqQ+9opYXT4KU2wQ9gC47h+ShotVzxwGgF/663Xj4dp99qOGLhM+cK9tyTUqk8UpVmz/TnpmrBNwuRbFl0RPr3E66yRUcAiYn8RA5UZXvwtNdG6ZpJD0QGzOgWpRBdFKihd1gLJ0Cuqdie7Xy9q3kXZSWo4+TksECWes2X7Od5iBWf4fxBIuqbDOa1oZ2mQ0otE1/+zk5xX+8Lwfvn5gI5lLKpgkWhPP/2E3ACELroP+dX+0LdDZyDdg4AV0x2u6ZHeYzrgk0uWR0ptU4ZLkHb9SWeXDeJH9cbdPcoEnFWHnLL65crxpo+t83xatY5FIud7wET1kg+Eu3p0wY9xiqZHuOL9OlT5xzIZKX8EWFB8C88WBuE5Jwy+pTa/W0pMzK2QTBrBg5toPlLWBlFZKNXgiGCaKIyXIOo48cnkSsYMr5bJq91Lw4icoD9QlZK75BhK40UZrpH1ukgwwkoY6Qq0anwIznBzTisaHRK3 x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:IA1PR11MB6466.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(376002)(346002)(39860400002)(366004)(136003)(396003)(230922051799003)(64100799003)(186009)(451199024)(1800799012)(55016003)(41300700001)(83380400001)(86362001)(33656002)(82960400001)(54906003)(38070700009)(122000001)(9686003)(38100700002)(26005)(6506007)(53546011)(7696005)(478600001)(2906002)(66946007)(71200400001)(76116006)(316002)(6916009)(4326008)(66476007)(66556008)(66446008)(64756008)(8676002)(52536014)(8936002)(5660300002);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?tIylRddnQETHv0NCIo6KCXh89qabfLwDtmFqVFgbn7wHcXO0Bf+070zCzz7v?= =?us-ascii?Q?KZdR+VVPFHSfn+bP/5/e13NoYezmgiezda8w/CiyJpwfnxaQdL9YaWZETyOj?= =?us-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BvqZwyRotEmzaRB0EDQA44dB?= =?us-ascii?Q?aC3LFv4etv5wraxbhM3rV6fiSSkiQToECXFS8NT6ucinKBkjm55YHdhsdDtD?= =?us-ascii?Q?ElrZQFp+lY6Xq4Ksi7vA8JPddb8WK4MkGHiGdZRUl0ANc9Qm1yz+1asLfMZV?= =?us-ascii?Q?l6QydfU5F3Mi4MNBRqnPpcf8TEdotdlcxRN0cJquoCqMcSaDHGGNqxOsyZ3b?= =?us-ascii?Q?klBvy2GpPFoiqkUhxHW1TafXgrlS2ZoBginK9wiIz/MH2VEZgv2czwnO+AMw?= =?us-ascii?Q?hCHUEVfuWa/sSzV+BvFhyuXgYl3F5ritMDhLN4eEO14HuOK7lYlanzE7BZAD?= =?us-ascii?Q?+iQKSb41ueFmtJD6MuI3P4FgVmZ2BS2sqQAdqKF0eGh9vkkbxxoSwM8DZGEb?= =?us-ascii?Q?QLIIt3FmNrFfEOBf1t8WpdM4LyrJ5ULyory/G8uNSNwvusSafOGRRreB7jAz?= =?us-ascii?Q?uFeWXlwCCZYpBF4/29QWxTDiYKW6FtSUJzoXllADPe+mmFnlIxFr/pEaQhRu?= =?us-ascii?Q?fNlfRHt9jKZGBfFw7GPQeh5aZ3JK1yu+Q+xckg82GrvFy+Y6G9tTXwCNTBKp?= =?us-ascii?Q?d8jnle/fwyNHgaL/MfITftokXuyxDI2QdLI+YddM?= Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: IA1PR11MB6466.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9cb4c6a8-213d-4bac-c1d7-08dc2322e6af X-MS-Exchange-CrossTenant-originalarrivaltime: 01 Feb 2024 12:39:58.5719 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: jQUz2hJktsKivYGcRD2ASGyFZuXPBhhn8+zG8iKqtJchzOJzIkTtPNEXMAuPWHRj+5Il8nuFhDf6ZE+uSeSA5w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR11MB7850 X-OriginatorOrg: intel.com X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,SPF_HELO_NONE,SPF_NONE,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 List-Id: Hi Andreas, Sorry for the late response. Thanks your comments! And I don't quite follow your comments. Could you please give some further information? > (gdb) ni > _start () at ../sysdeps/riscv/start.S:74 > 74 lla gp, __global_pointer$ > 1: x/i $pc > =3D> 0x3ff7f59ec6 : auipc gp,0xa0 > (gdb) > 0x0000003ff7f59eca 74 lla gp, __global_pointer$ > 1: x/i $pc > =3D> 0x3ff7f59eca <_start+38>: add gp,gp,706 > (gdb) > load_gp () at ../sysdeps/riscv/start.S:76 > 76 ret > 1: x/i $pc > =3D> 0x3ff7f59ece : ret > (gdb) > _start () at ../sysdeps/riscv/start.S:51 > 51 mv a5, a0 /* rtld_fini. */ > 1: x/i $pc > =3D> 0x3ff7f59ea8 <_start+4>: mv a5,a0 > (gdb) > 53 la a0, main > 1: x/i $pc > =3D> 0x3ff7f59eaa <_start+6>: auipc a0,0x9e > (gdb) > 0x0000003ff7f59eae 53 la a0, main > 1: x/i $pc > =3D> 0x3ff7f59eae <_start+10>: ld a0,-74(a0) > (gdb) > 54 REG_L a1, 0(sp) /* argc. */ > 1: x/i $pc > =3D> 0x3ff7f59eb2 <_start+14>: ld a1,0(sp) > (gdb) i reg a0 > a0 0x0 0 The first, it seems you have constructed a test case which should fail this patch. But based on your gdb comment, I'm not sure which step is not correct. Should the a0 register be non-zero or the gp register be wrong?=20 --- The code in the if will try to lookup the __global_pointer$ and move to the gp register. It will be failed because l->l_scope is NULL when static-pie. So I added this checking to avoid this failure. > > + if (l->l_type =3D=3D lt_executable && l->l_scope !=3D NULL) > This is not the right way to test for static PIE, it tries to access a > non-relocated non-zero pointer. The mold linker, when producing relative > relocations, puts the addend both in the relocation addend and the > relocated field, which is perfectly valid to do, so this is non-zero here= . The second, do you mean there's a case that l->l_scope is not NULL when bui= lt with static-pie? Or we should not access the members in link_map ? Thanks, Yanzhang > -----Original Message----- > From: Andreas Schwab > Sent: Monday, January 29, 2024 8:46 PM > To: Wang, Yanzhang > Cc: libc-alpha@sourceware.org; adhemerval.zanella@linaro.org > Subject: Re: [PATCH v3] RISC-V: Enable static-pie. >=20 > On Jan 02 2024, yanzhang.wang@intel.com wrote: >=20 > > diff --git a/sysdeps/riscv/dl-machine.h b/sysdeps/riscv/dl-machine.h > > index ffb8c4aaa0..0cbb476c05 100644 > > --- a/sysdeps/riscv/dl-machine.h > > +++ b/sysdeps/riscv/dl-machine.h > > @@ -348,7 +348,7 @@ elf_machine_runtime_setup (struct link_map *l, > struct r_scope_elem *scope[], > > gotplt[1] =3D (ElfW(Addr)) l; > > } > > > > - if (l->l_type =3D=3D lt_executable) > > + if (l->l_type =3D=3D lt_executable && l->l_scope !=3D NULL) >=20 > This is not the right way to test for static PIE, it tries to access a > non-relocated non-zero pointer. The mold linker, when producing relative > relocations, puts the addend both in the relocation addend and the > relocated field, which is perfectly valid to do, so this is non-zero here= . >=20 > -- > Andreas Schwab, SUSE Labs, schwab@suse.de GPG Key fingerprint =3D 0196 BA= D8 > 1CE9 1970 F4BE 1748 E4D4 88E3 0EEA B9D7 "And now for something > completely different."