From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS3215 2.6.0.0/16 X-Spam-Status: No, score=-4.2 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI,SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from 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 RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 389BB1F8C8 for ; Thu, 7 Oct 2021 15:12:38 +0000 (UTC) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 889733858013 for ; Thu, 7 Oct 2021 15:12:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 889733858013 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1633619556; bh=o36YCNHRLl596jv3Mlwjaa0mSGNrN6rQwTvPYv1JZmQ=; h=References:In-Reply-To:Date:Subject:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=RGuajqHVO00O3c+IUE94A/yxIdICSEAC7Z6H6/QmD3qVrAKcx5R5NSYJpJNxUbMur fn54eG8pOxgiWUQuJIJ/8kpT403RKvi+B4cahP0tEoW/f82vXglKlW3d8BMaXBzuYK bV1PNy8FXlrli1MZgz4RWcDPyFzP/M4JIQowg1wM= Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by sourceware.org (Postfix) with ESMTPS id 2BF953858C60 for ; Thu, 7 Oct 2021 15:12:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2BF953858C60 Received: by mail-pj1-x1036.google.com with SMTP id ls14-20020a17090b350e00b001a00e2251c8so5315885pjb.4 for ; Thu, 07 Oct 2021 08:12:17 -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; bh=o36YCNHRLl596jv3Mlwjaa0mSGNrN6rQwTvPYv1JZmQ=; b=pwTWGxjGWbUZqpBByRbrXY+3UOJbR5kQNVfGT/CXsOle4PvLs4q8tDHc49O5ZnqCck XM3nOe33C0HErsObQOi2xL7qUU1UzDUbQqsSwdKusQRD3RArwVuU0w72u6w/hjhhbQzc cUZN6pO2VDRoh/n73OcxjqlCv2RXzdpfB0rWYS2gh6gTgOEO+F+HGpQHx51TO03s16h9 ojDeh/g1MR1EOk6K+ho4dnPsJmCn8v+AvBtv5gzWQuw0oEMUJD/YoAbgBvNIxd1kUBvU +mJUgvKa6GdjIH8OLOftJX47VKdzHLovv3UDOsh7kSr4CVLES3evQY2Rce2q4vd70ywK /ijA== X-Gm-Message-State: AOAM530/Ok4hUBfyqSUJPIUIxA6/lAD+G81r6wEH+P7FrtRvOqowpspV aORJi6M3vgmUDOW85mg/2xhHXC+uClwhUvBV9w3wnWAyicM= X-Google-Smtp-Source: ABdhPJyWQTyFOzx5FL3GPbef1kgnWxJAMltpnzDMHvXr83cgrMyPOZy8OCGlwa6+5n312xNpzb3mb6S7mqRMo9aEt0Q= X-Received: by 2002:a17:90a:9292:: with SMTP id n18mr5984999pjo.120.1633619536072; Thu, 07 Oct 2021 08:12:16 -0700 (PDT) MIME-Version: 1.0 References: <20210803215914.4170913-1-hjl.tools@gmail.com> In-Reply-To: Date: Thu, 7 Oct 2021 08:11:40 -0700 Message-ID: Subject: Re: [PATCH 1/2] Initial support for GNU_PROPERTY_1_NEEDED To: Adhemerval Zanella Content-Type: text/plain; charset="UTF-8" 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: , From: "H.J. Lu via Libc-alpha" Reply-To: "H.J. Lu" Cc: GNU C Library Errors-To: libc-alpha-bounces+e=80x24.org@sourceware.org Sender: "Libc-alpha" On Thu, Oct 7, 2021 at 7:53 AM Adhemerval Zanella wrote: > > > > On 03/08/2021 18:59, H.J. Lu via Libc-alpha wrote: > > 1. Add GNU_PROPERTY_1_NEEDED: > > > > #define GNU_PROPERTY_1_NEEDED GNU_PROPERTY_UINT32_OR_LO > > > > to indicate the needed properties by the object file. > > 2. Add GNU_PROPERTY_1_NEEDED_INDIRECT_EXTERN_ACCESS: > > > > #define GNU_PROPERTY_1_NEEDED_INDIRECT_EXTERN_ACCESS (1U << 0) > > > > to indicate that the object file requires canonical function pointers and > > cannot be used with copy relocation. > > 3. Scan GNU_PROPERTY_1_NEEDED property and store it in l_1_needed. > > It was added by binutils with commit 6320fd00dc374f74658, maybe add on > the commit the version expected to have this support. > > LGTM, with a small suggestion below. > > Reviewed-by: Adhemerval Zanella > > > --- > > elf/elf.h | 17 +++++++++++++++++ > > sysdeps/generic/dl-prop.h | 9 ++++++++- > > sysdeps/generic/link_map.h | 3 ++- > > sysdeps/x86/dl-prop.h | 19 ++++++++++++++----- > > sysdeps/x86/link_map.h | 2 ++ > > 5 files changed, 43 insertions(+), 7 deletions(-) > > > > diff --git a/elf/elf.h b/elf/elf.h > > index 4738dfa28f..50f87baceb 100644 > > --- a/elf/elf.h > > +++ b/elf/elf.h > > @@ -1312,6 +1312,23 @@ typedef struct > > /* No copy relocation on protected data symbol. */ > > #define GNU_PROPERTY_NO_COPY_ON_PROTECTED 2 > > > > +/* A 4-byte unsigned integer property: A bit is set if it is set in all > > + relocatable inputs. */ > > +#define GNU_PROPERTY_UINT32_AND_LO 0xb0000000 > > +#define GNU_PROPERTY_UINT32_AND_HI 0xb0007fff > > + > > +/* A 4-byte unsigned integer property: A bit is set if it is set in any > > + relocatable inputs. */ > > +#define GNU_PROPERTY_UINT32_OR_LO 0xb0008000 > > +#define GNU_PROPERTY_UINT32_OR_HI 0xb000ffff > > + > > +/* The needed properties by the object file. */ > > +#define GNU_PROPERTY_1_NEEDED GNU_PROPERTY_UINT32_OR_LO > > + > > +/* Set if the object file requires canonical function pointers and > > + cannot be used with copy relocation. */ > > +#define GNU_PROPERTY_1_NEEDED_INDIRECT_EXTERN_ACCESS (1U << 0) > > + > > /* Processor-specific semantics, lo */ > > #define GNU_PROPERTY_LOPROC 0xc0000000 > > /* Processor-specific semantics, hi */ > > Ok. > > > diff --git a/sysdeps/generic/dl-prop.h b/sysdeps/generic/dl-prop.h > > index eaee8052b6..207aadb35d 100644 > > --- a/sysdeps/generic/dl-prop.h > > +++ b/sysdeps/generic/dl-prop.h > > @@ -47,7 +47,14 @@ static inline int __attribute__ ((always_inline)) > > _dl_process_gnu_property (struct link_map *l, int fd, uint32_t type, > > uint32_t datasz, void *data) > > { > > - return 0; > > + /* Continue until GNU_PROPERTY_1_NEEDED is found. */ > > + if (type == GNU_PROPERTY_1_NEEDED) > > + { > > + if (datasz == 4) > > + l->l_1_needed = *(unsigned int *) data; > > Although the pointer seems to be aligned, I think it would be better to > use memcpy here: > > unsigned int t; > memcpy (&t, data, sizeof (t)); > l->l_1_needed = t; > > (the x86 header might use a more relax since the architecture always > support unaligned access) The GNU property is guaranteed to be properly aligned: void _dl_process_pt_gnu_property (struct link_map *l, int fd, const ElfW(Phdr) *ph) { const ElfW(Nhdr) *note = (const void *) (ph->p_vaddr + l->l_addr); const ElfW(Addr) size = ph->p_memsz; const ElfW(Addr) align = ph->p_align; /* The NT_GNU_PROPERTY_TYPE_0 note must be aligned to 4 bytes in 32-bit objects and to 8 bytes in 64-bit objects. Skip notes with incorrect alignment. */ if (align != (__ELF_NATIVE_CLASS / 8)) return; data passed to _dl_process_gnu_property should be properly aligned. > > + return 0; > > + } > > + return 1; > > } > > > > #endif /* _DL_PROP_H */ > > diff --git a/sysdeps/generic/link_map.h b/sysdeps/generic/link_map.h > > index a056184690..9f482b8c20 100644 > > --- a/sysdeps/generic/link_map.h > > +++ b/sysdeps/generic/link_map.h > > @@ -1 +1,2 @@ > > -/* No architecture specific definitions. */ > > +/* GNU_PROPERTY_1_NEEDED of this object. */ > > +unsigned int l_1_needed; > > diff --git a/sysdeps/x86/dl-prop.h b/sysdeps/x86/dl-prop.h > > index 56bd020b3c..385548fad3 100644 > > --- a/sysdeps/x86/dl-prop.h > > +++ b/sysdeps/x86/dl-prop.h > > @@ -97,6 +97,7 @@ _dl_process_property_note (struct link_map *l, const ElfW(Nhdr) *note, > > > > const ElfW(Addr) start = (ElfW(Addr)) note; > > > > + unsigned int needed_1 = 0; > > unsigned int feature_1_and = 0; > > unsigned int isa_1_needed = 0; > > unsigned int last_type = 0; > > @@ -141,7 +142,8 @@ _dl_process_property_note (struct link_map *l, const ElfW(Nhdr) *note, > > last_type = type; > > > > if (type == GNU_PROPERTY_X86_FEATURE_1_AND > > - || type == GNU_PROPERTY_X86_ISA_1_NEEDED) > > + || type == GNU_PROPERTY_X86_ISA_1_NEEDED > > + || type == GNU_PROPERTY_1_NEEDED) > > { > > /* The sizes of types which we are searching for are > > 4 bytes. There is no point to continue if this > > Ok. > > > @@ -151,12 +153,18 @@ _dl_process_property_note (struct link_map *l, const ElfW(Nhdr) *note, > > > > /* NB: Stop the scan only after seeing all types which > > we are searching for. */ > > - _Static_assert ((GNU_PROPERTY_X86_ISA_1_NEEDED > > > - GNU_PROPERTY_X86_FEATURE_1_AND), > > + _Static_assert (((GNU_PROPERTY_X86_ISA_1_NEEDED > > + > GNU_PROPERTY_X86_FEATURE_1_AND) > > + && (GNU_PROPERTY_X86_FEATURE_1_AND > > + > GNU_PROPERTY_1_NEEDED)), > > "GNU_PROPERTY_X86_ISA_1_NEEDED > " > > - "GNU_PROPERTY_X86_FEATURE_1_AND"); > > + "GNU_PROPERTY_X86_FEATURE_1_AND && " > > + "GNU_PROPERTY_X86_FEATURE_1_AND > " > > + "GNU_PROPERTY_1_NEEDED"); > > if (type == GNU_PROPERTY_X86_FEATURE_1_AND) > > feature_1_and = *(unsigned int *) ptr; > > + else if (type == GNU_PROPERTY_1_NEEDED) > > + needed_1 = *(unsigned int *) ptr; > > else > > { > > isa_1_needed = *(unsigned int *) ptr; > > Ok. > > > @@ -187,9 +195,10 @@ _dl_process_property_note (struct link_map *l, const ElfW(Nhdr) *note, > > } > > > > /* We get here only if there is one or no GNU property note. */ > > - if (isa_1_needed != 0 || feature_1_and != 0) > > + if (needed_1 != 0 || isa_1_needed != 0 || feature_1_and != 0) > > { > > l->l_property = lc_property_valid; > > + l->l_1_needed = needed_1; > > l->l_x86_isa_1_needed = isa_1_needed; > > l->l_x86_feature_1_and = feature_1_and; > > } > > Ok. > > > diff --git a/sysdeps/x86/link_map.h b/sysdeps/x86/link_map.h > > index 4c46a25f83..0c7e25dc96 100644 > > --- a/sysdeps/x86/link_map.h > > +++ b/sysdeps/x86/link_map.h > > @@ -29,3 +29,5 @@ unsigned int l_x86_feature_1_and; > > > > /* GNU_PROPERTY_X86_ISA_1_NEEDED of this object. */ > > unsigned int l_x86_isa_1_needed; > > + > > +#include > > > > Ok. -- H.J.