[Issue 3226] New: -fPIC flag doesn't seem to work

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Aug 4 07:40:45 PDT 2009


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 at puremagic.com
        ReportedBy: snake.scaly at 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
Linux mordor-gen 2.6.22.18-co-0.7.3 #1 PREEMPT Sat May 24 22:27:30 UTC 2008
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: -------


More information about the Digitalmars-d-bugs mailing list