Segmentation Fault Core dumped

Been hard stucking on running the follow function as binary in Linux. It can run by mojo run .mojo just fine but it just can’t be executed as a binary … and the only error I got is in the title.
fn get_codewords(owned padded: List[Int]) -> List[Int]:
var ecwords = List[Int](0)*64
var values = List[Int]()

for i in range(222):
var temp: Int = (padded[i] + ecwords[0]) % 929
for j in range(63, -1, -1):
var val: Int = temp * EC_LV5[j] % 929
var factor: Int = ecwords[64-j] if j > 0 else 0
ecwords[63-j] = (factor + 929 - val) % 929

return ecwords
fn get_codewords(owned padded: List[Int]) -> List[Int]:
var ecwords = List[Int](0)*64
var values = List[Int]()

for i in range(222):
var temp: Int = (padded[i] + ecwords[0]) % 929
for j in range(63, -1, -1):
var val: Int = temp * EC_LV5[j] % 929
var factor: Int = ecwords[64-j] if j > 0 else 0
ecwords[63-j] = (factor + 929 - val) % 929

return ecwords
EC_LV5 is 64 bytes of error correction codewords ECL_LV5 = ListInt
16 Replies
sb
sb2mo ago
Do you have any way of putting this in gdb at the moment? We can try to tease apart where things might be falling over
benny
benny2mo ago
what is the intended value of ecwords?
randomasiandude
randomasiandude2mo ago
output value is correct . A list of 64 elements values from 0-929
sb
sb2mo ago
are you able to run any of this in GDB or some other debugger?
randomasiandude
randomasiandude2mo ago
I’ve only tested in Ubuntu terminal and vscode
sora
sora2mo ago
Could you share the full script?
randomasiandude
randomasiandude2mo ago
I can run the fn without any issue I couldn’t run it in binary execution form
sb
sb2mo ago
Yeah, can in the ubuntu VM/wsl can you install gdb?
randomasiandude
randomasiandude2mo ago
Like ./test I’ll try right now Not VM not WSL Ubuntu OS I’ll provide result in few mins
This GDB supports auto-downloading debuginfo from the following URLs:
<https://debuginfod.ubuntu.com>
Enable debuginfod for this session? (y or [n]) y
Debuginfod has been enabled.
To make this setting permanent, add 'set debuginfod enabled on' to .gdbinit.
Downloading separate debug info for system-supplied DSO at 0x7ffff7fc3000
Downloading separate debug info for /lib/x86_64-linux-gnu/libstdc++.so.6
Downloading separate debug info for /lib/x86_64-linux-gnu/libgcc_s.so.1
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7ffff6e006c0 (LWP 11477)]
[New Thread 0x7ffff64006c0 (LWP 11478)]
[New Thread 0x7ffff5a006c0 (LWP 11479)]
[New Thread 0x7ffff50006c0 (LWP 11480)]
[New Thread 0x7ffff46006c0 (LWP 11481)]

Thread 1 "errc" received signal SIGSEGV, Segmentation fault.
0x000055555555bf6c in main ()
This GDB supports auto-downloading debuginfo from the following URLs:
<https://debuginfod.ubuntu.com>
Enable debuginfod for this session? (y or [n]) y
Debuginfod has been enabled.
To make this setting permanent, add 'set debuginfod enabled on' to .gdbinit.
Downloading separate debug info for system-supplied DSO at 0x7ffff7fc3000
Downloading separate debug info for /lib/x86_64-linux-gnu/libstdc++.so.6
Downloading separate debug info for /lib/x86_64-linux-gnu/libgcc_s.so.1
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7ffff6e006c0 (LWP 11477)]
[New Thread 0x7ffff64006c0 (LWP 11478)]
[New Thread 0x7ffff5a006c0 (LWP 11479)]
[New Thread 0x7ffff50006c0 (LWP 11480)]
[New Thread 0x7ffff46006c0 (LWP 11481)]

Thread 1 "errc" received signal SIGSEGV, Segmentation fault.
0x000055555555bf6c in main ()
I somehow fixed it by putting var ECL_V5 from outside of the fn into inside of the fn…. Still don’t know what’s the actual reason behind
sb
sb2mo ago
can you maybe add -g or something to the compiler flags? need debug symbols to diagnose
randomasiandude
randomasiandude2mo ago
I discovered that if a variable is outside of the fn it should be defined as alias not var in order to make the binary work. If its defined as var the script can still run with mojo run
ModularBot
ModularBot2mo ago
Congrats @randomasiandude, you just advanced to level 1!
randomasiandude
randomasiandude2mo ago
Thank you for the gdb knowledge which I didn’t know 🙂 The issue was about defining global variables/constants as var vs. as alias . In my case it needs to be defined as alias for the binary to work As a dude from python took me a while to figure out. And still reading the variables scope thing
sb
sb2mo ago
interesting! weird that caused a segfault though? I forget if global vars are supported yet or not
Ryulord
Ryulord2mo ago
they're not currently supported and the segfault on attempting to use one is a known bug. There probably should be a warning from the lsp and a mention in the 'sharp edges' page
randomasiandude
randomasiandude2mo ago
Very True, especially for new comers from python.
Want results from more Discord servers?
Add your server