lpython
lpython copied to clipboard
runtime_errors/* fails on FreeBSD
Currently, I think conda-forge/miniforge
don't support FreeBSD (or any other BSD). The current README also doesn't hint any way to use LPython in FreeBSD (or NetBSD/DragonflyBSD/OpenBSD).
I manage to compile it with some commands, described below. It seems to compile and work, but it's not possible to "show the lines which errors occur" (the stack-trace).
Setup:
Install:
pkg install bash git python310 gmake re2c cmake py310-numpy py310-setuptools bison llvm11 zstd
python3.10 -m ensurepip
pip3.10 install flake8
Create "Alias":
bash -c 'ln -s $(which python3.10) $(dirname $(which python3.10))/python'
bash -c 'ln -s $(which python3.10) $(dirname $(which python3.10))/python3'
bash -c 'ln -s $(which pip3.10) $(dirname $(which pip3.10))/pip'
bash -c 'ln -s $(which llvm-dwarfdump11) $(dirname $(which llvm-dwarfdump11))/llvm-dwarfdump'
Clone:
git clone https://github.com/lcompilers/lpython.git
cd lpython
Patch lfortran_intrinsics.c
:
diff --git a/src/libasr/runtime/lfortran_intrinsics.c b/src/libasr/runtime/lfortran_intrinsics.c
index ce6c6901a..d32065f99 100644
--- a/src/libasr/runtime/lfortran_intrinsics.c
+++ b/src/libasr/runtime/lfortran_intrinsics.c
@@ -26,12 +26,14 @@
#ifdef HAVE_LFORTRAN_LINK
// For dl_iterate_phdr() functionality
# include <link.h>
+#ifndef _SYS_LINK_ELF_H_
struct dl_phdr_info {
ElfW(Addr) dlpi_addr;
const char *dlpi_name;
const ElfW(Phdr) *dlpi_phdr;
ElfW(Half) dlpi_phnum;
};
+#endif
extern int dl_iterate_phdr (int (*__callback) (struct dl_phdr_info *,
size_t, void *), void *__data);
#endif
Without that change, it causes:
[ 1%] Building C object src/runtime/legacy/CMakeFiles/lpython_runtime.dir/__/__/libasr/runtime/lfortran_intrinsics.c.o
[ 2%] Building C object src/runtime/legacy/CMakeFiles/lpython_runtime_static.dir/__/__/libasr/runtime/lfortran_intrinsics.c.o
[ 4%] Built target doctest
/home/benchmark/lpython/src/libasr/runtime/lfortran_intrinsics.c:29:8: error: redefinition of 'dl_phdr_info'
struct dl_phdr_info {
^
/usr/include/sys/link_elf.h:86:8: note: previous definition is here
struct dl_phdr_info
^
/home/benchmark/lpython/src/libasr/runtime/lfortran_intrinsics.c:29:8: error: redefinition of 'dl_phdr_info'
struct dl_phdr_info {
^
/usr/include/sys/link_elf.h:86:8: note: previous definition is here
struct dl_phdr_info
^
1 error generated.
That might be causing the issue with stack-trace, but I'm not sure why that duplication is happening.
Compile:
bash ./build0.sh
bash ./build1.sh
Some tests seems to fail, specially some at runtime_errors/*
. For instance, runtime_errors/test_assert_01.py
:
# cat tests/output/run_dbg-test_assert_01-2f34744.stderr
AssertionError
# cat tests/reference/run_dbg-test_assert_01-2f34744.stderr
File "tests/runtime_errors/test_assert_01.py", line 1
def test():
File "tests/runtime_errors/test_assert_01.py", line 4
test()
File "tests/runtime_errors/test_assert_01.py", line 2
assert False
AssertionError
I'm not sure why the "stack-trace" isn't working on FreeBSD. But, otherwise, it's working fine.
Thanks for the bug report!
I think the patch in lfortran_intrinsics.c
is responsible for the failure. dl_phdr_info
is used for printing the runtime stack trace.
I think you can use the option --skip-run-with-dbg
to skip it for now.
Running with --skip-run-with-dbg
works. So, the issue is exclusive to stacktrace.
I think my patch can cause it, but I'm not sure. So far, I notice that dlpi_name == \0
is always false on FreeBSD. Also, on Linux it's documented as "For the main program, the dlpi_name field will be an empty string.", but that is not mentioned on FreeBSD docs (https://man.freebsd.org/cgi/man.cgi?query=dl_iterate_phdr&sektion=3).
I'll keep experimenting.