Bug 3226 – -fPIC flag doesn't seem to work

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
Linux
Creation time
2009-08-04T07:40:00Z
Last change time
2014-04-18T09:12:04Z
Keywords
link-failure
Assigned to
nobody
Creator
snake.scaly

Comments

Comment #0 by snake.scaly — 2009-08-04T07:40:45Z
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 $
Comment #1 by code — 2014-02-06T16:25:21Z
This should be fixed by now.