[llvm] r252101 - Simplify .org processing and make it a bit more powerful.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 4 15:50:30 PST 2015


Author: rafael
Date: Wed Nov  4 17:50:29 2015
New Revision: 252101

URL: http://llvm.org/viewvc/llvm-project?rev=252101&view=rev
Log:
Simplify .org processing and make it a bit more powerful.

We now always create the fragment, which lets us handle things like .org after
a .align.

Modified:
    llvm/trunk/lib/MC/MCAssembler.cpp
    llvm/trunk/lib/MC/MCObjectStreamer.cpp
    llvm/trunk/test/MC/AsmParser/dot-symbol-non-absolute.s
    llvm/trunk/test/MC/ELF/dot-symbol-assignment.s

Modified: llvm/trunk/lib/MC/MCAssembler.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCAssembler.cpp?rev=252101&r1=252100&r2=252101&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCAssembler.cpp (original)
+++ llvm/trunk/lib/MC/MCAssembler.cpp Wed Nov  4 17:50:29 2015
@@ -533,12 +533,19 @@ uint64_t MCAssembler::computeFragmentSiz
 
   case MCFragment::FT_Org: {
     const MCOrgFragment &OF = cast<MCOrgFragment>(F);
-    int64_t TargetLocation;
-    if (!OF.getOffset().evaluateAsAbsolute(TargetLocation, Layout))
+    MCValue Value;
+    if (!OF.getOffset().evaluateAsValue(Value, Layout))
       report_fatal_error("expected assembly-time absolute expression");
 
     // FIXME: We need a way to communicate this error.
     uint64_t FragmentOffset = Layout.getFragmentOffset(&OF);
+    int64_t TargetLocation = Value.getConstant();
+    if (const MCSymbolRefExpr *A = Value.getSymA()) {
+      uint64_t Val;
+      if (!Layout.getSymbolOffset(A->getSymbol(), Val))
+        report_fatal_error("expected absolute expression");
+      TargetLocation += Val;
+    }
     int64_t Size = TargetLocation - FragmentOffset;
     if (Size < 0 || Size >= 0x40000000)
       report_fatal_error("invalid .org offset '" + Twine(TargetLocation) +

Modified: llvm/trunk/lib/MC/MCObjectStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCObjectStreamer.cpp?rev=252101&r1=252100&r2=252101&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCObjectStreamer.cpp (original)
+++ llvm/trunk/lib/MC/MCObjectStreamer.cpp Wed Nov  4 17:50:29 2015
@@ -393,23 +393,7 @@ void MCObjectStreamer::EmitCodeAlignment
 
 bool MCObjectStreamer::EmitValueToOffset(const MCExpr *Offset,
                                          unsigned char Value) {
-  int64_t Res;
-  if (Offset->evaluateAsAbsolute(Res, getAssembler())) {
-    insert(new MCOrgFragment(*Offset, Value));
-    return false;
-  }
-
-  MCSymbol *CurrentPos = getContext().createTempSymbol();
-  EmitLabel(CurrentPos);
-  MCSymbolRefExpr::VariantKind Variant = MCSymbolRefExpr::VK_None;
-  const MCExpr *Ref =
-    MCSymbolRefExpr::create(CurrentPos, Variant, getContext());
-  const MCExpr *Delta =
-    MCBinaryExpr::create(MCBinaryExpr::Sub, Offset, Ref, getContext());
-
-  if (!Delta->evaluateAsAbsolute(Res, getAssembler()))
-    return true;
-  EmitFill(Res, Value);
+  insert(new MCOrgFragment(*Offset, Value));
   return false;
 }
 

Modified: llvm/trunk/test/MC/AsmParser/dot-symbol-non-absolute.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/AsmParser/dot-symbol-non-absolute.s?rev=252101&r1=252100&r2=252101&view=diff
==============================================================================
--- llvm/trunk/test/MC/AsmParser/dot-symbol-non-absolute.s (original)
+++ llvm/trunk/test/MC/AsmParser/dot-symbol-non-absolute.s Wed Nov  4 17:50:29 2015
@@ -4,6 +4,6 @@
 
 	.extern foo
 
-# CHECK: error: expected absolute expression
+# CHECK: : expected absolute expression
 . = foo + 10
 	.byte 1

Modified: llvm/trunk/test/MC/ELF/dot-symbol-assignment.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ELF/dot-symbol-assignment.s?rev=252101&r1=252100&r2=252101&view=diff
==============================================================================
--- llvm/trunk/test/MC/ELF/dot-symbol-assignment.s (original)
+++ llvm/trunk/test/MC/ELF/dot-symbol-assignment.s Wed Nov  4 17:50:29 2015
@@ -11,6 +11,9 @@ two:
 three:
 	.quad 0xdddddddddddddddd
 
+        .align 4
+        . = three + 9
+
 // CHECK:        Section {
 // CHECK:          Name: .text
 // CHECK-NEXT:     Type:
@@ -18,5 +21,5 @@ three:
 // CHECK:          SectionData (
 // CHECK-NEXT:     0000: FFFFFFFF FFFFFFFF 00000000 00000000
 // CHECK-NEXT:     0010: 00000000 00000000 EEEEEEEE EEEEEEEE
-// CHECK-NEXT:     0020: DDDDDDDD DDDDDDDD
+// CHECK-NEXT:     0020: DDDDDDDD DDDDDDDD 00 |
 // CHECK-NEXT:     )




More information about the llvm-commits mailing list