Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7621845
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:17:54+00:00 2026-05-31T04:17:54+00:00

After weeks of effort I have managed to write F# programs that use LLVM

  • 0

After weeks of effort I have managed to write F# programs that use LLVM for JIT compilation. However, whenever I run my programs in Visual Studio 2010 with the debugger attached (i.e. by pressing F5) I get the following warning:

enter image description here

Now, I get this warning for every single PInvoke call when using my Windows 7 netbook but I only get it for some calls when using my Windows Vista desktop.

Other people hitting this problem seem to have solved it by adding attributes to the PInvoke calls requesting ANSI strings or the CDecl calling convention. I found that changing the calling convention fixes the warnings on my Windows Vista desktop but none of the available calling conventions (or ANSI format strings) fix the warnings on my Windows 7 netbook. Any ideas how to fix this?

Note that both machines are entirely 32-bit x86.

EDIT

People are posting comments asking for repros. The simplest way to reproduce this problem is to install LLVM and llvm-fs following the instructions I documented here and run any of the example programs given. They all exhibit this issue on all calls to LLVM on my netbook.

Alternatively, the following code (derived from llvm-fs) should repro the issue without requiring llvm-fs:

open System.Runtime.InteropServices

[<DllImport("LLVM-3.0.dll",
            EntryPoint="LLVMModuleCreateWithName",
            CharSet=CharSet.Ansi,
            CallingConvention=CallingConvention.Cdecl)>]
extern void *moduleCreateWithNameNative(string ModuleID)

let mdl = moduleCreateWithNameNative "foo"

Note that the corresponding definitions in the original C header file are:

typedef struct LLVMOpaqueModule *LLVMModuleRef;
...
LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T04:17:55+00:00Added an answer on May 31, 2026 at 4:17 am

    Are you targeting .NET 4.0 or an earlier version?

    The reason I ask is there’s a security/stability feature for the CLR which performs extra-strict checking of Pinvoke signatures; it’s been around since .NET 2.0, but was off by default until .NET 4.0.

    The switch in behavior has resulted in a number of developers reporting the same issue as you are; their bindings worked just fine on .NET 2.0/3.5, but started throwing errors when compiled for .NET 4.0. In reality, the problem is that prior versions of .NET allowed slightly-buggy PInvoke signatures to work without issue; now that the strict checking is on by default, the bugs are starting to show up.

    Another thing to note is that even if you change the configuration on your machine to disable this behavior in .NET 4.0, Visual Studio will still always use it when debugging a project. Worse yet, the strict checking is only on by default in the x86 version of .NET 4.0, not the x64 version, so an assembly which works just fine on a 64-bit machine may possibly crash on a 32-bit machine.

    MSDN has more information on the pInvokeStackImbalance MDA and this blog post also provides more detail about why the problem crops up during the debugging process.

    EDIT: I just noticed you edited your question to include a code example. This sort of confirms my suspicion about the PInvoke signature being slightly wrong. What happens if you change the signature from extern void *moduleCreateWithNameNative(string ModuleID) to extern LLVMModuleRef* moduleCreateWithNameNative(string ModuleID)?

    It also looks like there’s a compiler bug at work here — F# shouldn’t allow you to define a method called *moduleCreateWithNameNative. I’d guess it is allowing it (for whatever reason), so the return type of your function is compiled as void — and when the native method tries to return a value (a pointer to an LLVMModuleRef struct) the CLR gets tripped up and crashes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a stored proc that after a period of weeks will start to
I have used ACL in CakePHP 1.3 without a single issue, after 2 weeks
After weeks of using Prism I have been through every kind of navigation methods.
I have an app that requires me to take an action after some period
I have a few blogs that use Facebook comments. They all use the same
I solved a bug today after almost five weeks of effort. What was happening
Sorry for my inpatience but after weeks staying up late and just having put
I'm using Eclipse Galileo (v3.51). All of a sudden, after weeks of it starting
After few weeks break, I'm trying to expand and extend my knowlege of templates
After spending three weeks learning Objective-C and Cocoa programming for my work, I've been

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.