www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 12268] New: full static linking does not work, unresolved __tls_get_addr

reply d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12268

           Summary: full static linking does not work, unresolved
                    __tls_get_addr
           Product: D
           Version: unspecified
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: public dicebot.lv


--- Comment #0 from Dicebot <public dicebot.lv> 2014-02-26 12:19:58 PST ---
http://forum.dlang.org/post/slsscokbcjfyxbfaulom forum.dlang.org :

 $ dmd hellod.d -c
 $ gcc hellod.o -o hellod -m32 
 -L/home/me/d/dmd2/linux/bin32/../lib32 -Xlinker 
 --export-dynamic -l:libphobos2.a -lpthread -lm -lrt -static

 undefined reference to `__tls_get_addr'

-- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 26 2014
next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12268


AG <agordon wi.mit.edu> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |agordon wi.mit.edu


--- Comment #1 from AG <agordon wi.mit.edu> 2014-02-26 14:30:10 PST ---
I'll just mention too previous related bug reports:

http://d.puremagic.com/issues/show_bug.cgi?id=6952
http://d.puremagic.com/issues/show_bug.cgi?id=4376

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 26 2014
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12268



--- Comment #2 from Dicebot <public dicebot.lv> 2014-02-26 14:34:18 PST ---
Those 2 look like a different issue.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 26 2014
prev sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12268



--- Comment #3 from AG <agordon 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: -------
Feb 26 2014