From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from de-smtp-delivery-102.mimecast.com (de-smtp-delivery-102.mimecast.com [194.104.109.102]) by sourceware.org (Postfix) with ESMTPS id C3AC53858C60 for ; Wed, 13 Oct 2021 06:00:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C3AC53858C60 Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-vi1eur04lp2055.outbound.protection.outlook.com [104.47.14.55]) (Using TLS) by relay.mimecast.com with ESMTP id de-mta-15-jHAW0GYXNEWO6VsNj7GJlw-1; Wed, 13 Oct 2021 08:00:22 +0200 X-MC-Unique: jHAW0GYXNEWO6VsNj7GJlw-1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=n9GvSdBNzI8BVM6HsmLQgiwyJg9XTYkvcPyaNs5tjSlLaxSGlSjwTvG/5oU9aeMa6zEG4uSkB3ySYgpfmvxUkBx46y2jQpjmk/LFfoDSWih+ff9F1/c3JqjNQmg0RTSgAUH2BBxndFRhYjRhpJkCYl/cYsO4RvIiByMQjSdTPjIxHWLVNEJFYyFkLdfSFJnXSw2cJLhrMjzDXcvwY+VI4ZfNXs0xrB3a3EODCGmXvU5M1PxRUiAB4Sk8wVK2kBiC62Twle+rRE8anw1NFLHJ6q+jG26ROzPQeyilWwxCeZGzDS1MI6yRe7KINcpq7hswUDMoCppIlG6N5rNcgtopWA== 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=vXdBZHYUE7vftLtoRD6Q3uvvamJNJ/fWJxYk4VSiT6c=; b=hDR5oBl9xqQE0+KrLkpiHpe/h0Btke/23Y4qZ5qo/oOroSk/SeWPTiWEiD5YeUUZy4QsKwiipEjI8+uavoTIJs94V3oKBqh7r7EzhdDWGbEltdj9oxWAVWRiog/8W8WUEgoLjC/82D1wILJ3KDMZcKaiEbg8earNWs5TiR/eG0syUEedyyUNiU1z7jXXzhGw7RxNUmrjaF7aFzidQvPokz9Q2JhGjBgzSFBot6/ttpR2C8BonPlWV6S3X5MMeW2My/aSlfWNF8CuQSdhKQNmGX8QdRAdhyb5i0B8iQ+UnP8Iif1cKWjcrB+lAZOCkZfIDVBhPGsQ01vJ4EC6EkcWOA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none Received: from AM0PR04MB5587.eurprd04.prod.outlook.com (2603:10a6:208:125::12) by AM4PR0401MB2418.eurprd04.prod.outlook.com (2603:10a6:200:4d::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.25; Wed, 13 Oct 2021 06:00:21 +0000 Received: from AM0PR04MB5587.eurprd04.prod.outlook.com ([fe80::79a1:1c43:93d3:d136]) by AM0PR04MB5587.eurprd04.prod.outlook.com ([fe80::79a1:1c43:93d3:d136%6]) with mapi id 15.20.4587.027; Wed, 13 Oct 2021 06:00:20 +0000 Subject: Re: [PATCH] elf: Support DT_RELR relative relocation format [BZ #27924] To: =?UTF-8?B?RsSBbmctcnXDrCBTw7JuZw==?= CC: libc-alpha@sourceware.org, binutils@sourceware.org, "H.J. Lu" References: <20211008065740.1485737-1-maskray@google.com> <3368ef30-eb8c-8828-1af0-1a227d99dc93@suse.com> From: Jan Beulich Message-ID: Date: Wed, 13 Oct 2021 08:00:19 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: AM5PR04CA0021.eurprd04.prod.outlook.com (2603:10a6:206:1::34) To AM0PR04MB5587.eurprd04.prod.outlook.com (2603:10a6:208:125::12) MIME-Version: 1.0 Received: from [10.156.60.236] (37.24.206.209) by AM5PR04CA0021.eurprd04.prod.outlook.com (2603:10a6:206:1::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.26 via Frontend Transport; Wed, 13 Oct 2021 06:00:20 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8448f63b-b512-4e13-1fac-08d98e0ebd49 X-MS-TrafficTypeDiagnostic: AM4PR0401MB2418: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ja4QiG4teWBcWtVK0Y3oOVGCH8tHNrMkNYYiymWr8Nfq8fiwlY4oyE0ee7MzVdX8kckj0yU0JWoxDuC4ci9SQ5CYMHwh3WmpLd/b35oacnPtGZFjvyLeBxqmvWv5krh90CHeP/3GPWv0cTyEWUR9hj9r3NeyPryEy2/05rPJYy7cZNZKessV5nxOMTH8obcGAYWJzNFt/IZEx13nXbZdDxzWjwfCxXewGm56A/u86HrgvfhbkVfgUpvGlf7w7P8dmnb4Of/x26aTOdw+rX1pi0/RdN54ydkK8E6RunGxJH6CZ9LM/nWU5jWxS/7LfyIllTa/CjKi/JCHLPDd6/bgXdPjJclNTpQiF3faNs2iSYOktIg4kRC95+wD83hYhdtNkJqDbrqFkA1GeNtPl+AVFCVALjwSicHpE5731HV5mUj9HrpEgjUpOsMKP0xA8WvQrrewDtMI7GX1RoaHUF+iRJ1hYvAZE2yronxTvTaNijsHLmv5lDEmcMmXdI+2DpttohkmWwYDWPG964R3uAji5kO8bsr6nctg7BFxE+NBoD6M7drf/+DhHipTVBuPrLwJ+K6wBYjgzNwncQiYqafhQkEZsxA9QB7tnuKfcWA9gZIiWjhl9Wy0w4lvkgn/mfNt/TY6XSTU4BIvbzfso06KgMrAMMizzWmC0H/ZFpcClhf+b+nCJus4Hg22fqOG8ow2Sw4cnWcb2rieMy2jBQgJQUmoCO2xgDLTm6LLBtW0PZQ= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM0PR04MB5587.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(366004)(316002)(31696002)(6916009)(86362001)(83380400001)(66946007)(2906002)(66556008)(6486002)(5660300002)(8936002)(8676002)(38100700002)(16576012)(66476007)(26005)(956004)(508600001)(31686004)(186003)(66574015)(53546011)(4326008)(2616005)(36756003)(43740500002)(45980500001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?VEQaWzoND02Hib64WNOW+YSOPEOjlOwBDJJjfMPuNwRRhaU5TI1MfQLtHLL+?= =?us-ascii?Q?4yqGxbMG9D7wd/Rhyl689xASjc6xB0uQCjw5pzqAvCRgrgl6wcjiK5/OVgcX?= =?us-ascii?Q?QIzy3kiiwHdKMINtX7WvliOyUB5KsKNc5oOmUqNCEaM/6fbZFqDigD7pm8Ci?= =?us-ascii?Q?RSnTagBDQgpH+V+pX/HKaLvadtaG753B8stMKq668PlhTKIQIQcfhdMtPkwC?= =?us-ascii?Q?zJrvb5LtcwawqsRXKbyGBwuMR7TNQzGkk8C5UV6O59tBzzPReI5TocKyqKEH?= =?us-ascii?Q?Gtpe2Rgx2ZUSTxvCzkDpc6bCq3VQ5EeMaW94TcQD657O9PGwaYS+a6CRrcT0?= =?us-ascii?Q?/fOwsWkHS0678rWSL8mghZQMpxeXBqnjnCIonYmQraCojeS2ypwPeGHWBvyu?= =?us-ascii?Q?YQMXrA1IHvWhpO9fc15p4Sj1NUNnDPoqSPF91tow+wI0gfqEvxhbqfPal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ginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8448f63b-b512-4e13-1fac-08d98e0ebd49 X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB5587.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Oct 2021 06:00:20.7887 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f7a17af6-1c5c-4a36-aa8b-f5be247aa4ba X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: n/iVpnIp/fYzIMFJahCCtN8dXDRMds+xD4GsrqWPnLuwqGYxcgLlv82IkR9iqXrJfmHzOjmUf1eKnMCE2n+5hQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM4PR0401MB2418 X-Spam-Status: No, score=-1012.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, MSGID_FROM_MTA_HEADER, NICE_REPLY_A, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 13 Oct 2021 06:00:26 -0000 On 12.10.2021 18:07, F=C4=81ng-ru=C3=AC S=C3=B2ng wrote: > On Tue, Oct 12, 2021 at 7:10 AM H.J. Lu wrote: >> >> On Tue, Oct 12, 2021 at 1:18 AM Jan Beulich via Libc-alpha >> wrote: >>> >>> On 11.10.2021 20:43, F=C4=81ng-ru=C3=AC S=C3=B2ng wrote: >>>> On Mon, Oct 11, 2021 at 12:48 AM Jan Beulich wrote= : >>>>> >>>>> On 08.10.2021 08:57, Fangrui Song via Binutils wrote: >>>>>> --- a/elf/dynamic-link.h >>>>>> +++ b/elf/dynamic-link.h >>>>>> @@ -192,6 +192,33 @@ elf_machine_lazy_rel (struct link_map *map, str= uct r_scope_elem *scope[], >>>>>> # define ELF_DYNAMIC_DO_RELA(map, scope, lazy, skip_ifunc) /* Noth= ing to do. */ >>>>>> # endif >>>>>> >>>>>> +# define ELF_DYNAMIC_DO_RELR(map) = \ >>>>>> + do { = \ >>>>>> + ElfW(Addr) l_addr =3D (map)->l_addr, base =3D 0, start; = \ >>>>>> + const ElfW(Relr) *r =3D 0, *end =3D 0; = \ >>>>>> + if (!(map)->l_info[DT_RELR]) = \ >>>>>> + break; = \ >>>>>> + start =3D D_PTR((map), l_info[DT_RELR]); = \ >>>>>> + r =3D (const ElfW(Relr) *)start; = \ >>>>>> + end =3D (const ElfW(Relr) *)(start + (map)->l_info[DT_RELRSZ]->= d_un.d_val); \ >>>>>> + for (; r < end; ++r) { = \ >>>>>> + ElfW(Relr) entry =3D *r; = \ >>>>>> + if ((entry & 1) =3D=3D 0) { = \ >>>>>> + *((ElfW(Addr) *)(l_addr + entry)) +=3D l_addr; = \ >>>>>> + base =3D entry + sizeof(ElfW(Addr)); = \ >>>>>> + continue; = \ >>>>>> + } = \ >>>>>> + ElfW(Addr) offset =3D base; = \ >>>>>> + do { = \ >>>>>> + entry >>=3D 1; = \ >>>>>> + if ((entry & 1) !=3D 0) = \ >>>>>> + *((ElfW(Addr) *)(l_addr + offset)) +=3D l_addr; = \ >>>>>> + offset +=3D sizeof(ElfW(Addr)); = \ >>>>>> + } while (entry !=3D 0); = \ >>>>>> + base +=3D (8 * sizeof(ElfW(Relr)) - 1) * sizeof(ElfW(Addr)); = \ >>>>> >>>>> While in line with the proposed spec additions I'm afraid the uses of >>>>> ElfW(Addr) here aren't universally correct: You assume that ELF >>>>> container type (size) expresses an aspect of the ABI. While this is >>>>> indeed the case for several arch-es, I think this has been a mistake. >>>>> IA-64, while meanwhile mostly dead, is (was) an example where 64-bit >>>>> code can validly live in a 32-bit ELF container (at least as far as >>>>> the psABI is concerned; I have no idea whether glibc actually >>>>> followed the spec). There's a separate ELF header flag indicating the >>>>> ABI, and hence the size of a pointer. >>>> >>>> Thanks for chiming in. >>>> >>>> As of ia64 buildability, it works for me: >>>> >>>> scripts/build-many-glibcs.py /tmp/glibc-many compilers ia64-linux-gnu >>>> mkdir -p out/ia64; cd out/ia64 >>>> ../../configure --prefix=3D/tmp/glibc/ia64 --host=3Dia64-linux-gnu >>>> CC=3D/tmp/glibc-many/install/compilers/ia64-linux-gnu/bin/ia64-glibc-l= inux-gnu-gcc >>>> CXX=3D/tmp/glibc-many/install/compilers/ia64-linux-gnu/bin/ia64-glibc-= linux-gnu-g++ >>>> make -j 50 >>> >>> I didn't suggest the build would fail. What I said is that I don't >>> think the code is correct there. >>> >>>> As of the actual functionality, ugh, I cannot find ia64 in my Debian >>>> testing's qemu-user-static package:( So I cannot test. >>>> >>>> That said, gold and LLD don't support ia64. >>>> If we have a concern that ia64 may not work, the GNU ld maintainers >>>> can simply not add ia64 support:) >>> >>> But you realize that I took ia64 only as example, as that's where >>> I know ABI (pointer size) and ELF container size aren't connected. >>> As per my looking at merely EF_MIPS_* in context of reading >>> Joseph's reply, it might be that MIPS is another such example. But >>> I lack sufficient knowledge of MIPS ... >>> >> >> The new code should be tested and verified on all supported >> targets. That is another reason to implement this in binutils >> ld first. >=20 > --pack-dyn-relocs=3Drelr is well tested on arm, aarch64, and x86, and > works on popular arches like ppc64 as well. > For mips, it is no harm to keep the DT_RELR code path. Its > elf_machine_rel_relative is empty and it has no relative relocation > anyway. > I wish that our reasonable design decisions are not restricted by the > few retrocomputing architectures, especially when the concern is still > at the theoretical stage. For ia64 it's not theoretical at all, as long as you leave aside the fact the deprecation state of that architecture. I also have to admit that I have trouble seeing why the design can't be adjusted to fit original ELF intentions rather than (as said, imo bad) decisions taken by a few (popular) architectures. Besides adjusting the wording accordingly, all it takes for your implementation is to parameterize word (pointer) size. Jan