MC: permit emitting a symbol value as section relative
authorSaleem Abdulrasool <compnerd@compnerd.org>
Sat, 19 Jul 2014 21:01:58 +0000 (21:01 +0000)
committerSaleem Abdulrasool <compnerd@compnerd.org>
Sat, 19 Jul 2014 21:01:58 +0000 (21:01 +0000)
This adds an optional parameter to the EmitSymbolValue method in MCStreamer to
permit emitting a symbol value as a section relative value.  This is to cover
the use in MCDwarf which should not really know about how to emit a section
relative value for a given target.

This addresses post-review comments from Eric Christopher in SVN r213275.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@213463 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/MC/MCStreamer.h
lib/MC/MCDwarf.cpp
lib/MC/MCStreamer.cpp

index 6352e9b612d35ec71fe0dfeba60e6873ffcbb36d..63a43d08c3f21ab417c8100aad4b8fc465a0e5cc 100644 (file)
@@ -572,7 +572,8 @@ public:
 
   /// EmitSymbolValue - Special case of EmitValue that avoids the client
   /// having to pass in a MCExpr for MCSymbols.
-  void EmitSymbolValue(const MCSymbol *Sym, unsigned Size);
+  void EmitSymbolValue(const MCSymbol *Sym, unsigned Size,
+                       bool IsSectionRelative = false);
 
   /// EmitGPRel64Value - Emit the expression @p Value into the output as a
   /// gprel64 (64-bit GP relative) value.
index ae27686819869a0ab95f46a5ca9492339d8ff740..968cbc96a954faee7980d8b8b21f2b45a971c7cd 100644 (file)
@@ -655,14 +655,14 @@ static void EmitGenDwarfInfo(MCStreamer *MCOS,
   // The 2 byte DWARF version.
   MCOS->EmitIntValue(context.getDwarfVersion(), 2);
 
+  const MCAsmInfo &AsmInfo = *context.getAsmInfo();
   // The 4 byte offset to the debug abbrevs from the start of the .debug_abbrev,
   // it is at the start of that section so this is zero.
   if (AbbrevSectionSymbol == nullptr)
     MCOS->EmitIntValue(0, 4);
-  else if (context.getAsmInfo()->needsDwarfSectionOffsetDirective())
-    MCOS->EmitCOFFSecRel32(AbbrevSectionSymbol);
   else
-    MCOS->EmitSymbolValue(AbbrevSectionSymbol, 4);
+    MCOS->EmitSymbolValue(AbbrevSectionSymbol, 4,
+                          AsmInfo.needsDwarfSectionOffsetDirective());
 
   const MCAsmInfo *asmInfo = context.getAsmInfo();
   int AddrSize = asmInfo->getPointerSize();
index f3564027bf31c2fdce9440d0a47e0cd66ea627d5..46e80cc0c0d8e97c7787657190139793e9da24c4 100644 (file)
@@ -148,8 +148,15 @@ void MCStreamer::EmitValue(const MCExpr *Value, unsigned Size,
   EmitValueImpl(Value, Size, Loc);
 }
 
-void MCStreamer::EmitSymbolValue(const MCSymbol *Sym, unsigned Size) {
-  EmitValueImpl(MCSymbolRefExpr::Create(Sym, getContext()), Size);
+void MCStreamer::EmitSymbolValue(const MCSymbol *Sym, unsigned Size,
+                                 bool IsSectionRelative) {
+  assert((!IsSectionRelative || Size == 4) &&
+         "SectionRelative value requires 4-bytes");
+
+  if (!IsSectionRelative)
+    EmitValueImpl(MCSymbolRefExpr::Create(Sym, getContext()), Size);
+  else
+    EmitCOFFSecRel32(Sym);
 }
 
 void MCStreamer::EmitGPRel64Value(const MCExpr *Value) {