Bug 12268 – full static linking does not work, unresolved __tls_get_addr

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-02-26T12:19:58Z
Last change time
2024-12-13T18:17:30Z
Assigned to
No Owner
Creator
Dicebot
Moved to GitHub: dmd#18783 →

Comments

Comment #0 by public — 2014-02-26T12:19:58Z
http://forum.dlang.org/post/[email protected] : > $ 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'
Comment #1 by agordon — 2014-02-26T14:30:10Z
Comment #2 by public — 2014-02-26T14:34:18Z
Those 2 look like a different issue.
Comment #3 by agordon — 2014-02-26T15:15:58Z
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 ==================
Comment #4 by robert.schadek — 2024-12-13T18:17:30Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18783 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB