Closed rdebath closed 6 years ago
Hi @rdebath, do you have the source code for your helloworld.b ?
Is it the one located in the tests folder?
I will check it and answer as soon as possible! Thanks!
Yes, it's the one in your tests folder, from Wikipedia. However, the problem seems to happen whatever is in the file, even just a newline (an empty file gives "No such file" !?)
++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.
I think I had a linking problem related to that (and I fixed locally), but not cool, will fix it as soon as possible.
This line may be causing it. We are depending currently on C
and math.h
for IO
(must be removed later).
Just to test, try to run the command:
brain ./helloworld.b -c && $(CC) helloworld.o -o hello -lm && rm hello.o
I forgot to ask, is it on the dev
branch? Which branch are you using? @rdebath
Okay, I've now switched to the dev branch, recomplied and added the -c argument. Still getting a segfault.
debian-jessie64(robert)brain-labs$ git describe --long --tags
v1.0-84-g7b65871
debian-jessie64(robert)brain-labs$ gdb -args bin/brain tests/helloworld.b -c
GNU gdb (Debian 7.7.1+dfsg-5) 7.7.1
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from bin/brain...done.
(gdb) run
Starting program: /home/robert/brain-labs/bin/brain tests/helloworld.b -c
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Program received signal SIGSEGV, Segmentation fault.
0x0000000000ea7e52 in llvm::TypeFinder::incorporateType(llvm::Type*) ()
(gdb) bt
#0 0x0000000000ea7e52 in llvm::TypeFinder::incorporateType(llvm::Type*) ()
#1 0x0000000000ea7abb in llvm::TypeFinder::run(llvm::Module const&, bool) ()
#2 0x0000000000e9724b in llvm::Module::getIdentifiedStructTypes() const ()
#3 0x000000000043d20b in llvm::IRMover::move(std::unique_ptr<llvm::Module, std::default_delete<llvm::Module> >, llvm::ArrayRef<llvm::GlobalValue*>, std::function<void (llvm::GlobalValue&, std::function<void (llvm::GlobalValue&)>)>, bool) ()
#4 0x000000000043786b in llvm::Linker::linkInModule(std::unique_ptr<llvm::Module, std::default_delete<llvm::Module> >, unsigned int, std::function<void (llvm::Module&, llvm::StringSet<llvm::MallocAllocator> const&)>) ()
#5 0x0000000000437e7a in llvm::Linker::linkModules(llvm::Module&, std::unique_ptr<llvm::Module, std::default_delete<llvm::Module> >, unsigned int, std::function<void (llvm::Module&, llvm::StringSet<llvm::MallocAllocator> const&)>) ()
#6 0x000000000042e683 in Bootstrap::init (this=0x16a8170, argc=<optimized out>, argv=<optimized out>) at src/utils/Bootstrap.cpp:109
#7 0x00007ffff69ddb45 in __libc_start_main () from /lib/x86_64-linux-gnu/libc.so.6
#8 0x000000000042c7d7 in _start ()
(gdb)
I will check that when I get home! Please take a look to it too @rafaelcn. Will get back soon to you, @rdebath!
Sorry @rdebath but I couldn't reproduce your bug. It seems, superficially that something has changed between clang++ version 3.9
and clang++ version 5.0
, but nothing to assure yet.
Here's what I've done:
make debug
gdb -args bin/brain tests/helloworld.b -c
Here's the output. I've removed GNU's copyright notice.
ranu@ranu-laptop ‹ dev ↑● › : ~/Github/brain-labs/brain/bin
[0] % gdb -args brain_debug ../tests/helloworld.b -c
Reading symbols from brain_debug...done.
(gdb) run
Starting program: /home/ranu/Github/brain-labs/brain/bin/brain_debug ../tests/helloworld.b -c
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[Inferior 1 (process 30172) exited normally]
(gdb)
Again I tried with brain and I've got the same behavior.
make
gdb -args bin/brain tests/helloworld.b -c
ranu@ranu-laptop ‹ dev ↑● › : ~/Github/brain-labs/brain/bin
[0] % gdb -args brain ../tests/helloworld.b -c
Reading symbols from brain...done.
(gdb) run
Starting program: /home/ranu/Github/brain-labs/brain/bin/brain ../tests/helloworld.b -c
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[Inferior 1 (process 30488) exited normally]
Anyway, gonna inspect that profoundly later!
Okay, I set off a build of clang 4.0.1, amd64 and then downgraded from 5.0.0. Version 4.0.1 works for me.
That's quite weird! I was discussing this issue on PR #55. It looks like a problem when linking dwo
files. We are injecting C compiled code inside Brain when it is compiling.
We’re actually attaching LLVM IR (we’re compiling .c to .ll and only them attaching) as this is one of the plans of Brain for the future (attach other libraries into the code, so we can use all the power of LLVM), but the IO must go built-in later, the current solution has a lot of problems and is better to avoid them in the future. We already have a couple of issues regarding that and we will give priority to that. Thanks a lot for posting this issue @rdebath!
Not so sure if the error above is related to that @rafaelcn. I guess I’ll install clang 5 over the weekend and try to replicate/fix it
That was just a guess by the error provided in that SO answer.
Yet, we need to discuss the future of the Math and the IO library :v
Yeah for sure, #7 and #29 are still open for this reason. Will try to start working on that ASAP
WRT the math library the below should work fine. It depends on the fact that you already have Log base 256 of the maximum integer size (called sizeof) and simply converts that to a log10 by multiplying by 2.41 (log(256)/log(10) --> 2.408239965311849) and adding the necessary padding for sign, nul and the last digit.
diff --git a/libs/io.c b/libs/io.c
index 40dd1ad..3d935b7 100644
--- a/libs/io.c
+++ b/libs/io.c
@@ -5,10 +5,6 @@
// you can overwrite those functions! :)
-int number_size(int number) {
- return floor(log10(abs(number))) + 1 + (number > 0 ? 0 : 1);
-}
-
void b_show_tape(int idx, int *cells, int size) {
// TODO: ellipsize values based on index
size = 12;
@@ -34,9 +30,9 @@ void b_show_tape(int idx, int *cells, int size) {
tape[tape_idx++] = ' ';
// Has a value allocated on register
if (*cells) {
- unsigned int value_size = number_size(*cells);
- char number[value_size];
- sprintf(number, "%d", *cells);
+ unsigned int value_size;
+ char number[sizeof(*cells)*241/100+3];
+ value_size = sprintf(number, "%d", *cells);
// Append each number character
for (j = 0; j < value_size; j++) {
tape[tape_idx++] = number[j];
I could finally reproduce that on clang 5
, will check it
Hi @rdebath, do you want to open a PR on this change you made on the io.c
? Thanks for the heads up!
BTW, i am trying to run on clang 5
and so far i do not have any idea about what that can be xD
I could narrow down this problem. The problem is on the module, not on the engine
Hi @rdebath, I am so sorry for the delay to fix this PR! School was killing me! It has been fixed on https://github.com/brain-labs/brain/pull/59
Happens with v1.0 and master.