View previous topic :: View next topic |
Author |
Message |
baryluk
Joined: 02 Sep 2007 Posts: 7
|
Posted: Tue Jun 24, 2008 5:57 pm Post subject: LLVMDC on FreeBSD works |
|
|
Hi.
I just installed llvm 2.3 and boehm-gc 6.8 on FreeBSD CURRENT-8.
After few small fixes in llvmdc sources (freebsd's gcc is missing fmodl and changed #if linux to #if linux || __FreeBSD__, to include proper headers like errno.h).
Compilation was succesfull, but then got segmentation faults. After recompilation of boehm-gc with threading disabled, llvmdc just started working!
Now compiling Tango, very very slow... core/BitManip.d 5 minutes and still runing... Cpu usage 90%, strace shows nothing,
looping somewhere near this:
Code: |
Program received signal SIGINT, Interrupt.
0x080d384b in OutBuffer::vprintf (this=0xbfbfe790, format=0x8911528 "%s", args=0xbfbfe768 "�\017�\b-�\n\b\002") at dmd/root.c:1618
1618 p = (char *) alloca(psize); // buffer too small, try again with larger size
(gdb) bt
#0 0x080d384b in OutBuffer::vprintf (this=0xbfbfe790, format=0x8911528 "%s", args=0xbfbfe768 "�\017�\b-�\n\b\002") at dmd/root.c:1618
#1 0x080d3887 in OutBuffer::printf (this=0xbfbfe790, format=0x8911528 "%s") at dmd/root.c:1660
#2 0x080ad381 in Loc::toChars (this=0x8c31ebc) at dmd/mars.c:84
#3 0x0806d5fc in Dsymbol::locToChars (this=0x8c31ea0) at dmd/dsymbol.c:201
#4 0x0806d777 in Dsymbol::error (this=0x8c31ea0, loc={filename = 0x0, linnum = 0}, format=0x89116d7 "cannot read file '%s'") at dmd/dsymbol.c:469
#5 0x080ae820 in Module::read (this=0x8c31ea0, loc={filename = 0x0, linnum = 0}) at dmd/module.c:339
#6 0x080ace87 in main (argc=5, argv=0xbfbfe984) at dmd/mars.c:922
|
Will check tomorow.
BTW. Good work.
--
aleph |
|
Back to top |
|
|
ChristianK
Joined: 26 Sep 2006 Posts: 159 Location: Berlin, Germany
|
Posted: Thu Jun 26, 2008 4:49 am Post subject: Re: LLVMDC on FreeBSD works |
|
|
baryluk wrote: |
I just installed llvm 2.3 and boehm-gc 6.8 on FreeBSD CURRENT-8.
After few small fixes in llvmdc sources (freebsd's gcc is missing fmodl and changed #if linux to #if linux || __FreeBSD__, to include proper headers like errno.h).
|
Great! When you're happy with your fixes, feel free to send over a patch!
baryluk wrote: |
Compilation was succesfull, but then got segmentation faults. After recompilation of boehm-gc with threading disabled, llvmdc just started working!
|
You can skip boehm-gc entirely by passing --no-boehm to premake. However, the frontend will probably leak lots of memory then.
baryluk wrote: |
Now compiling Tango, very very slow... core/BitManip.d 5 minutes and still runing... Cpu usage 90%, strace shows nothing,
|
You are talking about compiling the backend, right? From your stacktrace, it seems to be hanging inside the DMD frontend while producing an error message. There's an "#if linux" in root.c:1640 (there are probably lots scattered about the frontend code...) - want to check it out? |
|
Back to top |
|
|
baryluk
Joined: 02 Sep 2007 Posts: 7
|
Posted: Thu Jun 26, 2008 2:52 pm Post subject: Re: LLVMDC on FreeBSD works |
|
|
ChristianK wrote: |
You are talking about compiling the backend, right? From your stacktrace, it seems to be hanging inside the DMD frontend while producing an error message. There's an "#if linux" in root.c:1640 (there are probably lots scattered about the frontend code...) - want to check it out? |
Yes, it was it. Added -Dlinux to premake.lua package.buildoptions. Kind of hack, but is working. Will do this in more portable way (probably changing all #if linux to #ifdef unix (which is defined on linux and on freebsd))
Compiled tango succesfully. Now having small problems with linking, but shouldn't be hard to fix this.
I will send patches when everything will work. |
|
Back to top |
|
|
ChristianK
Joined: 26 Sep 2006 Posts: 159 Location: Berlin, Germany
|
Posted: Thu Jul 10, 2008 6:45 am Post subject: |
|
|
Did you make any progress with this? As far as I remember, Tomas made some changes to linking when working on llvmdc on windows. Maybe that helped with your linking problems... |
|
Back to top |
|
|
baryluk
Joined: 02 Sep 2007 Posts: 7
|
Posted: Thu Jul 10, 2008 9:28 pm Post subject: |
|
|
Yesterday restarted work. It isn't so simple.
I merged newest tango because larsavi put there some freebsd stuff. But not all. I added missing stuff and fixed lots of typos (lots of pthread work, and exploring freebsd kernel headers), compiled everything. Fixed all #defines, and versions. Added few missing function (like log10l) and adjusted tango/lib/compiler to new garbage collector. Everything linked (manually, without -dl because it is in -lc) . No fighting with garbage collector (dlsym("__libc_stack_end") , and __data_start_ is probably problem.
Will provide raport tommorow, must fo sleep after 8 hours of fun hacking
BTW. I removed lots of linuxism in sources, so it should be easier to compile on solaris and other unixes. |
|
Back to top |
|
|
baryluk
Joined: 02 Sep 2007 Posts: 7
|
Posted: Thu Jul 10, 2008 11:36 pm Post subject: |
|
|
Code: |
[root@witek /home/baryluk/llvmdc-svn/tangotests]# llvm-ld -o=a -disable-opt -disable-inlining -L/usr/home/baryluk/llvmdc-svn/bin/../lib -L/usr/home/baryluk/llvmdc-svn/bin/../lib -native -ltango-base-c-llvmdc -lpthread -lm ./nmd_a.bc /usr/home/baryluk/llvmdc-svn/bin/../lib/libtango-base-llvmdc.a
[root@witek /home/baryluk/llvmdc-svn/tangotests]# gdb ./a
GNU gdb 6.1.1 [FreeBSD]
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "i386-marcel-freebsd"...
(gdb) r
Starting program: /usr/home/baryluk/llvmdc-svn/tangotests/a
[New LWP 100132]
[New Thread 0x8102040 (LWP 100132)]
main ctors
main args
main trap exceptions
main try exec
main runAll
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x8102040 (LWP 100132)]
0x080537f7 in thread_init () at eh.d:313
313 _Unwind_Resume(&exception_struct.unwind_info);
(gdb) bt
#0 0x080537f7 in thread_init () at eh.d:313
#1 0x0804e628 in gc_init () at gc.d:47
#2 0x0804f0fd in _D6dmain24mainUiPPaPPaZi6runAllMFZv () at dmain2.d:310
#3 0x0804ed21 in _D6dmain24mainUiPPaPPaZi7tryExecMFDFZvZv () at dmain2.d:259
#4 0x0804ec8e in main (argc=1, argv=0xbfbfe9dc, env=0xbfbfe9e4) at dmain2.d:322
(gdb)
|
Is exception handling working on any platform? |
|
Back to top |
|
|
ChristianK
Joined: 26 Sep 2006 Posts: 159 Location: Berlin, Germany
|
Posted: Fri Jul 11, 2008 12:19 am Post subject: |
|
|
Great work!
No, exception handling is probably only working on x86 (I was happy enough to get it to work at all and didn't look at platform dependent stuff yet). If your platform as a correct libunwind (which should be available if you got a working gcc, I think), all EH problems should be inside compiler/llvmdc/eh.d. I think I have generally put a comment where I expected issues.
It is generally useful to look at the EH tables generated in the assembly. Maybe they look different on FreeBSD. On x86 they look like so:
Code: |
GCC_except_table1:
.align 4
.byte 0x0 // header
.byte 0x0
.byte 0x0
.Lexception1:
.byte 0xff
.byte 0x0
.uleb128 34
.byte 0x3
.uleb128 26
.long .Llabel1-.Leh_func_begin1 // callsite table
.long .Llabel8-.Llabel1
.long .Llabel9-.Leh_func_begin1
.uleb128 1
.long .Llabel8-.Leh_func_begin1
.long .Leh_func_end1-.Llabel8
.long 0x0
.uleb128 0
.sleb128 1 // action table
.sleb128 0
.long _D7ehtest41C7__ClassZ // classinfo table
.align 4
|
However, if exception_struct.unwind_info fails, this could also be a problem with offsetof. I recommend setting a breakpoint in eh.d and checking if the address of exception_struct is calculated correctly.
If you need any help with making EH work on another platform, let me know. |
|
Back to top |
|
|
ChristianK
Joined: 26 Sep 2006 Posts: 159 Location: Berlin, Germany
|
Posted: Fri Jul 11, 2008 2:58 am Post subject: |
|
|
I have looked at it a bit, and if eh.d:313 fails, you probably need to figure out the right values for eh_exception_regno and eh_selector_regno defined in the same file. They contain the register numbers used to pass data between the personality routine and the landing pad and are currently hardwired to some x86-specific values.
Another thing: you don't have to fix it all in one go. If you have a patch for some particular issue, send it in! That way we won't have to deal with one huge patch later.
As far as I remember Tomas didn't plan to be overly strict with commit access for now, so if you're up to it (and don't expect your changes to break everything in horrible ways ;), send him an email! |
|
Back to top |
|
|
heromyth
Joined: 26 Nov 2006 Posts: 46
|
Posted: Sun Dec 07, 2008 10:02 am Post subject: |
|
|
Below is my patch for ldc on FreeBSD:
Code: |
diff -r f6dd817060fc dmd/mtype.c
--- a/dmd/mtype.c Thu Nov 27 18:31:09 2008 +0100
+++ b/dmd/mtype.c Sun Dec 07 23:48:34 2008 +0800
@@ -34,7 +34,7 @@
#if __APPLE__
#include <math.h>
static double zero = 0;
-#elif __MINGW32__
+#elif __MINGW32__ || __FreeBSD__
#include <math.h>
static double zero = 0;
#elif __GNUC__
diff -r f6dd817060fc dmd2/mtype.c
--- a/dmd2/mtype.c Thu Nov 27 18:31:09 2008 +0100
+++ b/dmd2/mtype.c Sun Dec 07 23:48:34 2008 +0800
@@ -34,7 +34,7 @@
#if __APPLE__
#include <math.h>
static double zero = 0;
-#elif __MINGW32__
+#elif __MINGW32__ || __FreeBSD__
#include <math.h>
static double zero = 0;
#elif __GNUC__
|
|
|
Back to top |
|
|
sleets
Joined: 29 Jun 2007 Posts: 27
|
Posted: Tue Dec 30, 2008 7:55 am Post subject: |
|
|
is this patch still work? |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|