From b401e940be030bfd6d9e26f77a256ed6fc832931 Mon Sep 17 00:00:00 2001 From: Matthias Benkard Date: Sun, 28 Sep 2008 17:22:37 +0200 Subject: LLVM compiler: Allocate va_list objects as i8** rather than i8*. This fixes a terrible stack smashing bug that was most visible on PowerPC-based machines. --- MLKLLVMCompiler.mm | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'MLKLLVMCompiler.mm') diff --git a/MLKLLVMCompiler.mm b/MLKLLVMCompiler.mm index 9e51112..b3a47d3 100644 --- a/MLKLLVMCompiler.mm +++ b/MLKLLVMCompiler.mm @@ -644,13 +644,14 @@ static Constant false), PointerType::get(Type::Int8Ty, 0)); - Value *ap = builder.CreateAlloca (Type::Int8Ty, NULL, "ap"); + Value *ap = builder.CreateAlloca (PointerTy, NULL, "ap"); + Value *ap2 = builder.CreateBitCast (ap, PointerTy); builder.CreateCall (module->getOrInsertFunction ("llvm.va_start", Type::VoidTy, PointerTy, NULL), - ap); + ap2); Value *mlkcons = [_compiler insertClassLookup:@"MLKCons"]; @@ -707,7 +708,7 @@ static Constant Type::VoidTy, PointerTy, NULL), - ap); + ap2); if ([_bodyContext variableHeapAllocationForSymbol:_lambdaListName]) { -- cgit v1.2.3 From ef2536760d6e144f7d903f9f488d3350c2bd2221 Mon Sep 17 00:00:00 2001 From: Matthias Benkard Date: Sun, 28 Sep 2008 17:26:35 +0200 Subject: LLVM compiler: Add various disabled debugging statements. --- MLKLLVMCompiler.mm | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'MLKLLVMCompiler.mm') diff --git a/MLKLLVMCompiler.mm b/MLKLLVMCompiler.mm index b3a47d3..39741ff 100644 --- a/MLKLLVMCompiler.mm +++ b/MLKLLVMCompiler.mm @@ -164,7 +164,7 @@ static Constant //module->dump(); //NSLog (@"%p", fn); - [pool release]; + LRELEASE (pool); //NSLog (@"Code compiled."); #if 1 @@ -537,6 +537,9 @@ static Constant closureDataCell = builder.Insert ([_context closureDataPointerValueForSymbol:_head]); closureDataPtr = builder.CreateLoad (closureDataCell); + //[_compiler insertTrace:[NSString stringWithFormat:@"Call: %@", MLKPrintToString(_head)]]; + //[_compiler insertPointerTrace:functionPtr]; + args.push_back (closureDataPtr); NSEnumerator *e = [_argumentForms objectEnumerator]; @@ -556,7 +559,11 @@ static Constant PointerTy); args.push_back (endmarker); - //[_compiler insertTrace:[NSString stringWithFormat:@"Function call: %@.", MLKPrintToString(_head)]]; + // If the pointer output here is different from the one above, + // there's some stack smashing going on. + //[_compiler insertTrace:[NSString stringWithFormat:@"Now calling: %@.", MLKPrintToString(_head)]]; + //[_compiler insertPointerTrace:functionPtr]; + CallInst *call = builder.CreateCall (functionPtr, args.begin(), args.end(), -- cgit v1.2.3 From 31eed182d7996b7dbc319bd5f2c474a734492b04 Mon Sep 17 00:00:00 2001 From: Matthias Benkard Date: Sun, 28 Sep 2008 21:04:44 +0200 Subject: LLVM compiler: Disable garbage collection for objects embedded in Lisp code. --- MLKLLVMCompiler.mm | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'MLKLLVMCompiler.mm') diff --git a/MLKLLVMCompiler.mm b/MLKLLVMCompiler.mm index 39741ff..4a1095e 100644 --- a/MLKLLVMCompiler.mm +++ b/MLKLLVMCompiler.mm @@ -27,6 +27,11 @@ #import #import +#ifdef __OBJC_GC__ +#import +#endif + + #include #include #include @@ -834,7 +839,14 @@ static Constant { // FIXME: When to release _quotedData? At the same time the code is // released, probably... + // FIXME: In garbage-collected code, _quotedData will be deleted even + // though it is referenced by compiled code! LRETAIN (_quotedData); +#ifdef __OBJC_GC__ + if (_quotedData && MLKInstanceP (_quotedData)) + [[NSGarbageCollector defaultCollector] disableCollectorForPointer:_quotedData]; +#endif + return builder.CreateIntToPtr (ConstantInt::get(Type::Int64Ty, (uint64_t)_quotedData, false), @@ -848,7 +860,14 @@ static Constant { // FIXME: When to release _form? At the same time the code is // released, probably... + // FIXME: In garbage-collected code, _form will be deleted even + // though it is referenced by compiled code! LRETAIN (_form); +#ifdef __OBJC_GC__ + if (_form && MLKInstanceP (_form)) + [[NSGarbageCollector defaultCollector] disableCollectorForPointer:_form]; +#endif + return builder.CreateIntToPtr (ConstantInt::get(Type::Int64Ty, (uint64_t)_form, false), -- cgit v1.2.3 From 45e00ec3f4dd6289cd14021ef1ee35568b4928c6 Mon Sep 17 00:00:00 2001 From: Matthias Benkard Date: Sun, 28 Sep 2008 21:35:04 +0200 Subject: LLVM compiler: Simplify allocation of closures. --- MLKLLVMCompiler.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'MLKLLVMCompiler.mm') diff --git a/MLKLLVMCompiler.mm b/MLKLLVMCompiler.mm index 4a1095e..ae9773b 100644 --- a/MLKLLVMCompiler.mm +++ b/MLKLLVMCompiler.mm @@ -615,7 +615,7 @@ static Constant builder.SetInsertPoint (outerBlock); NSArray *freeVariables = [[self freeVariables] allObjects]; - Value *closure_data = builder.CreateMalloc (PointerTy, + Value *closure_data = builder.CreateAlloca (PointerTy, ConstantInt::get(Type::Int32Ty, (uint32_t)[freeVariables count], false)); -- cgit v1.2.3