Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Ticket #857 (new defect)

Opened 2 years ago

Last modified 2 days ago

build runtime library conformant with dynamic libraries on linux

Reported by: jascha Assigned to: h3r3tic
Priority: major Milestone: 1.0
Component: Core Functionality Version: 0.99.4 Frank
Keywords: triage Cc:

Description

very few small changes in the build files only, make it possible to build Tango on linux with -fPIC and the GC set to GC_Use_Data_Dyld, such that it can be used in dynamically loaded libraries.

attached is a patch to 0.99.4 that does these changes. they would have to be integrated such that they can be selected as an option to the build-scripts.

Attachments

tango-0.99.4_dynload.patch (2.3 kB) - added by jascha on 01/17/08 17:23:35.
tango-0.99.4_dynload2.patch (3.5 kB) - added by jascha on 01/17/08 21:55:26.
tango-0.99.4_dynload3.patch (3.5 kB) - added by jascha on 01/20/08 13:49:59.
v2 didnt work with svn branch 0.99.4
sharedUserLibrary.patch (1.5 kB) - added by goshawk on 09/05/09 07:05:28.
shared user library for x86_64 ubuntu linux on 5/09/09

Change History

01/17/08 17:23:35 changed by jascha

  • attachment tango-0.99.4_dynload.patch added.

01/17/08 18:33:45 changed by kris

thank you

01/17/08 21:55:26 changed by jascha

  • attachment tango-0.99.4_dynload2.patch added.

01/17/08 21:56:01 changed by jascha

actually, that didn't work. the GC needs another mode for determining the segments. new patch attached.

01/18/08 06:22:49 changed by jascha

More problems: memory allocation works with the changed GC mode, but garbage collection crashes. I guess there are GC changes required that i don't know how to do. I can deliver a test-lib and app if required.

01/20/08 13:49:59 changed by jascha

  • attachment tango-0.99.4_dynload3.patch added.

v2 didnt work with svn branch 0.99.4

02/23/08 00:06:29 changed by kris

  • milestone set to 0.99.6.

04/21/08 20:34:40 changed by sean

  • milestone changed from 0.99.6 to 0.99.7.

I'm pushing this off because I don't know enough about *nix dynamic libs to fix this without some research.

05/11/08 17:46:54 changed by larsivi

  • keywords set to triage.

07/10/08 07:02:15 changed by larsivi

  • milestone changed from 0.99.7 to 0.99.8.

07/26/08 13:07:43 changed by sean

  • status changed from new to assigned.

I intend to fix this one but it's going to take some research. With any luck I'll be able to sort it out before the next release.

10/16/08 17:39:34 changed by larsivi

Did we get any further on this?

10/16/08 17:46:08 changed by sean

Not yet.

11/19/08 07:42:23 changed by larsivi

  • owner changed from sean to fawzi.
  • status changed from assigned to new.

03/05/09 13:15:44 changed by fawzi

(In [4387]) small changes toward -fPIC, refs #857

03/28/09 08:05:21 changed by larsivi

  • milestone changed from 0.99.8 to 0.99.9.

08/26/09 15:24:47 changed by goshawk

Are there any unreleased patches for this? I'll start working on it soon :)

08/26/09 17:55:32 changed by fawzi

Not that I know, the patches here are mostly outdated, because the things are compiler dependent, and they were for gdc.

With ldc, a lot of time ago I had tried to compiled shared libraries on mac and it sort of worked, there were some issues, but it was not clear if they were ldc issues or shared libs issues.

ldc can generate shared libs without problems (you have to pass -relocation-model=pic to it), and you can also look at how (for example) qtd does it.

I would just use a new version name for it, if you do ./build.sh --version soopt

or something like that, then you can define the arch files with the correct flags, and I would check them in. I am not sure if you can use the ldc.inc, I think that you will have to define an ldcSo.rules (to link stuff differently, and for the different extensions), but it will mostly mirror ldc.rules.

The easiest thing (0 effort) would be to make just tango-user a dynamic lib, keeping tango-base static, but some effort in making tango-base mostly dynamic would be for sure welcome.

There the main issue then is to get the correct addresses for the constants in the gc (which should also work with ldc, as it should use the dynamic segment tables but should be checked if it is still true in practice.

The last thing is the startup sequence of an executable I haven't really looked at it, but I think that one might have to link a static object file (basically dmain2 or something like it, maybe it can be even more stripped down) that has still to be statically linked.

08/27/09 19:15:28 changed by goshawk

Well, after our discussion i've

goshawk@earth:~/workspace/test$ ldc test.d -I/home/goshawk/Documents/Projects/tango/trunk/user/ -L-L/home/goshawk/Documents/Projects/tango/trunk/build/libs/ -L-ltango-user-ldc-soopt
/home/goshawk/Documents/Projects/tango/trunk/build/libs//libtango-user-ldc-soopt.so: undefined reference to `inflateEnd'
/home/goshawk/Documents/Projects/tango/trunk/build/libs//libtango-user-ldc-soopt.so: undefined reference to `CompareStringW'
/home/goshawk/Documents/Projects/tango/trunk/build/libs//libtango-user-ldc-soopt.so: undefined reference to `BZ2_bzCompressInit'
/home/goshawk/Documents/Projects/tango/trunk/build/libs//libtango-user-ldc-soopt.so: undefined reference to `deflate'
/home/goshawk/Documents/Projects/tango/trunk/build/libs//libtango-user-ldc-soopt.so: undefined reference to `deflateInit_'
/home/goshawk/Documents/Projects/tango/trunk/build/libs//libtango-user-ldc-soopt.so: undefined reference to `BZ2_bzCompress'
/home/goshawk/Documents/Projects/tango/trunk/build/libs//libtango-user-ldc-soopt.so: undefined reference to `inflateInit2_'
/home/goshawk/Documents/Projects/tango/trunk/build/libs//libtango-user-ldc-soopt.so: undefined reference to `inflate'
/home/goshawk/Documents/Projects/tango/trunk/build/libs//libtango-user-ldc-soopt.so: undefined reference to `deflateEnd'
/home/goshawk/Documents/Projects/tango/trunk/build/libs//libtango-user-ldc-soopt.so: undefined reference to `SetThreadLocale'
/home/goshawk/Documents/Projects/tango/trunk/build/libs//libtango-user-ldc-soopt.so: undefined reference to `BZ2_bzDecompress'
/home/goshawk/Documents/Projects/tango/trunk/build/libs//libtango-user-ldc-soopt.so: undefined reference to `inflateBackInit_'
/home/goshawk/Documents/Projects/tango/trunk/build/libs//libtango-user-ldc-soopt.so: undefined reference to `GetUserDefaultLCID'
/home/goshawk/Documents/Projects/tango/trunk/build/libs//libtango-user-ldc-soopt.so: undefined reference to `MultiByteToWideChar'
/home/goshawk/Documents/Projects/tango/trunk/build/libs//libtango-user-ldc-soopt.so: undefined reference to `BZ2_bzDecompressEnd'
/home/goshawk/Documents/Projects/tango/trunk/build/libs//libtango-user-ldc-soopt.so: undefined reference to `inflateInit_'
/home/goshawk/Documents/Projects/tango/trunk/build/libs//libtango-user-ldc-soopt.so: undefined reference to `deflateInit2_'
/home/goshawk/Documents/Projects/tango/trunk/build/libs//libtango-user-ldc-soopt.so: undefined reference to `BZ2_bzDecompressInit'
/home/goshawk/Documents/Projects/tango/trunk/build/libs//libtango-user-ldc-soopt.so: undefined reference to `BZ2_bzCompressEnd'
collect2: ld returned 1 exit status
Error: linking failed:
status: 1

I've to add -I/home/goshawk/Documents/Projects/tango/trunk/user/ due to bug #1733 and the ldc.conf is

goshawk@earth:~/workspace/test$ cat /etc/ldc/ldc.conf
// This configuration file uses libconfig.
// See http://www.hyperrealm.com/libconfig/ for syntax details.

// The default group is required
default:
{
    // 'switches' holds array of string that are appends to the command line
    // arguments before they are parsed.
    switches = [
        "-I/usr/include/d/ldc/libtango",
        "-I/usr/include/d/ldc/libtango/lib/common",
        "-L-L/usr/lib",
        //"-L-ltango-user-ldc",
        "-d-version=Tango",
        "-defaultlib=tango-base-ldc",
        "-debuglib=tango-base-ldc"
    ];
};

08/28/09 12:30:59 changed by goshawk

Well, finally i reached this point:

goshawk@earth:~/workspace/test$ ldc test.d -I/home/goshawk/Documents/Projects/tango/trunk/user/ -L-L/home/goshawk/Documents/Projects/tango/trunk/build/libs/ -L-ltango-user-ldc-soopt  -L-lz -L-lbz2
/home/goshawk/Documents/Projects/tango/trunk/build/libs//libtango-user-ldc-soopt.so: undefined reference to `CompareStringW'
/home/goshawk/Documents/Projects/tango/trunk/build/libs//libtango-user-ldc-soopt.so: undefined reference to `SetThreadLocale'
/home/goshawk/Documents/Projects/tango/trunk/build/libs//libtango-user-ldc-soopt.so: undefined reference to `GetUserDefaultLCID'
/home/goshawk/Documents/Projects/tango/trunk/build/libs//libtango-user-ldc-soopt.so: undefined reference to `MultiByteToWideChar'
collect2: ld returned 1 exit status
Error: linking failed:
status: 1

I've googled for the 4 missing functions and they are Win32 functions.

I think there is a problem while compiling which includes these functions in the tango .so file in linux version.

09/03/09 12:20:29 changed by goshawk

Thanks to lastest trunk fixed by fawzi, i'm able to build the library, but there are problems when i try to compile a simple hello world program:

goshawk@earth:~/workspace/test$ ldc test.d -I/home/goshawk/Documents/-L-L/home/goshawk/Documents/Projects/tango/trunk/build/libs/ -L-ltango-user-ldc-soopt  -L-lz -L-lbz2
goshawk@earth:~/workspace/test$ ./test
./test: Symbol `_d_eh_personality' causes overflow in R_X86_64_PC32 relocation
Segmentation fault
goshawk@earth:~/workspace/test$ cat test.d
import tango.io.Stdout;

int main(){
    Stdout("Hello World shared library");
    return 0;
}

09/03/09 17:47:39 changed by goshawk

I was finally able to compile a hello world program but i've this error:

goshawk@earth:~/workspace/test$ ldc test.d -I/home/goshawk/Documents/-L-L/home/goshawk/Documents/Projects/tango/trunk/build/libs/ -L-ltango-user-ldc-soopt  -L-lz -L-lbz2
goshawk@earth:~/workspace/test$ ./test                                                                                                                                   
./test: Symbol `_d_eh_personality' causes overflow in R_X86_64_PC32 relocation                                                                                           
Segmentation fault                                                                                                                                                       
goshawk@earth:~/workspace/test$ gdb ./test
GNU gdb 6.8-debian
Copyright (C) 2008 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"...
(gdb) run
Starting program: /home/goshawk/workspace/test/test
/home/goshawk/workspace/test/test: Symbol `_d_eh_personality' causes overflow in R_X86_64_PC32 relocation
[Thread debugging using libthread_db enabled]
[New Thread 0x7f79a4b296f0 (LWP 12764)]

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7f79a4b296f0 (LWP 12764)]
0x00007f79a450c06b in _D5tango4math6random7Twister7Twister4seedMFkbZv () at tango.math.random.Twister.d:244
244                             mt[mti] = (1812433253U * (mt[mti-1] ^ (mt[mti-1] >> 30)) + mti);
Current language:  auto; currently minimal
(gdb)
            

09/03/09 18:17:14 changed by goshawk

If i link the executable with both user and base compiled with -relocation-mode=pic i get:

goshawk@earth:~/workspace/test$ ldc test.d -I/home/goshawk/Documents/-L-L/home/goshawk/Documents/Projects/tango/trunk/build/libs/ -L-ltango-user-ldc-soopt -L-ltango-base-ldc-soopt  -L-lz -L-lbz2                                                                                                                                                                          
goshawk@earth:~/workspace/test$ ./test                                                                                                                                                
Segmentation fault
goshawk@earth:~/workspace/test$ gdb ./test
GNU gdb 6.8-debian
Copyright (C) 2008 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"...
(gdb) run
Starting program: /home/goshawk/workspace/test/test
[Thread debugging using libthread_db enabled]
[New Thread 0x7fc24da896f0 (LWP 12008)]

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7fc24da896f0 (LWP 12008)]
_D2rt7basicgc3gcx2GC12mallocNoSyncMFmkZPv () at rt.basicgc.gcx.d:572
572                 // Return next item from free list
Current language:  auto; currently minimal
(gdb) quit

If i compile using the tango user shared library and the tango base static library i get the previous error.

09/05/09 07:05:28 changed by goshawk

  • attachment sharedUserLibrary.patch added.

shared user library for x86_64 ubuntu linux on 5/09/09

09/10/09 14:08:17 changed by fawzi

(In [4934]) first attempts for dynamic lib, refs #857

09/10/09 18:14:12 changed by fawzi

the warning seems connected with http://hlvm.llvm.org/bugs/show_bug.cgi?id=2853 but there the binary seems to still work, but this is not the case with ldc

11/29/09 07:06:58 changed by fawzi

  • owner changed from fawzi to kris.

01/11/10 21:30:28 changed by kris

  • owner changed from kris to h3r3tic.

any thoughts on this, h3r3tic?

01/12/10 01:34:56 changed by h3r3tic

I'm afraid I know nothing about dynamic libs in Linux, Kris :(

02/07/10 16:43:47 changed by h3r3tic

  • milestone changed from 0.99.9 to 1.0.