Replacement for GMP as Bignum: ARPREC? Haskell?; OS-X and OpenSSL

GHC Task Ticket # 601 suggests replacing GMP with OpenSSL's Bignum library, BN. I have two questions concerning this: (1) Why not use the ARbitrary PRECision Computation Package (ARPREC) by David Bailey, Yozo Hida, Karthik Jeyabalan, Xiaoye Li and Brandon Thompson? Here is a reference web page: http://crd.lbl.gov/~dhbailey/mpdist/ ARPREC is written in C++ but supports calls from C (see include/arprec/c_mp.h in the distribution directory). ARPREC is very fast and supports more complex mathematics than BN. The Licensing for ARPREC is not a problem: essentially similar to BSD3. Note that there would be a basic configuration fix for building OpenSSL's BN library on OS 10.4: you would probably--I had to, myself--have to temporarily move the default installation of /usr/lib/libssl0.9.dylib (and variants) if you want to create a shared (.a) library because Apple's ln links dynamic libraries in preference to shared libraries. Those of you who have some experience with Apple's gcc also know that Apple's gcc does not recognise the -shared flag. (2) A much more aesthetic solution would be to replace any external Bignum library with a pure Haskell library. There are many problems with building a truly efficient and fast Bignum library in Haskell but challenges like that are how languages evolve... -Peter Tanski

On Sat, 29 Jul 2006 21:45:21 -0400 p.tanski@gmail.com wrote:
GHC Task Ticket # 601 suggests replacing GMP with OpenSSL's Bignum library, BN. I have two questions concerning this:
(1) Why not use the ARbitrary PRECision Computation Package (ARPREC) by David Bailey, Yozo Hida, Karthik Jeyabalan, Xiaoye Li and Brandon Thompson? Here is a reference web page: http://crd.lbl.gov/~dhbailey/mpdist/
ARPREC is written in C++ but supports calls from C (see include/arprec/c_mp.h in the distribution directory). ARPREC is very fast and supports more complex mathematics than BN. The Licensing for ARPREC is not a problem: essentially similar to BSD3.
Note that there would be a basic configuration fix for building OpenSSL's BN library on OS 10.4: you would probably--I had to, myself--have to temporarily move the default installation of /usr/lib/libssl0.9.dylib (and variants) if you want to create a shared (.a) library because Apple's ln links dynamic libraries in preference to shared libraries.
I think you meant "if you want to create a static (.a) library", not "if you want to create a shared (.a) library" Those of you who have some experience with
Apple's gcc also know that Apple's gcc does not recognise the -shared flag.
(2) A much more aesthetic solution would be to replace any external Bignum library with a pure Haskell library. There are many problems with building a truly efficient and fast Bignum library in Haskell but challenges like that are how languages evolve...
-Peter Tanski _______________________________________________ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users

p.tanski@gmail.com wrote:
GHC Task Ticket # 601 suggests replacing GMP with OpenSSL's Bignum library, BN. I have two questions concerning this:
From the ticket, this looks very scary:
but its LGPL license is problematic for users of GHC (it prohibits static linking of GHC-compiled programs, for example). Does this mean I can't distribute my Haskell app as a commercial application? I certainly don't want to distribute source code and I've got no idea how to compile a Haskell app other than using ghc --make, which creates a single exe ie with static linkage. If I only use Int's (not Integer's) in my code, is there a way to get rid of GMP so that I won't have an impossible licencing problem when trying to distribute my application binary? If not, then it would seem absolutely vital to get rid of GMP as soon as possible or else try to persuade the authors to add the usual static linking exception to their LGPL licence for it. Thanks, Brian. -- Logic empowers us and Love gives us purpose. Yet still phantoms restless for eras long past, congealed in the present in unthought forms, strive mightily unseen to destroy us. http://www.metamilk.com

On 7/30/06, Brian Hulley
p.tanski@gmail.com wrote:
GHC Task Ticket # 601 suggests replacing GMP with OpenSSL's Bignum library, BN. I have two questions concerning this:
From the ticket, this looks very scary:
but its LGPL license is problematic for users of GHC (it prohibits static linking of GHC-compiled programs, for example).
Does this mean I can't distribute my Haskell app as a commercial application? I certainly don't want to distribute source code and I've got
I am not a lawyer, and you should consult lawyer if you want real advice about licensing issues. Strict answer to first question: No. You can distribute statically compiled binaries.
no idea how to compile a Haskell app other than using ghc --make, which creates a single exe ie with static linkage.
But in this case, yes, you can't. You need to provide way to relink gmp in you program. As far as I know, this is simply possible by taking all the objs --make generates, other objs and libs and giving them on - users need to have ghc distro+their own gmp set in.
If I only use Int's (not Integer's) in my code, is there a way to get rid of GMP so that I won't have an impossible licencing problem when trying to
I am fairly certain you cannot force or rely GMP getting dropped by linker.
distribute my application binary? If not, then it would seem absolutely vital to get rid of GMP as soon as possible or else try to persuade the authors to add the usual static linking exception to their LGPL licence for it.
GMP being rather GNU ;-) replacing is probably the only option. There's other reason for dropping GMP as well: The ghc rts steals GMP memory allocation (sort of integrating it with garbage collector) which makes it impossible for other parts of program use GMP (in practice). HTH, --Esa

Esa Ilari Vuokko wrote:
On 7/30/06, Brian Hulley
wrote: p.tanski@gmail.com wrote:
GHC Task Ticket # 601 suggests replacing GMP with OpenSSL's Bignum library, BN. I have two questions concerning this:
From the ticket, this looks very scary:
but its LGPL license is problematic for users of GHC (it prohibits static linking of GHC-compiled programs, for example). [snip] But in this case, yes, you can't. You need to provide way to relink gmp in you program. As far as I know, this is simply possible by taking all the objs --make generates, other objs and libs and giving them on - users need to have ghc distro+their own gmp set in.
Hi Esa - Thanks for reminding me about the distinction between source and object files. I keep forgetting that object files exist (!) and that it's sufficient for LGPL to just make them available. Still, a slight problem is that since there is one object file per source file, the names of the object files give quite a lot of information away about the structure of the program especially when they are arranged in a module hierarchy, so I'll be glad when GMP is replaced by something without such a burdensome licence. (Although perhaps I can bundle my object files into a single library file but I don't know how to do this yet, or if it would really help in the goal to make the code completely obfuscated, impenetrable, and unavailable to any rival company... ;-) ) Thanks again, Brian. -- Logic empowers us and Love gives us purpose. Yet still phantoms restless for eras long past, congealed in the present in unthought forms, strive mightily unseen to destroy us. http://www.metamilk.com

Hi Brian,
On 7/30/06, Brian Hulley
Still, a slight problem is that since there is one object file per source file, the names of the object files give quite a lot of information away about the structure of the program especially when they are arranged in a module hierarchy, so I'll be glad when GMP is replaced by something without such a burdensome licence. (Although perhaps I can bundle my object files into a single library file but I don't know how to do this yet, or if it would really help in the goal to make the code completely obfuscated, impenetrable, and unavailable to any rival company... ;-) )
Assuming gnu toolchain, you can use ld to link object files together in a form that is definitely harder to break apart. (incremental linking to incomplete executable, iirc via switch -x). That should allow you to produce one big object file (of atleast haskell bits and c bits) that gets simply passed to ghc. Using strip to remove debug info/symbol tables also helps somewhat. (strip.exe is not part of ghc distribution, but you can find it in mingw bintools.) Using ar to create archives does not help at all - you can extract the original files using ar itself. HTH, --Esa

Esa Ilari Vuokko wrote:
Hi Brian,
On 7/30/06, Brian Hulley
wrote: Still, a slight problem is that since there is one object file per source file, the names of the object files give quite a lot of information away about the structure of the program especially when they are arranged in a module hierarchy, so I'll be glad when GMP is replaced by something without such a burdensome licence. (Although perhaps I can bundle my object files into a single library file but I don't know how to do this yet, or if it would really help in the goal to make the code completely obfuscated, impenetrable, and unavailable to any rival company... ;-) )
Assuming gnu toolchain, you can use ld to link object files together in a form that is definitely harder to break apart. (incremental linking to incomplete executable, iirc via switch -x). That should allow you to produce one big object file (of atleast haskell bits and c bits) that gets simply passed to ghc.
Using strip to remove debug info/symbol tables also helps somewhat. (strip.exe is not part of ghc distribution, but you can find it in mingw bintools.)
Using ar to create archives does not help at all - you can extract the original files using ar itself.
Thanks - I must look into these mingw tools (at the moment I'm just using the plain GHC Windows distro) I think the ideal solution in the long term would be if the windows version of GHC could put each LGPL lib such as GMP (are there any more?) into its own DLL so that it would only statically link user code + BSD3 stuff into the main executable. Then it would be very simple to distribute Windows apps (WinXP allows DLLs to be local to a specific app by putting them in the same directory as the exe) and would mirror the way GHC works on Unix (and would also make it easier for people to use updated LGPL components with the app in the spirit of LGPL). Best regards Brian. -- Logic empowers us and Love gives us purpose. Yet still phantoms restless for eras long past, congealed in the present in unthought forms, strive mightily unseen to destroy us. http://www.metamilk.com

On Sun, 2006-07-30 at 11:53 +0100, Brian Hulley wrote:
p.tanski@gmail.com wrote:
GHC Task Ticket # 601 suggests replacing GMP with OpenSSL's Bignum library, BN. I have two questions concerning this:
From the ticket, this looks very scary:
but its LGPL license is problematic for users of GHC (it prohibits static linking of GHC-compiled programs, for example).
Does this mean I can't distribute my Haskell app as a commercial application? I certainly don't want to distribute source code and I've got no idea how to compile a Haskell app other than using ghc --make, which creates a single exe ie with static linkage.
GHC only statically links Haskell code. It dynamically links to GMP and the system C library and other C libs. So you're fine. On unix you can check for yourself with ldd. It lists all the shared libs that your program needs. For example: $ ldd /usr/lib/ghc-6.4.2/ghc-6.4.2 libreadline.so.5 => /lib/libreadline.so.5 (0x00002b568fca6000) libncurses.so.5 => /lib/libncurses.so.5 (0x00002b568fde3000) libdl.so.2 => /lib/libdl.so.2 (0x00002b568ff3f000) libm.so.6 => /lib/libm.so.6 (0x00002b5690042000) libgmp.so.3 => /usr/lib/libgmp.so.3 (0x00002b569019a000) libpthread.so.0 => /lib/libpthread.so.0 (0x00002b56902cf000) libc.so.6 => /lib/libc.so.6 (0x00002b56903e4000) /lib64/ld-linux-x86-64.so.2 (0x00002b568fb8e000) Duncan

Hi Duncan,
On 7/30/06, Duncan Coutts
GHC only statically links Haskell code. It dynamically links to GMP and the system C library and other C libs.
In Windows (mingw) GMP is linked in statically (even this dll-stuff is bitrotted).
So you're fine.
On unix you can check for yourself with ldd. It lists all the shared libs that your program needs. For example:
FWIW, you can use dependencywalker to do this in Windows. Best regards, Esa PS For ghc.exe in 6.4.2 distro, walker gives: ACTIVEDS.DLL ADSLDPC.DLL ADVAPI32.DLL ADVPACK.DLL APPHELP.DLL ATL.DLL AUTHZ.DLL BROWSEUI.DLL CABINET.DLL CDFVIEW.DLL CERTCLI.DLL CFGMGR32.DLL CLUSAPI.DLL COMCTL32.DLL COMDLG32.DLL CREDUI.DLL CRYPT32.DLL CRYPTUI.DLL CSCDLL.DLL DBGHELP.DLL DEVMGR.DLL DHCPCSVC.DLL DNSAPI.DLL DUSER.DLL EFSADU.DLL ESENT.DLL GDI32.DLL GDIPLUS.DLL GHC.EXE HLINK.DLL HNETCFG.DLL IMAGEHLP.DLL IMGUTIL.DLL IMM32.DLL INETCOMM.DLL IPHLPAPI.DLL KERNEL32.DLL LINKINFO.DLL LZ32.DLL MFC42U.DLL MLANG.DLL MOBSYNC.DLL MPR.DLL MPRAPI.DLL MPRUI.DLL MSASN1.DLL MSGINA.DLL MSHTML.DLL MSI.DLL MSIMG32.DLL MSJAVA.DLL MSLS31.DLL MSOERT2.DLL MSRATING.DLL MSSIGN32.DLL MSVCP60.DLL MSVCRT.DLL MSWSOCK.DLL NETAPI32.DLL NETCFGX.DLL NETMAN.DLL NETPLWIZ.DLL NETRAP.DLL NETSHELL.DLL NETUI0.DLL NETUI1.DLL NETUI2.DLL NTDLL.DLL NTDSAPI.DLL NTLANMAN.DLL ODBC32.DLL OLE32.DLL OLEACC.DLL OLEAUT32.DLL OLEDLG.DLL OLEPRO32.DLL POWRPROF.DLL PRINTUI.DLL PSAPI.DLL QUERY.DLL RASAPI32.DLL RASDLG.DLL RASMAN.DLL REGAPI.DLL RPCRT4.DLL RTUTILS.DLL SAMLIB.DLL SCECLI.DLL SECUR32.DLL SETUPAPI.DLL SHDOCVW.DLL SHELL32.DLL SHLWAPI.DLL SHSVCS.DLL TAPI32.DLL URLMON.DLL USER32.DLL USERENV.DLL USP10.DLL UTILDLL.DLL UXTHEME.DLL VERSION.DLL W32TOPL.DLL WINHTTP.DLL WININET.DLL WINMM.DLL WINSCARD.DLL WINSPOOL.DRV WINSTA.DLL WINTRUST.DLL WLDAP32.DLL WMI.DLL WS2_32.DLL WS2HELP.DLL WSOCK32.DLL WTSAPI32.DLL WZCDLG.DLL WZCSAPI.DLL WZCSVC.DLL

Duncan Coutts wrote:
On Sun, 2006-07-30 at 11:53 +0100, Brian Hulley wrote:
p.tanski@gmail.com wrote:
GHC Task Ticket # 601 suggests replacing GMP with OpenSSL's Bignum library, BN. I have two questions concerning this:
From the ticket, this looks very scary:
but its LGPL license is problematic for users of GHC (it prohibits static linking of GHC-compiled programs, for example).
Does this mean I can't distribute my Haskell app as a commercial application? I certainly don't want to distribute source code and I've got no idea how to compile a Haskell app other than using ghc --make, which creates a single exe ie with static linkage.
GHC only statically links Haskell code. It dynamically links to GMP and the system C library and other C libs.
So you're fine.
On unix you can check for yourself with ldd. It lists all the shared libs that your program needs. For example:
$ ldd /usr/lib/ghc-6.4.2/ghc-6.4.2 libreadline.so.5 => /lib/libreadline.so.5 (0x00002b568fca6000) libncurses.so.5 => /lib/libncurses.so.5 (0x00002b568fde3000) libdl.so.2 => /lib/libdl.so.2 (0x00002b568ff3f000) libm.so.6 => /lib/libm.so.6 (0x00002b5690042000) libgmp.so.3 => /usr/lib/libgmp.so.3 (0x00002b569019a000) libpthread.so.0 => /lib/libpthread.so.0 (0x00002b56902cf000) libc.so.6 => /lib/libc.so.6 (0x00002b56903e4000) /lib64/ld-linux-x86-64.so.2 (0x00002b568fb8e000)
Is this also true on Windows? I've got a feeling that it's not because my program (ie main.exe + my own C++ DLL) runs on a plain WindowsXP installation that doesn't have anything else installed on it (apart from the Microsoft C runtime that comes as standard and which presumably doesn't contain GMP). Thanks, Brian. -- Logic empowers us and Love gives us purpose. Yet still phantoms restless for eras long past, congealed in the present in unthought forms, strive mightily unseen to destroy us. http://www.metamilk.com
participants (5)
-
Brian Hulley
-
Duncan Coutts
-
Esa Ilari Vuokko
-
p.tanski@gmail.com
-
Seth Kurtzberg