Segmentation fault on fresh build Ubuntu 18.04
After a fresh build on Ubuntu 18.04 64bits clang13:
valgrind Debug/bin/BeefBoot -out=Beef_fib -src=dad2/src -define=CLI -define=DEBUG -startup=BeefBuild.Program -linkparams='Debug/bin/libBeefRT_d.a Debug/bin/libIDEHelper_d.so Debug/bin/libBeefySysLib_d.so'
==8230== Memcheck, a memory error detector
==8230== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==8230== Using Valgrind-3.17.0 and LibVEX; rerun with -h for copyright info
==8230== Command: Debug/bin/BeefBoot -out=Beef_fib -src=dad2/src -define=CLI -define=DEBUG -startup=BeefBuild.Program -linkparams=Debug/bin/libBeefRT_d.a\ Debug/bin/libIDEHelper_d.so\ Debug/bin/libBeefySysLib_d.so
==8230==
==8230== Mismatched free() / delete / delete []
==8230== at 0x4C35CA1: operator delete(void*) (vg_replace_malloc.c:802)
==8230== by 0x4C1B90: Beefy::BootApp::QueueFile(Beefy::StringImpl const&, void*) (BeefBoot/BootApp.cpp:428)
==8230== by 0x4C1E02: Beefy::BootApp::QueuePath(Beefy::StringImpl const&) (BeefBoot/BootApp.cpp:443)
==8230== by 0x4C3AF8: Beefy::BootApp::Compile() (BeefBoot/BootApp.cpp:862)
==8230== by 0x4BFA7D: main (BeefBoot/BeefBoot.cpp:112)
==8230== Address 0xa544cd0 is 0 bytes inside a block of size 250 alloc'd
==8230== at 0x4C348C7: operator new[](unsigned long) (vg_replace_malloc.c:579)
==8230== by 0x91CB244: Beefy::LoadTextData(Beefy::StringImpl const&, int*) (BeefySysLib/Common.cpp:940)
==8230== by 0x4C18E5: Beefy::BootApp::QueueFile(Beefy::StringImpl const&, void*) (BeefBoot/BootApp.cpp:413)
==8230== by 0x4C1E02: Beefy::BootApp::QueuePath(Beefy::StringImpl const&) (BeefBoot/BootApp.cpp:443)
==8230== by 0x4C3AF8: Beefy::BootApp::Compile() (BeefBoot/BootApp.cpp:862)
==8230== by 0x4BFA7D: main (BeefBoot/BeefBoot.cpp:112)
==8230==
[==8230== Thread 2: ]
==8230== Invalid read of size 4
==8230== at 0x58EC405: Beefy::BfModule::ResolveTypeDef(Beefy::BfTypeDef*, Beefy::BfPopulateType, Beefy::BfResolveTypeRefFlags) (IDEHelper/Compiler/BfModuleTypeUtils.cpp:8161)
==8230== by 0x59070CE: Beefy::BfModule::DoTypeInstanceMethodProcessing(Beefy::BfTypeInstance*) (IDEHelper/Compiler/BfModuleTypeUtils.cpp:6268)
==8230== by 0x58FA0D9: Beefy::BfModule::DoPopulateType(Beefy::BfType*, Beefy::BfPopulateType) (IDEHelper/Compiler/BfModuleTypeUtils.cpp:6021)
==8230== by 0x58E7B96: Beefy::BfModule::PopulateType(Beefy::BfType*, Beefy::BfPopulateType) (IDEHelper/Compiler/BfModuleTypeUtils.cpp:1645)
==8230== by 0x56A6584: Beefy::BfContext::ProcessWorkList(bool, bool) (IDEHelper/Compiler/BfContext.cpp:468)
==8230== by 0x562BD5C: Beefy::BfCompiler::DoWorkLoop(bool, bool) (IDEHelper/Compiler/BfCompiler.cpp:5590)
==8230== by 0x5642E3A: Beefy::BfCompiler::PopulateReified() (IDEHelper/Compiler/BfCompiler.cpp:6019)
==8230== by 0x5646B20: Beefy::BfCompiler::CompileReified() (IDEHelper/Compiler/BfCompiler.cpp:6848)
==8230== by 0x564BA79: Beefy::BfCompiler::DoCompile(Beefy::StringImpl const&) (IDEHelper/Compiler/BfCompiler.cpp:7289)
==8230== by 0x564F070: Beefy::BfCompiler::Compile(Beefy::StringImpl const&) (IDEHelper/Compiler/BfCompiler.cpp:7906)
==8230== by 0x5654EC6: BfCompiler_Compile (IDEHelper/Compiler/BfCompiler.cpp:9622)
==8230== by 0x4C2477: CompileThread(void*) (BeefBoot/BootApp.cpp:471)
==8230== Address 0x28 is not stack'd, malloc'd or (recently) free'd
==8230==
==8230==
==8230== Process terminating with default action of signal 11 (SIGSEGV)
==8230== Access not within mapped region at address 0x28
==8230== at 0x58EC405: Beefy::BfModule::ResolveTypeDef(Beefy::BfTypeDef*, Beefy::BfPopulateType, Beefy::BfResolveTypeRefFlags) (IDEHelper/Compiler/BfModuleTypeUtils.cpp:8161)
==8230== by 0x59070CE: Beefy::BfModule::DoTypeInstanceMethodProcessing(Beefy::BfTypeInstance*) (IDEHelper/Compiler/BfModuleTypeUtils.cpp:6268)
==8230== by 0x58FA0D9: Beefy::BfModule::DoPopulateType(Beefy::BfType*, Beefy::BfPopulateType) (IDEHelper/Compiler/BfModuleTypeUtils.cpp:6021)
==8230== by 0x58E7B96: Beefy::BfModule::PopulateType(Beefy::BfType*, Beefy::BfPopulateType) (IDEHelper/Compiler/BfModuleTypeUtils.cpp:1645)
==8230== by 0x56A6584: Beefy::BfContext::ProcessWorkList(bool, bool) (IDEHelper/Compiler/BfContext.cpp:468)
==8230== by 0x562BD5C: Beefy::BfCompiler::DoWorkLoop(bool, bool) (IDEHelper/Compiler/BfCompiler.cpp:5590)
==8230== by 0x5642E3A: Beefy::BfCompiler::PopulateReified() (IDEHelper/Compiler/BfCompiler.cpp:6019)
==8230== by 0x5646B20: Beefy::BfCompiler::CompileReified() (IDEHelper/Compiler/BfCompiler.cpp:6848)
==8230== by 0x564BA79: Beefy::BfCompiler::DoCompile(Beefy::StringImpl const&) (IDEHelper/Compiler/BfCompiler.cpp:7289)
==8230== by 0x564F070: Beefy::BfCompiler::Compile(Beefy::StringImpl const&) (IDEHelper/Compiler/BfCompiler.cpp:7906)
==8230== by 0x5654EC6: BfCompiler_Compile (IDEHelper/Compiler/BfCompiler.cpp:9622)
==8230== by 0x4C2477: CompileThread(void*) (BeefBoot/BootApp.cpp:471)
==8230== If you believe this happened as a result of a stack
==8230== overflow in your program's main thread (unlikely but
==8230== possible), you can try to increase the size of the
==8230== main thread stack using the --main-stacksize= flag.
==8230== The main thread stack size used in this run was 8388608.
==8230==
==8230== HEAP SUMMARY:
==8230== in use at exit: 264,465 bytes in 1,946 blocks
==8230== total heap usage: 2,523 allocs, 577 frees, 531,666 bytes allocated
==8230==
==8230== LEAK SUMMARY:
==8230== definitely lost: 0 bytes in 0 blocks
==8230== indirectly lost: 0 bytes in 0 blocks
==8230== possibly lost: 320 bytes in 1 blocks
==8230== still reachable: 264,145 bytes in 1,945 blocks
==8230== suppressed: 0 bytes in 0 blocks
==8230== Rerun with --leak-check=full to see details of leaked memory
==8230==
==8230== For lists of detected and suppressed errors, rerun with: -s
==8230== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 0 from 0)
Segmentation fault (core dumped)
The fault code:
BfType* BfModule::ResolveTypeDef(BfTypeDef* typeDef, BfPopulateType populateType, BfResolveTypeRefFlags resolveFlags)
{
BF_ASSERT(typeDef->mDefState != BfTypeDef::DefState_Emitted); ////!!<<<< Here <<<<<
if (typeDef->mTypeDeclaration == NULL)
{
BF_ASSERT(!typeDef->mIsDelegate && !typeDef->mIsFunction);
}
The beef program:
using System;
namespace dad2;
class Program
{
static int fib(int n)
{
if(n < 2) return 1;
return fib(n-2)+fib(n-1);
}
public static int Main(String[] args)
{
int n = 32;
Console.WriteLine("fib({0}) = {1}", n, fib(n));
return 0;
}
}
BeefBoot is for bootstrapping only - the only program it is intended to compile is BeefBuild. You should be using BeefBuild to build your programs...
I believe this issue may be closed.
I have a machine that runs on Ubuntu 22.04.4 LTS, where Beef has been built from source (commit: https://github.com/beefytech/Beef/commit/1805316b70387a8cfabdee45f1e5204fa0c5d649).
Provided code succesfully compiled and runned:
cd ~/Projects/bug.1775
~/Beef/IDE/dist/BeefBuild -run
fib(32) = 3524578
if you have any troubles, feel free to hop onto official Discord server (https://discord.gg/rnsc9YP). Note: Currently Beef uses LLVM 18.