mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-02-01 05:01:59 +01:00
Fangrui Song
0b1b3b7f09
MCExpr::evaluateAsRelocatableImpl : allow evaluation of non-VK_None MCSymbolRefExpr when MCAsmLayout is available
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=4acf8c78e659833be8be047ba2f8561386a11d4b (1994) introduced this behavior: if a fixup symbol is equated to an expression with an undefined symbol, convert the fixup to be against the target symbol. glibc relies on this behavior to perform assembly level indirection ``` asm("memcpy = __GI_memcpy"); // from sysdeps/generic/symbol-hacks.h ... // call memcpy@PLT // The relocation references __GI_memcpy in GNU as, but memcpy in MC (without the patch) memcpy (...); ``` (1) It complements `extern __typeof(memcpy) memcpy asm("__GI_memcpy");` The frontend asm label does not redirect synthesized memcpy in the middle-end. (See D88712 for details) (2) `asm("memcpy = __GI_memcpy");` is in every translation unit, but the memcpy declaration may not be visible in the translation unit where memcpy is synthesized. MC already redirects `memcpy = __GI_memcpy; call memcpy` but not `memcpy = __GI_memcpy; call memcpy@plt`. This patch fixes the latter by allowing MCExpr::evaluateAsRelocatableImpl to evaluate a non-VK_None MCSymbolRefExpr, which is only done after the layout is available. GNU as allows `memcpy = __GI_memcpy+1; call memcpy@PLT` which seems nonsensical, so we don't allow it. `MC/PowerPC/pr38945.s` `NUMBER = 0x6ffffff9; cmpwi 8,NUMBER@l` requires the `symbol@l` form in AsmMatcher, so evaluation needs to be deferred. This is the place whether future simplification may be possible. Note, if we suppress the VM_None evaluation when MCAsmLayout is nullptr, we may lose the `invalid reassignment of non-absolute variable` diagnostic (`ARM/thumb_set-diagnostics.s` and `MC/AsmParser/variables-invalid.s`). We know that this diagnostic is troublesome in some cases (https://github.com/ClangBuiltLinux/linux/issues/1008), so we can consider making simplification in the future. Reviewed By: jyknight Differential Revision: https://reviews.llvm.org/D88625
The LLVM Compiler Infrastructure ================================ This directory and its subdirectories contain source code for LLVM, a toolkit for the construction of highly optimized compilers, optimizers, and runtime environments. LLVM is open source software. You may freely distribute it under the terms of the license agreement found in LICENSE.txt. Please see the documentation provided in docs/ for further assistance with LLVM, and in particular docs/GettingStarted.rst for getting started with LLVM and docs/README.txt for an overview of LLVM's documentation setup. If you are writing a package for LLVM, see docs/Packaging.rst for our suggestions.
Description
Languages
C++
96.9%
C
1%
Python
1%
CMake
0.6%
OCaml
0.2%
Other
0.1%