MrSmith33 / vox

Vox language compiler. AOT / JIT / Linker. Zero dependencies
Boost Software License 1.0
327 stars 18 forks source link

The example of "libvox" doesn't work for me. #45

Closed rempas closed 2 years ago

rempas commented 2 years ago

Expected behavior I was expecting the program to work (at least for the D version).

Describe the bug The example doesn't work.

To Reproduce I'm trying to compile the libvox example but I have no luck. I'm trying to do it both using D (and specifically LDC) and by using C. In the C version, I also had to copy the decorations from the "libvox" module and change some stuff to make it work with a C compiler. For that reason, there may be mistakes that I made here. Having "libvox" work with a C program is very important as pretty much everyone that's gonna make a language frontend will want to bootstrap at some point so it makes sense for me to test it and report back.

In the C version, the program compiles normally but when I try to run it, I get a segmentation fault. In the D version, I'm getting linker errors. More specifically:

/usr/bin/ld: test_libvox_d.o: in function `main':
test_libvox.d:(.text.main+0x4c): undefined reference to `_D6libvox__T5SliceTxaZQk6__ctorMFNaNbNcNiAxaZSQBs__TQBoTxaZQBv'
/usr/bin/ld: test_libvox.d:(.text.main+0x98): undefined reference to `_D6libvox__T5SliceTxaZQk6__ctorMFNaNbNcNiAxaZSQBs__TQBoTxaZQBv'
/usr/bin/ld: test_libvox.d:(.text.main+0xcf): undefined reference to `_D6libvox__T5SliceTxaZQk6__ctorMFNaNbNcNiAxaZSQBs__TQBoTxaZQBv'
collect2: error: ld returned 1 exit status
Error: /usr/bin/cc failed with status: 1

I have uploaded the files in a repo so you can easily test it out yourself and examine the code and see if I made any mistakes (if you prefer to do so). You can see more info in the 'README.md' in the repo. However, of course ask me if you need anything. I'll try to see and answer as fast as I can :)

Additional context

MrSmith33 commented 2 years ago

The compiler says undefined reference to Slice constructor. That is because you didn't include libvox.d into the compilation. Another thing to note is that prebuilt libvox.so statically links to druntime, which may cause a problem when loaded into non-better-c D program, but check this anyway. The intended use of libvox from regular D is either using source code or though dub package. I should document all this in the future.

rempas commented 2 years ago

Thank you! It now compiles! However, just like the C version of the program, I now get the same output as the C program. Which is the "segmentation fault". I copy-pasted the files from the "example" directory so I don't see any way I could mess up (but from my history, I would not be surprised 😅).

MrSmith33 commented 2 years ago

git clone gives me fatal: unable to access 'https://codeberg.org/rempas/libvox_error.git/': server certificate verification failed. CAfile: none CRLfile: none Can you run the program under the gdb and print a stacktrace? I suspect that the problem may be with libc that it was linked with during CI build. It was built on Ubuntu 20.4. What's your OS?

MrSmith33 commented 2 years ago

You can try building the .so file yourself with

vox/source> ldc2 -m64 -shared -O3 -mcpu=x86-64-v3 --d-debug -g -boundscheck=off -enable-inlining -flto=full -linkonce-templates --defaultlib=phobos2-ldc-lto,druntime-ldc-lto -fvisibility=hidden -link-defaultlib-shared=false -i c_api.d -of=../bin/libvox.so
MrSmith33 commented 2 years ago

In case this issue is the same as #46, and I guessed that the problem is -mcpu flag, you can try compiling without -mcpu=x86-64-v3

MrSmith33 commented 2 years ago

And I should probably build a version with lower CPU requirement too

rempas commented 2 years ago

Sorry for the late answers. I wasn't able to build "libvox.so". I'm getting errors when compiling and I don't know why as I copied the exact command you showed me. I changed the working directory to "source" and run the command. My output was:

/usr/include/dlang/ldc/std/format/write.d(1239): Error: none of the overloads of template `std.format.internal.write.formatValueImpl` are callable using argument types `!()(void delegate(const(char)[]), const(IntervalIndex), const(FormatSpec!char))`
/usr/include/dlang/ldc/std/format/internal/write.d(31):        Candidates are: `formatValueImpl(Writer, T, Char)(auto ref Writer w, const(T) obj, ref scope const FormatSpec!Char f)`
  with `Writer = void delegate(const(char)[]),
       T = IntervalIndex,
       Char = char`
  must satisfy the following constraint:
`       is(BooleanTypeOf!T)`
/usr/include/dlang/ldc/std/format/internal/write.d(126):                        `formatValueImpl(Writer, T, Char)(auto ref Writer w, const(T) obj, ref scope const FormatSpec!Char f)`
  with `Writer = void delegate(const(char)[]),
       T = IntervalIndex,
       Char = char`
  must satisfy the following constraint:
`       is(immutable(T) == immutable(typeof(null)))`
/usr/include/dlang/ldc/std/format/internal/write.d(160):                        `formatValueImpl(Writer, T, Char)(auto ref Writer w, const(T) obj, ref scope const FormatSpec!Char f)`
  with `Writer = void delegate(const(char)[]),
       T = IntervalIndex,
       Char = char`
  must satisfy the following constraint:
`       !hasToString!(T, Char)`
/usr/include/dlang/ldc/std/format/internal/write.d(610):                        `formatValueImpl(Writer, T, Char)(auto ref Writer w, const(T) obj, ref scope const FormatSpec!Char f)`
  with `Writer = void delegate(const(char)[]),
       T = IntervalIndex,
       Char = char`
  must satisfy the following constraint:
`       is(FloatingPointTypeOf!T)`
/usr/include/dlang/ldc/std/format/internal/write.d(1020):                        `formatValueImpl(Writer, T, Char)(auto ref Writer w, const(T) obj, ref scope const FormatSpec!Char f)`
  with `Writer = void delegate(const(char)[]),
       T = IntervalIndex,
       Char = char`
  must satisfy the following constraint:
`       is(immutable(T) : immutable(creal))`
/usr/include/dlang/ldc/std/format/write.d(1239):        ... (13 more, -v to show) ...
/usr/include/dlang/ldc/std/format/write.d(632): Error: template instance `std.format.write.formatValue!(void delegate(const(char)[]), const(IntervalIndex), char)` error instantiating
vox/utils/array.d(236):        instantiated from here: `formattedWrite!(void delegate(const(char)[]), char, const(IntervalIndex))`
vox/be/reg_alloc/linear_scan.d(142):        instantiated from here: `Array!(IntervalIndex)`
/usr/include/dlang/ldc/std/format/internal/write.d(2593): Error: template instance `std.format.internal.write.formatElement!(void delegate(const(char)[]), const(IntervalIndex), char)` error instantiating
/usr/include/dlang/ldc/std/format/write.d(1239):        instantiated from here: `formatValueImpl!(void delegate(const(char)[]), const(IntervalPriority), char)`
/usr/include/dlang/ldc/std/format/write.d(632):        instantiated from here: `formatValue!(void delegate(const(char)[]), const(IntervalPriority), char)`
vox/utils/array.d(236):        instantiated from here: `formattedWrite!(void delegate(const(char)[]), char, const(IntervalPriority))`
vox/be/reg_alloc/linear_scan.d(1255):        instantiated from here: `Array!(IntervalPriority)`
/usr/include/dlang/ldc/std/format/write.d(1239): Error: none of the overloads of template `std.format.internal.write.formatValueImpl` are callable using argument types `!()(void delegate(const(char)[]), const(LiveRangeIndex), const(FormatSpec!char))`
/usr/include/dlang/ldc/std/format/internal/write.d(31):        Candidates are: `formatValueImpl(Writer, T, Char)(auto ref Writer w, const(T) obj, ref scope const FormatSpec!Char f)`
  with `Writer = void delegate(const(char)[]),
       T = LiveRangeIndex,
       Char = char`
  must satisfy the following constraint:
`       is(BooleanTypeOf!T)`
/usr/include/dlang/ldc/std/format/internal/write.d(126):                        `formatValueImpl(Writer, T, Char)(auto ref Writer w, const(T) obj, ref scope const FormatSpec!Char f)`
  with `Writer = void delegate(const(char)[]),
       T = LiveRangeIndex,
       Char = char`
  must satisfy the following constraint:
`       is(immutable(T) == immutable(typeof(null)))`
/usr/include/dlang/ldc/std/format/internal/write.d(160):                        `formatValueImpl(Writer, T, Char)(auto ref Writer w, const(T) obj, ref scope const FormatSpec!Char f)`
  with `Writer = void delegate(const(char)[]),
       T = LiveRangeIndex,
       Char = char`
  must satisfy the following constraint:
`       !hasToString!(T, Char)`
/usr/include/dlang/ldc/std/format/internal/write.d(610):                        `formatValueImpl(Writer, T, Char)(auto ref Writer w, const(T) obj, ref scope const FormatSpec!Char f)`
  with `Writer = void delegate(const(char)[]),
       T = LiveRangeIndex,
       Char = char`
  must satisfy the following constraint:
`       is(FloatingPointTypeOf!T)`
/usr/include/dlang/ldc/std/format/internal/write.d(1020):                        `formatValueImpl(Writer, T, Char)(auto ref Writer w, const(T) obj, ref scope const FormatSpec!Char f)`
  with `Writer = void delegate(const(char)[]),
       T = LiveRangeIndex,
       Char = char`
  must satisfy the following constraint:
`       is(immutable(T) : immutable(creal))`
/usr/include/dlang/ldc/std/format/write.d(1239):        ... (13 more, -v to show) ...
/usr/include/dlang/ldc/std/format/internal/write.d(3274): Error: template instance `std.format.write.formatValue!(void delegate(const(char)[]), const(LiveRangeIndex), char)` error instantiating
/usr/include/dlang/ldc/std/format/internal/write.d(2593):        instantiated from here: `formatElement!(void delegate(const(char)[]), const(LiveRangeIndex), char)`
/usr/include/dlang/ldc/std/format/write.d(1239):        instantiated from here: `formatValueImpl!(void delegate(const(char)[]), const(LiveInterval), char)`
/usr/include/dlang/ldc/std/format/write.d(632):        instantiated from here: `formatValue!(void delegate(const(char)[]), const(LiveInterval), char)`
vox/utils/array.d(236):        instantiated from here: `formattedWrite!(void delegate(const(char)[]), char, const(LiveInterval))`
vox/be/reg_alloc/liveness_info.d(56):        instantiated from here: `Array!(LiveInterval)`
MrSmith33 commented 2 years ago

What's you compiler version?

rempas commented 2 years ago

Good morning! I have tested out on my work's laptop without the mcpu=x86-64-v3 flag and it works without problems! I suppose this also fixes #46 (I haven't tested it out tho) so I will close that too! Once again, thank you for your help!