From f7ad048f1e122ee4f735398786f4859392f74144 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Sun, 20 Feb 2011 20:20:07 +0000 Subject: [PATCH] Add some limited support for labels in org directives. Hopefully enough to fix PR9245. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@126091 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/MC/MCObjectStreamer.cpp | 18 +++++++++++++++++- test/MC/ELF/org.s | 13 +++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 test/MC/ELF/org.s diff --git a/lib/MC/MCObjectStreamer.cpp b/lib/MC/MCObjectStreamer.cpp index 035826690cd..e67d9b03a95 100644 --- a/lib/MC/MCObjectStreamer.cpp +++ b/lib/MC/MCObjectStreamer.cpp @@ -242,7 +242,23 @@ void MCObjectStreamer::EmitDwarfAdvanceFrameAddr(const MCSymbol *LastLabel, void MCObjectStreamer::EmitValueToOffset(const MCExpr *Offset, unsigned char Value) { - new MCOrgFragment(*Offset, Value, getCurrentSectionData()); + int64_t Res; + if (Offset->EvaluateAsAbsolute(Res, getAssembler())) { + new MCOrgFragment(*Offset, Value, getCurrentSectionData()); + return; + } + + 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())) + report_fatal_error("expected assembly-time absolute expression"); + EmitFill(Res, Value, 0); } void MCObjectStreamer::Finish() { diff --git a/test/MC/ELF/org.s b/test/MC/ELF/org.s new file mode 100644 index 00000000000..c073fa5d808 --- /dev/null +++ b/test/MC/ELF/org.s @@ -0,0 +1,13 @@ +// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | elf-dump | FileCheck %s + + .zero 4 +foo: + .zero 4 + .org foo+16 + +// CHECK: (('sh_name', 0x00000001) # '.text' +// CHECK-NEXT: ('sh_type', +// CHECK-NEXT: ('sh_flags', +// CHECK-NEXT: ('sh_addr', +// CHECK-NEXT: ('sh_offset' +// CHECK-NEXT: ('sh_size', 0x00000014)