www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 3226] New: -fPIC flag doesn't seem to work

http://d.puremagic.com/issues/show_bug.cgi?id=3226

           Summary: -fPIC flag doesn't seem to work
           Product: D
           Version: 1.046
          Platform: x86
        OS/Version: Linux
            Status: NEW
          Keywords: link-failure
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: snake.scaly gmail.com


Here is a test case:

$ cat test.d
module test; // file "test.d"
export int testMe() { return 1; }
export class Test
{
    private int n;
    this(int i) { n = i; }
    int get() { return n; }
}
$ dmd -c -fPIC test.d
$ gcc -shared test.o -o libtest.so
/usr/lib/gcc/i686-pc-linux-gnu/4.3.3/../../../../i686-pc-linux-gnu/bin/ld:
warning: creating a DT_TEXTREL in object.

Note the warning above.  This is how GCC complains about relocations found in
an object file.  Linking with this shared object consequently fails:

$ cat prog.d
module prog; // file "prog.d"
import std.stdio;
import test;
void main()
{
   writefln("testMe: %d", testMe());
   writefln("Test class: %d", (new Test(3)).get());
}
$ dmd prog.d -L-L. -L-ltest
/usr/lib/gcc/i686-pc-linux-gnu/4.3.3/../../../../i686-pc-linux-gnu/bin/ld:
dynamic variable `_D4test4Test7__ClassZ' is zero size
/usr/lib/gcc/i686-pc-linux-gnu/4.3.3/../../../../i686-pc-linux-gnu/bin/ld:
prog.o(.text._Dmain+0x22): unresolvable R_386_32 relocation against symbol
`_D4test4Test7__ClassZ'
/usr/lib/gcc/i686-pc-linux-gnu/4.3.3/../../../../i686-pc-linux-gnu/bin/ld:
final link failed: Nonrepresentable section on output
collect2: ld returned 1 exit status

The tools used:

$ dmd | head -n1
Digital Mars D Compiler v1.046
$ gcc --version | head -n1
gcc (Gentoo 4.3.3-r2 p1.1, pie-10.1.5) 4.3.3
$ uname -a

i686 Intel(R) Core(TM)2 CPU T5600   1.83GHz GenuineIntel GNU/Linux
$

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 04 2009