www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Linker error for d.o: relocation R_X86_64_32 against

reply rcorre <ryan rcorre.net> writes:
===
$ dmd /tmp/d.d
/usr/bin/ld: d.o: relocation R_X86_64_32 against 
`__dmd_personality_v0' can not be used when making a shared 
object; recompile with -fPIC
d.o: error adding symbols: Bad value
collect2: error: ld returned 1 exit status
--- errorlevel 1
===

I'm seeing the above trying to compile a simple d program.

/tmp/d.d:
===
void main() { }
===

Any idea what this might be? I'm on dmd 2.071.0 on Archlinux.
Apr 20 2016
next sibling parent reply rcorre <ryan rcorre.net> writes:
On Wednesday, 20 April 2016 at 12:04:45 UTC, rcorre wrote:
 ===
 $ dmd /tmp/d.d
 /usr/bin/ld: d.o: relocation R_X86_64_32 against 
 `__dmd_personality_v0' can not be used when making a shared 
 object; recompile with -fPIC
 d.o: error adding symbols: Bad value
 collect2: error: ld returned 1 exit status
 --- errorlevel 1
 ===

 I'm seeing the above trying to compile a simple d program.

 /tmp/d.d:
 ===
 void main() { }
 ===

 Any idea what this might be? I'm on dmd 2.071.0 on Archlinux.
My desktop is fine (Archlinux, same DMD version, both recently updated). I'm guessing this is some weird misconfiguration on my laptop that happened fairly recently.
Apr 20 2016
parent rcorre <ryan rcorre.net> writes:
On Wednesday, 20 April 2016 at 12:48:46 UTC, rcorre wrote:
 On Wednesday, 20 April 2016 at 12:04:45 UTC, rcorre wrote:
 ===
 $ dmd /tmp/d.d
 /usr/bin/ld: d.o: relocation R_X86_64_32 against 
 `__dmd_personality_v0' can not be used when making a shared 
 object; recompile with -fPIC
 d.o: error adding symbols: Bad value
 collect2: error: ld returned 1 exit status
 --- errorlevel 1
 ===

 I'm seeing the above trying to compile a simple d program.

 /tmp/d.d:
 ===
 void main() { }
 ===

 Any idea what this might be? I'm on dmd 2.071.0 on Archlinux.
My desktop is fine (Archlinux, same DMD version, both recently updated). I'm guessing this is some weird misconfiguration on my laptop that happened fairly recently.
Compiling with -fPIC doesn't help.
Apr 20 2016
prev sibling parent reply Chris <wendlec tcd.ie> writes:
On Wednesday, 20 April 2016 at 12:04:45 UTC, rcorre wrote:
 ===
 $ dmd /tmp/d.d
 /usr/bin/ld: d.o: relocation R_X86_64_32 against 
 `__dmd_personality_v0' can not be used when making a shared 
 object; recompile with -fPIC
 d.o: error adding symbols: Bad value
 collect2: error: ld returned 1 exit status
 --- errorlevel 1
 ===

 I'm seeing the above trying to compile a simple d program.

 /tmp/d.d:
 ===
 void main() { }
 ===

 Any idea what this might be? I'm on dmd 2.071.0 on Archlinux.
I had a similar error. Could you show us the code? Do you refer/link to a dynamic library?
Apr 20 2016
parent reply rcorre <ryan rcorre.net> writes:
On Wednesday, 20 April 2016 at 19:24:49 UTC, Chris wrote:
 On Wednesday, 20 April 2016 at 12:04:45 UTC, rcorre wrote:
 ===
 $ dmd /tmp/d.d
 /usr/bin/ld: d.o: relocation R_X86_64_32 against 
 `__dmd_personality_v0' can not be used when making a shared 
 object; recompile with -fPIC
 d.o: error adding symbols: Bad value
 collect2: error: ld returned 1 exit status
 --- errorlevel 1
 ===

 I'm seeing the above trying to compile a simple d program.

 /tmp/d.d:
 ===
 void main() { }
 ===

 Any idea what this might be? I'm on dmd 2.071.0 on Archlinux.
I had a similar error. Could you show us the code? Do you refer/link to a dynamic library?
The code is shown above. Literally `void main() { }`. I can't compile anything.
Apr 20 2016
parent reply rcorre <ryan rcorre.net> writes:
On Thursday, 21 April 2016 at 01:18:14 UTC, rcorre wrote:
 On Wednesday, 20 April 2016 at 19:24:49 UTC, Chris wrote:
 On Wednesday, 20 April 2016 at 12:04:45 UTC, rcorre wrote:
 ===
 $ dmd /tmp/d.d
 /usr/bin/ld: d.o: relocation R_X86_64_32 against 
 `__dmd_personality_v0' can not be used when making a shared 
 object; recompile with -fPIC
 d.o: error adding symbols: Bad value
 collect2: error: ld returned 1 exit status
 --- errorlevel 1
 ===

 I'm seeing the above trying to compile a simple d program.

 /tmp/d.d:
 ===
 void main() { }
 ===

 Any idea what this might be? I'm on dmd 2.071.0 on Archlinux.
I had a similar error. Could you show us the code? Do you refer/link to a dynamic library?
The code is shown above. Literally `void main() { }`. I can't compile anything.
s/compile/link I _can_ compile a D library, but as soon as I try to link anything compiled with DMD it falls over.
Apr 20 2016
next sibling parent Chris <wendlec tcd.ie> writes:
On Thursday, 21 April 2016 at 01:20:27 UTC, rcorre wrote:

 s/compile/link
 I _can_ compile a D library, but as soon as I try to link 
 anything compiled with DMD it falls over.
Sorry, I didn't see the code in your first post. I tried it myself (in only have 2.070.2) and it worked fine. Have you had a look at https://dlang.org/dll-linux.html
Apr 21 2016
prev sibling parent reply Rene Zwanenburg <renezwanenburg gmail.com> writes:
On Thursday, 21 April 2016 at 01:20:27 UTC, rcorre wrote:
 s/compile/link
 I _can_ compile a D library, but as soon as I try to link 
 anything compiled with DMD it falls over.
What is dmd's verbose output? (add -v switch) Some of the things it outputs are the location of the config file it uses, you can inspect that file to see if it has been borked somehow. Near the bottom you can find the used link command, that could also reveal the problem.
Apr 21 2016
parent reply rcorre <ryan rcorre.net> writes:
On Thursday, 21 April 2016 at 09:55:30 UTC, Rene Zwanenburg wrote:
 On Thursday, 21 April 2016 at 01:20:27 UTC, rcorre wrote:
 s/compile/link
 I _can_ compile a D library, but as soon as I try to link 
 anything compiled with DMD it falls over.
What is dmd's verbose output? (add -v switch) Some of the things it outputs are the location of the config file it uses, you can inspect that file to see if it has been borked somehow. Near the bottom you can find the used link command, that could also reveal the problem.
Thanks for the tip. Here's the linking code it shows: cc d.o -o d -m64 -L/usr/lib -L/usr/lib32 -Xlinker --export-dynamic -Xlinker -Bstatic -lphobos2 -Xlinker -Bdynamic -lpthread -lm -lrt -ldl /usr/bin/ld: d.o: relocation R_X86_64_32 against `__dmd_personality_v0' can not be used when making a shared object; recompile with -fPIC I tried `cc d.o -o d -m64 -fPIC and still get the error.
Apr 21 2016
parent reply Rene Zwanenburg <renezwanenburg gmail.com> writes:
On Thursday, 21 April 2016 at 11:54:27 UTC, rcorre wrote:
 Thanks for the tip. Here's the linking code it shows:


 cc d.o -o d -m64 -L/usr/lib -L/usr/lib32 -Xlinker 
 --export-dynamic -Xlinker -Bstatic -lphobos2 -Xlinker -Bdynamic 
 -lpthread -lm -lrt -ldl
 /usr/bin/ld: d.o: relocation R_X86_64_32 against 
 `__dmd_personality_v0' can not be used when making a shared 
 object; recompile with -fPIC

 I tried `cc d.o -o d -m64 -fPIC and still get the error.
Right, the -fPIC should be used while compiling the source code, but that's a gcc option. I think DMD is supposed to always generates position independent code. Here are a few things you can try to narrow the problem down. I'm not too familiar with this stuff though, so I'm just shooting in the dark here and not all of it may make sense ^^ - What happens when you mark main() as nothrow? That personality symbol has to do with exception handling. - Is it possible the linker is picking up 32 bit libraries? That -L/usr/lib32 switch is a bit suspicious. - What happens when you compile for 32 bit? - What happens when you compile a binary without phobos and druntime, and with a custom entry point? I've never done that myself and don't remember how to do that off the top of my head, but the info should be somewhere on dlang.org. - What happens when you compile some D code as a static lib, and link it with a main written in C? Oh, and I take it you've already tried to simply reinstall DMD? If you uninstall DMD, look if there are still sc.ini's and libphobos.a's floating around.
Apr 21 2016
parent reply rcorre <ryan rcorre.net> writes:
On Thursday, 21 April 2016 at 12:57:36 UTC, Rene Zwanenburg wrote:
 On Thursday, 21 April 2016 at 11:54:27 UTC, rcorre wrote:
 Thanks for the tip. Here's the linking code it shows:


 cc d.o -o d -m64 -L/usr/lib -L/usr/lib32 -Xlinker 
 --export-dynamic -Xlinker -Bstatic -lphobos2 -Xlinker 
 -Bdynamic -lpthread -lm -lrt -ldl
 /usr/bin/ld: d.o: relocation R_X86_64_32 against 
 `__dmd_personality_v0' can not be used when making a shared 
 object; recompile with -fPIC

 I tried `cc d.o -o d -m64 -fPIC and still get the error.
Right, the -fPIC should be used while compiling the source code, but that's a gcc option. I think DMD is supposed to always generates position independent code. Here are a few things you can try to narrow the problem down. I'm not too familiar with this stuff though, so I'm just shooting in the dark here and not all of it may make sense ^^ - What happens when you mark main() as nothrow? That personality symbol has to do with exception handling.
Nothing.
 - Is it possible the linker is picking up 32 bit libraries? 
 That -L/usr/lib32 switch is a bit suspicious.
Sure is. I tried manually linking without that but get the same error. As a matter of fact, I tried removing all the linker flags and still get that error (just `cc d.o -o d`).
 - What happens when you compile for 32 bit?
/usr/bin/ld: skipping incompatible /usr/lib/libphobos2.a when searching for -lphobos2 /usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-unknown-linux-gnu/5.3.0/../../../libphobos2.a when searching for -lphobos2 /usr/bin/ld: skipping incompatible /usr/lib/libphobos2.a when searching for -lphobos2 /usr/bin/ld: cannot find -lphobos2 /usr/bin/ld: skipping incompatible /usr/lib/libpthread.so when searching for -lpthread /usr/bin/ld: skipping incompatible /usr/lib/libpthread.a when searching for -lpthread collect2: error: ld returned 1 exit status
 - What happens when you compile a binary without phobos and 
 druntime, and with a custom entry point? I've never done that 
 myself and don't remember how to do that off the top of my 
 head, but the info should be somewhere on dlang.org.
I'll look into it.
 - What happens when you compile some D code as a static lib, 
 and link it with a main written in C?
Same error.
 Oh, and I take it you've already tried to simply reinstall DMD? 
 If you uninstall DMD, look if there are still sc.ini's and 
 libphobos.a's floating around.
I did. /etc/dmd.conf looks normal, aside from the inclusion of 32-bit libs: [Environment] DFLAGS=-I/usr/include/dlang/dmd -L-L/usr/lib -L-L/usr/lib32 -L--export-dynamic But that's how it gets set up after a fresh install.
Apr 21 2016
parent reply Rene Zwanenburg <renezwanenburg gmail.com> writes:
On Thursday, 21 April 2016 at 16:29:14 UTC, rcorre wrote:
 - What happens when you compile a binary without phobos and 
 druntime, and with a custom entry point? I've never done that 
 myself and don't remember how to do that off the top of my 
 head, but the info should be somewhere on dlang.org.
I'll look into it.
Declaring a C-like main and the -defaultlib switch do the trick: ---- cmain.d extern(C) void main() nothrow {} ---
 dmd cmain.d -defaultlib=""
If even that fails to link I honestly wouldn't know where to look next..
Apr 22 2016
parent reply Chris <wendlec tcd.ie> writes:
On Friday, 22 April 2016 at 09:49:02 UTC, Rene Zwanenburg wrote:
 On Thursday, 21 April 2016 at 16:29:14 UTC, rcorre wrote:
 - What happens when you compile a binary without phobos and 
 druntime, and with a custom entry point? I've never done that 
 myself and don't remember how to do that off the top of my 
 head, but the info should be somewhere on dlang.org.
I'll look into it.
Declaring a C-like main and the -defaultlib switch do the trick: ---- cmain.d extern(C) void main() nothrow {} ---
 dmd cmain.d -defaultlib=""
If even that fails to link I honestly wouldn't know where to look next..
This seems odd. Have you tried to reinstall dmd? You could use dvm [1] to install different versions of dmd and see what happens. It seems as if there's something wrong with your installation. I have Ubuntu at work and ArchLinux at home. It works fine, there shouldn't be any problem with compiling your program. [1] https://github.com/jacob-carlborg/dvm
Apr 22 2016
parent reply rcorre <ryan rcorre.net> writes:
On Friday, 22 April 2016 at 10:25:34 UTC, Chris wrote:
 On Friday, 22 April 2016 at 09:49:02 UTC, Rene Zwanenburg wrote:
 On Thursday, 21 April 2016 at 16:29:14 UTC, rcorre wrote:
 - What happens when you compile a binary without phobos and 
 druntime, and with a custom entry point? I've never done 
 that myself and don't remember how to do that off the top of 
 my head, but the info should be somewhere on dlang.org.
I'll look into it.
Declaring a C-like main and the -defaultlib switch do the trick: ---- cmain.d extern(C) void main() nothrow {} ---
 dmd cmain.d -defaultlib=""
If even that fails to link I honestly wouldn't know where to look next..
This seems odd. Have you tried to reinstall dmd? You could use dvm [1] to install different versions of dmd and see what happens. It seems as if there's something wrong with your installation. I have Ubuntu at work and ArchLinux at home. It works fine, there shouldn't be any problem with compiling your program. [1] https://github.com/jacob-carlborg/dvm
No luck with cmain.d. Its definitely an environmental problem -- I have an almost identical Archlinux desktop that is fine. I thought I'd try my dev DMD, but realized I can't even compile it now that DMD is written in D >.<
Apr 22 2016
parent reply rcorre <ryan rcorre.net> writes:
On Saturday, 23 April 2016 at 00:55:07 UTC, rcorre wrote:
 On Friday, 22 April 2016 at 10:25:34 UTC, Chris wrote:
 On Friday, 22 April 2016 at 09:49:02 UTC, Rene Zwanenburg 
 wrote:
 On Thursday, 21 April 2016 at 16:29:14 UTC, rcorre wrote:
 - What happens when you compile a binary without phobos and 
 druntime, and with a custom entry point? I've never done 
 that myself and don't remember how to do that off the top 
 of my head, but the info should be somewhere on dlang.org.
I'll look into it.
Declaring a C-like main and the -defaultlib switch do the trick: ---- cmain.d extern(C) void main() nothrow {} ---
 dmd cmain.d -defaultlib=""
If even that fails to link I honestly wouldn't know where to look next..
This seems odd. Have you tried to reinstall dmd? You could use dvm [1] to install different versions of dmd and see what happens. It seems as if there's something wrong with your installation. I have Ubuntu at work and ArchLinux at home. It works fine, there shouldn't be any problem with compiling your program. [1] https://github.com/jacob-carlborg/dvm
No luck with cmain.d. Its definitely an environmental problem -- I have an almost identical Archlinux desktop that is fine. I thought I'd try my dev DMD, but realized I can't even compile it now that DMD is written in D >.<
Got it! I installed hardening-wrapper to build python34. gcc was pointing to /usr/bin/hardening-wrapper/gcc. I had to look up what hardening-wrapper even is -- and I found my way straight to the archwiki article describing exactly my problem: https://wiki.archlinux.org/index.php/D_(programming_language)#hardening-wrapper Thank you to everyone who tried to help!
Apr 23 2016
parent Basile B. <b2.temp gmx.com> writes:
On Saturday, 23 April 2016 at 17:06:07 UTC, rcorre wrote:
 On Saturday, 23 April 2016 at 00:55:07 UTC, rcorre wrote:
 On Friday, 22 April 2016 at 10:25:34 UTC, Chris wrote:
 [...]
No luck with cmain.d. Its definitely an environmental problem -- I have an almost identical Archlinux desktop that is fine. I thought I'd try my dev DMD, but realized I can't even compile it now that DMD is written in D >.<
Got it! I installed hardening-wrapper to build python34. gcc was pointing to /usr/bin/hardening-wrapper/gcc. I had to look up what hardening-wrapper even is -- and I found my way straight to the archwiki article describing exactly my problem: https://wiki.archlinux.org/index.php/D_(programming_language)#hardening-wrapper Thank you to everyone who tried to help!
I wish this could have been a more general issue with a more general fix. Actually I follow this topic since 3 days because of this horror: http://imgur.com/6YHJF0P Note the similar dmd_personnality thing.
Apr 23 2016