aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/MC/WinCOFFObjectWriter.cpp
diff options
context:
space:
mode:
authorDavid Majnemer <david.majnemer@gmail.com>2015-02-09 06:31:31 +0000
committerDavid Majnemer <david.majnemer@gmail.com>2015-02-09 06:31:31 +0000
commit1de3094d78700caf404928bf40dba1df972bb864 (patch)
treed07c86732e814a5537e478ea4df5c8d3ed5753eb /llvm/lib/MC/WinCOFFObjectWriter.cpp
parenta54d7de655191a7ed8ec23761db2ab19954250bf (diff)
downloadllvm-1de3094d78700caf404928bf40dba1df972bb864.zip
llvm-1de3094d78700caf404928bf40dba1df972bb864.tar.gz
llvm-1de3094d78700caf404928bf40dba1df972bb864.tar.bz2
MC: Calculate intra-section symbol differences correctly for COFF
This fixes PR22060. llvm-svn: 228565
Diffstat (limited to 'llvm/lib/MC/WinCOFFObjectWriter.cpp')
-rw-r--r--llvm/lib/MC/WinCOFFObjectWriter.cpp17
1 files changed, 11 insertions, 6 deletions
diff --git a/llvm/lib/MC/WinCOFFObjectWriter.cpp b/llvm/lib/MC/WinCOFFObjectWriter.cpp
index bd750af..e398581 100644
--- a/llvm/lib/MC/WinCOFFObjectWriter.cpp
+++ b/llvm/lib/MC/WinCOFFObjectWriter.cpp
@@ -706,17 +706,22 @@ void WinCOFFObjectWriter::RecordRelocation(
CrossSection = &Symbol.getSection() != &B->getSection();
// Offset of the symbol in the section
- int64_t a = Layout.getSymbolOffset(&B_SD);
+ int64_t OffsetOfB = Layout.getSymbolOffset(&B_SD);
- // Offset of the relocation in the section
- int64_t b = Layout.getFragmentOffset(Fragment) + Fixup.getOffset();
-
- FixedValue = b - a;
// In the case where we have SymbA and SymB, we just need to store the delta
// between the two symbols. Update FixedValue to account for the delta, and
// skip recording the relocation.
- if (!CrossSection)
+ if (!CrossSection) {
+ int64_t OffsetOfA = Layout.getSymbolOffset(&A_SD);
+ FixedValue = (OffsetOfA - OffsetOfB) + Target.getConstant();
return;
+ }
+
+ // Offset of the relocation in the section
+ int64_t OffsetOfRelocation =
+ Layout.getFragmentOffset(Fragment) + Fixup.getOffset();
+
+ FixedValue = OffsetOfRelocation - OffsetOfB;
} else {
FixedValue = Target.getConstant();
}