From: Rafael Espindola Date: Wed, 4 Nov 2015 23:50:29 +0000 (+0000) Subject: Simplify .org processing and make it a bit more powerful. X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=036ec43e830d75c763a5edbd61fa31752adcfd11;p=oota-llvm.git 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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@252101 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/MC/MCAssembler.cpp b/lib/MC/MCAssembler.cpp index 971dc526ea6..06f65fcb49a 100644 --- a/lib/MC/MCAssembler.cpp +++ b/lib/MC/MCAssembler.cpp @@ -533,12 +533,19 @@ uint64_t MCAssembler::computeFragmentSize(const MCAsmLayout &Layout, case MCFragment::FT_Org: { const MCOrgFragment &OF = cast(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) + diff --git a/lib/MC/MCObjectStreamer.cpp b/lib/MC/MCObjectStreamer.cpp index 0da61b5ddce..667384e76ca 100644 --- a/lib/MC/MCObjectStreamer.cpp +++ b/lib/MC/MCObjectStreamer.cpp @@ -393,23 +393,7 @@ void MCObjectStreamer::EmitCodeAlignment(unsigned ByteAlignment, 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; } diff --git a/test/MC/AsmParser/dot-symbol-non-absolute.s b/test/MC/AsmParser/dot-symbol-non-absolute.s index 7342365fe1b..7cc97f9ed2b 100644 --- a/test/MC/AsmParser/dot-symbol-non-absolute.s +++ b/test/MC/AsmParser/dot-symbol-non-absolute.s @@ -4,6 +4,6 @@ .extern foo -# CHECK: error: expected absolute expression +# CHECK: : expected absolute expression . = foo + 10 .byte 1 diff --git a/test/MC/ELF/dot-symbol-assignment.s b/test/MC/ELF/dot-symbol-assignment.s index 00fe205082b..284bef0f337 100644 --- a/test/MC/ELF/dot-symbol-assignment.s +++ b/test/MC/ELF/dot-symbol-assignment.s @@ -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: )