From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf1-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) by sourceware.org (Postfix) with ESMTPS id 3916E385222B for ; Thu, 17 Nov 2022 21:20:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3916E385222B Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=google.com Received: by mail-pf1-x42c.google.com with SMTP id q9so3005909pfg.5 for ; Thu, 17 Nov 2022 13:20:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=8/psC6vzW3ez86RzXIF4qTDDkv9tPcBvD7rE23VGUCM=; b=VuwJX4P0OUkEGbEg2DtICmLBqsVqq3wvolVdDrYTazbpSgMyPtOnIqJg4m9rtAph51 5q2MMN7P3OkuaxGvwev87Cm987bRcK7qW33KMAkrS6v6H85yV4OFytDowg1vgHmlx3b2 vEpYSiRtsn4chMUmRQWjxjSEgK7snEM1l11JMBzs+VLXIMzjhzCK+yIqh60RSFlH8gGh g2yeOLl+TBrSVzh5mDoWiccsMRFRtrpPak9o0yHI/EviM9B9/YoN2HvsMIfsy6kJupc5 XF6qBm/y+3AChopH883aJAEc1K+cQWihDkrHsUIOsaBex6U68S2IwaU6+jGhYEIRJvr4 oCpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=8/psC6vzW3ez86RzXIF4qTDDkv9tPcBvD7rE23VGUCM=; b=OhiGrc/n1h6oVPD3mMBkfbaswg4PdBcyHzkjqMZCYAsO94JbN/FDszvO+hMd7Hpcmq q5kyHhGUPYWhX/k7rLRxiuaV/8veCkOPGNWZmyA8gF73K9kMsOQd/9piCceP63EeVcWu eAO3blehz3xhBv3mQkivQD/hHcdK/2YTbS7SegQtGQgiDaTrdhDfKIKsRjUmhf0PBq1j ITsw0dqFmh+OU9XPzxVifpcSIUreW+iNdJ0576Jw49IaHIgxlphAy6JlATMjmgZRwAL3 lL/V+9jxLLK6Ivw+JRzR6vhFL0gUpVJ4JOyDpi46uSC54NLz538U13bmxft8/qOcIQNO 92kg== X-Gm-Message-State: ANoB5pkN58cU5S5G6BmVTsTDPMl+zKKZyjAiFUoNE3z7egrLt1HKaqnl iKzQwXDxDxfYCjyhxQfK1X6+HQ== X-Google-Smtp-Source: AA0mqf5XqzM5TTuqW5k5PtIbZEkNWU4y+jliw3PhuTxHoX7478EH/fqQqY3tWBd2mB3wrXv1OfafxQ== X-Received: by 2002:a63:db0d:0:b0:44c:2e6b:4a4 with SMTP id e13-20020a63db0d000000b0044c2e6b04a4mr3777128pgg.47.1668720009021; Thu, 17 Nov 2022 13:20:09 -0800 (PST) Received: from google.com (25.11.145.34.bc.googleusercontent.com. [34.145.11.25]) by smtp.gmail.com with ESMTPSA id x15-20020a63fe4f000000b00434272fe870sm1465341pgj.88.2022.11.17.13.20.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Nov 2022 13:20:08 -0800 (PST) Date: Thu, 17 Nov 2022 21:20:06 +0000 From: "maskray@google.com" To: Wilco Dijkstra Cc: Richard Sandiford , Ramana Radhakrishnan , GCC Patches , Kyrylo Tkachov Subject: Re: [PATCH] AArch64: Add support for -mdirect-extern-access Message-ID: <20221117212006.dspm45znjyqj6ktf@google.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-19.5 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.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: > +.. option:: -mdirect-extern-access, -mno-direct-extern-access > + > + Use direct accesses for external data symbols. It avoids a GOT indirection > + on all external data symbols with :option:`-fpie` or :option:`-fPIE`. This is > + useful for executables linked with :option:`-static` or :option:`-static-pie`. > + With :option:`-fpic` or :option:`-fPIC`, it only affects accesses to protected > + data symbols. It has no effect on non-position independent code. The default > + is :option:`-mno-direct-extern-access`. > + > + .. warning:: > + > + Use :option:`-mdirect-extern-access` either in shared libraries or in > + executables, but not in both. Protected symbols used both in a shared > + library and executable may cause linker errors or fail to work correctly. I think current GCC and Clang's behavior is: * -mdirect-extern-access is the default for -fno-pic. This is to enable optimizations for -static programs but may introduce copy relocations. * -mno-direct-extern-access is the default for -fpie and -fpic. This uses some GOT-generating relocations which can be optimized out (lld, see https://maskray.me/blog/2021-08-29-all-about-global-offset-table) but the instruction is nevertheless slightly longer. (-mdirect-extern-access for -fpic probably doesn't make sense.) The option I introduced to Clang is -fdirect-access-external-data (see https://maskray.me/blog/2021-01-09-copy-relocations-canonical-plt-entries-and-protected). If -mdirect-extern-access gets more popular, I can add a Clang alias. But I am opposed to forcing a GNU property for -mdirect-extern-access/-mno-direct-extern-access. FWIW I used https://gist.github.com/MaskRay/c03a90922003df666551589f1629df22 to test my Clang changes related to -fno-semantic-interposition on various visibility attributes x non-weak/weak x nopic/pie/pic x dllimport/not x ... On 2022-11-17, Ramana Radhakrishnan wrote: >On Thu, Nov 17, 2022 at 5:30 PM Richard Sandiford via Gcc-patches > wrote: >> >> Wilco Dijkstra writes: >> > Hi Richard, >> > >> >> Can you go into more detail about: >> >> >> >> Use :option:`-mdirect-extern-access` either in shared libraries or in >> >> executables, but not in both. Protected symbols used both in a shared >> >> library and executable may cause linker errors or fail to work correctly >> >> >> >> If this is LLVM's default for PIC (and by assumption shared libraries), >> >> is it then invalid to use -mdirect-extern-access for any PIEs that >> >> are linked against those shared libraries and use protected symbols >> >> from those libraries? How would a user know that one of the shared >> >> libraries they're linking against was built in this way? >> > >> > Yes, the usage model is that you'd either use it for static PIE or only on >> > data that is not shared. If you get it wrong them you'll get the copy >> > relocation error. >> >> Thanks. I think I'm still missing something though. If, for the >> non-executable case, people should only use the feature on data that >> is not shared, why do we need to relax the binds-local condition for >> protected symbols on -fPIC? Oughtn't the symbol to be hidden rather >> than protected if the data isn't shared? >> >> I can understand the reasoning for the PIE changes but I'm still >> struggling with the PIC-but-not-PIE bits. > >I think I'm with Richard S on hidden vs protected on first reading. I >can see why this works out of the box and can even be default for >static-pie. > >Any reason why this is not on by default - it's early enough in the >stage3 cycle and we can always flip the defaults if there are more >problems found. > >You probably need a rebase for the documentation bits,. > >regards >Ramana > > >Ramana + is :option:`-mno-direct-extern-access`.