From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-yb1-xb34.google.com (mail-yb1-xb34.google.com [IPv6:2607:f8b0:4864:20::b34]) by sourceware.org (Postfix) with ESMTPS id 0D1E13858C27 for ; Wed, 13 Oct 2021 06:14:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0D1E13858C27 Received: by mail-yb1-xb34.google.com with SMTP id q189so3796886ybq.1 for ; Tue, 12 Oct 2021 23:14:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=aEE6+H25t87tXo680xqpuKdTpNt7Cdk4eaApTv/aZJI=; b=C2CHd9dJoBEw3FX47EzGjPG0AzqAZ4puo67vF1EZRDDnqrZT33MChZKNJAa1Kt3kpq kgLoM5OgAc4T17IJ6kxa5XrRIredJY/bChKg7zVyMo1KrhAUYyt2O0A20GStGdnN4RbE Cyjeu9BzBqW/B9PMIVRVc4vz4mSOKKq5Qqbjj8+lor/WY1VRgkMtZsKxLIk5F4QNlzfu k7o0O7YkTDY7ngrhzTJ7nYe/B+5LCRL43EIRdlr3MmaHO4Tgd9R3wxw4nBsQY0tNLsl5 VJozb9s/diZ02Y4+LUFLinC6kzr1DoVByeC5PtRnvhjLKiBsNGezFfNUT2TDM5Gp7k9l PIBA== X-Gm-Message-State: AOAM533yztfXBBC2lDCmScm1TAQ29fk2gUGogNiFzH3RVdOPumyw2zWu YpugTtwS96h2+siQ9R/gFvqa9el2PRRTBzrpxnivwdsh7YuyIA== X-Google-Smtp-Source: ABdhPJz0sfuoG0JvBeVhZVvWVGFvV/Lro1mtjh75EYPySuUjl3iz0g/PkK6lMYR1C3aGiLuVXkK9xPAVP/H6BV4VGkw= X-Received: by 2002:a25:abd1:: with SMTP id v75mr30990259ybi.492.1634105646395; Tue, 12 Oct 2021 23:14:06 -0700 (PDT) MIME-Version: 1.0 References: <20211008065740.1485737-1-maskray@google.com> <3368ef30-eb8c-8828-1af0-1a227d99dc93@suse.com> In-Reply-To: From: =?UTF-8?B?RsSBbmctcnXDrCBTw7JuZw==?= Date: Tue, 12 Oct 2021 23:13:55 -0700 Message-ID: Subject: Re: [PATCH] elf: Support DT_RELR relative relocation format [BZ #27924] To: Jan Beulich Cc: libc-alpha@sourceware.org, binutils@sourceware.org, "H.J. Lu" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-17.8 required=5.0 tests=BAYES_00, DKIMWL_WL_MED, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH, KAM_INFOUSMEBIZ, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, USER_IN_DEF_DKIM_WL, USER_IN_DEF_SPF_WL autolearn=no 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:14:08 -0000 On Tue, Oct 12, 2021 at 11:00 PM Jan Beulich wrote: > > 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 wro= te: > >>>>> > >>>>> 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, s= truct r_scope_elem *scope[], > >>>>>> # define ELF_DYNAMIC_DO_RELA(map, scope, lazy, skip_ifunc) /* No= thing 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 mistak= e. > >>>>> IA-64, while meanwhile mostly dead, is (was) an example where 64-bi= t > >>>>> 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 t= he > >>>>> 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-gn= u > >>>> 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= -linux-gnu-gcc > >>>> CXX=3D/tmp/glibc-many/install/compilers/ia64-linux-gnu/bin/ia64-glib= c-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. > > > > --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 > I re-read your first reply. Did you mean 64-bit small code model code in an ELFCLASS32 ET_EXEC/ET_DYN file? OK. I considered it as a size optimization for a different task. "AArch64 and x86-64 define ILP32 ABIs and use ELFCLASS32, but technically they can use ELFCLASS32 for small code model with regular ABIs, if the kernel allows." (from https://maskray.me/blog/2021-01-31-metadata-sections-comdat-and-shf-link-or= der) I assume that switching *((ElfW(Addr) *)(l_addr + entry)) +=3D l_addr; to `unsigned long` makes this use case work, though I doubt glibc's ia64 implementation supports this as sysdeps/ia64/dl-machine.h uses Elf64.