Skip to content

Commit

Permalink
patch llvm win64 dwarf4 relocations
Browse files Browse the repository at this point in the history
afaict, this is how other platforms treat this flag
  • Loading branch information
vtjnash authored and tkelman committed May 11, 2016
1 parent c9d4051 commit a485acf
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
2 changes: 2 additions & 0 deletions deps/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,7 @@ $(eval $(call LLVM_PATCH,llvm-3.7.1_2))
$(eval $(call LLVM_PATCH,llvm-3.7.1_3))
$(eval $(call LLVM_PATCH,llvm-D14260))
$(LLVM_SRC_DIR)/llvm-3.7.1_2.patch-applied: $(LLVM_SRC_DIR)/llvm-3.7.1.patch-applied
$(eval $(call LLVM_PATCH,llvm-win64-reloc-dwarf))
else ifeq ($(LLVM_VER),3.8.0)
$(eval $(call LLVM_PATCH,llvm-3.7.1_3))
$(eval $(call LLVM_PATCH,llvm-D14260))
Expand All @@ -728,6 +729,7 @@ $(eval $(call LLVM_PATCH,llvm-3.8.0_winshlib))
$(eval $(call LLVM_PATCH,llvm-3.8.0_threads))
# fix replutil test on unix
$(eval $(call LLVM_PATCH,llvm-D17165-D18583))
$(eval $(call LLVM_PATCH,llvm-win64-reloc-dwarf))
endif # LLVM_VER

ifeq ($(LLVM_VER),3.7.1)
Expand Down
54 changes: 54 additions & 0 deletions deps/llvm-win64-reloc-dwarf.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
diff -pru llvm-3.7.1.src/include/llvm/MC/MCWinCOFFObjectWriter.h llvm-3.7.1/include/llvm/MC/MCWinCOFFObjectWriter.h
--- llvm-3.7.1.src/include/llvm/MC/MCWinCOFFObjectWriter.h 2015-06-23 05:49:53.000000000 -0400
+++ llvm-3.7.1/include/llvm/MC/MCWinCOFFObjectWriter.h 2016-02-10 16:43:05.717412100 -0500
@@ -31,6 +31,7 @@ class raw_pwrite_stream;
unsigned getMachine() const { return Machine; }
virtual unsigned getRelocType(const MCValue &Target, const MCFixup &Fixup,
bool IsCrossSection,
+ bool IsPCRel,
const MCAsmBackend &MAB) const = 0;
virtual bool recordRelocation(const MCFixup &) const { return true; }
};
diff -pru llvm-3.7.1.src/lib/MC/WinCOFFObjectWriter.cpp llvm-3.7.1/lib/MC/WinCOFFObjectWriter.cpp
--- llvm-3.7.1.src/lib/MC/WinCOFFObjectWriter.cpp 2015-06-23 05:49:53.000000000 -0400
+++ llvm-3.7.1/lib/MC/WinCOFFObjectWriter.cpp 2016-02-10 16:44:28.592762200 -0500
@@ -776,7 +776,7 @@ void WinCOFFObjectWriter::recordRelocati

Reloc.Data.VirtualAddress += Fixup.getOffset();
Reloc.Data.Type = TargetObjectWriter->getRelocType(
- Target, Fixup, CrossSection, Asm.getBackend());
+ Target, Fixup, CrossSection, IsPCRel, Asm.getBackend());

// FIXME: Can anyone explain what this does other than adjust for the size
// of the offset?
diff -pru llvm-3.7.1.src/lib/Target/X86/MCTargetDesc/X86WinCOFFObjectWriter.cpp llvm-3.7.1/lib/Target/X86/MCTargetDesc/X86WinCOFFObjectWriter.cpp
--- llvm-3.7.1.src/lib/Target/X86/MCTargetDesc/X86WinCOFFObjectWriter.cpp 2015-06-23 05:49:53.000000000 -0400
+++ llvm-3.7.1/lib/Target/X86/MCTargetDesc/X86WinCOFFObjectWriter.cpp 2016-02-10 16:43:48.593885400 -0500
@@ -29,6 +29,7 @@ namespace {

unsigned getRelocType(const MCValue &Target, const MCFixup &Fixup,
bool IsCrossSection,
+ bool IsPCRel,
const MCAsmBackend &MAB) const override;
};
}
@@ -42,6 +43,7 @@ X86WinCOFFObjectWriter::~X86WinCOFFObjec
unsigned X86WinCOFFObjectWriter::getRelocType(const MCValue &Target,
const MCFixup &Fixup,
bool IsCrossSection,
+ bool IsPCRel,
const MCAsmBackend &MAB) const {
unsigned FixupKind = IsCrossSection ? FK_PCRel_4 : Fixup.getKind();

@@ -55,6 +57,11 @@ unsigned X86WinCOFFObjectWriter::getRelo
case X86::reloc_riprel_4byte_movq_load:
return COFF::IMAGE_REL_AMD64_REL32;
case FK_Data_4:
+ if (IsPCRel)
+ return COFF::IMAGE_REL_AMD64_REL32;
+ if (Modifier == MCSymbolRefExpr::VK_COFF_IMGREL32)
+ return COFF::IMAGE_REL_AMD64_ADDR32NB;
+ return COFF::IMAGE_REL_AMD64_SECREL;
case X86::reloc_signed_4byte:
if (Modifier == MCSymbolRefExpr::VK_COFF_IMGREL32)
return COFF::IMAGE_REL_AMD64_ADDR32NB;

0 comments on commit a485acf

Please sign in to comment.