From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf1-x435.google.com (mail-pf1-x435.google.com [IPv6:2607:f8b0:4864:20::435]) by sourceware.org (Postfix) with ESMTPS id F23513846056 for ; Thu, 26 May 2022 21:27:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org F23513846056 Received: by mail-pf1-x435.google.com with SMTP id j6so2692103pfe.13 for ; Thu, 26 May 2022 14:27:58 -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=NzUYQt9nIkhIAIzXlXmkZxzAVQRTllzrhfNRG7ygTXU=; b=u615kS+8dLJZ9XidCGZ+UGLqyFMllo1ndXfzb7QZiz7hBFzddJikNTTKO67hhSfV7c R6gQY8iGn9DYV/LZlXvjnPOO9zAbDB5HDZ2ySbZR0K2l4Pxf9QSoJ/Z3BSMk5yvv9hhY 1Usj2biXS4f0np9RnItgZgtR/NSqsV5rF2/I9f+aQonJVqHt2369sFr6kURNBomSnt8c HEKaVUdwQXbt4+4hVpzYhscPYHj66CJ1MPGlIvjcx7K+5phGP1FeFqvqcFDah2v84b89 PsULJC2lvfYEtitz3un3zMUJ7zdkYZCw1DboURWQRHuUymFyWZZ+glgNfEn+AKn7yrdw N1TA== X-Gm-Message-State: AOAM531d/CFPzfAzz+VLB8/nGM/2b27ODKEH5qDO9pej10YtJEdVmUNA zJkEyFD1uzVEuZkS7stzIw8OZH9JuzsYQzcskiE= X-Google-Smtp-Source: ABdhPJyNenF/H211sNZ4A3EwELzi0XROmw2YPNd5np7aD9YF1EaqCrfvUijSmziwgqLZ/IezRq3dlre9hG8zmSFRrAU= X-Received: by 2002:a05:6a00:2d0:b0:518:95f8:d00a with SMTP id b16-20020a056a0002d000b0051895f8d00amr24122789pft.8.1653600477939; Thu, 26 May 2022 14:27:57 -0700 (PDT) MIME-Version: 1.0 References: <87mtf5wk0k.fsf@oldenburg.str.redhat.com> <8735gwhz9i.fsf@oldenburg.str.redhat.com> In-Reply-To: From: "H.J. Lu" Date: Thu, 26 May 2022 14:27:22 -0700 Message-ID: Subject: Re: [PATCH 2/3] Revert "[AArch64][BZ #17711] Fix extern protected data handling" To: Wilco Dijkstra Cc: Florian Weimer , Wilco Dijkstra via Libc-alpha , Szabolcs Nagy Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-3019.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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-List-Received-Date: Thu, 26 May 2022 21:28:00 -0000 On Thu, May 26, 2022 at 1:03 PM Wilco Dijkstra wrote: > > Hi Florian, > > Sure, something basic like this shows the issues: > > int x; > int f(void) { return ++x; } > int main(void) { return f(); } > > compile with -O2 -fPIC -flto -shared: -fPIC is the issue. x can be marked as "export" with the protected visibility. GCC 12 with -fvisibility=protected -flto -mno-direct-extern-access works on x86-64: 0000000000001040
: 1040: 8b 05 d6 2f 00 00 mov 0x2fd6(%rip),%eax # 401c 1046: 83 c0 01 add $0x1,%eax 1049: 89 05 cd 2f 00 00 mov %eax,0x2fcd(%rip) # 401c 104f: c3 ret 0000000000001110 : 1110: 8b 05 06 2f 00 00 mov 0x2f06(%rip),%eax # 401c 1116: 83 c0 01 add $0x1,%eax 1119: 89 05 fd 2e 00 00 mov %eax,0x2efd(%rip) # 401c 111f: c3 ret > > 00000000000004f0 : > 4f0: b0000090 adrp x16, 11000 <__cxa_finalize@GLIBC_2.17> > 4f4: f9400611 ldr x17, [x16, #8] > 4f8: 91002210 add x16, x16, #0x8 > 4fc: d61f0220 br x17 > > 0000000000000510
: > 510: 17fffff8 b 4f0 > > 0000000000000600 : > 600: 90000081 adrp x1, 10000 <__FRAME_END__+0xf8f8> > 604: f947e821 ldr x1, [x1, #4048] > 608: b9400020 ldr w0, [x1] > 60c: 11000400 add w0, w0, #0x1 > 610: b9000020 str w0, [x1] > 614: d65f03c0 ret > > So f() does not get inlined into main, it is redirected via PLT, and it uses a GOT > indirection to access the global. The underlying problem is that ELF assumes by > default that you want interposition/export for all symbols. In reality that is > almost never needed. LLVM makes -fno-semantic-interposition the default, > which solves the PLT and inlining issue, but not the unnecessary GOT indirections. > > Cheers, > Wilco -- H.J.