[Issue 12268] full static linking does not work, unresolved __tls_get_addr
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Feb 26 15:16:04 PST 2014
https://d.puremagic.com/issues/show_bug.cgi?id=12268
--- Comment #3 from AG <agordon at wi.mit.edu> 2014-02-26 15:15:58 PST ---
Perhaps those are different issue, but I'll explain why I think they are
related:
1. by default, "dmd" creates dynamic executables.
2. if we run "dmd -v", we see the "gcc" command line that DMD uses.
In this bug, and with the mention thread, the person took the output from dmd,
and added (manually) "-static" - directly to the gcc command line.
3. In the other two mention threads, the person used "-L-static" to tell DMD to
pass "-static" to the linker. But the way DMD passes the parameter to the
linker is by adding "-Xlinker -static" - which has slightly different effect
(and different error message).
So,
while it could be that the error messages are different (and perhaps the root
cause is different),
These are related bugs (IMHO) - they both try to compile static binaries on
linux.
At least it's worth knowing about those two.
Example:
$ cat hello.d
import std.stdio;
void main()
{
writeln("hello world");
}
# Compile
$ dmd -ofhello.o -c hello.d
# Link, dynamically, and see the default "gcc" command line
$ dmd -v -ofhello hello.o
binary dmd
version v2.064
gcc hello.o -o hello -m64 -L/usr/lib64/ -l:libphobos2.a -lpthread -lm -lrt
##
## This bug: try to compile it statically, directly with gcc.
##
## This bug: directly add "-static" to gcc:
$ gcc hello.o -o hello -m64 -L//usr/lib64/ -l:libphobos2.a -lpthread -lm -lrt
-static
/usr/lib64/libphobos2.a(sections_linux_4ce_420.o): In function
`_D2rt14sections_linux11getTLSRangeFmmZAv':
src/rt/sections_linux.d:(.text._D2rt14sections_linux11getTLSRangeFmmZAv+0x38):
undefined reference to `__tls_get_addr'
collect2: error: ld returned 1 exit status
##
## The other two bugs: add "-static" through "dmd"
##
$ dmd -L-static -v -ofhello hello.o
binary dmd
version v2.064
gcc hello.o -o hello -m64 -Xlinker -static -L/usr/lib64 -l:libphobos2.a
-lpthread -lm -lrt
.../x86_64-unknown-linux-gnu/bin/ld: cannot find -lgcc_s
.../x86_64-unknown-linux-gnu/bin/ld: cannot find -lgcc_s
collect2: error: ld returned 1 exit status
--- errorlevel 1
==================
--
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list