Giter VIP home page Giter VIP logo

Comments (6)

TheDan64 avatar TheDan64 commented on May 25, 2024

Thanks for reporting this! I think I'm already aware of this issue but I haven't been able to figure out a way to avoid the segfault and error because IIRC LLVM doesn't provide a way to check if any target has yet been initialized and also because LLVM's global state seems quite messy from an outside perspective so keeping track of it manually seemed really tricky if not impossible

from inkwell.

TheDan64 avatar TheDan64 commented on May 25, 2024

One possible soution might be to generate a ZST from those target initializers which is required to be passed into the EE creation method, which would ensure at least one initializer has been called (so long as the user can't create the ZST themselves)

from inkwell.

RReverser avatar RReverser commented on May 25, 2024

Yeah I've noticed this happens inside of

inkwell/src/module.rs

Lines 497 to 502 in 949634d

if code == 1 {
// The module still seems "owned" in this error case, despite failing to create an EE. This would normally
// end in a segfault on Module drop, however we're avoiding that by cloning the module and replacing the underlying pointer
// REVIEW: Ensure this doesn't lead to unexpected behavior... If it does, the alternate strategy would be to change the fn
// signature to take ownership of self and return it with good EE: (self, opt_level) -> Result<(Module, EE), LLVMString>
let module = self.clone();
which specifically mentions potential undefined behaviour and segfaults.

FWIW error string returned by LLVM in that particular case is "Unable to find target for this triple (no targets are registered)"... but comparing them would be a horrible idea and I shouldn't even think about that :)

Another interesting place is implementation of Clone itself:

inkwell/src/module.rs

Lines 1323 to 1325 in 949634d

let verify = self.verify();
assert!(verify.is_ok(), "Cloning a Module seems to segfault when module is not valid. We are preventing that here. Error: {}", verify.unwrap_err());

That one says it calls verify to make sure that actual cloning doesn't segfault, but then if verify itself segfaults, what's the difference? Although removing it doesn't fix the issue either...

from inkwell.

RReverser avatar RReverser commented on May 25, 2024

As far as I can tell, calling initialize_native multiple times is no-op, as LLVM should already know whether target has been previously initialised.

As such, I wonder if it would make sense and be simpler to just call it as part of create_jit_execution_engine so that user wouldn't need to remember to do so?

from inkwell.

TheDan64 avatar TheDan64 commented on May 25, 2024

Hmm maybe. You can only run a JIT with a native target, right?

from inkwell.

RReverser avatar RReverser commented on May 25, 2024

As far as I understand, yeah. (Same for interpreter engine I guess.)

from inkwell.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.