From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qk1-x72c.google.com (mail-qk1-x72c.google.com [IPv6:2607:f8b0:4864:20::72c]) by sourceware.org (Postfix) with ESMTPS id 83D2C3870866 for ; Thu, 17 Jun 2021 20:25:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 83D2C3870866 Received: by mail-qk1-x72c.google.com with SMTP id d196so5334255qkg.12 for ; Thu, 17 Jun 2021 13:25:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Z/NDIcLZ/IwoRNU3hub8lO3ynoE759okY1jrCNkJ+20=; b=BYsqZ0H6tdlZ5/OZ+iGT2hSOk8gCs9QsIpdTQkswdZynn3PEIiR/aaBI81ntZ/nDo2 L5rBYcjIMUbrdV5IEJ1oxEsV7qnuXkha/b9lUWih5gXiYj4XC4V9DUo6WN9iFLKi3evY h3/rUNeP8VCyo06KbmFwLXFns+XkmIOAF+IcOym1MteC86k3KUuHeAB6/pHz1xF9lY1F lLti547dgbZ9IdL+RihZ93YulMkYh1ZM1rn8DtQwJp00jCXJWZLsIgmiS+RHRDXVhgLF t8WlVNDPNjc/8pvILxvjxQA5V2R4HV5o04MCAiQ3QvWvtgrKXvWf0hwjG/n4gA5Dc0Bx XPUA== X-Gm-Message-State: AOAM531kQKEWBgqhUlFwTUJfB8ayYSt1BmMMDUo+CIBTHZeels2/QIWR 3WAeFPgCwCteKCfnrGDKaRSkhpQJz4C9iwOJYCsYDw== X-Google-Smtp-Source: ABdhPJzhzglAC8OB910wox4h6LGbUzxdDMNfmG+qOSOlpUJH/FzJSEg9T5B9X8g9VBV2m2scUWPk5Cc582VBXxa1OEk= X-Received: by 2002:a25:e741:: with SMTP id e62mr9472019ybh.484.1623961514797; Thu, 17 Jun 2021 13:25:14 -0700 (PDT) MIME-Version: 1.0 References: <20210617193825.zzjyoybttajksw5x@google.com> In-Reply-To: From: =?UTF-8?B?RsSBbmctcnXDrCBTw7JuZw==?= Date: Thu, 17 Jun 2021 13:25:03 -0700 Message-ID: Subject: Re: [llvm-dev] RFC: Add GNU_PROPERTY_UINT32_AND_XXX/GNU_PROPERTY_UINT32_OR_XXX To: "H.J. Lu" Cc: GNU gABI gnu-gabi , GCC Development , Binutils , GNU C Library , llvm-dev@lists.llvm.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-19.1 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_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, USER_IN_DEF_DKIM_WL, USER_IN_DEF_SPF_WL 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: gcc@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Jun 2021 20:25:17 -0000 On Thu, Jun 17, 2021 at 12:46 PM H.J. Lu wrote: > > On Thu, Jun 17, 2021 at 12:38 PM Fangrui Song wrote: > > > > On 2021-06-17, H.J. Lu via llvm-dev wrote: > > >On Thu, Jan 21, 2021 at 7:02 AM H.J. Lu wrote: > > >> > > >> On Wed, Jan 13, 2021 at 9:06 AM H.J. Lu wrote: > > >> > > > >> > 1. GNU_PROPERTY_UINT32_AND_LO..GNU_PROPERTY_UINT32_AND_HI > > >> > > > >> > #define GNU_PROPERTY_UINT32_AND_LO 0xb0000000 > > >> > #define GNU_PROPERTY_UINT32_AND_HI 0xb0007fff > > >> > > > >> > A bit in the output pr_data field is set only if it is set in all > > >> > relocatable input pr_data fields. If all bits in the the output > > >> > pr_data field are zero, this property should be removed from output. > > >> > > > >> > If the bit is 1, all input relocatables have the feature. If the > > >> > bit is 0 or the property is missing, the info is unknown. > > > > How to use AND in practice? > > Are you going to add .note.gnu.property to all of crt1.o crti.o > > crtbegin.o crtend.o crtn.o and miscellaneous libc_nonshared.a object > > files written in assembly? > > > > >> > 2. GNU_PROPERTY_UINT32_OR_LO..GNU_PROPERTY_UINT32_OR_HI > > >> > > > >> > #define GNU_PROPERTY_UINT32_OR_LO 0xb0008000 > > >> > #define GNU_PROPERTY_UINT32_OR_HI 0xb000ffff > > >> > > > >> > A bit in the output pr_data field is set if it is set in any > > >> > relocatable input pr_data fields. If all bits in the the output > > >> > pr_data field are zero, this property should be removed from output. > > >> > > > >> > If the bit is 1, some input relocatables have the feature. If the > > >> > bit is 0 or the property is missing, the info is unknown. > > >> > > > >> > The PDF is at > > >> > > > >> > https://gitlab.com/x86-psABIs/Linux-ABI/-/wikis/uploads/0690db0a3b7e5d8a44e0271a4be54aa7/linux-gABI-and-or-2021-01-13.pdf > > >> > > > >> > -- > > >> > H.J. > > >> > > >> Here is the binutils patch to implement it. > > >> > > > > > >If there are no objections, I will check it in tomorrow. > > > > If the use case is just ELF_RTYPE_CLASS_EXTERN_PROTECTED_DATA, it'd be > > very kind of you if you can collect more use cases before generalizing > > this into a non-arch-specific GNU PROPERTY. > > > > The "copy relocations on protected data symbols" thing is x86 specific > > and only applies with gcc+GNU ld+glibc. > > Non-x86 architectures don't have this thing. > > gold doesn't have this thing. > > clang doesn't have this thing. > > It will be used to remove copy relocation and implement canonical function > pointers, which will benefit protected data and function. The action items in https://gitlab.com/x86-psABIs/x86-64-ABI/-/issues/8#note_593822281 can be applied without a GNU PROPERTY. If we want to enforce the link-time check that a shared object is no longer compatible with copy relocations, just make the shared object's non-weak definitions protected, and add a GNU ld diagnostic like gold (https://sourceware.org/bugzilla/show_bug.cgi?id=19823) --- For functions, On x86-64, gcc -fpic has been using leaq addr()(%rip), %rax since at least 4.1.2 (oldest gcc I can find on godbolt): __attribute__((visibility("protected"))) void *addr() { return (void*)addr; } // a protected non-definition declaration is the same. // while asm(".protected addr") can use GOT, it is super rare if ever exists // outside glibc elf/vis*.c I have checked all of binutils 2.11, 2.16, 2.20, 2.24, 2.35. The have the same diagnostic: relocation R_X86_64_PC32 against protected function `addr' can not be used when making a shared object I think we can assert that taking the address of a protected function never works with GNU ld. So no compatibility concern. Fixing it (https://sourceware.org/pipermail/binutils/2021-June/116985.html) doesn't need any GNU PROPERTY. --- For variables, if an object file/archive member does not have GNU PROPERTY, do you consider it incompatible with "single global definition"? That is why I mentioned crt1.o crti.o crtbegin.o crtend.o crtn.o and libc_nonshared.a members written in assembly. If you consider such an object compatible with "single global definition", I don't see why a GNU PROPERTY is needed. If you consider such an object incompatible with "single global definition", I don't see how "single global definition" benefits can be claimed giving so many prebuilt object files without GNU PROPERTY. If we still want "absolutely no copy relocation for -fno-pic", just use GOT for default visibility external data access (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98112) Some architectures may not like it (i386/ppc32), just leave them behind. Modern architectures can do it. When things get matured, add a ld warning, then add a ld.so warning. When things get more matured, change the warnings to errors. Such changes should use a mechanism similar to glibc LD_DYNAMIC_WEAK (weak can preempt global) and Solaris LD_BREADTH (breadth-first order based dependency order) and LD_NODIRECT (direct bindings). At some point, introduce a behavior change. I don't think how an explicit marker can improve the compatibility story. The conceived compatibility issues likely don't really exist for functions. For copy relocations, I think we may need to wait an extended period of time.