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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@207728 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Rafael Espindola 2014-05-01 00:10:17 +00:00
parent 21b719dfcf
commit b77f8919bc
2 changed files with 32 additions and 10 deletions

View File

@ -385,6 +385,18 @@ void WinCOFFObjectWriter::DefineSection(MCSectionData const &SectionData) {
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(MCSymbolData const &SymbolData,
} 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(MCAssembler &Asm,
assert(Symbol->Section != nullptr);
Symbol->Data.SectionNumber = Symbol->Section->Number;
Symbol->Data.Value = Layout.getFragmentOffset(SymbolData->Fragment)
+ SymbolData->Offset;
}
if (Symbol->should_keep()) {

19
test/MC/COFF/offset.s Normal file
View File

@ -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: }