[PATCH] D16188: LLVMRunStaticConstructors can be called before object is finalized, #24028

David Herberth via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 14 15:44:14 PST 2016


Dav1d added a comment.

In http://reviews.llvm.org/D16188#327370, @joker.eph wrote:

> It is not clear to me why LLVMGetPointerToGlobal calls it but not LLVMGetGlobalValueAddress (or LLVMAddGlobalMapping or ...)


As I mentioned in the Issue (https://llvm.org/bugs/show_bug.cgi?id=24028), I am not happy with the C-API, stuff is missing (less and less with every new version, yay!), stuff happens implicitly without being mentioned (like finalizeObject). Changing the API now will break a lot of code, even if you only want to add a function to call finalizeObject explicitly (which is btw marked with a 'TODO rename me') and make it more consistent (add the function and remove the implicit calls).

I am not sure how far you want to go with breaking the API. In my opinion a 'dumb' binding which simply only exposes the functionality of C++ to C would be the best *but* this would break existing code in a really bad manner (LLVMRunFunction suddenly segfaults for no obvious reason).

This patch only focuses on the problem I ran into, the patch could be extended to call finalizeObject before every method call which requires a finalized object, but I don't think this is a good solution. If you want me to I can (probably, if I figure out how to with phabricator) update the patch to call finalizeObject on all the other functions which require a finalized object.

PS: My current workaround:
I have an empty function in my module, so before calling the constructors I run the function:

  		// workaround which calls ee->finalizeObjects, which makes
  		// LLVMRunStaticConstructors not segfault
  		LLVMDisposeGenericValue(LLVMRunFunction(ee, "vmain", []));
  		LLVMRunStaticConstructors(ee);


http://reviews.llvm.org/D16188





More information about the llvm-commits mailing list