exaloop / codon

A high-performance, zero-overhead, extensible Python compiler using LLVM
https://docs.exaloop.io/codon
Other
15.15k stars 520 forks source link

raypyc binding for codon #391

Closed sDos280 closed 1 year ago

sDos280 commented 1 year ago

Hi, πŸ‘‹. some background: I am the developer of raypyc (the python binding for the raylib graphics library), And I would really like to make a binding of raypyc that works with codon. I am currently trying to use codon to call functions from the dynamic library (of raylib) but it seems that whatever I do I get a core dump, but not right after the function call but "a bit after".

Here is the script that I use: image

Here is the output that I get: image

mingodad commented 1 year ago

Maybe the string "hhh" goes out of scope ? What happens if you use a string variable that is alive all the time ?

Cheers !

sDos280 commented 1 year ago

do you mean like that: image

it seems to still not work... if you want I can probably build a template project for my test so you will be to test it yourself.

p.s. sorry for the English, my English isn't perfect :)

mingodad commented 1 year ago

Yes ! Can you publish the full source to test it ?

sDos280 commented 1 year ago

sure! but it may take me some time

sDos280 commented 1 year ago

Done: https://github.com/sDos280/raypyc-codon-demo

mingodad commented 1 year ago

I tested it on my machine and it does work but when running under valgrind there is some memory issues, so probably you are right and somehow on my machine it's working by luck .

sh run-codon.sh 
==19105== Memcheck, a memory error detector
==19105== Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al.
==19105== Using Valgrind-3.21.0 and LibVEX; rerun with -h for copyright info
==19105== Command: codon run -l /home/mingo/local/raylib/lib/libraylib.so.4.5.0 test-raylib.codon
==19105== 
==19105== Invalid read of size 4
==19105==    at 0x5D7C140: codon::ir::LLVMVisitor::clearLLVMData() (in /home/mingo/local/codon-deploy/lib/codon/libcodonc.so)
==19105==    by 0x5D892B7: codon::ir::LLVMVisitor::run(std::vector<std::string, std::allocator<std::string> > const&, std::vector<std::string, std::allocator<std::string> > const&, char const* const*) (in /home/mingo/local/codon-deploy/lib/codon/libcodonc.so)
==19105==    by 0x18BC69: runMode(std::vector<char const*, std::allocator<char const*> > const&) (in /home/mingo/local/codon-deploy/bin/codon)
==19105==    by 0x18E992: main (in /home/mingo/local/codon-deploy/bin/codon)
==19105==  Address 0x14a8eec8 is 40 bytes inside a block of size 128 free'd
==19105==    at 0x4C35FD9: operator delete(void*) (vg_replace_malloc.c:1025)
==19105==    by 0x7EAA20B: llvm::GlobalDCEPass::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (in /home/mingo/local/codon-deploy/lib/codon/libcodonc.so)
==19105==    by 0x5D749DC: llvm::detail::PassModel<llvm::Module, llvm::GlobalDCEPass, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (in /home/mingo/local/codon-deploy/lib/codon/libcodonc.so)
==19105==    by 0x8EDAF27: llvm::CoroConditionalWrapper::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (in /home/mingo/local/codon-deploy/lib/codon/libcodonc.so)
==19105==    by 0x8A1C66D: llvm::detail::PassModel<llvm::Module, llvm::CoroConditionalWrapper, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (in /home/mingo/local/codon-deploy/lib/codon/libcodonc.so)
==19105==    by 0x7D95FC7: llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (in /home/mingo/local/codon-deploy/lib/codon/libcodonc.so)
==19105==    by 0x5DA8B66: codon::ir::(anonymous namespace)::runLLVMOptimizationPasses(llvm::Module*, bool, bool, codon::PluginManager*) (in /home/mingo/local/codon-deploy/lib/codon/libcodonc.so)
==19105==    by 0x5DA82AC: codon::ir::optimize(llvm::Module*, bool, bool, codon::PluginManager*) (in /home/mingo/local/codon-deploy/lib/codon/libcodonc.so)
==19105==    by 0x5D88AB8: codon::ir::LLVMVisitor::run(std::vector<std::string, std::allocator<std::string> > const&, std::vector<std::string, std::allocator<std::string> > const&, char const* const*) (in /home/mingo/local/codon-deploy/lib/codon/libcodonc.so)
==19105==    by 0x18BC69: runMode(std::vector<char const*, std::allocator<char const*> > const&) (in /home/mingo/local/codon-deploy/bin/codon)
==19105==    by 0x18E992: main (in /home/mingo/local/codon-deploy/bin/codon)
==19105==  Block was alloc'd at
==19105==    at 0x4C337DB: operator new(unsigned long) (vg_replace_malloc.c:472)
==19105==    by 0x7DC72BC: llvm::User::operator new(unsigned long) (in /home/mingo/local/codon-deploy/lib/codon/libcodonc.so)
==19105==    by 0x7D78B6C: llvm::Module::getOrInsertFunction(llvm::StringRef, llvm::FunctionType*) (in /home/mingo/local/codon-deploy/lib/codon/libcodonc.so)
==19105==    by 0x5D7A511: codon::ir::LLVMVisitor::makeLLVMFunction(codon::ir::Func const*) (in /home/mingo/local/codon-deploy/lib/codon/libcodonc.so)
==19105==    by 0x5D79EB6: codon::ir::LLVMVisitor::registerGlobal(codon::ir::Var const*) (in /home/mingo/local/codon-deploy/lib/codon/libcodonc.so)
==19105==    by 0x5D8AB7B: codon::ir::LLVMVisitor::visit(codon::ir::Module const*) (in /home/mingo/local/codon-deploy/lib/codon/libcodonc.so)
==19105==    by 0x5AC9284: codon::Compiler::compile() (in /home/mingo/local/codon-deploy/lib/codon/libcodonc.so)
==19105==    by 0x18ABF5: processSource(std::vector<char const*, std::allocator<char const*> > const&, bool, std::function<bool ()>) (in /home/mingo/local/codon-deploy/bin/codon)
==19105==    by 0x18B851: runMode(std::vector<char const*, std::allocator<char const*> > const&) (in /home/mingo/local/codon-deploy/bin/codon)
==19105==    by 0x18E992: main (in /home/mingo/local/codon-deploy/bin/codon)
==19105== 
...
==19105== 
Testing raylib !
INFO: Initializing raylib 4.6-dev
INFO: Supported raylib modules:
INFO:     > rcore:..... loaded (mandatory)
INFO:     > rlgl:...... loaded (mandatory)
INFO:     > rshapes:... loaded (optional)
INFO:     > rtextures:. loaded (optional)
INFO:     > rtext:..... loaded (optional)
INFO:     > rmodels:... loaded (optional)
INFO:     > raudio:.... loaded (optional)
INFO: DISPLAY: Device initialized successfully
INFO:     > Display size: 1920 x 1080
INFO:     > Screen size:  100 x 100
INFO:     > Render size:  100 x 100
INFO:     > Viewport offsets: 0, 0
INFO: GLAD: OpenGL extensions loaded successfully
INFO: GL: Supported extensions count: 217
INFO: GL: OpenGL device information:
INFO:     > Vendor:   Intel Open Source Technology Center
INFO:     > Renderer: Mesa DRI Intel(R) HD Graphics 530 (SKL GT2)
INFO:     > Version:  4.6 (Core Profile) Mesa 20.0.8
INFO:     > GLSL:     4.60
INFO: GL: VAO extension detected, VAO functions loaded successfully
INFO: GL: NPOT textures extension detected, full NPOT textures supported
INFO: GL: DXT compressed textures supported
INFO: GL: ETC2/EAC compressed textures supported
INFO: TEXTURE: [ID 1] Texture loaded successfully (1x1 | R8G8B8A8 | 1 mipmaps)
INFO: TEXTURE: [ID 1] Default texture loaded successfully
INFO: SHADER: [ID 1] Vertex shader compiled successfully
INFO: SHADER: [ID 2] Fragment shader compiled successfully
INFO: SHADER: [ID 3] Program shader loaded successfully
INFO: SHADER: [ID 3] Default shader loaded successfully
INFO: RLGL: Render batch vertex buffers loaded successfully in RAM (CPU)
INFO: RLGL: Render batch vertex buffers loaded successfully in VRAM (GPU)
INFO: RLGL: Default OpenGL state initialized successfully
INFO: TEXTURE: [ID 2] Texture loaded successfully (128x128 | GRAY_ALPHA | 1 mipmaps)
INFO: FONT: Default font loaded successfully (224 glyphs)
INFO: TEXTURE: [ID 2] Unloaded texture data from VRAM (GPU)
INFO: SHADER: [ID 3] Default shader unloaded successfully
INFO: TEXTURE: [ID 1] Default texture unloaded successfully
INFO: Window closed successfully
==19105== 
==19105== HEAP SUMMARY:
==19105==     in use at exit: 386,262 bytes in 3,300 blocks
==19105==   total heap usage: 5,157,822 allocs, 5,154,522 frees, 379,488,035 bytes allocated
==19105== 
==19105== LEAK SUMMARY:
==19105==    definitely lost: 1,568 bytes in 3 blocks
==19105==    indirectly lost: 12,179 bytes in 48 blocks
==19105==      possibly lost: 4,813 bytes in 9 blocks
==19105==    still reachable: 366,010 bytes in 3,239 blocks
==19105==                       of which reachable via heuristic:
==19105==                         stdstring          : 2,284 bytes in 41 blocks
==19105==         suppressed: 1,692 bytes in 1 blocks
==19105== Rerun with --leak-check=full to see details of leaked memory
==19105== 
==19105== Use --track-origins=yes to see where uninitialised values come from
==19105== For lists of detected and suppressed errors, rerun with: -s
==19105== ERROR SUMMARY: 573 errors from 12 contexts (suppressed: 0 from 0)

My test programs: C test program:

#include <stdio.h>
#include "raylib.h"

int main(int argc, char *argv[])
{
    printf("Testing raylib !\n");
    InitWindow(100, 100, "Testing raylib !");
    CloseWindow();
    return 0;
}

Codon program:

from C import InitWindow(int, int, cobj) -> None
from C import CloseWindow() -> None

print("Testing raylib !")
title = "Testing raylib!"
InitWindow(100, 100, title.c_str())
CloseWindow()
mingodad commented 1 year ago

What do you get if you run this:

valgrind codon run -l ./raylib/src/libraylib.so.4.5.0 test.codon

Notice that it can take a while to run under valgrind !

sDos280 commented 1 year ago
==163689== Memcheck, a memory error detector
==163689== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==163689== Using Valgrind-3.15.0 and LibVEX; rerun with -h for copyright info
==163689== Command: codon run -l ./raylib/src/libraylib.so.4.5.0 test.codon
==163689== 
==163689== Invalid read of size 1
==163689==    at 0xC102712: GC_find_limit_with_bound (in /home/dor283/.codon/lib/codon/libcodonrt.so)
==163689==    by 0xC10252F: GC_init_linux_data_start (in /home/dor283/.codon/lib/codon/libcodonrt.so)
==163689==    by 0xC10071C: GC_init (in /home/dor283/.codon/lib/codon/libcodonrt.so)
==163689==    by 0xC103A27: GC_add_roots (in /home/dor283/.codon/lib/codon/libcodonrt.so)
==163689==    by 0x551163D: codon::BoehmGCJITLinkMemoryManager::allocate(llvm::jitlink::JITLinkDylib const*, llvm::jitlink::LinkGraph&, llvm::unique_function<void (llvm::Expected<std::unique_ptr<llvm::jitlink::JITLinkMemoryManager::InFlightAlloc, std::default_delete<llvm::jitlink::JITLinkMemoryManager::InFlightAlloc> > >)>) (in /home/dor283/.codon/lib/codon/libcodonc.so)
==163689==    by 0x8D19CC5: llvm::jitlink::JITLinkerBase::linkPhase1(std::unique_ptr<llvm::jitlink::JITLinkerBase, std::default_delete<llvm::jitlink::JITLinkerBase> >) (in /home/dor283/.codon/lib/codon/libcodonc.so)
==163689==    by 0x8D0A296: llvm::jitlink::link_ELF_x86_64(std::unique_ptr<llvm::jitlink::LinkGraph, std::default_delete<llvm::jitlink::LinkGraph> >, std::unique_ptr<llvm::jitlink::JITLinkContext, std::default_delete<llvm::jitlink::JITLinkContext> >) (in /home/dor283/.codon/lib/codon/libcodonc.so)
==163689==    by 0x8CF7047: llvm::jitlink::link_ELF(std::unique_ptr<llvm::jitlink::LinkGraph, std::default_delete<llvm::jitlink::LinkGraph> >, std::unique_ptr<llvm::jitlink::JITLinkContext, std::default_delete<llvm::jitlink::JITLinkContext> >) (in /home/dor283/.codon/lib/codon/libcodonc.so)
==163689==    by 0x8CC959E: llvm::jitlink::link(std::unique_ptr<llvm::jitlink::LinkGraph, std::default_delete<llvm::jitlink::LinkGraph> >, std::unique_ptr<llvm::jitlink::JITLinkContext, std::default_delete<llvm::jitlink::JITLinkContext> >) (in /home/dor283/.codon/lib/codon/libcodonc.so)
==163689==    by 0x7C4859B: llvm::orc::ObjectLinkingLayer::emit(std::unique_ptr<llvm::orc::MaterializationResponsibility, std::default_delete<llvm::orc::MaterializationResponsibility> >, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer> >) (in /home/dor283/.codon/lib/codon/libcodonc.so)
==163689==    by 0x7C53E30: llvm::orc::ObjectTransformLayer::emit(std::unique_ptr<llvm::orc::MaterializationResponsibility, std::default_delete<llvm::orc::MaterializationResponsibility> >, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer> >) (in /home/dor283/.codon/lib/codon/libcodonc.so)
==163689==    by 0x7C09527: llvm::orc::IRCompileLayer::emit(std::unique_ptr<llvm::orc::MaterializationResponsibility, std::default_delete<llvm::orc::MaterializationResponsibility> >, llvm::orc::ThreadSafeModule) (in /home/dor283/.codon/lib/codon/libcodonc.so)
==163689==  Address 0x107f00 is not stack'd, malloc'd or (recently) free'd
==163689== 
==163689== Conditional jump or move depends on uninitialised value(s)
==163689==    at 0xC10782F: GC_push_all_eager (in /home/dor283/.codon/lib/codon/libcodonrt.so)
==163689==    by 0xC10225E: GC_with_callee_saves_pushed (in /home/dor283/.codon/lib/codon/libcodonrt.so)
==163689==    by 0xC1043E7: GC_push_roots (in /home/dor283/.codon/lib/codon/libcodonrt.so)
==163689==    by 0xC105AEA: GC_mark_some (in /home/dor283/.codon/lib/codon/libcodonrt.so)
==163689==    by 0xC0FB2CC: GC_stopped_mark (in /home/dor283/.codon/lib/codon/libcodonrt.so)
==163689==    by 0xC0FB098: GC_try_to_collect_inner (in /home/dor283/.codon/lib/codon/libcodonrt.so)
==163689==    by 0xC1008A7: GC_init (in /home/dor283/.codon/lib/codon/libcodonrt.so)
==163689==    by 0xC103A27: GC_add_roots (in /home/dor283/.codon/lib/codon/libcodonrt.so)
==163689==    by 0x551163D: codon::BoehmGCJITLinkMemoryManager::allocate(llvm::jitlink::JITLinkDylib const*, llvm::jitlink::LinkGraph&, llvm::unique_function<void (llvm::Expected<std::unique_ptr<llvm::jitlink::JITLinkMemoryManager::InFlightAlloc, std::default_delete<llvm::jitlink::JITLinkMemoryManager::InFlightAlloc> > >)>) (in /home/dor283/.codon/lib/codon/libcodonc.so)
==163689==    by 0x8D19CC5: llvm::jitlink::JITLinkerBase::linkPhase1(std::unique_ptr<llvm::jitlink::JITLinkerBase, std::default_delete<llvm::jitlink::JITLinkerBase> >) (in /home/dor283/.codon/lib/codon/libcodonc.so)
==163689==    by 0x8D0A296: llvm::jitlink::link_ELF_x86_64(std::unique_ptr<llvm::jitlink::LinkGraph, std::default_delete<llvm::jitlink::LinkGraph> >, std::unique_ptr<llvm::jitlink::JITLinkContext, std::default_delete<llvm::jitlink::JITLinkContext> >) (in /home/dor283/.codon/lib/codon/libcodonc.so)
==163689==    by 0x8CF7047: llvm::jitlink::link_ELF(std::unique_ptr<llvm::jitlink::LinkGraph, std::default_delete<llvm::jitlink::LinkGraph> >, std::unique_ptr<llvm::jitlink::JITLinkContext, std::default_delete<llvm::jitlink::JITLinkContext> >) (in /home/dor283/.codon/lib/codon/libcodonc.so)
==163689== 
==163689== Conditional jump or move depends on uninitialised value(s)
==163689==    at 0xC107834: GC_push_all_eager (in /home/dor283/.codon/lib/codon/libcodonrt.so)
==163689==    by 0xC10225E: GC_with_callee_saves_pushed (in /home/dor283/.codon/lib/codon/libcodonrt.so)
==163689==    by 0xC1043E7: GC_push_roots (in /home/dor283/.codon/lib/codon/libcodonrt.so)
==163689==    by 0xC105AEA: GC_mark_some (in /home/dor283/.codon/lib/codon/libcodonrt.so)
==163689==    by 0xC0FB2CC: GC_stopped_mark (in /home/dor283/.codon/lib/codon/libcodonrt.so)
==163689==    by 0xC0FB098: GC_try_to_collect_inner (in /home/dor283/.codon/lib/codon/libcodonrt.so)
==163689==    by 0xC1008A7: GC_init (in /home/dor283/.codon/lib/codon/libcodonrt.so)
==163689==    by 0xC103A27: GC_add_roots (in /home/dor283/.codon/lib/codon/libcodonrt.so)
==163689==    by 0x551163D: codon::BoehmGCJITLinkMemoryManager::allocate(llvm::jitlink::JITLinkDylib const*, llvm::jitlink::LinkGraph&, llvm::unique_function<void (llvm::Expected<std::unique_ptr<llvm::jitlink::JITLinkMemoryManager::InFlightAlloc, std::default_delete<llvm::jitlink::JITLinkMemoryManager::InFlightAlloc> > >)>) (in /home/dor283/.codon/lib/codon/libcodonc.so)
==163689==    by 0x8D19CC5: llvm::jitlink::JITLinkerBase::linkPhase1(std::unique_ptr<llvm::jitlink::JITLinkerBase, std::default_delete<llvm::jitlink::JITLinkerBase> >) (in /home/dor283/.codon/lib/codon/libcodonc.so)
==163689==    by 0x8D0A296: llvm::jitlink::link_ELF_x86_64(std::unique_ptr<llvm::jitlink::LinkGraph, std::default_delete<llvm::jitlink::LinkGraph> >, std::unique_ptr<llvm::jitlink::JITLinkContext, std::default_delete<llvm::jitlink::JITLinkContext> >) (in /home/dor283/.codon/lib/codon/libcodonc.so)
==163689==    by 0x8CF7047: llvm::jitlink::link_ELF(std::unique_ptr<llvm::jitlink::LinkGraph, std::default_delete<llvm::jitlink::LinkGraph> >, std::unique_ptr<llvm::jitlink::JITLinkContext, std::default_delete<llvm::jitlink::JITLinkContext> >) (in /home/dor283/.codon/lib/codon/libcodonc.so)
==163689== 
==163689== Conditional jump or move depends on uninitialised value(s)
==163689==    at 0xC106382: GC_mark_from (in /home/dor283/.codon/lib/codon/libcodonrt.so)
==163689==    by 0xC106F81: GC_mark_local (in /home/dor283/.codon/lib/codon/libcodonrt.so)
==163689==    by 0xC1056A1: GC_mark_some (in /home/dor283/.codon/lib/codon/libcodonrt.so)
==163689==    by 0xC0FB2CC: GC_stopped_mark (in /home/dor283/.codon/lib/codon/libcodonrt.so)
==163689==    by 0xC0FB098: GC_try_to_collect_inner (in /home/dor283/.codon/lib/codon/libcodonrt.so)
==163689==    by 0xC1008A7: GC_init (in /home/dor283/.codon/lib/codon/libcodonrt.so)
==163689==    by 0xC103A27: GC_add_roots (in /home/dor283/.codon/lib/codon/libcodonrt.so)
==163689==    by 0x551163D: codon::BoehmGCJITLinkMemoryManager::allocate(llvm::jitlink::JITLinkDylib const*, llvm::jitlink::LinkGraph&, llvm::unique_function<void (llvm::Expected<std::unique_ptr<llvm::jitlink::JITLinkMemoryManager::InFlightAlloc, std::default_delete<llvm::jitlink::JITLinkMemoryManager::InFlightAlloc> > >)>) (in /home/dor283/.codon/lib/codon/libcodonc.so)
==163689==    by 0x8D19CC5: llvm::jitlink::JITLinkerBase::linkPhase1(std::unique_ptr<llvm::jitlink::JITLinkerBase, std::default_delete<llvm::jitlink::JITLinkerBase> >) (in /home/dor283/.codon/lib/codon/libcodonc.so)
==163689==    by 0x8D0A296: llvm::jitlink::link_ELF_x86_64(std::unique_ptr<llvm::jitlink::LinkGraph, std::default_delete<llvm::jitlink::LinkGraph> >, std::unique_ptr<llvm::jitlink::JITLinkContext, std::default_delete<llvm::jitlink::JITLinkContext> >) (in /home/dor283/.codon/lib/codon/libcodonc.so)
==163689==    by 0x8CF7047: llvm::jitlink::link_ELF(std::unique_ptr<llvm::jitlink::LinkGraph, std::default_delete<llvm::jitlink::LinkGraph> >, std::unique_ptr<llvm::jitlink::JITLinkContext, std::default_delete<llvm::jitlink::JITLinkContext> >) (in /home/dor283/.codon/lib/codon/libcodonc.so)
==163689==    by 0x8CC959E: llvm::jitlink::link(std::unique_ptr<llvm::jitlink::LinkGraph, std::default_delete<llvm::jitlink::LinkGraph> >, std::unique_ptr<llvm::jitlink::JITLinkContext, std::default_delete<llvm::jitlink::JITLinkContext> >) (in /home/dor283/.codon/lib/codon/libcodonc.so)
==163689== 
==163689== Conditional jump or move depends on uninitialised value(s)
==163689==    at 0xC106398: GC_mark_from (in /home/dor283/.codon/lib/codon/libcodonrt.so)
==163689==    by 0xC106F81: GC_mark_local (in /home/dor283/.codon/lib/codon/libcodonrt.so)
==163689==    by 0xC1056A1: GC_mark_some (in /home/dor283/.codon/lib/codon/libcodonrt.so)
==163689==    by 0xC0FB2CC: GC_stopped_mark (in /home/dor283/.codon/lib/codon/libcodonrt.so)
==163689==    by 0xC0FB098: GC_try_to_collect_inner (in /home/dor283/.codon/lib/codon/libcodonrt.so)
==163689==    by 0xC1008A7: GC_init (in /home/dor283/.codon/lib/codon/libcodonrt.so)
==163689==    by 0xC103A27: GC_add_roots (in /home/dor283/.codon/lib/codon/libcodonrt.so)
==163689==    by 0x551163D: codon::BoehmGCJITLinkMemoryManager::allocate(llvm::jitlink::JITLinkDylib const*, llvm::jitlink::LinkGraph&, llvm::unique_function<void (llvm::Expected<std::unique_ptr<llvm::jitlink::JITLinkMemoryManager::InFlightAlloc, std::default_delete<llvm::jitlink::JITLinkMemoryManager::InFlightAlloc> > >)>) (in /home/dor283/.codon/lib/codon/libcodonc.so)
==163689==    by 0x8D19CC5: llvm::jitlink::JITLinkerBase::linkPhase1(std::unique_ptr<llvm::jitlink::JITLinkerBase, std::default_delete<llvm::jitlink::JITLinkerBase> >) (in /home/dor283/.codon/lib/codon/libcodonc.so)
==163689==    by 0x8D0A296: llvm::jitlink::link_ELF_x86_64(std::unique_ptr<llvm::jitlink::LinkGraph, std::default_delete<llvm::jitlink::LinkGraph> >, std::unique_ptr<llvm::jitlink::JITLinkContext, std::default_delete<llvm::jitlink::JITLinkContext> >) (in /home/dor283/.codon/lib/codon/libcodonc.so)
==163689==    by 0x8CF7047: llvm::jitlink::link_ELF(std::unique_ptr<llvm::jitlink::LinkGraph, std::default_delete<llvm::jitlink::LinkGraph> >, std::unique_ptr<llvm::jitlink::JITLinkContext, std::default_delete<llvm::jitlink::JITLinkContext> >) (in /home/dor283/.codon/lib/codon/libcodonc.so)
==163689==    by 0x8CC959E: llvm::jitlink::link(std::unique_ptr<llvm::jitlink::LinkGraph, std::default_delete<llvm::jitlink::LinkGraph> >, std::unique_ptr<llvm::jitlink::JITLinkContext, std::default_delete<llvm::jitlink::JITLinkContext> >) (in /home/dor283/.codon/lib/codon/libcodonc.so)
==163689== 
==163689== Conditional jump or move depends on uninitialised value(s)
==163689==    at 0xC10639D: GC_mark_from (in /home/dor283/.codon/lib/codon/libcodonrt.so)
==163689==    by 0xC106F81: GC_mark_local (in /home/dor283/.codon/lib/codon/libcodonrt.so)
==163689==    by 0xC1056A1: GC_mark_some (in /home/dor283/.codon/lib/codon/libcodonrt.so)
==163689==    by 0xC0FB2CC: GC_stopped_mark (in /home/dor283/.codon/lib/codon/libcodonrt.so)
==163689==    by 0xC0FB098: GC_try_to_collect_inner (in /home/dor283/.codon/lib/codon/libcodonrt.so)
==163689==    by 0xC1008A7: GC_init (in /home/dor283/.codon/lib/codon/libcodonrt.so)
==163689==    by 0xC103A27: GC_add_roots (in /home/dor283/.codon/lib/codon/libcodonrt.so)
==163689==    by 0x551163D: codon::BoehmGCJITLinkMemoryManager::allocate(llvm::jitlink::JITLinkDylib const*, llvm::jitlink::LinkGraph&, llvm::unique_function<void (llvm::Expected<std::unique_ptr<llvm::jitlink::JITLinkMemoryManager::InFlightAlloc, std::default_delete<llvm::jitlink::JITLinkMemoryManager::InFlightAlloc> > >)>) (in /home/dor283/.codon/lib/codon/libcodonc.so)
==163689==    by 0x8D19CC5: llvm::jitlink::JITLinkerBase::linkPhase1(std::unique_ptr<llvm::jitlink::JITLinkerBase, std::default_delete<llvm::jitlink::JITLinkerBase> >) (in /home/dor283/.codon/lib/codon/libcodonc.so)
==163689==    by 0x8D0A296: llvm::jitlink::link_ELF_x86_64(std::unique_ptr<llvm::jitlink::LinkGraph, std::default_delete<llvm::jitlink::LinkGraph> >, std::unique_ptr<llvm::jitlink::JITLinkContext, std::default_delete<llvm::jitlink::JITLinkContext> >) (in /home/dor283/.codon/lib/codon/libcodonc.so)
==163689==    by 0x8CF7047: llvm::jitlink::link_ELF(std::unique_ptr<llvm::jitlink::LinkGraph, std::default_delete<llvm::jitlink::LinkGraph> >, std::unique_ptr<llvm::jitlink::JITLinkContext, std::default_delete<llvm::jitlink::JITLinkContext> >) (in /home/dor283/.codon/lib/codon/libcodonc.so)
==163689==    by 0x8CC959E: llvm::jitlink::link(std::unique_ptr<llvm::jitlink::LinkGraph, std::default_delete<llvm::jitlink::LinkGraph> >, std::unique_ptr<llvm::jitlink::JITLinkContext, std::default_delete<llvm::jitlink::JITLinkContext> >) (in /home/dor283/.codon/lib/codon/libcodonc.so)
==163689== 
==163689== Conditional jump or move depends on uninitialised value(s)
==163689==    at 0xC106387: GC_mark_from (in /home/dor283/.codon/lib/codon/libcodonrt.so)
==163689==    by 0xC106F81: GC_mark_local (in /home/dor283/.codon/lib/codon/libcodonrt.so)
==163689==    by 0xC1056A1: GC_mark_some (in /home/dor283/.codon/lib/codon/libcodonrt.so)
==163689==    by 0xC0FB2CC: GC_stopped_mark (in /home/dor283/.codon/lib/codon/libcodonrt.so)
==163689==    by 0xC0FB098: GC_try_to_collect_inner (in /home/dor283/.codon/lib/codon/libcodonrt.so)
==163689==    by 0xC1008A7: GC_init (in /home/dor283/.codon/lib/codon/libcodonrt.so)
==163689==    by 0xC103A27: GC_add_roots (in /home/dor283/.codon/lib/codon/libcodonrt.so)
==163689==    by 0x551163D: codon::BoehmGCJITLinkMemoryManager::allocate(llvm::jitlink::JITLinkDylib const*, llvm::jitlink::LinkGraph&, llvm::unique_function<void (llvm::Expected<std::unique_ptr<llvm::jitlink::JITLinkMemoryManager::InFlightAlloc, std::default_delete<llvm::jitlink::JITLinkMemoryManager::InFlightAlloc> > >)>) (in /home/dor283/.codon/lib/codon/libcodonc.so)
==163689==    by 0x8D19CC5: llvm::jitlink::JITLinkerBase::linkPhase1(std::unique_ptr<llvm::jitlink::JITLinkerBase, std::default_delete<llvm::jitlink::JITLinkerBase> >) (in /home/dor283/.codon/lib/codon/libcodonc.so)
==163689==    by 0x8D0A296: llvm::jitlink::link_ELF_x86_64(std::unique_ptr<llvm::jitlink::LinkGraph, std::default_delete<llvm::jitlink::LinkGraph> >, std::unique_ptr<llvm::jitlink::JITLinkContext, std::default_delete<llvm::jitlink::JITLinkContext> >) (in /home/dor283/.codon/lib/codon/libcodonc.so)
==163689==    by 0x8CF7047: llvm::jitlink::link_ELF(std::unique_ptr<llvm::jitlink::LinkGraph, std::default_delete<llvm::jitlink::LinkGraph> >, std::unique_ptr<llvm::jitlink::JITLinkContext, std::default_delete<llvm::jitlink::JITLinkContext> >) (in /home/dor283/.codon/lib/codon/libcodonc.so)
==163689==    by 0x8CC959E: llvm::jitlink::link(std::unique_ptr<llvm::jitlink::LinkGraph, std::default_delete<llvm::jitlink::LinkGraph> >, std::unique_ptr<llvm::jitlink::JITLinkContext, std::default_delete<llvm::jitlink::JITLinkContext> >) (in /home/dor283/.codon/lib/codon/libcodonc.so)
==163689== 
==163689== Conditional jump or move depends on uninitialised value(s)
==163689==    at 0xC106382: GC_mark_from (in /home/dor283/.codon/lib/codon/libcodonrt.so)
==163689==    by 0xC106F1C: GC_mark_local (in /home/dor283/.codon/lib/codon/libcodonrt.so)
==163689==    by 0xC1056A1: GC_mark_some (in /home/dor283/.codon/lib/codon/libcodonrt.so)
==163689==    by 0xC0FB2CC: GC_stopped_mark (in /home/dor283/.codon/lib/codon/libcodonrt.so)
==163689==    by 0xC0FB098: GC_try_to_collect_inner (in /home/dor283/.codon/lib/codon/libcodonrt.so)
==163689==    by 0xC1008A7: GC_init (in /home/dor283/.codon/lib/codon/libcodonrt.so)
==163689==    by 0xC103A27: GC_add_roots (in /home/dor283/.codon/lib/codon/libcodonrt.so)
==163689==    by 0x551163D: codon::BoehmGCJITLinkMemoryManager::allocate(llvm::jitlink::JITLinkDylib const*, llvm::jitlink::LinkGraph&, llvm::unique_function<void (llvm::Expected<std::unique_ptr<llvm::jitlink::JITLinkMemoryManager::InFlightAlloc, std::default_delete<llvm::jitlink::JITLinkMemoryManager::InFlightAlloc> > >)>) (in /home/dor283/.codon/lib/codon/libcodonc.so)
==163689==    by 0x8D19CC5: llvm::jitlink::JITLinkerBase::linkPhase1(std::unique_ptr<llvm::jitlink::JITLinkerBase, std::default_delete<llvm::jitlink::JITLinkerBase> >) (in /home/dor283/.codon/lib/codon/libcodonc.so)
==163689==    by 0x8D0A296: llvm::jitlink::link_ELF_x86_64(std::unique_ptr<llvm::jitlink::LinkGraph, std::default_delete<llvm::jitlink::LinkGraph> >, std::unique_ptr<llvm::jitlink::JITLinkContext, std::default_delete<llvm::jitlink::JITLinkContext> >) (in /home/dor283/.codon/lib/codon/libcodonc.so)
==163689==    by 0x8CF7047: llvm::jitlink::link_ELF(std::unique_ptr<llvm::jitlink::LinkGraph, std::default_delete<llvm::jitlink::LinkGraph> >, std::unique_ptr<llvm::jitlink::JITLinkContext, std::default_delete<llvm::jitlink::JITLinkContext> >) (in /home/dor283/.codon/lib/codon/libcodonc.so)
==163689==    by 0x8CC959E: llvm::jitlink::link(std::unique_ptr<llvm::jitlink::LinkGraph, std::default_delete<llvm::jitlink::LinkGraph> >, std::unique_ptr<llvm::jitlink::JITLinkContext, std::default_delete<llvm::jitlink::JITLinkContext> >) (in /home/dor283/.codon/lib/codon/libcodonc.so)
==163689== 
==163689== Conditional jump or move depends on uninitialised value(s)
==163689==    at 0xC106398: GC_mark_from (in /home/dor283/.codon/lib/codon/libcodonrt.so)
==163689==    by 0xC106F1C: GC_mark_local (in /home/dor283/.codon/lib/codon/libcodonrt.so)
==163689==    by 0xC1056A1: GC_mark_some (in /home/dor283/.codon/lib/codon/libcodonrt.so)
==163689==    by 0xC0FB2CC: GC_stopped_mark (in /home/dor283/.codon/lib/codon/libcodonrt.so)
==163689==    by 0xC0FB098: GC_try_to_collect_inner (in /home/dor283/.codon/lib/codon/libcodonrt.so)
==163689==    by 0xC1008A7: GC_init (in /home/dor283/.codon/lib/codon/libcodonrt.so)
==163689==    by 0xC103A27: GC_add_roots (in /home/dor283/.codon/lib/codon/libcodonrt.so)
==163689==    by 0x551163D: codon::BoehmGCJITLinkMemoryManager::allocate(llvm::jitlink::JITLinkDylib const*, llvm::jitlink::LinkGraph&, llvm::unique_function<void (llvm::Expected<std::unique_ptr<llvm::jitlink::JITLinkMemoryManager::InFlightAlloc, std::default_delete<llvm::jitlink::JITLinkMemoryManager::InFlightAlloc> > >)>) (in /home/dor283/.codon/lib/codon/libcodonc.so)
==163689==    by 0x8D19CC5: llvm::jitlink::JITLinkerBase::linkPhase1(std::unique_ptr<llvm::jitlink::JITLinkerBase, std::default_delete<llvm::jitlink::JITLinkerBase> >) (in /home/dor283/.codon/lib/codon/libcodonc.so)
==163689==    by 0x8D0A296: llvm::jitlink::link_ELF_x86_64(std::unique_ptr<llvm::jitlink::LinkGraph, std::default_delete<llvm::jitlink::LinkGraph> >, std::unique_ptr<llvm::jitlink::JITLinkContext, std::default_delete<llvm::jitlink::JITLinkContext> >) (in /home/dor283/.codon/lib/codon/libcodonc.so)
==163689==    by 0x8CF7047: llvm::jitlink::link_ELF(std::unique_ptr<llvm::jitlink::LinkGraph, std::default_delete<llvm::jitlink::LinkGraph> >, std::unique_ptr<llvm::jitlink::JITLinkContext, std::default_delete<llvm::jitlink::JITLinkContext> >) (in /home/dor283/.codon/lib/codon/libcodonc.so)
==163689==    by 0x8CC959E: llvm::jitlink::link(std::unique_ptr<llvm::jitlink::LinkGraph, std::default_delete<llvm::jitlink::LinkGraph> >, std::unique_ptr<llvm::jitlink::JITLinkContext, std::default_delete<llvm::jitlink::JITLinkContext> >) (in /home/dor283/.codon/lib/codon/libcodonc.so)
==163689== 
==163689== Conditional jump or move depends on uninitialised value(s)
==163689==    at 0xC10639D: GC_mark_from (in /home/dor283/.codon/lib/codon/libcodonrt.so)
==163689==    by 0xC106F1C: GC_mark_local (in /home/dor283/.codon/lib/codon/libcodonrt.so)
==163689==    by 0xC1056A1: GC_mark_some (in /home/dor283/.codon/lib/codon/libcodonrt.so)
==163689==    by 0xC0FB2CC: GC_stopped_mark (in /home/dor283/.codon/lib/codon/libcodonrt.so)
==163689==    by 0xC0FB098: GC_try_to_collect_inner (in /home/dor283/.codon/lib/codon/libcodonrt.so)
==163689==    by 0xC1008A7: GC_init (in /home/dor283/.codon/lib/codon/libcodonrt.so)
==163689==    by 0xC103A27: GC_add_roots (in /home/dor283/.codon/lib/codon/libcodonrt.so)
==163689==    by 0x551163D: codon::BoehmGCJITLinkMemoryManager::allocate(llvm::jitlink::JITLinkDylib const*, llvm::jitlink::LinkGraph&, llvm::unique_function<void (llvm::Expected<std::unique_ptr<llvm::jitlink::JITLinkMemoryManager::InFlightAlloc, std::default_delete<llvm::jitlink::JITLinkMemoryManager::InFlightAlloc> > >)>) (in /home/dor283/.codon/lib/codon/libcodonc.so)
==163689==    by 0x8D19CC5: llvm::jitlink::JITLinkerBase::linkPhase1(std::unique_ptr<llvm::jitlink::JITLinkerBase, std::default_delete<llvm::jitlink::JITLinkerBase> >) (in /home/dor283/.codon/lib/codon/libcodonc.so)
==163689==    by 0x8D0A296: llvm::jitlink::link_ELF_x86_64(std::unique_ptr<llvm::jitlink::LinkGraph, std::default_delete<llvm::jitlink::LinkGraph> >, std::unique_ptr<llvm::jitlink::JITLinkContext, std::default_delete<llvm::jitlink::JITLinkContext> >) (in /home/dor283/.codon/lib/codon/libcodonc.so)
==163689==    by 0x8CF7047: llvm::jitlink::link_ELF(std::unique_ptr<llvm::jitlink::LinkGraph, std::default_delete<llvm::jitlink::LinkGraph> >, std::unique_ptr<llvm::jitlink::JITLinkContext, std::default_delete<llvm::jitlink::JITLinkContext> >) (in /home/dor283/.codon/lib/codon/libcodonc.so)
==163689==    by 0x8CC959E: llvm::jitlink::link(std::unique_ptr<llvm::jitlink::LinkGraph, std::default_delete<llvm::jitlink::LinkGraph> >, std::unique_ptr<llvm::jitlink::JITLinkContext, std::default_delete<llvm::jitlink::JITLinkContext> >) (in /home/dor283/.codon/lib/codon/libcodonc.so)
==163689== 
==163689== Conditional jump or move depends on uninitialised value(s)
==163689==    at 0xC106387: GC_mark_from (in /home/dor283/.codon/lib/codon/libcodonrt.so)
==163689==    by 0xC106F1C: GC_mark_local (in /home/dor283/.codon/lib/codon/libcodonrt.so)
==163689==    by 0xC1056A1: GC_mark_some (in /home/dor283/.codon/lib/codon/libcodonrt.so)
==163689==    by 0xC0FB2CC: GC_stopped_mark (in /home/dor283/.codon/lib/codon/libcodonrt.so)
==163689==    by 0xC0FB098: GC_try_to_collect_inner (in /home/dor283/.codon/lib/codon/libcodonrt.so)
==163689==    by 0xC1008A7: GC_init (in /home/dor283/.codon/lib/codon/libcodonrt.so)
==163689==    by 0xC103A27: GC_add_roots (in /home/dor283/.codon/lib/codon/libcodonrt.so)
==163689==    by 0x551163D: codon::BoehmGCJITLinkMemoryManager::allocate(llvm::jitlink::JITLinkDylib const*, llvm::jitlink::LinkGraph&, llvm::unique_function<void (llvm::Expected<std::unique_ptr<llvm::jitlink::JITLinkMemoryManager::InFlightAlloc, std::default_delete<llvm::jitlink::JITLinkMemoryManager::InFlightAlloc> > >)>) (in /home/dor283/.codon/lib/codon/libcodonc.so)
==163689==    by 0x8D19CC5: llvm::jitlink::JITLinkerBase::linkPhase1(std::unique_ptr<llvm::jitlink::JITLinkerBase, std::default_delete<llvm::jitlink::JITLinkerBase> >) (in /home/dor283/.codon/lib/codon/libcodonc.so)
==163689==    by 0x8D0A296: llvm::jitlink::link_ELF_x86_64(std::unique_ptr<llvm::jitlink::LinkGraph, std::default_delete<llvm::jitlink::LinkGraph> >, std::unique_ptr<llvm::jitlink::JITLinkContext, std::default_delete<llvm::jitlink::JITLinkContext> >) (in /home/dor283/.codon/lib/codon/libcodonc.so)
==163689==    by 0x8CF7047: llvm::jitlink::link_ELF(std::unique_ptr<llvm::jitlink::LinkGraph, std::default_delete<llvm::jitlink::LinkGraph> >, std::unique_ptr<llvm::jitlink::JITLinkContext, std::default_delete<llvm::jitlink::JITLinkContext> >) (in /home/dor283/.codon/lib/codon/libcodonc.so)
==163689==    by 0x8CC959E: llvm::jitlink::link(std::unique_ptr<llvm::jitlink::LinkGraph, std::default_delete<llvm::jitlink::LinkGraph> >, std::unique_ptr<llvm::jitlink::JITLinkContext, std::default_delete<llvm::jitlink::JITLinkContext> >) (in /home/dor283/.codon/lib/codon/libcodonc.so)
==163689== 
INFO: Initializing raylib 4.6-dev
INFO: Supported raylib modules:
INFO:     > rcore:..... loaded (mandatory)
INFO:     > rlgl:...... loaded (mandatory)
INFO:     > rshapes:... loaded (optional)
INFO:     > rtextures:. loaded (optional)
INFO:     > rtext:..... loaded (optional)
INFO:     > rmodels:... loaded (optional)
INFO:     > raudio:.... loaded (optional)
==163689== 
==163689== Process terminating with default action of signal 6 (SIGABRT)
==163689==    at 0xBE6100B: raise (raise.c:51)
==163689==    by 0xBE40858: abort (abort.c:79)
==163689==    by 0x2176D208: llvm::report_fatal_error(llvm::Twine const&, bool) (in /usr/lib/x86_64-linux-gnu/libLLVM-12.so.1)
==163689==    by 0x2176D025: llvm::report_fatal_error(char const*, bool) (in /usr/lib/x86_64-linux-gnu/libLLVM-12.so.1)
==163689==    by 0x2175C9FC: ??? (in /usr/lib/x86_64-linux-gnu/libLLVM-12.so.1)
==163689==    by 0x217515A4: ??? (in /usr/lib/x86_64-linux-gnu/libLLVM-12.so.1)
==163689==    by 0x2175E8DC: ??? (in /usr/lib/x86_64-linux-gnu/libLLVM-12.so.1)
==163689==    by 0x217A2363: llvm::ManagedStaticBase::RegisterManagedStatic(void* (*)(), void (*)(void*)) const (in /usr/lib/x86_64-linux-gnu/libLLVM-12.so.1)
==163689==    by 0x2162FE93: ??? (in /usr/lib/x86_64-linux-gnu/libLLVM-12.so.1)
==163689==    by 0x4011B99: call_init.part.0 (dl-init.c:72)
==163689==    by 0x4011CA0: call_init (dl-init.c:30)
==163689==    by 0x4011CA0: _dl_init (dl-init.c:119)
==163689==    by 0xBF7E984: _dl_catch_exception (dl-error-skeleton.c:182)
==163689== 
==163689== HEAP SUMMARY:
==163689==     in use at exit: 46,705,441 bytes in 502,980 blocks
==163689==   total heap usage: 4,767,119 allocs, 4,264,139 frees, 336,697,782 bytes allocated
==163689== 
==163689== LEAK SUMMARY:
==163689==    definitely lost: 1,456 bytes in 8 blocks
==163689==    indirectly lost: 10,532 bytes in 13 blocks
==163689==      possibly lost: 61,397 bytes in 68 blocks
==163689==    still reachable: 46,632,056 bytes in 502,891 blocks
==163689==                       of which reachable via heuristic:
==163689==                         stdstring          : 6,506,071 bytes in 119,176 blocks
==163689==         suppressed: 0 bytes in 0 blocks
==163689== Rerun with --leak-check=full to see details of leaked memory
==163689== 
==163689== Use --track-origins=yes to see where uninitialised values come from
==163689== For lists of detected and suppressed errors, rerun with: -s
==163689== ERROR SUMMARY: 517 errors from 11 contexts (suppressed: 2 from 2)
Aborted (core dumped)
mingodad commented 1 year ago

What version of codon do you have ? I tested with 0.16.0 and 0.16.0.1 .

codon --version
0.16.0
sDos280 commented 1 year ago

it seems that I use codon 0.16.1

codon --version
0.16.1
mingodad commented 1 year ago

And also can you test with the small C program I showed here https://github.com/exaloop/codon/issues/391#issuecomment-1562772299 ?

raylibh=$HOME/local/raylib
gcc -o test-raylib-c test-raylib.c -I$raylibh/include -L$raylibh/lib -lraylib -lm -ldl -lpthread
sDos280 commented 1 year ago

It seems that I don't have $HOME/local/raylib have you used raylib before? it seems that you already make install it, but it isn't really possible when compiling raylib as a dynamic linking...

would you want me to test that with the dynamic or static raylib's library?

mingodad commented 1 year ago

You need to adjust it to where do you have your installation include/lib and to run if they are not in the LD_LIBRARY_PATH youll need something like:

LD_LIBRARY_PATH=your_raylib_lib_path:$LD_LIBRARY_PATH ./test-raylib-c
mingodad commented 1 year ago

Looking at your example and assuming the same folder is used:

LD_LIBRARY_PATH=./raylib/src:$LD_LIBRARY_PATH ./test-raylib-c
sDos280 commented 1 year ago

I tested this (https://github.com/exaloop/codon/issues/391#issuecomment-1562789576) test and it seems to work well.

so, does this mean that my problem is a codon problem?

mingodad commented 1 year ago

I believe so ! I noticed that you are using LLVM12 and I'm using LLVM15 but your valgrind output doesn't show the problems as mine. Definetly there is something with codon here in my opinion.

Let's see if the authors can shed some light here !!!

sDos280 commented 1 year ago

Let's see if the authors can shed some light here !!!

Should we ping them?

p.s. Thanks for all the help πŸ™πŸ™πŸ™

elisbyberi commented 1 year ago

@sDos280 Did you build Codon from source? How is it possible that it's utilizing LLVM12?

sDos280 commented 1 year ago

No, I used the command installation from the README file. this one: /bin/bash -c "$(curl -fsSL https://exaloop.io/install.sh)"

elisbyberi commented 1 year ago

@sDos280 Please verify the location where these headers are being searched or looked up: https://github.com/exaloop/codon/blob/develop/codon/cir/llvm/llvm.h

sDos280 commented 1 year ago

I am not really sure how to do that... also I am not that sure what to look for (just the folder path?)

mingodad commented 1 year ago

Out of curiosity what's the output of uname -a on your machine ? Mine:

uname -a
Linux mingo-X550VX 5.4.0-137-generic #154~18.04.1-Ubuntu SMP Tue Jan 10 16:58:20 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
sDos280 commented 1 year ago
uname -a
Linux Dell-G15-Special-Edition-5521 5.14.0-1059-oem #67-Ubuntu SMP Mon Mar 13 14:22:10 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
arshajii commented 1 year ago

Hi everyone,

So from the code in the original post, the thing to be aware of is the fact that Codon uses a GC so passing allocated objects to C/C++ might cause issues if that object is stored somewhere and then deallocated by the GC.

In this case, you're passing a string but c_str() is going to allocate with the GC (to create a null-terminated string) and perhaps run into this issue. String literals are guaranteed to be in static memory and null-terminated, though, so you can just use "hhh".ptr which gets the underlying pointer directly and won't do any allocations. (I've been meaning to actually add an IR pass that converts <str literal>.c_str() to <literal>.ptr.)

Let me know if that works!

sDos280 commented 1 year ago

String literals are guaranteed to be in static memory and null-terminated, though, so you can just use "hhh".ptr which gets the underlying pointer directly and won't do any allocations.

@arshajii it seems that this doesn't really make a difference, nevertheless, I appreciate the help.

@elisbyberi For some reason I can't find those files on my machine, or llvm in general... should I try to reinstall llvm?

elisbyberi commented 1 year ago

@sDos280 You only need LLVM if you intend to build Codon from source. Also, I'm unable to reproduce the error in Ubuntu 22.04. It appears to be an issue specific to your operating system configuration.

sDos280 commented 1 year ago

ok, then I guess that raypyc binding for codon won't be a thing after all... Nevertheless, thank you all for the help!!!

arshajii commented 1 year ago

@sDos280 I just tried downloading raylib and using it from Codon. Here's the code:

Color = Tuple[u8, u8, u8, u8]

def color(r: int, g: int, b: int, a: int = 255):
    return (u8(r), u8(g), u8(b), u8(a))

RAYWHITE  = color(255, 255, 255)
LIGHTGRAY = color(123, 123, 123)

from C import InitWindow(i32, i32, cobj)
from C import SetTargetFPS(i32)
from C import WindowShouldClose() -> bool
from C import BeginDrawing()
from C import EndDrawing()
from C import CloseWindow()
from C import DrawText(cobj, i32, i32, i32, Color)
from C import ClearBackground(Color)

screen_width = 800
screen_height = 450

InitWindow(i32(screen_width), i32(screen_height), "raylib [core] example - basic window".ptr)
SetTargetFPS(i32(60))

while not WindowShouldClose():
    BeginDrawing()
    ClearBackground(RAYWHITE)
    DrawText("Congrats! You created your first window!".ptr, i32(190), i32(200), i32(20), LIGHTGRAY)
    EndDrawing()

CloseWindow()

It works and shows the window. However, the colors are off somehow -- need to see how exactly they're representing that.

Running with codon run -release -l /opt/homebrew/Cellar/raylib/4.5.0/lib/libraylib.dylib test.codon.

sDos280 commented 1 year ago

glad to see that it works for you! unfortunately, i still get the same error πŸ˜•.

elisbyberi commented 1 year ago

@sDos280 You may consider testing the code in a virtual machine.

This is the expected result from the example provided by arshajii. The colors are displayed correctly. Screenshot from 2023-05-25 17-26-14

Here's another example using red text: image

sDos280 commented 1 year ago

would running it in VM really help? and what VM should i use?

p.s. I am still new to Linux so I am not that sure how to use VM...

arshajii commented 1 year ago

FYI this version works with correct colors on my system:

def color(r: int, g: int, b: int, a: int = 255):
    return (a << 24) | (b << 16) | (g << 8) | r

RAYWHITE  = color(245, 245, 245)
LIGHTGRAY = color(200, 200, 200)

from C import InitWindow(i32, i32, cobj)
from C import SetTargetFPS(i32)
from C import WindowShouldClose() -> bool
from C import BeginDrawing()
from C import EndDrawing()
from C import CloseWindow()
from C import DrawText(cobj, i32, i32, i32, int)
from C import ClearBackground(int)

screen_width = 800
screen_height = 450

InitWindow(i32(screen_width), i32(screen_height), "raylib [core] example - basic window".ptr)
SetTargetFPS(i32(60))

while not WindowShouldClose():
    BeginDrawing()
    ClearBackground(RAYWHITE)
    DrawText("Congrats! You created your first window!".ptr, i32(190), i32(200), i32(20), LIGHTGRAY)
    EndDrawing()

CloseWindow()
elisbyberi commented 1 year ago

@sDos280 It can be beneficial because starting fresh with a new system installation provides a clean slate.

It is recommended to use Ubuntu 22.04 LTS as it is a widely used Linux distribution. Being popular, any issues that arise are typically addressed promptly due to the large user base and active community support. Here is a tutorial: https://ubuntu.com/tutorials/how-to-run-ubuntu-desktop-on-a-virtual-machine-using-virtualbox#1-overview

sDos280 commented 1 year ago

Ok, I will take a look into that! Thanks πŸ™

p.s. I have an old pc that also run Linux laying around but I think I need to fix some things on that pc, unfortunately I can't do that now because I'm a bit busy so I will try that only later tonight... I really thank you all for all the help!!! πŸ™πŸ™πŸ™

sDos280 commented 1 year ago

Ok, sorry for making you wait so long. i tested the raylib codon test on my other machine and know i get an error massage that says LLVM ERROR: inconsistency in registered CommandLine options. @elisbyberi do you know what is the fix?

the full error massage:

INFO: Initializing raylib 4.6-dev
INFO: Supported raylib modules:
INFO:     > rcore:..... loaded (mandatory)
INFO:     > rlgl:...... loaded (mandatory)
INFO:     > rshapes:... loaded (optional)
INFO:     > rtextures:. loaded (optional)
INFO:     > rtext:..... loaded (optional)
INFO:     > rmodels:... loaded (optional)
INFO:     > raudio:.... loaded (optional)
: CommandLine Error: Option 'help-list' registered more than once!
LLVM ERROR: inconsistency in registered CommandLine options
Aborted (core dumped)
mingodad commented 1 year ago

And with valgrind what's the output ? Also the output of uname -a ?

mingodad commented 1 year ago

Can you also give the output of ldd codon on both machines ? (need to be executed on the same folder of the binary codon)

sDos280 commented 1 year ago

the output of uname -a in the new machine is: Linux dor-Default-string 5.15.0-56-generic #62-Ubuntu SMP Tue Nov 22 19:54:14 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux. the output of ldd codon in the new machine is:

    linux-vdso.so.1 (0x00007fff645e3000)
    libcodonc.so => /home/dor/.codon/bin/./../lib/codon/libcodonc.so (0x00007f5ba542b000)
    libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f5ba5332000)
    libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f5ba5312000)
    libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f5ba530d000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f5ba50e5000)
    /lib64/ld-linux-x86-64.so.2 (0x00007f5bac9ab000)
    libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f5ba50de000)
    libcodonrt.so => /home/dor/.codon/bin/./../lib/codon/libcodonrt.so (0x00007f5ba4bfe000)
    librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f5ba4bf9000)
    libomp.so => /home/dor/.codon/bin/./../lib/codon/libomp.so (0x00007f5ba4b0f000)

the output of ldd codon in the "old"(the one that i used when opening this issue) machine is:

    linux-vdso.so.1 (0x00007ffec7d91000)
    libcodonc.so => /home/dor283/.codon/bin/./../lib/codon/libcodonc.so (0x00007f4c89f80000)
    libcodon_jupyter.so => /home/dor283/.codon/bin/./../lib/codon/libcodon_jupyter.so (0x00007f4c89f7b000)
    libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f4c89e16000)
    libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f4c89dfb000)
    libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f4c89dd8000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f4c89be6000)
    /lib64/ld-linux-x86-64.so.2 (0x00007f4c9153c000)
    libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f4c89bde000)
    libcodonrt.so => /home/dor283/.codon/bin/./../lib/codon/libcodonrt.so (0x00007f4c896fe000)
    librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f4c896f4000)
    libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f4c89512000)
    libomp.so => /home/dor283/.codon/bin/./../lib/codon/libomp.so (0x00007f4c89428000)
elisbyberi commented 1 year ago

@sDos280 The first step is to be able to reproduce the error. Since we are unable to do so, please provide us with detailed system information such as the operating system, CPU info, graphic card/s info, and the version of clang/llvm installed in the system.

To gather the necessary information, utilize these commands:

Operation system
cat /proc/version

CPU info grep -m 1 'model name' /proc/cpuinfo

Graphic card/s info lspci | grep VGA

clang/llvm dpkg -l | egrep -i "clang|llvm" and locate llvm/ADT/FunctionExtras.h

This issue is well known to the LLVM community: https://discourse.llvm.org/t/can-something-be-done-with-the-inconsistency-in-registered-commandline-options-error/1720

sDos280 commented 1 year ago

Info on the old machine: Operation system:

Linux version 5.14.0-1059-oem (buildd@lcy02-amd64-027) (gcc (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0, GNU ld (GNU Binutils for Ubuntu) 2.34) #67-Ubuntu SMP Mon Mar 13 14:22:10 UTC 2023

CPU info:

model name  : 12th Gen Intel(R) Core(TM) i9-12900H

Graphic card/s info:

00:02.0 VGA compatible controller: Intel Corporation Device 46a6 (rev 0c)
01:00.0 VGA compatible controller: NVIDIA Corporation Device 24e0 (rev a1)

clang/llvm: dpkg -l | grep -i "clang|llvm":

(no output) locate llvm/ADT/FunctionExtras.h:

(no output)

does it mean that I don't have llvm installed?

elisbyberi commented 1 year ago
@sDos280 I noticed that you are using an operating system that is three years old: Name Date
Ubuntu 20.04.1 August 6, 2020
Linux 5.14 Aug 29, 2021
GCC 9.4.0 June 1, 2021
GNU Binutils 2.34 Feb 1, 2020

Many bugs have been fixed since those releases. Please consider upgrading your operating system to Ubuntu 22.04 or utilizing a virtual machine with an updated operating system to test your code.

Quoting from: https://discourse.llvm.org/t/can-something-be-done-with-the-inconsistency-in-registered-commandline-options-error/1720/5

The most common reason for this issue is that an application uses its own statically-linked version of LLVM, likely to JIT-compile something, while the user’s graphics driver likely links against the graphics driver, libGL.so, which for users of either Intel or AMD (or any other Mesa-based) drivers, links against the distro’s libLLVM.so

It appears that this issue has been resolved in more recent operating system releases.

mingodad commented 1 year ago

But I'm using Lubuntu-18.04 and it works !

elisbyberi commented 1 year ago

@mingodad The bug occurs instead of this line: INFO: DISPLAY: Device initialized successfully

It appears to be related to the graphics card driver or another library utilized by the graphics driver.