public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: "H.J. Lu" <hjl.tools@gmail.com>
To: Wilco Dijkstra <Wilco.Dijkstra@arm.com>
Cc: Florian Weimer <fweimer@redhat.com>,
	 Wilco Dijkstra via Libc-alpha <libc-alpha@sourceware.org>,
	Szabolcs Nagy <Szabolcs.Nagy@arm.com>
Subject: Re: [PATCH 2/3] Revert "[AArch64][BZ #17711] Fix extern protected data handling"
Date: Thu, 26 May 2022 14:27:22 -0700	[thread overview]
Message-ID: <CAMe9rOp_4dCydWTx-p2rRcPsK2FmW9=KfyO38Xbgj8zTy-JvbA@mail.gmail.com> (raw)
In-Reply-To: <AM5PR0801MB187563FD4CCC0B7ED114BABF83D99@AM5PR0801MB1875.eurprd08.prod.outlook.com>

On Thu, May 26, 2022 at 1:03 PM Wilco Dijkstra <Wilco.Dijkstra@arm.com> 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 <main>:
    1040: 8b 05 d6 2f 00 00    mov    0x2fd6(%rip),%eax        # 401c <x>
    1046: 83 c0 01              add    $0x1,%eax
    1049: 89 05 cd 2f 00 00    mov    %eax,0x2fcd(%rip)        # 401c <x>
    104f: c3                    ret

0000000000001110 <f>:
    1110: 8b 05 06 2f 00 00    mov    0x2f06(%rip),%eax        # 401c <x>
    1116: 83 c0 01              add    $0x1,%eax
    1119: 89 05 fd 2e 00 00    mov    %eax,0x2efd(%rip)        # 401c <x>
    111f: c3                    ret

>
> 00000000000004f0 <f@plt>:
>  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 <main>:
>  510:   17fffff8        b       4f0 <f@plt>
>
> 0000000000000600 <f>:
>  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.

  reply	other threads:[~2022-05-26 21:27 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-24 13:46 Wilco Dijkstra
2022-05-24 17:28 ` maskray
2022-05-24 21:58 ` H.J. Lu
2022-05-25 17:13   ` Wilco Dijkstra
2022-05-25 18:21     ` Florian Weimer
2022-05-25 20:44       ` H.J. Lu
2022-05-26 19:17         ` Wilco Dijkstra
2022-05-26 19:25           ` Florian Weimer
2022-05-26 20:03             ` Wilco Dijkstra
2022-05-26 21:27               ` H.J. Lu [this message]
2022-05-27 12:43               ` Florian Weimer
2022-05-31  2:03                 ` H.J. Lu
2022-05-31  7:49                   ` Fangrui Song
2022-05-31  9:42                     ` Wilco Dijkstra
2022-05-31 13:47                     ` H.J. Lu
2022-05-31  7:42               ` Fangrui Song
2022-05-25 20:10     ` maskray
  -- strict thread matches above, loose matches on Subject: below --
2022-05-01  6:06 [PATCH 0/3] Simplify ELF_RTYPE_CLASS_EXTERN_PROTECTED_DATA and revert aarch64/arm's extern protected data handling Fangrui Song
2022-05-01  6:06 ` [PATCH 2/3] Revert "[AArch64][BZ #17711] Fix extern protected data handling" Fangrui Song
2022-05-23 20:10   ` Szabolcs Nagy
2022-05-23 20:17     ` Fangrui Song
2022-05-24  5:13       ` Fangrui Song

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAMe9rOp_4dCydWTx-p2rRcPsK2FmW9=KfyO38Xbgj8zTy-JvbA@mail.gmail.com' \
    --to=hjl.tools@gmail.com \
    --cc=Szabolcs.Nagy@arm.com \
    --cc=Wilco.Dijkstra@arm.com \
    --cc=fweimer@redhat.com \
    --cc=libc-alpha@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).