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.111.102]) by sourceware.org (Postfix) with ESMTPS id 61CF43858D28 for ; Mon, 11 Oct 2021 07:48:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 61CF43858D28 Received: from EUR02-HE1-obe.outbound.protection.outlook.com (mail-he1eur02lp2059.outbound.protection.outlook.com [104.47.5.59]) (Using TLS) by relay.mimecast.com with ESMTP id de-mta-40-oGC0BopKOT2pmQKCdth0Uw-1; Mon, 11 Oct 2021 09:48:04 +0200 X-MC-Unique: oGC0BopKOT2pmQKCdth0Uw-1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Ok9l9Dah6H+8puwiGz3707gY7JHxhC6juwpvm4TXD4lkJRvwatAth3Ly9KEbcd/HQdk5TbaSRMKeNwIGUAf8sGXbBc6dvNWX9vLECZtUGqeX2G69z0Sk4iLtwXgBbS+PwIG99+QXgURvLxH4QUH4QM7rRH/j6rW+ISelzwM/KZenDhLH6Rc2VVYRgEqvkNAiTBfuqQ7Pa6opNX/G3nV5tPMxi36Yb4CvpTG52mN2rHS34eL9Lo6twX55WPmFCrhKCCv94uH3GUr7n9dg2LGp22IDA2ODi6lZUpLiaW+4v7/erlFcIyTs+TL0MTsKBQOkfNOA2kRKxpcedQ3SVCifMg== 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=euSmdZXkco5Tfz4vD3Mm5DXvjHx4/Dx9Rwb5U/dEKZQ=; b=SbeMnbuzLPQg4aGDnGXIgvmijjmJLm0eoDtTMqCu3rqVEtZpsConPOLFoz3Pd1uWd+zxj6VEL+CsZNE9Bhi43J1DUnZ05ByVH+PijqgPY8vo/lGh8EQYK7zp2cuogBRUWfBi3KXiMJ/ex+L3hmQsbj0cbMQAAbHm0OcZV3BSt48ZkXyEeBULykf1LS1UlIdhHy7ntsn7TLNXEZ2kmu9DtHNDk+ZDqtBK21h9cv1Kb0tIb5eKlo06PPipyagTX9e8Z2vnrpHINX/9HNNPO0Ckl7QQV8usgg7GhGmqIG4dnIUFO+Y0clEg5pmlTVbecWFp1j+5ExRDhLCRqVayxHNa2g== 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 VI1PR04MB5600.eurprd04.prod.outlook.com (2603:10a6:803:e7::16) by VI1PR04MB7149.eurprd04.prod.outlook.com (2603:10a6:800:12e::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.18; Mon, 11 Oct 2021 07:48:02 +0000 Received: from VI1PR04MB5600.eurprd04.prod.outlook.com ([fe80::4d37:ec64:4e90:b16b]) by VI1PR04MB5600.eurprd04.prod.outlook.com ([fe80::4d37:ec64:4e90:b16b%7]) with mapi id 15.20.4587.026; Mon, 11 Oct 2021 07:48:02 +0000 Subject: Re: [PATCH] elf: Support DT_RELR relative relocation format [BZ #27924] To: Fangrui Song Cc: binutils@sourceware.org, libc-alpha@sourceware.org References: <20211008065740.1485737-1-maskray@google.com> From: Jan Beulich Message-ID: <3368ef30-eb8c-8828-1af0-1a227d99dc93@suse.com> Date: Mon, 11 Oct 2021 09:48:03 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 In-Reply-To: <20211008065740.1485737-1-maskray@google.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-ClientProxiedBy: AM6PR0202CA0038.eurprd02.prod.outlook.com (2603:10a6:20b:3a::15) To VI1PR04MB5600.eurprd04.prod.outlook.com (2603:10a6:803:e7::16) MIME-Version: 1.0 Received: from [10.156.60.236] (37.24.206.209) by AM6PR0202CA0038.eurprd02.prod.outlook.com (2603:10a6:20b:3a::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.24 via Frontend Transport; Mon, 11 Oct 2021 07:48:01 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ed984619-b34c-4568-f846-08d98c8b73e1 X-MS-TrafficTypeDiagnostic: VI1PR04MB7149: 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: ZP9Km+4hBCE54ZH8X3To9f8Orih9Ivdk/v45B+qf0U5tFUXlLPkL8rKrTaUy6pTkfmVBuh2yg93w6Cq/Di0nBFGu/o4QH9rYcguQ/jqYs7fi/PHByaj3cZrAtmgMiRabSZJ2afutRNvvcjAUlkyTWk3et+cg2nhBZrHgObufKsjcQrIcixc/45Vv9vTDyM/YD0lwDsBEZDwBfZft3W80PzAqgpF1ujcWrpI0miRkqNLk4j2cBKVzZCkroYYIK8hbOAne5b98BZiU6VxQaD3covxoGANMhVctjnLsmzv/FBYubMrkxainXBIaPUE2rt/hMILfsUCcJJ0JAv9iGjoC7+irfSNihXkJT5qU1K5ktOTGQ3d1Czj4BMVlXbR8X90nBFfxcHDF7+VOMdirr7ShpJTl78+3MNJSU4IhAlWWXI8dPaFS87Bk+rC7rwrbeFYreOwuzuGR1ndkBdBELpV7riSV4y2Yf+phTkk+7YoE0sVWLOCkxFU/snfFTAg2mexPfFvQZeNm99UfjPbNzHVHDthUd5+oSgEve9M2eW5RKR4d5j/m6wrO9h+idJ+RlI4ek7rXlNmHOcVKUi2dybRrWuEWpht8vjHcSxfRACN3gi2JfeYk71a5Oz1ZpLRmKJI3u322iZUhsbKDmNb3q6XFWSFRB5/09nvLgExEPsAVxsnjN+e6g0pOQfQIbx2jEj4GcAMqRzqMx3VwhIGj/BXIodCZul6ifIfKsn8auRADgSM= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VI1PR04MB5600.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(366004)(508600001)(36756003)(5660300002)(6486002)(66946007)(316002)(4326008)(66556008)(66476007)(53546011)(186003)(26005)(8936002)(8676002)(31686004)(38100700002)(2906002)(956004)(31696002)(16576012)(2616005)(86362001)(6916009)(43740500002)(45980500001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?RXp3V3hzckRidXl3cVViZXBPL29Bc2phdEtuR2lvNWJOTFZDcG45cUF5OW43?= =?utf-8?B?R1F6eml6cmlWdWRiU1hXRlVQMjIzN0J1Zm9rL0d0cDlOMGhweE4yN1BsRXBk?= =?utf-8?B?bDVZZzVDNkZMeUdROEw3eDN3TEx1b2RuYW1EUlZMT0NaVktBZnBIeUo0YnV6?= =?utf-8?B?bFBmb3U2MkZXRjdEU3dLdzlsSGxoYjMrVmM5NGJEbmpuL0d2WlpTc09mVW9r?= =?utf-8?B?ZFBNcDd3ZnE4TU45L0JQOTZySG1DempUcVNGd2Q4aitYZFZMMWFOSThJWGhR?= =?utf-8?B?RXVNSVBnd2NzVGtuSDlDKys5MStZSzFrUzM4OE1Gb1gwT0pTZ29NbTZNVEJS?= =?utf-8?B?Y1RCb2FSUmY2Ykh0ODkyUHdsSit3dk1ySUxESXgzSG5FU2p5N29vaDNkWS9E?= =?utf-8?B?eE1zVU5OczM2SlZQR2RSbWFONVNmMVlWMjFrZVpLNGpiV1BMV0x5M0xmMFRq?= =?utf-8?B?RXJib1ZJclRIdEZYT3J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?B?NEMzZkx5UDFPVENkUjlCTUE0Z3VpRkIxTXhsSTNXdFc5WHB2OE1TNE1vM0pt?= =?utf-8?B?THBuTzVzZ1RGRElIVjYzSENUSWhIK3AxbUFXZ1Z2Q3MvNCtzWmxwYWZuSjlD?= =?utf-8?B?bmpjK2hWMWFTcUZWTXFPN0VXcytxZ0x3QXNVR3UrM0tURUdzdEl3SVBwM29h?= =?utf-8?B?dkZtMU5kWmQ2dTRQblFQbTljOURpOHgxeUlrVFRTSGREaEpBbUFmZzA2MHRY?= =?utf-8?B?SzN3NDByb2xmdUxldjd3eGltUWFCdzBoQzRobzZIYWVTOXRCZjByVk4rYjNw?= =?utf-8?B?MVo4ZmJCZGxoaS8vbG5Banc3TUl5cGd0eEJFOWMvTWxoYjNrcjU3a2dmejlJ?= =?utf-8?Q?KESBBLRzZFsN7vcWkJoZmMJUfeVAYHDMYEPLYs1?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: ed984619-b34c-4568-f846-08d98c8b73e1 X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5600.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Oct 2021 07:48:02.3506 (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: CW+Qz+Wfk7R7MvwvTVElbshRA3mPrKy0pKDipI0jxf2pP/B8XMkGwJhGhWELxfXM9QKqBLN7e3+SbnIV13GmpA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB7149 X-Spam-Status: No, score=-3032.1 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: Mon, 11 Oct 2021 07:48:09 -0000 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, struct r_scope_elem *scope[], > # define ELF_DYNAMIC_DO_RELA(map, scope, lazy, skip_ifunc) /* Nothing to do. */ > # endif > > +# define ELF_DYNAMIC_DO_RELR(map) \ > + do { \ > + ElfW(Addr) l_addr = (map)->l_addr, base = 0, start; \ > + const ElfW(Relr) *r = 0, *end = 0; \ > + if (!(map)->l_info[DT_RELR]) \ > + break; \ > + start = D_PTR((map), l_info[DT_RELR]); \ > + r = (const ElfW(Relr) *)start; \ > + end = (const ElfW(Relr) *)(start + (map)->l_info[DT_RELRSZ]->d_un.d_val); \ > + for (; r < end; ++r) { \ > + ElfW(Relr) entry = *r; \ > + if ((entry & 1) == 0) { \ > + *((ElfW(Addr) *)(l_addr + entry)) += l_addr; \ > + base = entry + sizeof(ElfW(Addr)); \ > + continue; \ > + } \ > + ElfW(Addr) offset = base; \ > + do { \ > + entry >>= 1; \ > + if ((entry & 1) != 0) \ > + *((ElfW(Addr) *)(l_addr + offset)) += l_addr; \ > + offset += sizeof(ElfW(Addr)); \ > + } while (entry != 0); \ > + base += (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. > --- /dev/null > +++ b/elf/tst-relr.c > @@ -0,0 +1,20 @@ > +static int o, x; > +void *arr[] = { > + &o, &o, &o, &o, &o, &o, &o, &o, &o, &o, &o, &o, &o, &o, &o, &o, > + 0, > + &x, &x, &x, &x, &x, &x, &x, &x, &x, &x, &x, &x, &x, &x, &x, &x, > +}; Personally I consider this overly simplistic a testcase. The two sequences are fully identical, have no gaps except for the one in the middle, and there's also no interleaving / mixing of pointers. None of this should matter as the specific symbol the relocation is for is not supposed to be of interest, but in a testcase you want to make sure none of this has an effect. I also wonder whether it is a good idea to have a testcase with "fundamentally" different behavior on 32-bit vs 64-bit: The former will require two RELR entries afaict, while the latter will get away with one here. Jan > +static int > +do_test (void) > +{ > + for (int i = 0; i < 16; i++) > + if (arr[i] != &o) > + return 1; > + for (int i = 17; i < 33; i++) > + if (arr[i] != &x) > + return 1; > + return 0; > +} > + > +#include >