Bug 8548 – relocation R_X86_64_32 against can not be used when making a shared object

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-08-15T05:13:29Z
Last change time
2024-12-13T18:01:01Z
Assigned to
No Owner
Creator
wbrana
Moved to GitHub: dmd#18460 →

Comments

Comment #0 by wbrana — 2012-08-15T05:13:29Z
$ ./dmd hello.d /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.2/../../../../x86_64-pc-linux-gnu/bin/ld: hello.o: relocation R_X86_64_32 against `.data' can not be used when making a shared object; recompile with -fPIC hello.o: could not read symbols: Bad value collect2: error: ld returned 1 exit status --- errorlevel 1 $ ./dmd -fPIC hello.d /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.2/../../../../x86_64-pc-linux-gnu/bin/ld: ./../lib64/libphobos2.a(object__c_58c.o): relocation R_X86_64_32 against `_D10TypeInfo_m6__initZ' can not be used when making a shared object; recompile with -fPIC ./../lib64/libphobos2.a: could not read symbols: Bad value collect2: error: ld returned 1 exit status --- errorlevel 1
Comment #1 by maxim — 2012-08-15T07:57:01Z
Which version of dmd are you using and what is in hello.d?
Comment #2 by wbrana — 2012-08-15T08:09:12Z
dmd.2.060.zip dmd2/linux/bin64/dmd import std.stdio; void main(string[] args) { writeln("hello world"); writefln("args.length = %d", args.length); foreach (index, arg; args) { writefln("args[%d] = '%s'", index, arg); } }
Comment #3 by wbrana — 2012-08-15T08:19:34Z
It seems dmd is incompatible with Gentoo Hardened gcc.
Comment #4 by wbrana — 2012-08-15T08:45:11Z
following command fails also with non-hardened gcc ./dmd -shared -fPIC hello.d /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.2-pre9999/../../../../x86_64-pc-linux-gnu/bin/ld: ./../lib64/libphobos2.a(object__c_58c.o): relocation R_X86_64_32 against `_D10TypeInfo_m6__initZ' can not be used when making a shared object; recompile with -fPIC ./../lib64/libphobos2.a: could not read symbols: Bad value collect2: error: ld returned 1 exit status --- errorlevel 1
Comment #5 by maxim — 2012-08-15T10:28:14Z
(In reply to comment #4) > following command fails also with non-hardened gcc > > ./dmd -shared -fPIC hello.d > /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.2-pre9999/../../../../x86_64-pc-linux-gnu/bin/ld: > ./../lib64/libphobos2.a(object__c_58c.o): relocation R_X86_64_32 against > `_D10TypeInfo_m6__initZ' can not be used when making a shared object; recompile > with -fPIC > ./../lib64/libphobos2.a: could not read symbols: Bad value > collect2: error: ld returned 1 exit status > --- errorlevel 1 Libraries may be built in two steps (currently I don't know better solution): dmd hello.d -fPIC -c gcc --shared hello.o -o ... if there is really need to make a library with main function. Additionally, when linking object files from manually compiled sources, core modules have to be linked with phobos2.a, librt.so, libpthread.so.
Comment #6 by ibuclaw — 2015-02-13T10:10:18Z
*** Issue 14175 has been marked as a duplicate of this issue. ***
Comment #7 by code — 2015-03-29T22:52:24Z
Try using this to build a shared library. dmd -shared -fPIC hello.d --defaultlib=libphobos2.so
Comment #8 by robert.schadek — 2024-12-13T18:01:01Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18460 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB