Skip to content

Commit 2034b2c

Browse files
committed
llvm: Support work for using versions 9 and 10-dev
1 parent 7bc3742 commit 2034b2c

15 files changed

+144
-119
lines changed

src/ccall.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1981,7 +1981,7 @@ jl_cgval_t function_sig_t::emit_a_ccall(
19811981
// ARM and AArch64 can use a LLVM type larger than the julia type.
19821982
// When this happens, cast through memory.
19831983
auto slot = emit_static_alloca(ctx, resultTy);
1984-
slot->setAlignment(boxalign);
1984+
slot->setAlignment(Align(boxalign));
19851985
ctx.builder.CreateAlignedStore(result, slot, boxalign);
19861986
emit_memcpy(ctx, strct, tbaa, slot, tbaa, rtsz, boxalign, tbaa);
19871987
}

src/cgutils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2265,7 +2265,7 @@ static AllocaInst *try_emit_union_alloca(jl_codectx_t &ctx, jl_uniontype_t *ut,
22652265
Type *AT = ArrayType::get(IntegerType::get(jl_LLVMContext, 8 * min_align), (nbytes + min_align - 1) / min_align);
22662266
AllocaInst *lv = emit_static_alloca(ctx, AT);
22672267
if (align > 1)
2268-
lv->setAlignment(align);
2268+
lv->setAlignment(Align(align));
22692269
return lv;
22702270
}
22712271
return NULL;

src/clangsa/GCChecker.cpp

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
#else
1818
#include "clang/StaticAnalyzer/Core/CheckerRegistry.h"
1919
#endif
20+
2021
#include <iostream>
22+
#include <memory>
2123

2224
#if defined(__GNUC__)
2325
# define USED_FUNC __attribute__((used))
@@ -28,12 +30,18 @@
2830
# define USED_FUNC
2931
#endif
3032

33+
#if LLVM_VERSION_MAJOR >= 10
34+
using std::make_unique;
35+
#else
36+
using llvm::make_unique;
37+
#endif
38+
3139
namespace {
3240
using namespace clang;
3341
using namespace ento;
3442

3543
#define PDP std::shared_ptr<PathDiagnosticPiece>
36-
#define MakePDP llvm::make_unique<PathDiagnosticEventPiece>
44+
#define MakePDP make_unique<PathDiagnosticEventPiece>
3745

3846
class GCChecker : public Checker<eval::Call,
3947
check::BeginFunction,
@@ -387,13 +395,13 @@ PDP GCChecker::GCValueBugVisitor::ExplainNoPropagationFromExpr(const clang::Expr
387395
const ValueState *ValS = N->getState()->get<GCValueMap>(Parent);
388396
assert(ValS);
389397
if (ValS->isPotentiallyFreed()) {
390-
BR.addVisitor(llvm::make_unique<GCValueBugVisitor>(Parent));
398+
BR.addVisitor(make_unique<GCValueBugVisitor>(Parent));
391399
return MakePDP(Pos, "Root not propagated because it may have been freed. Tracking.");
392400
} else if (ValS->isRooted()) {
393-
BR.addVisitor(llvm::make_unique<GCValueBugVisitor>(Parent));
401+
BR.addVisitor(make_unique<GCValueBugVisitor>(Parent));
394402
return MakePDP(Pos, "Root was not propagated due to a bug. Tracking base value.");
395403
} else {
396-
BR.addVisitor(llvm::make_unique<GCValueBugVisitor>(Parent));
404+
BR.addVisitor(make_unique<GCValueBugVisitor>(Parent));
397405
return MakePDP(Pos, "No Root to propagate. Tracking.");
398406
}
399407
}
@@ -506,8 +514,8 @@ void GCChecker::report_error(callback f, CheckerContext &C, const char *message)
506514
if (!BT)
507515
BT.reset(new BugType(this, "Invalid GC thingy",
508516
categories::LogicError));
509-
auto Report = llvm::make_unique<BugReport>(*BT, message, N);
510-
Report->addVisitor(llvm::make_unique<GCBugVisitor>());
517+
auto Report = make_unique<BugReport>(*BT, message, N);
518+
Report->addVisitor(make_unique<GCBugVisitor>());
511519
f(Report.get());
512520
C.emitReport(std::move(Report));
513521
}
@@ -522,10 +530,10 @@ void GCChecker::report_value_error(CheckerContext &C, SymbolRef Sym, const char
522530
if (!BT)
523531
BT.reset(new BugType(this, "Invalid GC thingy",
524532
categories::LogicError));
525-
auto Report = llvm::make_unique<BugReport>(*BT, message, N);
526-
Report->addVisitor(llvm::make_unique<GCValueBugVisitor>(Sym));
527-
Report->addVisitor(llvm::make_unique<GCBugVisitor>());
528-
Report->addVisitor(llvm::make_unique<ConditionBRVisitor>());
533+
auto Report = make_unique<BugReport>(*BT, message, N);
534+
Report->addVisitor(make_unique<GCValueBugVisitor>(Sym));
535+
Report->addVisitor(make_unique<GCBugVisitor>());
536+
Report->addVisitor(make_unique<ConditionBRVisitor>());
529537
if (!range.isInvalid()) {
530538
Report->addRange(range);
531539
}

src/codegen.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2701,7 +2701,7 @@ static bool emit_builtin_call(jl_codectx_t &ctx, jl_cgval_t *ret, jl_value_t *f,
27012701
ConstantAsMetadata::get(ConstantInt::get(T_int8, union_max)) }));
27022702
AllocaInst *lv = emit_static_alloca(ctx, AT);
27032703
if (al > 1)
2704-
lv->setAlignment(al);
2704+
lv->setAlignment(Align(al));
27052705
emit_memcpy(ctx, lv, tbaa_arraybuf, ctx.builder.CreateInBoundsGEP(AT, data, idx), tbaa_arraybuf, elsz, al, false);
27062706
*ret = mark_julia_slot(lv, ety, ctx.builder.CreateNUWAdd(ConstantInt::get(T_int8, 1), tindex), tbaa_arraybuf);
27072707
}
@@ -3156,7 +3156,7 @@ static jl_cgval_t emit_call_specfun_other(jl_codectx_t &ctx, jl_code_instance_t
31563156
case jl_returninfo_t::Union:
31573157
result = emit_static_alloca(ctx, ArrayType::get(T_int8, returninfo.union_bytes));
31583158
if (returninfo.union_align > 1)
3159-
result->setAlignment(returninfo.union_align);
3159+
result->setAlignment(Align(returninfo.union_align));
31603160
argvals[idx] = result;
31613161
idx++;
31623162
break;
@@ -3564,18 +3564,16 @@ static jl_cgval_t emit_varinfo(jl_codectx_t &ctx, jl_varinfo_t &vi, jl_sym_t *va
35643564
AllocaInst *varslot = cast<AllocaInst>(vi.value.V);
35653565
Type *T = varslot->getAllocatedType();
35663566
assert(!varslot->isArrayAllocation() && "variables not expected to be VLA");
3567-
AllocaInst *ssaslot = emit_static_alloca(ctx, T);
3568-
unsigned al = varslot->getAlignment();
3569-
if (al)
3570-
ssaslot->setAlignment(al);
3567+
AllocaInst *ssaslot = cast<AllocaInst>(varslot->clone());
3568+
ssaslot->insertAfter(varslot);
35713569
if (vi.isVolatile) {
35723570
Value *unbox = ctx.builder.CreateLoad(vi.value.V, true);
35733571
ctx.builder.CreateStore(unbox, ssaslot);
35743572
}
35753573
else {
35763574
const DataLayout &DL = jl_data_layout;
35773575
uint64_t sz = DL.getTypeStoreSize(T);
3578-
emit_memcpy(ctx, ssaslot, tbaa_stack, vi.value, sz, al);
3576+
emit_memcpy(ctx, ssaslot, tbaa_stack, vi.value, sz, ssaslot->getAlignment());
35793577
}
35803578
Value *tindex = NULL;
35813579
if (vi.pTIndex)
@@ -5253,7 +5251,7 @@ static Function *gen_invoke_wrapper(jl_method_instance_t *lam, jl_value_t *jlret
52535251
case jl_returninfo_t::Union:
52545252
result = ctx.builder.CreateAlloca(ArrayType::get(T_int8, f.union_bytes));
52555253
if (f.union_align > 1)
5256-
result->setAlignment(f.union_align);
5254+
result->setAlignment(Align(f.union_align));
52575255
args[idx] = result;
52585256
idx++;
52595257
break;
@@ -5708,7 +5706,7 @@ static std::unique_ptr<Module> emit_function(
57085706

57095707
if (returninfo.cc == jl_returninfo_t::Union) {
57105708
f->addAttribute(1, Attribute::getWithDereferenceableBytes(jl_LLVMContext, returninfo.union_bytes));
5711-
f->addAttribute(1, Attribute::getWithAlignment(jl_LLVMContext, returninfo.union_align));
5709+
f->addAttribute(1, Attribute::getWithAlignment(jl_LLVMContext, Align(returninfo.union_align)));
57125710
}
57135711

57145712
#ifdef JL_DEBUG_BUILD

src/debuginfo.cpp

Lines changed: 69 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -177,30 +177,50 @@ class JuliaJITEventListener: public JITEventListener
177177
return linfo;
178178
}
179179

180-
virtual void NotifyObjectEmitted(const object::ObjectFile &obj,
180+
virtual void NotifyObjectEmitted(const object::ObjectFile &Object,
181181
const RuntimeDyld::LoadedObjectInfo &L)
182182
{
183-
return _NotifyObjectEmitted(obj,obj,L,nullptr);
183+
return _NotifyObjectEmitted(Object, L, nullptr);
184184
}
185185

186-
virtual void _NotifyObjectEmitted(const object::ObjectFile &obj,
187-
const object::ObjectFile &debugObj,
186+
virtual void _NotifyObjectEmitted(const object::ObjectFile &Object,
188187
const RuntimeDyld::LoadedObjectInfo &L,
189188
RTDyldMemoryManager *memmgr)
190189
{
191190
jl_ptls_t ptls = jl_get_ptls_states();
192191
// This function modify codeinst->fptr in GC safe region.
193192
// This should be fine since the GC won't scan this field.
194193
int8_t gc_state = jl_gc_safe_enter(ptls);
194+
195+
auto SavedObject = L.getObjectForDebug(Object).takeBinary();
196+
// If the debug object is unavailable, save (a copy of) the original object
197+
// for our backtraces
198+
if (!SavedObject.first) {
199+
// This is unfortunate, but there doesn't seem to be a way to take
200+
// ownership of the original buffer
201+
auto NewBuffer = MemoryBuffer::getMemBufferCopy(
202+
Object.getData(), Object.getFileName());
203+
auto NewObj = object::ObjectFile::createObjectFile(NewBuffer->getMemBufferRef());
204+
assert(NewObj);
205+
SavedObject = std::make_pair(std::move(*NewObj), std::move(NewBuffer));
206+
}
207+
const object::ObjectFile &debugObj = *SavedObject.first.release();
208+
SavedObject.second.release();
209+
195210
object::section_iterator Section = debugObj.section_begin();
196211
object::section_iterator EndSection = debugObj.section_end();
197212

198-
std::map<StringRef,object::SectionRef,strrefcomp> loadedSections;
199-
for (const object::SectionRef &lSection: obj.sections()) {
213+
std::map<StringRef, object::SectionRef, strrefcomp> loadedSections;
214+
for (const object::SectionRef &lSection: Object.sections()) {
215+
#if JL_LLVM_VERSION >= 100000
216+
auto sName = lSection.getName();
217+
if (sName)
218+
loadedSections[*sName] = lSection;
219+
#else
200220
StringRef sName;
201-
if (!lSection.getName(sName)) {
221+
if (!lSection.getName(sName))
202222
loadedSections[sName] = lSection;
203-
}
223+
#endif
204224
}
205225
auto getLoadAddress = [&] (const StringRef &sName) -> uint64_t {
206226
auto search = loadedSections.find(sName);
@@ -215,15 +235,21 @@ class JuliaJITEventListener: public JITEventListener
215235
size_t arm_exidx_len = 0;
216236
uint64_t arm_text_addr = 0;
217237
size_t arm_text_len = 0;
218-
for (auto &section: obj.sections()) {
238+
for (auto &section: Object.sections()) {
219239
bool istext = false;
220240
if (section.isText()) {
221241
istext = true;
222242
}
223243
else {
244+
#if JL_LLVM_VERSION >= 100000
245+
auto sName = section.getName();
246+
if (!sName)
247+
continue;
248+
#else
224249
StringRef sName;
225250
if (section.getName(sName))
226251
continue;
252+
#endif
227253
if (sName != ".ARM.exidx") {
228254
continue;
229255
}
@@ -285,8 +311,14 @@ class JuliaJITEventListener: public JITEventListener
285311
Section = SectionOrError.get();
286312
assert(Section != EndSection && Section->isText());
287313
SectionAddr = Section->getAddress();
314+
#if JL_LLVM_VERSION >= 100000
315+
auto secName = Section->getName();
316+
assert(secName);
317+
SectionLoadAddr = getLoadAddress(*secName);
318+
#else
288319
Section->getName(sName);
289320
SectionLoadAddr = getLoadAddress(sName);
321+
#endif
290322
Addr -= SectionAddr - SectionLoadAddr;
291323
*pAddr = (uint8_t*)Addr;
292324
if (SectionAddrCheck)
@@ -342,9 +374,15 @@ class JuliaJITEventListener: public JITEventListener
342374
if (Section == EndSection) continue;
343375
if (!Section->isText()) continue;
344376
uint64_t SectionAddr = Section->getAddress();
377+
#if JL_LLVM_VERSION >= 100000
378+
Expected<StringRef> secName = Section->getName();
379+
assert(secName);
380+
uint64_t SectionLoadAddr = getLoadAddress(*secName);
381+
#else
345382
StringRef secName;
346383
Section->getName(secName);
347384
uint64_t SectionLoadAddr = getLoadAddress(secName);
385+
#endif
348386
Addr -= SectionAddr - SectionLoadAddr;
349387
auto sNameOrError = sym_iter.getName();
350388
assert(sNameOrError);
@@ -373,7 +411,7 @@ class JuliaJITEventListener: public JITEventListener
373411
ObjectInfo tmp = {&debugObj,
374412
(size_t)SectionSize,
375413
(ptrdiff_t)(SectionAddr - SectionLoadAddr),
376-
DWARFContext::create(debugObj, &L).release(),
414+
DWARFContext::create(debugObj).release(),
377415
};
378416
objectmap[SectionLoadAddr] = tmp;
379417
first = false;
@@ -384,7 +422,7 @@ class JuliaJITEventListener: public JITEventListener
384422
}
385423

386424
// must implement if we ever start freeing code
387-
// virtual void NotifyFreeingObject(const ObjectImage &obj) {}
425+
// virtual void NotifyFreeingObject(const ObjectImage &Object) {}
388426
// virtual void NotifyFreeingObject(const object::ObjectFile &Obj) {}
389427

390428
std::map<size_t, ObjectInfo, revcomp>& getObjectMap()
@@ -395,12 +433,11 @@ class JuliaJITEventListener: public JITEventListener
395433
};
396434

397435
JL_DLLEXPORT void ORCNotifyObjectEmitted(JITEventListener *Listener,
398-
const object::ObjectFile &obj,
399-
const object::ObjectFile &debugObj,
436+
const object::ObjectFile &Object,
400437
const RuntimeDyld::LoadedObjectInfo &L,
401438
RTDyldMemoryManager *memmgr)
402439
{
403-
((JuliaJITEventListener*)Listener)->_NotifyObjectEmitted(obj,debugObj,L,memmgr);
440+
((JuliaJITEventListener*)Listener)->_NotifyObjectEmitted(Object, L, memmgr);
404441
}
405442

406443
static std::pair<char *, bool> jl_demangle(const char *name)
@@ -445,12 +482,14 @@ JITEventListener *CreateJuliaJITEventListener()
445482
// *frames is a one element array containing whatever we could come up
446483
// with for the current frame. here we'll try to expand it using debug info
447484
// func_name and file_name are either NULL or malloc'd pointers
448-
static int lookup_pointer(DIContext *context, jl_frame_t **frames,
449-
size_t pointer, int demangle, int noInline)
485+
static int lookup_pointer(
486+
const object::ObjectFile *object, DIContext *context,
487+
jl_frame_t **frames, size_t pointer,
488+
int demangle, int noInline)
450489
{
451490
// This function is not allowed to reference any TLS variables
452491
// since it can be called from an unmanaged thread on OSX.
453-
if (!context) {
492+
if (!context || !object) {
454493
if (demangle) {
455494
char *oldname = (*frames)[0].func_name;
456495
if (oldname != NULL) {
@@ -473,14 +512,14 @@ static int lookup_pointer(DIContext *context, jl_frame_t **frames,
473512
DILineInfoSpecifier infoSpec(DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath,
474513
DILineInfoSpecifier::FunctionNameKind::ShortName);
475514

476-
auto inlineInfo = context->getInliningInfoForAddress(makeAddress(pointer), infoSpec);
515+
auto inlineInfo = context->getInliningInfoForAddress(makeAddress(object, pointer), infoSpec);
477516

478517
int fromC = (*frames)[0].fromC;
479518
int n_frames = inlineInfo.getNumberOfFrames();
480519
if (n_frames == 0) {
481520
jl_mutex_unlock_maybe_nogc(&codegen_lock);
482521
// no line number info available in the context, return without the context
483-
return lookup_pointer(NULL, frames, pointer, demangle, noInline);
522+
return lookup_pointer(NULL, NULL, frames, pointer, demangle, noInline);
484523
}
485524
if (noInline)
486525
n_frames = 1;
@@ -497,7 +536,7 @@ static int lookup_pointer(DIContext *context, jl_frame_t **frames,
497536
info = inlineInfo.getFrame(i);
498537
}
499538
else {
500-
info = context->getLineInfoForAddress(makeAddress(pointer), infoSpec);
539+
info = context->getLineInfoForAddress(makeAddress(object, pointer), infoSpec);
501540
}
502541

503542
jl_frame_t *frame = &(*frames)[i];
@@ -571,8 +610,14 @@ static debug_link_info getDebuglink(const object::ObjectFile &Obj)
571610
{
572611
debug_link_info info = {};
573612
for (const object::SectionRef &Section: Obj.sections()) {
613+
#if JL_LLVM_VERSION >= 100000
614+
Expected<StringRef> sName = Section.getName();
615+
if (sName && *sName == ".gnu_debuglink")
616+
#else
574617
StringRef sName;
575-
if (!Section.getName(sName) && sName == ".gnu_debuglink") {
618+
if (!Section.getName(sName) && sName == ".gnu_debuglink")
619+
#endif
620+
{
576621
StringRef Contents;
577622
#if JL_LLVM_VERSION >= 90000
578623
auto found = Section.getContents();
@@ -1135,7 +1180,7 @@ static int jl_getDylibFunctionInfo(jl_frame_t **frames, size_t pointer, int skip
11351180
}
11361181
}
11371182
}
1138-
return lookup_pointer(context, frames, pointer + slide, isSysImg, noInline);
1183+
return lookup_pointer(object, context, frames, pointer + slide, isSysImg, noInline);
11391184
}
11401185

11411186
int jl_DI_for_fptr(uint64_t fptr, uint64_t *symsize, int64_t *slide, int64_t *section_slide,
@@ -1222,12 +1267,12 @@ int jl_getFunctionInfo(jl_frame_t **frames_out, size_t pointer, int skipC, int n
12221267
*frames_out = frames;
12231268

12241269
llvm::DIContext *context;
1225-
const llvm::object::ObjectFile *object;
1270+
const object::ObjectFile *object;
12261271
uint64_t symsize;
12271272
int64_t slide = 0;
12281273
if (jl_DI_for_fptr(pointer, &symsize, &slide, NULL, &object, &context)) {
12291274
frames[0].linfo = jl_jit_events->lookupLinfo(pointer);
1230-
int nf = lookup_pointer(context, frames_out, pointer+slide, 1, noInline);
1275+
int nf = lookup_pointer(object, context, frames_out, pointer+slide, 1, noInline);
12311276
return nf;
12321277
}
12331278
return jl_getDylibFunctionInfo(frames_out, pointer, skipC, noInline);

0 commit comments

Comments
 (0)