Skip to content

Commit

Permalink
determine jl_in_sysimg based on memory location rather than file name
Browse files Browse the repository at this point in the history
  • Loading branch information
vtjnash committed Nov 29, 2014
1 parent 2a3aa77 commit a140c6b
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 111 deletions.
104 changes: 52 additions & 52 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,88 +20,88 @@
#endif

#include "llvm-version.h"
#include "llvm/ExecutionEngine/ExecutionEngine.h"
#include "llvm/ExecutionEngine/JITEventListener.h"
#include "llvm/PassManager.h"
#include "llvm/Target/TargetLibraryInfo.h"
#include "llvm/Support/TargetRegistry.h"
#include "llvm/Analysis/Passes.h"
#include "llvm/Bitcode/ReaderWriter.h"
#include <llvm/ExecutionEngine/ExecutionEngine.h>
#include <llvm/ExecutionEngine/JITEventListener.h>
#include <llvm/PassManager.h>
#include <llvm/Target/TargetLibraryInfo.h>
#include <llvm/Support/TargetRegistry.h>
#include <llvm/Analysis/Passes.h>
#include <llvm/Bitcode/ReaderWriter.h>
#ifdef _OS_DARWIN_
#include "llvm/Object/MachO.h"
#include <llvm/Object/MachO.h>
#endif
#ifdef _OS_WINDOWS_
#include "llvm/Object/COFF.h"
#include <llvm/Object/COFF.h>
#endif
#ifndef LLVM36
#include "llvm/ExecutionEngine/JITMemoryManager.h"
#include <llvm/ExecutionEngine/JITMemoryManager.h>
#endif
#ifdef LLVM35
#include "llvm/IR/Verifier.h"
#include "llvm/Object/ObjectFile.h"
#include "llvm/IR/DIBuilder.h"
#include "llvm/Target/TargetMachine.h"
#include <llvm/IR/Verifier.h>
#include <llvm/Object/ObjectFile.h>
#include <llvm/IR/DIBuilder.h>
#include <llvm/Target/TargetMachine.h>
#include <llvm/AsmParser/Parser.h>
#else
#include <llvm/Assembly/Parser.h>
#include "llvm/Analysis/Verifier.h"
#include <llvm/Analysis/Verifier.h>
#endif
#include "llvm/DebugInfo/DIContext.h"
#include <llvm/DebugInfo/DIContext.h>
#ifdef USE_MCJIT
#include "llvm/ExecutionEngine/MCJIT.h"
#include "llvm/ExecutionEngine/SectionMemoryManager.h"
#include "llvm/ExecutionEngine/ObjectImage.h"
#include "llvm/ADT/DenseMapInfo.h"
#include "llvm/Object/ObjectFile.h"
#include <llvm/ExecutionEngine/MCJIT.h>
#include <llvm/ExecutionEngine/SectionMemoryManager.h>
#include <llvm/ExecutionEngine/ObjectImage.h>
#include <llvm/ADT/DenseMapInfo.h>
#include <llvm/Object/ObjectFile.h>
#else
#include "llvm/ExecutionEngine/JIT.h"
#include <llvm/ExecutionEngine/JIT.h>
#endif
#ifdef LLVM33
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Intrinsics.h"
#include "llvm/IR/Attributes.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/MDBuilder.h"
#include <llvm/IR/DerivedTypes.h>
#include <llvm/IR/LLVMContext.h>
#include <llvm/IR/Module.h>
#include <llvm/IR/Intrinsics.h>
#include <llvm/IR/Attributes.h>
#include <llvm/IR/IRBuilder.h>
#include <llvm/IR/MDBuilder.h>
#else
#include "llvm/DerivedTypes.h"
#include "llvm/LLVMContext.h"
#include "llvm/Module.h"
#include "llvm/Intrinsics.h"
#include "llvm/Attributes.h"
#include <llvm/DerivedTypes.h>
#include <llvm/LLVMContext.h>
#include <llvm/Module.h>
#include <llvm/Intrinsics.h>
#include <llvm/Attributes.h>
#endif
#ifdef LLVM32
#ifndef LLVM35
#include "llvm/DebugInfo.h"
#include "llvm/DIBuilder.h"
#include <llvm/DebugInfo.h>
#include <llvm/DIBuilder.h>
#endif
#ifndef LLVM33
#include "llvm/IRBuilder.h"
#include <llvm/IRBuilder.h>
#endif
#else // LLVM31 and before
#include "llvm/Analysis/DebugInfo.h"
#include "llvm/Analysis/DIBuilder.h"
#include "llvm/Target/TargetData.h"
#include "llvm/Support/IRBuilder.h"
#include <llvm/Analysis/DebugInfo.h>
#include <llvm/Analysis/DIBuilder.h>
#include <llvm/Target/TargetData.h>
#include <llvm/Support/IRBuilder.h>
#endif
#include "llvm/Target/TargetOptions.h"
#include "llvm/Transforms/Scalar.h"
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
#include "llvm/Transforms/Instrumentation.h"
#include <llvm/Target/TargetOptions.h>
#include <llvm/Transforms/Scalar.h>
#include <llvm/Transforms/Utils/BasicBlockUtils.h>
#include <llvm/Transforms/Instrumentation.h>
#ifdef LLVM31
#include "llvm/Transforms/Vectorize.h"
#include <llvm/Transforms/Vectorize.h>
#endif
#include "llvm/Support/TargetSelect.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/FormattedStream.h"
#include "llvm/Support/DynamicLibrary.h"
#include <llvm/Support/TargetSelect.h>
#include <llvm/Support/raw_ostream.h>
#include <llvm/Support/FormattedStream.h>
#include <llvm/Support/DynamicLibrary.h>
#include <llvm/Support/PrettyStackTrace.h>
#include <llvm/Support/SourceMgr.h>
#ifdef JL_DEBUG_BUILD
#include "llvm/Support/CommandLine.h"
#include <llvm/Support/CommandLine.h>
#endif
#include "llvm/Transforms/Utils/Cloning.h"
#include <llvm/Transforms/Utils/Cloning.h>

#if defined(_OS_WINDOWS_) && !defined(NOMINMAX)
#define NOMINMAX
Expand Down
80 changes: 34 additions & 46 deletions src/debuginfo.cpp
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
#include "platform.h"

#include "llvm-version.h"
#include "llvm/ExecutionEngine/ExecutionEngine.h"
#include "llvm/ExecutionEngine/JITEventListener.h"
#include "llvm/DebugInfo/DIContext.h"
#include <llvm/ExecutionEngine/ExecutionEngine.h>
#include <llvm/ExecutionEngine/JITEventListener.h>
#include <llvm/DebugInfo/DIContext.h>
#include <llvm/Support/MemoryBuffer.h>
#ifdef LLVM33
#include "llvm/IR/Function.h"
#include "llvm/ADT/StringRef.h"
#include <llvm/IR/Function.h>
#include <llvm/ADT/StringRef.h>
#else
#include "llvm/Function.h"
#include <llvm/Function.h>
#endif
#ifdef LLVM35
#include "llvm/IR/DebugInfo.h"
#include <llvm/IR/DebugInfo.h>
#elif defined(LLVM32)
#include "llvm/DebugInfo.h"
#include <llvm/DebugInfo.h>
#else
#include "llvm/Analysis/DebugInfo.h"
#include <llvm/Analysis/DebugInfo.h>
#endif

#include "julia.h"
#include "julia_internal.h"

#include <string>
#include <sstream>
Expand Down Expand Up @@ -60,7 +61,6 @@ struct ObjectInfo {
extern "C" EXCEPTION_DISPOSITION _seh_exception_handler(PEXCEPTION_RECORD ExceptionRecord,void *EstablisherFrame, PCONTEXT ContextRecord, void *DispatcherContext);
#endif
#include <dbghelp.h>
extern "C" volatile int jl_in_stackwalk;
static void create_PRUNTIME_FUNCTION(uint8_t *Code, size_t Size, StringRef fnname,
uint8_t *Section, size_t Allocated)
{
Expand Down Expand Up @@ -331,48 +331,29 @@ bool getObjUUID(llvm::object::MachOObjectFile *obj, uint8_t uuid[16])
}
#endif

extern "C" char *jl_sysimage_name;

bool jl_is_sysimg(const char *path)
{
if (!jl_sysimage_name)
return 0;
const char *filename = strrchr(path,'/');
if (filename == NULL)
filename = path;
const char *sysimgname = strrchr(jl_sysimage_name,'/');
if (sysimgname == NULL)
sysimgname = jl_sysimage_name;
return strncmp(filename,sysimgname,strrchr(path,'.')-filename) == 0;
}
extern "C" uint64_t jl_sysimage_base;

void jl_getDylibFunctionInfo(const char **name, size_t *line, const char **filename, size_t pointer, int *fromC, int skipC)
{
#ifdef _OS_WINDOWS_
char *fname = 0;
DWORD64 fbase;
printf("pointer: %llx\n", (long long)pointer);
DWORD64 fbase = 0;
if (!jl_in_stackwalk) {
jl_in_stackwalk = 1;
fbase = SymGetModuleBase64(GetCurrentProcess(),(DWORD)pointer);
fbase = SymGetModuleBase64(GetCurrentProcess(),(DWORD64)pointer);
jl_in_stackwalk = 0;
printf("fbase: %llx\n", fbase);
}
if (fbase != 0) {
*fromC = (fbase != jl_sysimage_base);
if (skipC && *fromC) {
return;
}
IMAGEHLP_MODULE64 ModuleInfo;
ModuleInfo.SizeOfStruct = sizeof(IMAGEHLP_MODULE64);
jl_in_stackwalk = 1;
SymGetModuleInfo64(GetCurrentProcess(), (DWORD64)pointer, &ModuleInfo);
jl_in_stackwalk = 0;
fname = ModuleInfo.LoadedImageName;
if (ModuleInfo.LoadedImageName)
printf("LoadedImageName: %s\n", ModuleInfo.LoadedImageName);
if (ModuleInfo.ImageName)
printf("Imagename: %s\n", ModuleInfo.ImageName);
*fromC = !jl_is_sysimg(fname);
if (skipC && *fromC) {
return;
}
static char frame_info_func[
sizeof(SYMBOL_INFO) +
MAX_SYM_NAME * sizeof(TCHAR)];
Expand All @@ -387,38 +368,43 @@ printf("LoadedImageName: %s\n", ModuleInfo.LoadedImageName);
if (SymFromAddr(GetCurrentProcess(), dwAddress, &dwDisplacement64, pSymbol)) {
// SymFromAddr returned success
*name = strdup(pSymbol->Name);
printf("name: %s\n",*name);
}
else {
// SymFromAddr failed
//fprintf(stderr,"SymFromAddr returned error : %lu\n", GetLastError());
}

frame_info_line.SizeOfStruct = sizeof(IMAGEHLP_LINE64);
if (SymGetLineFromAddr64(GetCurrentProcess(), dwAddress, &dwDisplacement, &frame_info_line)) {
// SymGetLineFromAddr64 returned success
*filename = strdup(frame_info_line.FileName);
// record source file name and line number
if (frame_info_line.FileName)
*filename = strdup(frame_info_line.FileName);
*line = frame_info_line.LineNumber;
printf("filename: %s\n",*filename);
printf("line: %d\n",(int)*line);
}
else {
} else if (*fromC) {
// No debug info, use dll name instead
*filename = fname;
} else {
*filename = "";
}
jl_in_stackwalk = 0;
#else // ifdef _OS_WINDOWS_
Dl_info dlinfo;
const char *fname = 0;
if ((dladdr((void*)pointer, &dlinfo) != 0) && dlinfo.dli_fname) {
*fromC = !jl_is_sysimg(dlinfo.dli_fname);
uint64_t fbase = (uint64_t)dlinfo.dli_fbase;
*fromC = (fbase != jl_sysimage_base);
if (skipC && *fromC)
return;
// In case we fail with the debug info lookup, we at least still
// have the function name, even if we don't have line numbers
*name = dlinfo.dli_sname;
*filename = dlinfo.dli_fname;
fname = dlinfo.dli_fname;
uint64_t fbase = (uint64_t)dlinfo.dli_fbase;
#endif // ifdef _OS_WINDOWS_
DIContext *context = NULL;
int64_t slide = 0;
#if defined(_OS_WINDOWS_) && !defined(LLVM35)
#if defined(_OS_WINDOWS_) && defined(LLVM35)
obfiletype::iterator it = objfilemap.find(fbase);
llvm::object::ObjectFile *obj = NULL;
if (it == objfilemap.end()) {
Expand Down Expand Up @@ -542,8 +528,10 @@ printf("line: %d\n",(int)*line);
slide = it->second.slide;
}
#endif // ifdef _OS_WINDOWS && !LLVM35
#ifdef _OS_DARWIN_
lookup:
lookup_pointer(context, name, line, filename, pointer+slide, jl_is_sysimg(fname), fromC);
#endif
lookup_pointer(context, name, line, filename, pointer+slide, fbase == jl_sysimage_base, fromC);
}
else {
*fromC = 1;
Expand Down
10 changes: 5 additions & 5 deletions src/disasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,16 @@
#endif
#include <llvm/ExecutionEngine/JITEventListener.h>
#ifdef LLVM33
#include "llvm/IR/LLVMContext.h"
#include <llvm/IR/LLVMContext.h>
#else
#include "llvm/LLVMContext.h"
#include <llvm/LLVMContext.h>
#endif
#ifdef LLVM35
#include "llvm/IR/DebugInfo.h"
#include <llvm/IR/DebugInfo.h>
#elif defined(LLVM32)
#include "llvm/DebugInfo.h"
#include <llvm/DebugInfo.h>
#else
#include "llvm/Analysis/DebugInfo.h"
#include <llvm/Analysis/DebugInfo.h>
#endif


Expand Down
18 changes: 16 additions & 2 deletions src/dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,16 @@ extern int globalUnique;
extern void jl_cpuid(int32_t CPUInfo[4], int32_t InfoType);
extern const char *jl_cpu_string;
uv_lib_t *jl_sysimg_handle = NULL;
char *jl_sysimage_name = NULL;
uint64_t jl_sysimage_base = NULL;
#ifdef _OS_WINDOWS_
#include <dbghelp.h>
#endif

static void jl_load_sysimg_so(char *fname)
{
#ifndef _OS_WINDOWS_
Dl_info dlinfo;
#endif
// attempt to load the pre-compiled sysimg at fname
// if this succeeds, sysimg_gvars will be a valid array
// otherwise, it will be NULL
Expand All @@ -193,7 +199,15 @@ static void jl_load_sysimg_so(char *fname)
jl_error("The current host does not support SSSE3, but the system image was compiled for Core2.\n"
"Please delete or regenerate sys.{so,dll,dylib}.");
}
jl_sysimage_name = strdup(fname);
#ifdef _OS_WINDOWS_
jl_sysimage_base = (DWORD64)jl_sysimg_handle->handle;
#else
if (dladdr((void*)sysimg_gvars, &dlinfo) != 0) {
jl_sysimage_base = dlinfo.dli_fbase;
} else {
jl_sysimage_base = 0;
}
#endif
}
else {
sysimg_gvars = 0;
Expand Down
1 change: 1 addition & 0 deletions src/julia_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ void jl_fptr_to_llvm(void *fptr, jl_lambda_info_t *lam, int specsig);
extern volatile HANDLE hMainThread;
typedef CONTEXT *bt_context_t;
DWORD64 jl_getUnwindInfo(ULONG64 dwBase);
extern volatile int jl_in_stackwalk;
#else
#define UNW_LOCAL_ONLY
#include <libunwind.h>
Expand Down
11 changes: 6 additions & 5 deletions src/llvm-simdloop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
// global function annotateSimdLoop: mark a loop as a SIMD loop.
// createLowerSimdLoopPass: construct LLVM for lowering a marked loop later.

#include "llvm/Analysis/LoopPass.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Metadata.h"
#include "llvm/Support/Debug.h"
#include "llvm-version.h"
#include <llvm/Analysis/LoopPass.h>
#include <llvm/IR/Instructions.h>
#include <llvm/IR/LLVMContext.h>
#include <llvm/IR/Metadata.h>
#include <llvm/Support/Debug.h>
#include <cstdio>

namespace llvm {
Expand Down
2 changes: 1 addition & 1 deletion src/llvm-version.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "llvm/Config/llvm-config.h"
#include <llvm/Config/llvm-config.h>

#if defined(LLVM_VERSION_MAJOR) && LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 6
#define LLVM36 1
Expand Down

3 comments on commit a140c6b

@Keno
Copy link
Member

@Keno Keno commented on a140c6b Nov 29, 2014

Choose a reason for hiding this comment

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

I remember trying this and it not working correctly on all platforms. Have you verified that this works?

@vtjnash
Copy link
Member Author

Choose a reason for hiding this comment

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

seems to work on ubuntu, osx, and windows

@vtjnash
Copy link
Member Author

Choose a reason for hiding this comment

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

and it helps significantly for dealing with case-insensitive operating systems

Please sign in to comment.