[PATCH] D101872: [AArch64][ELF] Prefer to lower MC_GlobalAddress operands to .Lfoo$local

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed May 5 18:05:56 PDT 2021


MaskRay marked an inline comment as done.
MaskRay added a comment.

In D101872#2740878 <https://reviews.llvm.org/D101872#2740878>, @efriedma wrote:

> In D101872#2740867 <https://reviews.llvm.org/D101872#2740867>, @MaskRay wrote:
>
>> If D101873 <https://reviews.llvm.org/D101873> is enabled without this patch, clang may produce assembly like
>>
>>   ; CHECK-NEXT:    adrp x0, gv0  # instead of .Lgv0$local
>>   ; CHECK-NEXT:    ldr w0, [x0, :lo12:gv0]
>>
>> This will be rejected by `{ld.bfd,gold,ld.lld} -shared` because in ELF, gv0 (STV_DEFAULT STB_GLOBAL) is by default preemptible and direct access relocations referencing a preemptible symbol cannot be used in -shared mode.
>
> So this is basically a bugfix for dso_local handling?  Okay.

I may perceive this as an unimplemented feature (lowering of default visibility external linkage dso_local definitions).



================
Comment at: llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp:592
   assert(MO.isGlobal() && "caller should check MO.isGlobal");
-  getSymbol(MO.getGlobal())->print(OS, MAI);
+  getSymbolPreferLocal(*MO.getGlobal())->print(OS, MAI);
   printOffset(MO.getOffset(), OS);
----------------
efriedma wrote:
> MaskRay wrote:
> > efriedma wrote:
> > > This is target-independent code; what targets does it affect?
> > Only aarch64. No-op for others.
> > 
> > With D101873, aarch64 will behave like x86: -fpic -fno-semantic-interposition will set dso_local on default visibility external linkage definitions.
> > 
> Do you mean this code is unreachable for non-aarch64 targets?  Or that getSymbolPreferLocal() does the same thing as getSymbol() on other targets?  Or that clang won't emit IR that's impacted by this change?
On other targets, clang doesn't emit IR which may observe different behavior due to getSymbol -> getSymbolPreferLocal.

On aarch64, D101873 will cause clang to emit IR which may observe different behavior.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D101872/new/

https://reviews.llvm.org/D101872



More information about the llvm-commits mailing list