From patchwork Thu Jun 24 13:49:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 43995 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 32FDC3888C51 for ; Thu, 24 Jun 2021 13:51:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 32FDC3888C51 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1624542696; bh=iNZ2J08RTW6liljTviM+v4P9y2QdNYe/+TASlhLSYTI=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=m3PmqerHIISYzWmUPJ1Ggg7BACpuc6RQJDjfZYzS7jW1lNDdkn8gtqEpmwtE5Mxsh vmwwNLeuUCVBhPvipRWTfqUwUp9sOi0cOvnMqHZc9ZUK0bEtET/psM73wPOH4sfrWV fTh3+0r77Cw8VW2HmEaF90PZi3ubKXGVJdydJAb8= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pf1-x431.google.com (mail-pf1-x431.google.com [IPv6:2607:f8b0:4864:20::431]) by sourceware.org (Postfix) with ESMTPS id 469E83888026 for ; Thu, 24 Jun 2021 13:49:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 469E83888026 Received: by mail-pf1-x431.google.com with SMTP id s14so3946550pfg.0 for ; Thu, 24 Jun 2021 06:49:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=iNZ2J08RTW6liljTviM+v4P9y2QdNYe/+TASlhLSYTI=; b=H2WDQSam8PYWg1vg9Rh1IH5HoJREcL1lJ8/yYi5DhN5PmqbRXNps+lxllSNDlHuuHX z06uZ0ewjNevzKKLN92xvGVlE8w/Kb86lRJ80gpdAOd3h/w5yqXGdMjQllVLA8rGfS7/ Dtde7JDqFNzUncjPgTqst/k4kA1sZ/WJeZAkpTkTv86yVlYgUGVxjidvm3NsUKz8gMZ2 BnkWtHF5SZTCx/2srlTUFi0+QqXHvZZBKFdxh1A/2Unyp1iuoddP36YrM0FMKubLsJUP j5ZOf/BJolTM3pR06NJgGD4pUI5kJGX7n7vJRp/gdB5GhWBu3IfTcGAABD2KXJwGTYgP d2eA== X-Gm-Message-State: AOAM5311lY7HkIbVJLaijpVqam5Rgn9TGy8Gdhn87eD5b6P3uoQO/AP0 f5iryCDcx7IJz2OLQ1BNWBU= X-Google-Smtp-Source: ABdhPJwP7BYi6DMazJ4rtlhvkrPsOz/fogKGFpb1Nh+THbrZ+B8wdvqkNYRm0Qtxjy6Gr0WF9/SwWA== X-Received: by 2002:a65:44c1:: with SMTP id g1mr4903695pgs.76.1624542580423; Thu, 24 Jun 2021 06:49:40 -0700 (PDT) Received: from gnu-cfl-2.localdomain ([172.56.39.115]) by smtp.gmail.com with ESMTPSA id q18sm2546155pgj.8.2021.06.24.06.49.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Jun 2021 06:49:40 -0700 (PDT) Received: from gnu-cfl-2.. (localhost [IPv6:::1]) by gnu-cfl-2.localdomain (Postfix) with ESMTP id D11BCC0337; Thu, 24 Jun 2021 06:49:38 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v2 1/4] Initial support for GNU_PROPERTY_1_NEEDED Date: Thu, 24 Jun 2021 06:49:35 -0700 Message-Id: <20210624134938.2025098-2-hjl.tools@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210624134938.2025098-1-hjl.tools@gmail.com> References: <20210624134938.2025098-1-hjl.tools@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-3032.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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-Patchwork-Original-From: "H.J. Lu via Libc-alpha" From: "H.J. Lu" Reply-To: "H.J. Lu" Cc: Florian Weimer Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" 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. --- 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 2a62b98d4a..dd661a6a64 100644 --- a/elf/elf.h +++ b/elf/elf.h @@ -1310,6 +1310,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 */ 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; + 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 @@ -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; @@ -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; } 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