[llvm-commits] [patch] Add MCObjectFormat. Fix "a + (b - c)" for ELF
Michael Spencer
bigcheesegs at gmail.com
Fri Oct 15 21:49:05 PDT 2010
On Sat, Oct 16, 2010 at 12:21 AM, Rafael Espindola <espindola at google.com> wrote:
> Now the patch is attached.
>
> Cheers,
> --
> Rafael Ávila de Espíndola
>
Looks like an improvement to me. The only thing I wonder is if
IsFixupFullyResolved should be moved there. Seems like a similar
query.
Inline comments below.
diff --git a/lib/MC/MCExpr.cpp b/lib/MC/MCExpr.cpp
index e9a6062..3524b80 100644
--- a/lib/MC/MCExpr.cpp
+++ b/lib/MC/MCExpr.cpp
@@ -14,6 +14,7 @@
#include "llvm/MC/MCAsmLayout.h"
#include "llvm/MC/MCAssembler.h"
#include "llvm/MC/MCContext.h"
+#include "llvm/MC/MCObjectFormat.h"
#include "llvm/MC/MCSymbol.h"
#include "llvm/MC/MCValue.h"
#include "llvm/Support/Debug.h"
@@ -237,7 +238,8 @@ bool MCExpr::EvaluateAsAbsolute(int64_t &Res,
const MCAsmLayout *Layout) const {
return true;
}
-static bool EvaluateSymbolicAdd(const MCValue &LHS,const
MCSymbolRefExpr *RHS_A,
+static bool EvaluateSymbolicAdd(const MCAsmLayout *Layout, bool InSet,
+ const MCValue &LHS,const
MCSymbolRefExpr *RHS_A,
const MCSymbolRefExpr *RHS_B, int64_t RHS_Cst,
MCValue &Res) {
// We can't add or subtract two symbols.
@@ -255,12 +257,40 @@ static bool EvaluateSymbolicAdd(const MCValue
&LHS,const MCSymbolRefExpr *RHS_A,
if (!A)
return false;
}
+
+ // Absolutize symbol differences between defined symbols when we have a
+ // layout object and the target requests it.
+
+ if (Layout && A && B) {
+ const MCSymbol &SA = A->getSymbol();
+ const MCSymbol &SB = B->getSymbol();
+ const MCObjectFormat &F =
+ Layout->getAssembler().getBackend().getObjectFormat();
+ if (SA.isDefined() && SB.isDefined() && F.isAbsolute(InSet, SA, SB)) {
+ const MCAssembler &Asm = Layout->getAssembler();
+ MCSymbolData &AD = Asm.getSymbolData(A->getSymbol());
+ MCSymbolData &BD = Asm.getSymbolData(B->getSymbol());
+ Res = MCValue::get(+ Layout->getSymbolAddress(&AD)
I have finally found a useful application of unary +.
+ - Layout->getSymbolAddress(&BD)
+ + LHS.getConstant()
+ + RHS_Cst);
+ return true;
+ }
+ }
+
+
Res = MCValue::get(A, B, LHS.getConstant() + RHS_Cst);
return true;
}
diff --git a/lib/MC/MCObjectFormat.cpp b/lib/MC/MCObjectFormat.cpp
new file mode 100644
index 0000000..9c14179
--- /dev/null
+++ b/lib/MC/MCObjectFormat.cpp
@@ -0,0 +1,31 @@
+//===- lib/MC/MCObjectFormat.cpp - MCObjectFormat implementation
----------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/MC/MCObjectFormat.h"
+#include "llvm/MC/MCSymbol.h"
+
+using namespace llvm;
+
+bool MCELFObjectFormat::isAbsolute(bool IsSet, const MCSymbol &A,
+ const MCSymbol &B) const {
+ // On ELF A - B is absolute if A and B are in the same section.
+ return &A.getSection() == &B.getSection();
+}
+
+bool MCMachOObjectFormat::isAbsolute(bool IsSet, const MCSymbol &A,
+ const MCSymbol &B) const {
+ // On MachO A - B is absolute only if in a set.
+ return IsSet;
+}
+
+bool MCCOFFObjectFormat::isAbsolute(bool IsSet, const MCSymbol &A,
+ const MCSymbol &B) const {
+ // FIXME: Is this correct?
This should be the same as the ELF case.
+ return false;
+}
- Michael Spencer
More information about the llvm-commits
mailing list