Thread overview
[Issue 8548] New: relocation R_X86_64_32 against can not be used when making a shared object
Aug 15, 2012
wbrana@gmail.com
Aug 15, 2012
Maxim Fomin
Aug 15, 2012
wbrana@gmail.com
Aug 15, 2012
wbrana@gmail.com
Aug 15, 2012
wbrana@gmail.com
Aug 15, 2012
Maxim Fomin
August 15, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8548

           Summary: relocation R_X86_64_32 against can not be used when
                    making a shared object
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: wbrana@gmail.com


--- Comment #0 from wbrana@gmail.com 2012-08-15 05:13:29 PDT ---
$ ./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

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
August 15, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8548


Maxim Fomin <maxim@maxim-fomin.ru> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |maxim@maxim-fomin.ru


--- Comment #1 from Maxim Fomin <maxim@maxim-fomin.ru> 2012-08-15 07:57:01 PDT ---
Which version of dmd are you using and what is in hello.d?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
August 15, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8548



--- Comment #2 from wbrana@gmail.com 2012-08-15 08:09:12 PDT ---
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);
    }
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
August 15, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8548



--- Comment #3 from wbrana@gmail.com 2012-08-15 08:19:34 PDT ---
It seems dmd is incompatible with Gentoo Hardened gcc.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
August 15, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8548



--- Comment #4 from wbrana@gmail.com 2012-08-15 08:45:11 PDT ---
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

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
August 15, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8548



--- Comment #5 from Maxim Fomin <maxim@maxim-fomin.ru> 2012-08-15 10:28:14 PDT ---
(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.

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