Skip to content

Commit

Permalink
Merge pull request #15859 from JuliaLang/jn/win64dwarf
Browse files Browse the repository at this point in the history
patch llvm to give correct win64 DWARF relocations
  • Loading branch information
vtjnash authored Jun 29, 2016
2 parents 05f2e31 + 664f8b7 commit cfc10f0
Show file tree
Hide file tree
Showing 2 changed files with 165 additions and 0 deletions.
2 changes: 2 additions & 0 deletions deps/llvm.mk
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ $(eval $(call LLVM_PATCH,llvm-3.8.0_bindir))
$(eval $(call LLVM_PATCH,llvm-D14260))
$(eval $(call LLVM_PATCH,llvm-nodllalias))
$(eval $(call LLVM_PATCH,llvm-D21271-instcombine-tbaa-3.7))
$(eval $(call LLVM_PATCH,llvm-win64-reloc-dwarf))

This comment has been minimized.

Copy link
@kmsquire

kmsquire Jun 29, 2016

Member

This patch does not apply cleanly to llvm-3.7.1:

~/src/julia/deps$ make compile-llvm
/Users/kevin/Source/julia/deps/tools/jldownload /Users/kevin/Source/julia/deps/srccache/llvm-3.7.1.src.tar.xz http://llvm.org/releases/3.7.1/llvm-3.7.1.src.tar.xz
...
cd /Users/kevin/Source/julia/deps/srccache/llvm-3.7.1 && patch -p1 < /Users/kevin/Source/julia/deps/patches/llvm-win64-reloc-dwarf.patch
patching file include/llvm/MC/MCStreamer.h
patching file include/llvm/MC/MCWinCOFFStreamer.h
patching file lib/CodeGen/AsmPrinter/AsmPrinter.cpp
Hunk #1 succeeded at 1598 (offset -131 lines).
patching file lib/CodeGen/AsmPrinter/AsmPrinterDwarf.cpp
Hunk #1 succeeded at 162 (offset 12 lines).
patching file lib/CodeGen/AsmPrinter/DIE.cpp
Hunk #1 succeeded at 457 (offset -30 lines).
patching file lib/CodeGen/AsmPrinter/WinCodeViewLineTables.cpp
Hunk #1 succeeded at 221 (offset -10 lines).
Hunk #2 succeeded at 262 (offset -10 lines).
patching file lib/MC/MCAsmStreamer.cpp
Hunk #1 succeeded at 138 (offset -5 lines).
Hunk #2 succeeded at 514 (offset -11 lines).
patching file lib/MC/MCParser/COFFAsmParser.cpp
Hunk #1 succeeded at 451 (offset 1 line).
patching file lib/MC/MCStreamer.cpp
Hunk #1 succeeded at 120 (offset 1 line).
Hunk #2 succeeded at 562 (offset -8 lines).
patching file lib/MC/WinCOFFStreamer.cpp
Hunk #1 FAILED at 199.
1 out of 1 hunk FAILED -- saving rejects to file lib/MC/WinCOFFStreamer.cpp.rej
/Users/kevin/Source/julia/deps/llvm.mk:433: recipe for target '/Users/kevin/Source/julia/deps/srccache/llvm-3.7.1/llvm-win64-reloc-dwarf.patch-applied' failed
make: *** [/Users/kevin/Source/julia/deps/srccache/llvm-3.7.1/llvm-win64-reloc-dwarf.patch-applied] Error 1

This comment has been minimized.

Copy link
@kmsquire

kmsquire Jun 29, 2016

Member

(Already noted by @tkelman here)

This comment has been minimized.

Copy link
@tkelman

tkelman Jun 29, 2016

Contributor
else ifeq ($(LLVM_VER),3.8.0)
$(eval $(call LLVM_PATCH,llvm-3.7.1_3))
$(eval $(call LLVM_PATCH,llvm-D14260))
Expand All @@ -447,6 +448,7 @@ $(eval $(call LLVM_PATCH,llvm-PR26180))
$(eval $(call LLVM_PATCH,llvm-PR27046))
$(eval $(call LLVM_PATCH,llvm-3.8.0_ppc64_SUBFC8))
$(eval $(call LLVM_PATCH,llvm-D21271-instcombine-tbaa-3.8))
$(eval $(call LLVM_PATCH,llvm-win64-reloc-dwarf))
endif # LLVM_VER

ifeq ($(LLVM_VER),3.7.1)
Expand Down
163 changes: 163 additions & 0 deletions deps/patches/llvm-win64-reloc-dwarf.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
diff -rpu llvm-3.8.0/include/llvm/MC/MCStreamer.h llvm-3.8.0-reloc/include/llvm/MC/MCStreamer.h
--- llvm-3.8.0/include/llvm/MC/MCStreamer.h 2016-01-12 08:38:15.000000000 -0500
+++ llvm-3.8.0-reloc/include/llvm/MC/MCStreamer.h 2016-05-23 18:54:01.830143100 -0400
@@ -456,7 +456,7 @@ public:
/// \brief Emits a COFF section relative relocation.
///
/// \param Symbol - Symbol the section relative relocation should point to.
- virtual void EmitCOFFSecRel32(MCSymbol const *Symbol);
+ virtual void EmitCOFFSecRel32(MCSymbol const *Symbol, uint64_t Offset);

/// \brief Emit an ELF .size directive.
///
diff -rpu llvm-3.8.0/include/llvm/MC/MCWinCOFFStreamer.h llvm-3.8.0-reloc/include/llvm/MC/MCWinCOFFStreamer.h
--- llvm-3.8.0/include/llvm/MC/MCWinCOFFStreamer.h 2015-11-17 05:00:43.000000000 -0500
+++ llvm-3.8.0-reloc/include/llvm/MC/MCWinCOFFStreamer.h 2016-05-23 18:54:01.845722400 -0400
@@ -52,7 +52,7 @@ public:
void EndCOFFSymbolDef() override;
void EmitCOFFSafeSEH(MCSymbol const *Symbol) override;
void EmitCOFFSectionIndex(MCSymbol const *Symbol) override;
- void EmitCOFFSecRel32(MCSymbol const *Symbol) override;
+ void EmitCOFFSecRel32(MCSymbol const *Symbol, uint64_t Offset) override;
void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
unsigned ByteAlignment) override;
void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
diff -rpu llvm-3.8.0/lib/CodeGen/AsmPrinter/AsmPrinter.cpp llvm-3.8.0-reloc/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
--- llvm-3.8.0/lib/CodeGen/AsmPrinter/AsmPrinter.cpp 2016-01-12 20:18:13.000000000 -0500
+++ llvm-3.8.0-reloc/lib/CodeGen/AsmPrinter/AsmPrinter.cpp 2016-05-23 18:54:01.845722400 -0400
@@ -1729,7 +1729,7 @@ void AsmPrinter::EmitLabelPlusOffset(con
unsigned Size,
bool IsSectionRelative) const {
if (MAI->needsDwarfSectionOffsetDirective() && IsSectionRelative) {
- OutStreamer->EmitCOFFSecRel32(Label);
+ OutStreamer->EmitCOFFSecRel32(Label, Offset);
return;
}

diff -rpu llvm-3.8.0/lib/CodeGen/AsmPrinter/AsmPrinterDwarf.cpp llvm-3.8.0-reloc/lib/CodeGen/AsmPrinter/AsmPrinterDwarf.cpp
--- llvm-3.8.0/lib/CodeGen/AsmPrinter/AsmPrinterDwarf.cpp 2015-11-17 19:34:10.000000000 -0500
+++ llvm-3.8.0-reloc/lib/CodeGen/AsmPrinter/AsmPrinterDwarf.cpp 2016-05-23 20:17:42.105695800 -0400
@@ -150,7 +150,7 @@ void AsmPrinter::emitDwarfSymbolReferenc
if (!ForceOffset) {
// On COFF targets, we have to emit the special .secrel32 directive.
if (MAI->needsDwarfSectionOffsetDirective()) {
- OutStreamer->EmitCOFFSecRel32(Label);
+ OutStreamer->EmitCOFFSecRel32(Label, /*offset*/0);
return;
}

diff -rpu llvm-3.8.0/lib/CodeGen/AsmPrinter/DIE.cpp llvm-3.8.0-reloc/lib/CodeGen/AsmPrinter/DIE.cpp
--- llvm-3.8.0/lib/CodeGen/AsmPrinter/DIE.cpp 2016-01-07 09:28:20.000000000 -0500
+++ llvm-3.8.0-reloc/lib/CodeGen/AsmPrinter/DIE.cpp 2016-05-23 19:08:35.434799900 -0400
@@ -487,7 +487,7 @@ void DIEEntry::EmitValue(const AsmPrinte
Addr += CU->getDebugInfoOffset();
if (AP->MAI->doesDwarfUseRelocationsAcrossSections())
AP->EmitLabelPlusOffset(CU->getSectionSym(), Addr,
- DIEEntry::getRefAddrSize(AP));
+ DIEEntry::getRefAddrSize(AP), true);
else
AP->OutStreamer->EmitIntValue(Addr, DIEEntry::getRefAddrSize(AP));
} else
diff -rpu llvm-3.8.0/lib/CodeGen/AsmPrinter/WinCodeViewLineTables.cpp llvm-3.8.0-reloc/lib/CodeGen/AsmPrinter/WinCodeViewLineTables.cpp
--- llvm-3.8.0/lib/CodeGen/AsmPrinter/WinCodeViewLineTables.cpp 2016-01-12 20:05:23.000000000 -0500
+++ llvm-3.8.0-reloc/lib/CodeGen/AsmPrinter/WinCodeViewLineTables.cpp 2016-05-23 21:19:31.454460900 -0400
@@ -231,7 +231,7 @@ void WinCodeViewLineTables::emitDebugInf
// code is located and what's its size:
EmitLabelDiff(*Asm->OutStreamer, Fn, FI.End);
Asm->OutStreamer->EmitFill(12, 0);
- Asm->OutStreamer->EmitCOFFSecRel32(Fn);
+ Asm->OutStreamer->EmitCOFFSecRel32(Fn, /*offset*/0);
Asm->OutStreamer->EmitCOFFSectionIndex(Fn);
Asm->EmitInt8(0);
// Emit the function display name as a null-terminated string.
@@ -272,7 +272,7 @@ void WinCodeViewLineTables::emitDebugInf
Asm->OutStreamer->EmitLabel(LineTableBegin);

// Identify the function this subsection is for.
- Asm->OutStreamer->EmitCOFFSecRel32(Fn);
+ Asm->OutStreamer->EmitCOFFSecRel32(Fn, /*offset*/0);
Asm->OutStreamer->EmitCOFFSectionIndex(Fn);
// Insert flags after a 16-bit section index.
Asm->EmitInt16(COFF::DEBUG_LINE_TABLES_HAVE_COLUMN_RECORDS);
diff -rpu llvm-3.8.0/lib/MC/MCAsmStreamer.cpp llvm-3.8.0-reloc/lib/MC/MCAsmStreamer.cpp
--- llvm-3.8.0/lib/MC/MCAsmStreamer.cpp 2015-11-12 08:33:00.000000000 -0500
+++ llvm-3.8.0-reloc/lib/MC/MCAsmStreamer.cpp 2016-05-23 18:54:01.859727900 -0400
@@ -143,7 +143,7 @@ public:
void EndCOFFSymbolDef() override;
void EmitCOFFSafeSEH(MCSymbol const *Symbol) override;
void EmitCOFFSectionIndex(MCSymbol const *Symbol) override;
- void EmitCOFFSecRel32(MCSymbol const *Symbol) override;
+ void EmitCOFFSecRel32(MCSymbol const *Symbol, uint64_t Offset) override;
void emitELFSize(MCSymbolELF *Symbol, const MCExpr *Value) override;
void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
unsigned ByteAlignment) override;
@@ -525,7 +525,7 @@ void MCAsmStreamer::EmitCOFFSectionIndex
EmitEOL();
}

-void MCAsmStreamer::EmitCOFFSecRel32(MCSymbol const *Symbol) {
+void MCAsmStreamer::EmitCOFFSecRel32(MCSymbol const *Symbol, uint64_t Offset) {
OS << "\t.secrel32\t";
Symbol->print(OS, MAI);
EmitEOL();
diff -rpu llvm-3.8.0/lib/MC/MCParser/COFFAsmParser.cpp llvm-3.8.0-reloc/lib/MC/MCParser/COFFAsmParser.cpp
--- llvm-3.8.0/lib/MC/MCParser/COFFAsmParser.cpp 2015-11-18 01:02:15.000000000 -0500
+++ llvm-3.8.0-reloc/lib/MC/MCParser/COFFAsmParser.cpp 2016-05-23 18:54:15.937859600 -0400
@@ -450,7 +450,7 @@ bool COFFAsmParser::ParseDirectiveSecRel
MCSymbol *Symbol = getContext().getOrCreateSymbol(SymbolID);

Lex();
- getStreamer().EmitCOFFSecRel32(Symbol);
+ getStreamer().EmitCOFFSecRel32(Symbol, /*Offset=*/0);
return false;
}

diff -rpu llvm-3.8.0/lib/MC/MCStreamer.cpp llvm-3.8.0-reloc/lib/MC/MCStreamer.cpp
--- llvm-3.8.0/lib/MC/MCStreamer.cpp 2015-11-04 18:59:18.000000000 -0500
+++ llvm-3.8.0-reloc/lib/MC/MCStreamer.cpp 2016-05-23 18:54:15.953281800 -0400
@@ -119,7 +119,7 @@ void MCStreamer::EmitSymbolValue(const M
if (!IsSectionRelative)
EmitValueImpl(MCSymbolRefExpr::create(Sym, getContext()), Size);
else
- EmitCOFFSecRel32(Sym);
+ EmitCOFFSecRel32(Sym, /*Offset=*/0);
}

void MCStreamer::EmitGPRel64Value(const MCExpr *Value) {
@@ -570,7 +570,7 @@ void MCStreamer::EmitCOFFSafeSEH(MCSymbo
void MCStreamer::EmitCOFFSectionIndex(MCSymbol const *Symbol) {
}

-void MCStreamer::EmitCOFFSecRel32(MCSymbol const *Symbol) {
+void MCStreamer::EmitCOFFSecRel32(MCSymbol const *Symbol, uint64_t Offset) {
}

/// EmitRawText - If this file is backed by an assembly streamer, this dumps
diff -rpu llvm-3.8.0/lib/MC/WinCOFFStreamer.cpp llvm-3.8.0-reloc/lib/MC/WinCOFFStreamer.cpp
--- llvm-3.8.0/lib/MC/WinCOFFStreamer.cpp 2015-11-17 05:00:43.000000000 -0500
+++ llvm-3.8.0-reloc/lib/MC/WinCOFFStreamer.cpp 2016-06-25 22:00:26.530421900 -0400
@@ -199,14 +199,21 @@ void MCWinCOFFStreamer::EmitCOFFSectionI
DF->getContents().resize(DF->getContents().size() + 2, 0);
}

-void MCWinCOFFStreamer::EmitCOFFSecRel32(MCSymbol const *Symbol) {
+void MCWinCOFFStreamer::EmitCOFFSecRel32(MCSymbol const *Symbol, uint64_t Offset) {
MCDataFragment *DF = getOrCreateDataFragment();
- const MCSymbolRefExpr *SRE = MCSymbolRefExpr::create(Symbol, getContext());
- MCFixup Fixup = MCFixup::create(DF->getContents().size(), SRE, FK_SecRel_4);
+ // Create Symbol A for the relocation relative reference.
+ const MCExpr *MCE = MCSymbolRefExpr::create(Symbol, getContext());
+ // Add the constant offset, if given
+ if (Offset)
+ MCE = MCBinaryExpr::createAdd(MCE, MCConstantExpr::create(Offset, getContext()), getContext());
+ // Build the secrel32 relocation.
+ MCFixup Fixup = MCFixup::create(DF->getContents().size(), MCE, FK_SecRel_4);
+ // Record the relocation.
DF->getFixups().push_back(Fixup);
+ // Emit 4 bytes (zeros) to the object file.
DF->getContents().resize(DF->getContents().size() + 4, 0);
}

void MCWinCOFFStreamer::EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
unsigned ByteAlignment) {
assert((!Symbol->isInSection() ||

2 comments on commit cfc10f0

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Executing the daily benchmark build, I will reply here when finished:

@nanosoldier runbenchmarks(ALL, isdaily = true)

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your benchmark job has completed - possible performance regressions were detected. A full report can be found here. cc @jrevels

Please sign in to comment.