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
This commit is contained in:
Rafael Espindola 2011-02-20 20:20:07 +00:00
parent 8e04fc3adf
commit f7ad048f1e
2 changed files with 30 additions and 1 deletions

View File

@ -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() {

13
test/MC/ELF/org.s Normal file
View File

@ -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)