[llvm] 5d57578 - [MC] Recursively calculate symbol offset
Nico Weber via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 20 11:37:45 PDT 2021
Author: Leonard Grey
Date: 2021-10-20T14:29:43-04:00
New Revision: 5d57578a4e48e4b4cdd41533670a012ad265c8a1
URL: https://github.com/llvm/llvm-project/commit/5d57578a4e48e4b4cdd41533670a012ad265c8a1
DIFF: https://github.com/llvm/llvm-project/commit/5d57578a4e48e4b4cdd41533670a012ad265c8a1.diff
LOG: [MC] Recursively calculate symbol offset
This is speculative since I'm not sure if there's some implicit contract that a
variable symbol must not have another variable symbol in its evaluation tree.
Downstream bug: https://bugs.chromium.org/p/chromium/issues/detail?id=471146#c23.
Test is based on alias.s (removed checks since we just need to know it didn't
crash).
Differential Revision: https://reviews.llvm.org/D109109
Added:
llvm/test/MC/MachO/chained-alias-offset.s
Modified:
llvm/lib/MC/MCFragment.cpp
Removed:
################################################################################
diff --git a/llvm/lib/MC/MCFragment.cpp b/llvm/lib/MC/MCFragment.cpp
index 0f8543f51096a..4634de863b2fc 100644
--- a/llvm/lib/MC/MCFragment.cpp
+++ b/llvm/lib/MC/MCFragment.cpp
@@ -128,7 +128,11 @@ static bool getSymbolOffsetImpl(const MCAsmLayout &Layout, const MCSymbol &S,
const MCSymbolRefExpr *A = Target.getSymA();
if (A) {
uint64_t ValA;
- if (!getLabelOffset(Layout, A->getSymbol(), ReportError, ValA))
+ // FIXME: On most platforms, `Target`'s component symbols are labels from
+ // having been simplified during evaluation, but on Mach-O they can be
+ // variables due to PR19203. This, and the line below for `B` can be
+ // restored to call `getLabelOffset` when PR19203 is fixed.
+ if (!getSymbolOffsetImpl(Layout, A->getSymbol(), ReportError, ValA))
return false;
Offset += ValA;
}
@@ -136,7 +140,7 @@ static bool getSymbolOffsetImpl(const MCAsmLayout &Layout, const MCSymbol &S,
const MCSymbolRefExpr *B = Target.getSymB();
if (B) {
uint64_t ValB;
- if (!getLabelOffset(Layout, B->getSymbol(), ReportError, ValB))
+ if (!getSymbolOffsetImpl(Layout, B->getSymbol(), ReportError, ValB))
return false;
Offset -= ValB;
}
diff --git a/llvm/test/MC/MachO/chained-alias-offset.s b/llvm/test/MC/MachO/chained-alias-offset.s
new file mode 100644
index 0000000000000..23b45a3978deb
--- /dev/null
+++ b/llvm/test/MC/MachO/chained-alias-offset.s
@@ -0,0 +1,12 @@
+// RUN: llvm-mc -triple x86_64-apple-macos %s -filetype=obj | llvm-readobj --symbols - | FileCheck %s
+l_a:
+l_b = l_a + 1
+l_c = l_b
+ .long l_c
+
+// CHECK: Name: l_a
+// CHECK: Value: 0x0
+// CHECK: Name: l_b
+// CHECK: Value: 0x1
+// CHECK: Name: l_c
+// CHECK: Value: 0x1
More information about the llvm-commits
mailing list