Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

statepoints instead of the shadow stack #16847

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Make.inc
Original file line number Diff line number Diff line change
Expand Up @@ -687,9 +687,11 @@ endif
ifeq ($(OS),WINNT)
LIBUNWIND:=
else
# -lunwind must come _before_ -lunwind-generic to avoid
# shadowing the actual _U_dyn_info_list_addr with a weak definition
ifeq ($(USE_SYSTEM_LIBUNWIND), 1)
ifneq ($(OS),Darwin)
LIBUNWIND:=-lunwind-generic -lunwind
LIBUNWIND:=-lunwind -lunwind-generic
# Only for linux since we want to use not yet released libunwind features
JCFLAGS+=-DSYSTEM_LIBUNWIND
JCPPFLAGS+=-DSYSTEM_LIBUNWIND
Expand All @@ -699,7 +701,7 @@ ifeq ($(OS),Darwin)
LIBUNWIND:=$(build_libdir)/libosxunwind.a
JCPPFLAGS+=-DLIBOSXUNWIND
else
LIBUNWIND:=$(build_libdir)/libunwind-generic.a $(build_libdir)/libunwind.a
LIBUNWIND:=$(build_libdir)/libunwind.a $(build_libdir)/libunwind-generic.a
endif
endif
endif
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ $(build_sysconfdir)/julia/juliarc.jl: $(JULIAHOME)/contrib/windows/juliarc.jl
endif

$(build_private_libdir)/%.$(SHLIB_EXT): $(build_private_libdir)/%.o
objcopy --globalize-symbol __LLVM_StackMaps $<
Copy link
Contributor

Choose a reason for hiding this comment

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

osx binutils doesn't have objcopy, and for cross-compile it would need the cross prefix

@$(call PRINT_LINK, $(CXX) $(LDFLAGS) -shared $(fPIC) -L$(build_private_libdir) -L$(build_libdir) -L$(build_shlibdir) -o $@ $< \
$(if $(findstring -debug.$(SHLIB_EXT),$(notdir $@)),-ljulia-debug,-ljulia) \
$$([ $(OS) = WINNT ] && echo '' -lssp))
Expand Down
16 changes: 16 additions & 0 deletions deps/libunwind-remote-unw-hack.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
diff -ur libunwind-1.1-julia2/src/mi/Gfind_dynamic_proc_info.c libunwind-1.1-julia2.MINE/src/mi/Gfind_dynamic_proc_info.c
--- libunwind-1.1-julia2/src/mi/Gfind_dynamic_proc_info.c 2016-01-06 07:48:23.000000000 -0500
+++ libunwind-1.1-julia2.MINE/src/mi/Gfind_dynamic_proc_info.c 2016-06-06 08:37:55.364416906 -0400
@@ -84,8 +84,8 @@
unw_proc_info_t *pi, int need_unwind_info,
void *arg)
{
- if (as == unw_local_addr_space)
+ //if (as == unw_local_addr_space)
return local_find_proc_info (as, ip, pi, need_unwind_info, arg);
- else
- return remote_find_proc_info (as, ip, pi, need_unwind_info, arg);
+ /*else
+ return remote_find_proc_info (as, ip, pi, need_unwind_info, arg);*/
}
Only in libunwind-1.1-julia2.MINE/src/mi: Gfind_dynamic_proc_info.c~
2 changes: 2 additions & 0 deletions deps/llvm.mk
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,8 @@ $(eval $(call LLVM_PATCH,llvm-D17712))
$(eval $(call LLVM_PATCH,llvm-PR26180))
$(eval $(call LLVM_PATCH,llvm-PR27046))
$(eval $(call LLVM_PATCH,llvm-3.8.0_ppc64_SUBFC8))
else ifeq ($(LLVM_VER),svn)
$(eval $(call LLVM_PATCH,llvm-3.9_statepoint))
endif # LLVM_VER

ifeq ($(LLVM_VER),3.7.1)
Expand Down
41 changes: 41 additions & 0 deletions deps/patches/llvm-3.9_statepoint.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
diff --git a/lib/Analysis/AliasAnalysis.cpp b/lib/Analysis/AliasAnalysis.cpp
index 117f8cb..263dd48 100644
--- a/lib/Analysis/AliasAnalysis.cpp
+++ b/lib/Analysis/AliasAnalysis.cpp
@@ -445,7 +445,7 @@ ModRefInfo AAResults::callCapturesBefore(const Instruction *I,

unsigned ArgNo = 0;
ModRefInfo R = MRI_NoModRef;
- for (ImmutableCallSite::arg_iterator CI = CS.arg_begin(), CE = CS.arg_end();
+ for (auto CI = CS.data_operands_begin(), CE = CS.data_operands_end();
CI != CE; ++CI, ++ArgNo) {
// Only look at the no-capture or byval pointer arguments. If this
// pointer were passed to arguments that were neither of these, then it
diff --git a/lib/CodeGen/PrologEpilogInserter.cpp b/lib/CodeGen/PrologEpilogInserter.cpp
index be3e5e2..6064e6f 100644
--- a/lib/CodeGen/PrologEpilogInserter.cpp
+++ b/lib/CodeGen/PrologEpilogInserter.cpp
@@ -1094,7 +1094,7 @@ void PEI::replaceFrameIndices(MachineBasicBlock *BB, MachineFunction &Fn,
unsigned Reg;
MachineOperand &Offset = MI->getOperand(i + 1);
const unsigned refOffset =
- TFI->getFrameIndexReferenceFromSP(Fn, MI->getOperand(i).getIndex(),
+ TFI->getFrameIndexReference(Fn, MI->getOperand(i).getIndex(),
Reg);

Offset.setImm(Offset.getImm() + refOffset);
diff --git a/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
index 6a727a1..5defd28 100644
--- a/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
+++ b/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
@@ -7180,8 +7180,8 @@ void SelectionDAGBuilder::populateCallLoweringInfo(

// Populate the argument list.
// Attributes for args start at offset 1, after the return attribute.
- for (unsigned ArgI = ArgIdx, ArgE = ArgIdx + NumArgs, AttrI = ArgIdx + 1;
- ArgI != ArgE; ++ArgI) {
+ for (unsigned ArgI = ArgIdx, ArgE = ArgIdx + NumArgs, AttrI = ArgIdx+1;
+ ArgI != ArgE; ++ArgI, ++AttrI) {
const Value *V = CS->getOperand(ArgI);

assert(!V->getType()->isEmptyTy() && "Empty type passed to intrinsic.");
1 change: 1 addition & 0 deletions deps/unwind.mk
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ $(SRCDIR)/srccache/libunwind-$(UNWIND_VER).tar.gz: | $(SRCDIR)/srccache
$(SRCDIR)/srccache/libunwind-$(UNWIND_VER)/configure: $(SRCDIR)/srccache/libunwind-$(UNWIND_VER).tar.gz
$(JLCHECKSUM) $<
cd $(dir $<) && $(TAR) xfz $<
patch -d $(SRCDIR)/srccache -p0 < $(SRCDIR)/libunwind-remote-unw-hack.diff
touch -c $@
$(BUILDDIR)/libunwind-$(UNWIND_VER)/config.status: $(SRCDIR)/srccache/libunwind-$(UNWIND_VER)/configure
mkdir -p $(dir $@)
Expand Down
2 changes: 1 addition & 1 deletion src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ $(BUILDDIR)/anticodegen.o $(BUILDDIR)/anticodegen.dbg.obj: $(SRCDIR)/intrinsics.
$(BUILDDIR)/debuginfo.o $(BUILDDIR)/debuginfo.dbg.obj: $(SRCDIR)/codegen_internal.h
$(BUILDDIR)/disasm.o $(BUILDDIR)/disasm.dbg.obj: $(SRCDIR)/codegen_internal.h
$(BUILDDIR)/builtins.o $(BUILDDIR)/builtins.dbg.obj: $(SRCDIR)/table.c
$(BUILDDIR)/gc.o $(BUILDDIR)/gc.dbg.obj: $(SRCDIR)/gc.h
$(BUILDDIR)/gc.o $(BUILDDIR)/gc.dbg.obj: $(SRCDIR)/gc.h $(SRCDIR)/gc-stackmaps.c
$(BUILDDIR)/gc-debug.o $(BUILDDIR)/gc-debug.dbg.obj: $(SRCDIR)/gc.h
$(BUILDDIR)/gc-pages.o $(BUILDDIR)/gc-pages.dbg.obj: $(SRCDIR)/gc.h
$(BUILDDIR)/signal-handling.o $(BUILDDIR)/signal-handling.dbg.obj: $(addprefix $(SRCDIR)/,signals-*.c)
Expand Down
7 changes: 4 additions & 3 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5658,6 +5658,7 @@ static inline SmallVector<std::string,10> getTargetFeatures() {
}
return attr;
}
#include <llvm/CodeGen/LinkAllCodegenComponents.h>

extern "C" void jl_init_codegen(void)
{
Expand All @@ -5670,7 +5671,7 @@ extern "C" void jl_init_codegen(void)
#ifdef JL_DEBUG_BUILD
cl::ParseEnvironmentOptions("Julia", "JULIA_LLVM_ARGS");
#endif

llvm::linkStatepointExampleGC();
imaging_mode = jl_generating_output();
jl_init_debuginfo();
jl_init_runtime_ccall();
Expand Down Expand Up @@ -5778,8 +5779,8 @@ extern "C" void jl_init_codegen(void)
" Is the LLVM backend for this CPU enabled?");
#if defined(USE_MCJIT) && (!defined(_CPU_ARM_) && !defined(_CPU_PPC64_))
// FastISel seems to be buggy for ARM. Ref #13321
if (jl_options.opt_level < 3)
jl_TargetMachine->setFastISel(true);
//if (jl_options.opt_level < 3)
// jl_TargetMachine->setFastISel(true);
#endif

#ifdef USE_ORCJIT
Expand Down
14 changes: 12 additions & 2 deletions src/debuginfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ using namespace llvm;
#include "julia_internal.h"
#include "codegen_internal.h"
#ifdef _OS_LINUX_
# define UNW_LOCAL_ONLY
//# define UNW_LOCAL_ONLY
Copy link
Contributor Author

Choose a reason for hiding this comment

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

(note this is probably not needed here, I'm not sure anymore I'll have to check)

# include <libunwind.h>
# include <link.h>
#endif
Expand Down Expand Up @@ -233,7 +233,7 @@ void jl_callback_triggered_linfos(void)
jl_call_tracer(jl_linfo_tracer, (jl_value_t*)linfo);
}
}

#include <iostream>
class JuliaJITEventListener: public JITEventListener
{
#ifndef USE_MCJIT
Expand Down Expand Up @@ -322,12 +322,22 @@ class JuliaJITEventListener: public JITEventListener

#ifdef LLVM38
std::map<StringRef,object::SectionRef,strrefcomp> loadedSections;
uint8_t *text_addr = NULL, *stackmaps_addr = NULL;
size_t text_size = 0;
for (const object::SectionRef &lSection: obj.sections()) {
StringRef sName;
if (!lSection.getName(sName)) {
loadedSections[sName] = lSection;
if (sName == ".llvm_stackmaps") {
stackmaps_addr = (uint8_t*)L.getSectionLoadAddress(lSection);
} else if (sName == ".text") {
text_addr = (uint8_t*)L.getSectionLoadAddress(lSection);
text_size = lSection.getSize();
}
}
}
if (stackmaps_addr)
jl_gc_register_stackmaps(stackmaps_addr);
auto getLoadAddress = [&] (const StringRef &sName) -> uint64_t {
auto search = loadedSections.find(sName);
if (search == loadedSections.end())
Expand Down
2 changes: 1 addition & 1 deletion src/disasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ void jl_dump_asm_internal(uintptr_t Fptr, size_t Fsize, int64_t slide,
MCContext Ctx(*MAI, *MRI, MOFI.get(), &SrcMgr);
#endif
#ifdef LLVM39
MOFI->InitMCObjectFileInfo(TheTriple, /* PIC */ false,
MOFI->InitMCObjectFileInfo(TheTriple, false,
CodeModel::Default, Ctx);
#elif defined(LLVM37)
MOFI->InitMCObjectFileInfo(TheTriple, Reloc::Default, CodeModel::Default, Ctx);
Expand Down
1 change: 1 addition & 0 deletions src/dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ static int jl_load_sysimg_so(void)
}
#endif
}
jl_gc_register_stackmaps((uint8_t*)jl_dlsym_e(jl_sysimg_handle, "__LLVM_StackMaps"));
const char *sysimg_data = (const char*)jl_dlsym_e(jl_sysimg_handle, "jl_system_image_data");
if (sysimg_data) {
size_t len = *(size_t*)jl_dlsym(jl_sysimg_handle, "jl_system_image_size");
Expand Down
Loading