[all-commits] [llvm/llvm-project] 30e8f8: [GlobalOpt] Don't replace alias with aliasee if ei...

Fangrui Song via All-commits all-commits at lists.llvm.org
Tue Feb 1 10:41:32 PST 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 30e8f83c84c5a302a559722fc0d2973dc3f425ee
      https://github.com/llvm/llvm-project/commit/30e8f83c84c5a302a559722fc0d2973dc3f425ee
  Author: Fangrui Song <i at maskray.me>
  Date:   2022-02-01 (Tue, 01 Feb 2022)

  Changed paths:
    M llvm/docs/LangRef.rst
    M llvm/lib/Transforms/IPO/GlobalOpt.cpp
    M llvm/test/Transforms/GlobalOpt/2009-02-15-ResolveAlias.ll
    M llvm/test/Transforms/GlobalOpt/alias-resolve.ll
    M llvm/test/Transforms/GlobalOpt/alias-used-address-space.ll
    M llvm/test/Transforms/GlobalOpt/alias-used.ll

  Log Message:
  -----------
  [GlobalOpt] Don't replace alias with aliasee if either alias/aliasee may be preemptible

Generalize D99629 for ELF. A default visibility non-local symbol is preemptible
in a -shared link. `isInterposable` is an insufficient condition.

Moreover, a non-preemptible alias may be referenced in a sub constant expression
which intends to lower to a PC-relative relocation. Replacing the alias with a
preemptible aliasee may introduce a linker error.

Respect dso_preemptable and suppress optimization to fix the abose issues. With
the change, `alias = 345` will not be rewritten to use aliasee in a `-fpic`
compile.
```
int aliasee;
extern int alias __attribute__((alias("aliasee"), visibility("hidden")));
void foo() { alias = 345; } // intended to access the local copy
```

While here, refine the condition for the alias as well.

For some binary formats like COFF, `isInterposable` is a sufficient condition.
But I think canonicalization for the changed case has little advantage, so I
don't bother to add the `Triple(M.getTargetTriple()).isOSBinFormatELF()` or
`getPICLevel/getPIELevel` complexity.

For instrumentations, it's recommended not to create aliases that refer to
globals that have a weak linkage or is preemptible. However, the following is
supported and the IR needs to handle such cases.
```
int aliasee __attribute__((weak));
extern int alias __attribute__((alias("aliasee")));
```

There are other places where GlobalAlias isInterposable usage may need to be
fixed.

Reviewed By: rnk

Differential Revision: https://reviews.llvm.org/D107249




More information about the All-commits mailing list