From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pj1-f48.google.com (mail-pj1-f48.google.com [209.85.216.48]) by sourceware.org (Postfix) with ESMTPS id A483D3857027; Sat, 17 Apr 2021 18:25:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org A483D3857027 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=maskray.me Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=emacsray@gmail.com Received: by mail-pj1-f48.google.com with SMTP id e8-20020a17090a7288b029014e51f5a6baso11118428pjg.2; Sat, 17 Apr 2021 11:25:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=AU0+VA36c9/+dgX9UFAEzi24SOOgg+EpQy31OkGHsGU=; b=lUiWAMCK63P3brpz5U57Ceoy0h+VEZ85pUa3PWRwX44aTSDtuOOQuSFlaehZ+VFmCm UsOf2iYYgqi2eWILkZEMnrojZIhevoUD9vTppdS6PhT3pUOTdsktFV4OZ5ixbdh8ycVw mTMuGv1giD4eKaw7V71bjzA8RLe3zXrDDPwVIsq00CfbIpKJz1V92c8VJmMMIEoN9Oqn /SYQoRl9dPEwvOZ9BtzS16xapoGVcfudZX6GVvTpNd4Avh0w7cp3O/HixZ4ksBLK+FyK 7UISO7GEkeEcpAu8iwU6IHFDD0QZxqmIXwTB+KpbU5lxNUKzNilI0OrvFlmCX/pNEhIb qlDw== X-Gm-Message-State: AOAM532OPVZKSY3riziaDouxEZ2yrcCgP8lzgoTH0E/0be5oHLS9PqQQ 54F3HnkKiyrJI/MKJQxdynE= X-Google-Smtp-Source: ABdhPJyKlNpfJYrZmX0LxBmXf3tMOhx4LO28QCdlw+ADx6koBzVdIp/UD1YQcueSHIcipWPQBHwnMA== X-Received: by 2002:a17:902:e2d1:b029:e9:ec4:e0da with SMTP id l17-20020a170902e2d1b02900e90ec4e0damr15409893plc.85.1618683956473; Sat, 17 Apr 2021 11:25:56 -0700 (PDT) Received: from localhost ([2601:647:4b01:ae80:9ba2:d29f:8ae7:123b]) by smtp.gmail.com with ESMTPSA id q22sm7762061pfk.2.2021.04.17.11.25.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 17 Apr 2021 11:25:56 -0700 (PDT) Date: Sat, 17 Apr 2021 11:25:55 -0700 From: Fangrui Song To: "H.J. Lu" Cc: GNU gABI gnu-gabi , GCC Development , Binutils , GNU C Library , llvm-dev@lists.llvm.org Subject: Re: RFC: Add GNU_PROPERTY_UINT32_AND_XXX/GNU_PROPERTY_UINT32_OR_XXX Message-ID: <20210417182555.kmng5g6by7i6a7nk@gmail.com> References: <20210121214242.3ha7fiecfbohxgyd@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, KAM_INFOUSMEBIZ, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=no autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gnu-gabi@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gnu-gabi mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 17 Apr 2021 18:26:08 -0000 On 2021-04-17, H.J. Lu wrote: >On Thu, Jan 21, 2021 at 1:42 PM Fangrui Song wrote: >> >> On 2021-01-21, H.J. Lu via Gnu-gabi 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. >> >> >> >> 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. >> > >> >-- >> >H.J. >> >> Hi, H.J. >> >> Thank you for CCing llvm-dev:) In the past various GNU ABI proposals >> went unnoticed by LLVM folks who don't happen to subscribe to GNU lists. >> (A lot! I personally subscribe to some lists and check the discussion >> just in case I miss something important:) ) >> >> I have researched a bit and observed that the following GNU_PROPERTY >> values are currently used by compilers/linkers: >> >> Bitwise OR for relocatable links. Bitwise AND for executable/shared >> object links. >> >> * GNU_PROPERTY_X86_FEATURE_1_AND = GNU_PROPERTY_X86_UINT32_AND_LO + 0, >> * used by Intel Indirect branch tracking and Shadow Stack >> * GNU_PROPERTY_AARCH64_FEATURE_1_AND, used by AArch64 Branch Target >> * Identification and Pointer Authentication >> >> Bitwise OR for all links. >> >> * GNU_PROPERTY_X86_ISA_1_NEEDED = GNU_PROPERTY_X86_UINT32_OR_LO + 2, >> * used by GCC -mneeded (for -march=x86-64-v[234]) >> >> There appear to be another type of AND/OR bits which are not defined in >> ABIs (AFAICT): >> >> * GNU_PROPERTY_X86_ISA_1_USED = GNU_PROPERTY_X86_UINT32_OR_AND_LO + 2 >> * GNU_PROPERTY_X86_FEATURE_2_USED = GNU_PROPERTY_X86_UINT32_OR_AND_LO + >> * 1 > >I have no use for these operations for generic targets. > >> >> I think generalizing the AND/OR idea to all architectures probably >> requires us to think about these questions: >> >> * What's the impending usage of the generic AND/OR ranges? ifunc? :) > >I'd like to add GNU_PROPERTY_SINGLE_GLOBAL_DEFINITION: > >https://groups.google.com/g/x86-64-abi/c/DRvKxJ1AH3Q > >> * Does the concept generalize well to other architectures? If we > >It should work for GNU_PROPERTY_SINGLE_GLOBAL_DEFINITION. > >> * consider AArch64/x86 FEATURE_1_AND to be the same thing, the current >> * usage is purely x86 specific. >> * Is AND/OR encoding expressive enough to represent the required states? > >For GNU_PROPERTY_SINGLE_GLOBAL_DEFINITION, yes. > >> * I've asked two folks and they expressed concerns. I think the three >> * AND/OR usage above speak for themselves. >> * Szabolcs Nagy mentioned that GNU_PROPERTY is an OS-specific mechanism >> * (GNU), but the features are oftentimes arch specific which make sense >> * to other OSes or bare-metal. >> * Szabolcs: Do we need any versioning mechanism? >> >> The feature selection and compatibility checking mechanism has some >> overlap with GNU/arch-specific attributes (e.g .ARM.attributes, >> .riscv.attributes). If I understand correctly, GNU_PROPERTY has an >> associated program header so it can be checked by loaders >> (kernel/ld.so/emulator) while Attributes don't have program headers so >> they are largely assembler/linker protocols. In an inflexible way that >> such feature bits can affect observable states to loaders as well, e.g. >> .ARM.attributes can affect e_flags (soft/hard float). .MIPS.abiflags >> has an associated program header PT_MIPS_ABIFLAGS (I know nearly nothing >> about mips) Some thoughts from mips folks would be useful. >> >> Last, I think a feature selection and compatibility checking mechanism >> is assuredly useful, but whether the current AND/OR scheme can perfectly >> satisfy that goal I am unsure. Having the proposal is a very good start, >> though:) Thanks a lot for driving the discussion:) > >My current ultimate goal is GNU_PROPERTY_SINGLE_GLOBAL_DEFINITION >with a compiler option, -fsingle-global-definition: > >1. All accesses to protected definitions are local access. >2. In executable, all accesses to defined symbols are local access. For other folks, I think https://maskray.me/blog/2021-01-09-copy-relocations-canonical-plt-entries-and-protected#protected-data-symbols-and-copy-relocations has summarized the current toolchain state and answered these questions. clang always emits local access for protected definitions so there should be no change. gcc does use GOT for protected data symbols but the scheme only works on i386 and x86-64. (arm and aarch64 have glibc support bot no binutils support IIUC). ld.lld always errors for copy relocations on protected data, and it will continue doing so, like gold (https://sourceware.org/bugzilla/show_bug.cgi?id=19823) So on the clang side, there is no needed change. On the GCC side, switching to local access for protected data symbols technically changes the behavior for i386 and x86-64 and might be considered an ABI change. But I'd argue that that does not matter because of three reasons: * clang i386 and x86-64 always emits local access for protected definitions * protected data+copy relocations never work on non-x86. (glibc has support for arm/aarch64 but binutils doesn't support it) * gold never supports protected data+copy relocations, even for x86 (https://sourceware.org/bugzilla/show_bug.cgi?id=19823) So if there is breakage (if any..), it must be x86 specific code using protected definitions, only built with gcc, not caring about traditional behavior (<~2015 or 2016), never supporting non-x86 architectures, only linkable with GNU ld (not gold), never supporting libc other than glibc. OK, I cannot even imagine who is doing this:) My blog post has mentioned what'd be great if gcc does: * GCC: add -f[no-]direct-access-external-data. * GCC: drop HAVE_LD_PIE_COPYRELOC in favor of -f[no-]direct-access-external-data. * GCC x86-64: default to GOT indirection for external data symbols in -fpie mode. * GCC or GNU as i386: emit R_386_PLT32 for branches to undefined function symbols. * GNU ld x86: disallow copy relocations on protected data symbols. (I think canonical PLT entries on protected symbols have been disallowed.) * GCC aarch64/arm/x86/...: allow direct access relocations on protected symbols in -fpic mode. * GNU ld aarch64/x86: allow direct access relocations on protected data symbols in -shared mode. I can understand that some GCC folks may like -f[no-]direct-access-external-data. That doesn't matter: just ignore -f[no-]direct-access-external-data (which gives the user a choice) and do the rest. >3. All global function pointers, whose function bodies aren't >locally defined, must use GOT. This should be the case for -fpie and -fpic. For -fno-pic, some users may want direct access and I think the compiler should give users a choice for compatibility. clang -fno-pic -fdirect-access-external-data (in -fno-pic mode, -fdirect-access-external-data is the default)does this perfectly. I know some GCC folks may not like the idea that the option name does not talk about function pointers.... That is unfortunate. >4. All read/write accesses to symbols, which aren't locally defined >must, use GOT. Ditto. >5. Branches to undefined symbols may use PLT. This has always been the case for most non-x86 architectures. For x86-64, the 2018 R_X86_64_PLT32 switch made this true. There is just a disagreement for R_386_PC32/R_386_PLT32 due to an ifunc diagnostic (which I think is not a big deal). Since i386 is becoming more and more irrelevant, this can be left unresolved. If you want to switch to R_386_PLT32, that'd certainly be great news to me:) >GNU_PROPERTY_SINGLE_GLOBAL_DEFINITION will be enforced >by assembler, linker and ld.so. With the above, I think we won't break code without introducing a new gnu property. It is just that GCC/GNU ld need to take some actions which reflect traditional/non-x86 behaviors.