aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/MC/MCExpr.cpp
diff options
context:
space:
mode:
authorFangrui Song <i@maskray.me>2023-06-16 17:08:58 -0700
committerFangrui Song <i@maskray.me>2023-06-16 17:08:58 -0700
commitdef6158f957e77d67f74aa9c8bb342c4b64a159b (patch)
tree256a68a74d7fa0000a5b4bc034448f527e25b44f /llvm/lib/MC/MCExpr.cpp
parent441108ccba948d76e7002c61236e3bcbca0203ce (diff)
downloadllvm-def6158f957e77d67f74aa9c8bb342c4b64a159b.zip
llvm-def6158f957e77d67f74aa9c8bb342c4b64a159b.tar.gz
llvm-def6158f957e77d67f74aa9c8bb342c4b64a159b.tar.bz2
[MC] Restore a special case to support limited A-B folding when A/B are in the same fragment being laided out
Add subsection-if.s to test what we can fold (in the same fragment) and what we cannot. Fix https://github.com/ClangBuiltLinux/linux/issues/1876 Fixes: 4bdc7f7a331f82cca1637388cf68bdc5b32ab43b
Diffstat (limited to 'llvm/lib/MC/MCExpr.cpp')
-rw-r--r--llvm/lib/MC/MCExpr.cpp6
1 files changed, 6 insertions, 0 deletions
diff --git a/llvm/lib/MC/MCExpr.cpp b/llvm/lib/MC/MCExpr.cpp
index 46a0367..df305c8 100644
--- a/llvm/lib/MC/MCExpr.cpp
+++ b/llvm/lib/MC/MCExpr.cpp
@@ -625,6 +625,12 @@ static void AttemptToFoldSymbolOffsetDifference(
return;
if (Layout) {
+ // If both symbols are in the same fragment, return the difference of their
+ // offsets. canGetFragmentOffset(FA) may be false.
+ if (FA == FB && !SA.isVariable() && !SB.isVariable()) {
+ Addend += SA.getOffset() - SB.getOffset();
+ return FinalizeFolding();
+ }
// One of the symbol involved is part of a fragment being laid out. Quit now
// to avoid a self loop.
if (!Layout->canGetFragmentOffset(FA) || !Layout->canGetFragmentOffset(FB))