Git Product home page Git Product logo

Comments (6)

jondgoodwin avatar jondgoodwin commented on May 28, 2024

Appreciate you doing that research on how one might build the LLVM IR to mark globals with the equivalent of attribute((used)) in C. I suspect you do have much of it worked out.

That said, I think there is a simpler option available near-term. Cone does distinguish between public and private globals (the latter when a name begins with an underscore), and it already marks them differently to LLVM: public globals are marked with default visibility and private ones are not. So, if you use wasm-ld's --export-dynamic, that will only take the public globals and not the private ones.

Let me know if that works for you, as I cannot test it today.

from cone.

Meai1 avatar Meai1 commented on May 28, 2024

No, --export-dynamic also exports the fn _bro() as well as the fn blah()
The only option to limit it to certain functions seems to be to specifically pass it via --export=blah, then it exports only exactly that one. You are right though, that should work. I kinda read over the part that the llvm.used stuff is only supposed to be needed for executable wasm files, which I dont need anyway.

from cone.

Meai1 avatar Meai1 commented on May 28, 2024

ok @jondgoodwin, it does work but only with the following modification because it never jumps into the first if block and even if it does, the x86 calling convention thing ruins it for wasm so I would suggest this:

        if (glofn->flags & FlagSystem)
        {
            LLVMSetFunctionCallConv(glofn->llvmvar, LLVMX86StdcallCallConv);
            LLVMSetDLLStorageClass(glofn->llvmvar, LLVMDLLImportStorageClass);
            LLVMSetVisibility(glofn->llvmvar, LLVMHiddenVisibility);
        }
        else if(fnname[0] == '_'){
            LLVMSetVisibility(glofn->llvmvar, LLVMHiddenVisibility);
        }
        else if (fnname[0] != '_')
        {
            //LLVMSetDLLStorageClass(glofn->llvmvar, LLVMDLLExportStorageClass);
            LLVMSetVisibility(glofn->llvmvar, LLVMDefaultVisibility);
            LLVMSetLinkage(glofn->llvmvar, LLVMExternalLinkage);        
         }

from cone.

jondgoodwin avatar jondgoodwin commented on May 28, 2024

I took a quick pass in committing a code change so that private globals use HiddenVisibility (assuming that if unspecified, the remaining ones will have DefaultVisibility). I did not add the ExternalLinkage, as I am currently unsure that it is needed.

"extern"s (the first if condition) should not be marked with HiddenVisibility, as that defeats the purpose of being able to find and link them in!

I am unable to test the change right now, but if you are, let me know if it works for you.

from cone.

Meai1 avatar Meai1 commented on May 28, 2024

yeah it works. The sad thing is that technically I guess we can't close the issue because it still wouldn't work for executable wasm (wasm with a main method?) according to the docs. Unless that wont be supported by Cone anyway.

from cone.

jondgoodwin avatar jondgoodwin commented on May 28, 2024

So long as an executable is linked using the --export-dynamic option, all public globals (including _main) will be exported, so I think we are okay for now. Thanks for picking up this issue and helping so much with its resolution.

from cone.

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.