[llvm] r207728 - Start fixing pr19147.
Rafael Espindola
rafael.espindola at gmail.com
Wed Apr 30 17:10:17 PDT 2014
Author: rafael
Date: Wed Apr 30 19:10:17 2014
New Revision: 207728
URL: http://llvm.org/viewvc/llvm-project?rev=207728&view=rev
Log:
Start fixing pr19147.
This makes the coff writer compute the correct symbol value for the test in
pr19147. The section is still incorrect, that will be fixed in a followup patch.
Added:
llvm/trunk/test/MC/COFF/offset.s
Modified:
llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp
Modified: llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp?rev=207728&r1=207727&r2=207728&view=diff
==============================================================================
--- llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp Wed Apr 30 19:10:17 2014
@@ -385,6 +385,18 @@ void WinCOFFObjectWriter::DefineSection(
SectionMap[&SectionData.getSection()] = coff_section;
}
+static uint64_t getSymbolValue(const MCSymbolData &Data,
+ const MCAsmLayout &Layout) {
+ if (Data.isCommon() && Data.isExternal())
+ return Data.getCommonSize();
+
+ uint64_t Res;
+ if (!Layout.getSymbolOffset(&Data, Res))
+ return 0;
+
+ return Res;
+}
+
/// This function takes a symbol data object from the assembler
/// and creates the associated COFF symbol staging object.
void WinCOFFObjectWriter::DefineSymbol(MCSymbolData const &SymbolData,
@@ -429,14 +441,7 @@ void WinCOFFObjectWriter::DefineSymbol(M
} else {
const MCSymbolData &ResSymData =
Assembler.getSymbolData(Symbol.AliasedSymbol());
-
- if (Symbol.isVariable()) {
- int64_t Addr;
- if (Symbol.getVariableValue()->EvaluateAsAbsolute(Addr, Layout))
- coff_symbol->Data.Value = Addr;
- } else if (SymbolData.isExternal() && SymbolData.isCommon()) {
- coff_symbol->Data.Value = SymbolData.getCommonSize();
- }
+ coff_symbol->Data.Value = getSymbolValue(ResSymData, Layout);
coff_symbol->Data.Type = (ResSymData.getFlags() & 0x0000FFFF) >> 0;
coff_symbol->Data.StorageClass = (ResSymData.getFlags() & 0x00FF0000) >> 16;
@@ -828,8 +833,6 @@ void WinCOFFObjectWriter::WriteObject(MC
assert(Symbol->Section != nullptr);
Symbol->Data.SectionNumber = Symbol->Section->Number;
- Symbol->Data.Value = Layout.getFragmentOffset(SymbolData->Fragment)
- + SymbolData->Offset;
}
if (Symbol->should_keep()) {
Added: llvm/trunk/test/MC/COFF/offset.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/COFF/offset.s?rev=207728&view=auto
==============================================================================
--- llvm/trunk/test/MC/COFF/offset.s (added)
+++ llvm/trunk/test/MC/COFF/offset.s Wed Apr 30 19:10:17 2014
@@ -0,0 +1,19 @@
+// RUN: llvm-mc -filetype=obj -triple i686-pc-win32 %s -o - | llvm-readobj -t -r | FileCheck %s
+
+ .data
+ .globl test1_foo
+test1_foo:
+ .long 42
+
+ .globl test1_zed
+test1_zed = test1_foo + 1
+
+// CHECK: Symbol {
+// CHECK: Name: test1_zed
+// CHECK-NEXT: Value: 1
+// CHECK-NEXT: Section:
+// CHECK-NEXT: BaseType: Null
+// CHECK-NEXT: ComplexType: Null
+// CHECK-NEXT: StorageClass: External
+// CHECK-NEXT: AuxSymbolCount: 0
+// CHECK-NEXT: }
More information about the llvm-commits
mailing list