[LLVMbugs] [Bug 23095] New: using C bindings, calling LLVMSetGC("shadow-stack") fails with an unsupported error

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Tue Mar 31 17:56:13 PDT 2015


https://llvm.org/bugs/show_bug.cgi?id=23095

            Bug ID: 23095
           Summary: using C bindings, calling LLVMSetGC("shadow-stack")
                    fails with an unsupported error
           Product: new-bugs
           Version: 3.6
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: normal
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: halivingston at gmail.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

I'm using LLVMSharp, which require .NET or Mono. I suspect it'll reproduce in
LLVM-C bindings as well.

I've attached the C# program I used on Windows.

Step 1:
Open Visual Studio
Create Solution
Install-Package LLVMSharp (it comes with a shared library inside)

Put the following program and notice the console output which says unsupported
error:

namespace ConsoleApplication2
{
    using System;
    using System.Runtime.InteropServices;
    using LLVMSharp;

    class Program
    {
        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
        public delegate int Add();

        static void Main(string[] args)
        {
            LLVMBool False = new LLVMBool(0);
            LLVMModuleRef mod = LLVM.ModuleCreateWithName("LLVMSharpIntro");

            LLVMTypeRef param_types = new LLVMTypeRef();
            LLVMTypeRef ret_type = LLVM.FunctionType(LLVM.Int32Type(), out
param_types, 0, False);
            LLVMValueRef sum = LLVM.AddFunction(mod, "sum", ret_type);
            LLVM.SetGC(sum, "erlang");

            LLVMBasicBlockRef entry = LLVM.AppendBasicBlock(sum, "entry");

            LLVMBuilderRef builder = LLVM.CreateBuilder();

            LLVM.PositionBuilderAtEnd(builder, entry);
            var p = LLVM.BuildAlloca(builder, LLVM.Int32Type(), "p");
            LLVM.BuildStore(builder, LLVM.ConstInt(LLVM.Int32Type(), 10,
False), p);
            var x = LLVM.BuildLoad(builder, p, "foo");
            LLVM.BuildRet(builder, x);

            IntPtr error;
            LLVM.VerifyModule(mod,
LLVMVerifierFailureAction.LLVMAbortProcessAction, out error);
            LLVM.DisposeMessage(error);

            LLVMExecutionEngineRef engine;

            LLVM.LinkInMCJIT();
            LLVM.InitializeX86Target();
            LLVM.InitializeX86TargetInfo();
            LLVM.InitializeX86TargetMC();
            LLVM.InitializeX86AsmPrinter();

            var platform = Environment.OSVersion.Platform;
            if (platform == PlatformID.Win32NT) // On Windows, LLVM currently
(3.6) does not support PE/COFF
            {
                LLVM.SetTarget(mod,
Marshal.PtrToStringAnsi(LLVM.GetDefaultTargetTriple()) + "-elf");
            }

            var options = new LLVMMCJITCompilerOptions();
            var optionsSize = (4 * sizeof(int)) + IntPtr.Size; //
LLVMMCJITCompilerOptions has 4 ints and a pointer

            LLVM.DumpModule(mod);

            LLVM.InitializeMCJITCompilerOptions(out options, optionsSize);
            LLVM.CreateMCJITCompilerForModule(out engine, mod, out options,
optionsSize, out error);

            var addMethod =
(Add)Marshal.GetDelegateForFunctionPointer(LLVM.GetPointerToGlobal(engine,
sum), typeof(Add));
            int result = addMethod();

            Console.WriteLine("Result of sum is: " + result);

            if (LLVM.WriteBitcodeToFile(mod, "sum.bc") != 0)
            {
                Console.WriteLine("error writing bitcode to file, skipping");
            }

            LLVM.DumpModule(mod);

            LLVM.DisposeBuilder(builder);
            LLVM.DisposeExecutionEngine(engine);
            Console.ReadKey();
        }
    }
}

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20150401/273dd2a8/attachment.html>


More information about the llvm-bugs mailing list