public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug d/113081] New: static linking does not work
@ 2023-12-19  7:49 rguenth at gcc dot gnu.org
  2023-12-19 17:59 ` [Bug d/113081] " pinskia at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-12-19  7:49 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113081

            Bug ID: 113081
           Summary: static linking does not work
           Product: gcc
           Version: 13.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: d
          Assignee: ibuclaw at gdcproject dot org
          Reporter: rguenth at gcc dot gnu.org
  Target Milestone: ---

Trying to statically link a Hello World doesn't work:

import std.stdio;

void main()
{
    writeln("Hello, World!");
}

> gdc-13 t.d -static
...
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld:
/usr/lib64/gcc/x86_64-suse-linux/13/libgphobos.a(elf.o): in function
`_D3gcc8sections3elf11getTLSRangeFNbNimmZAv':
/home/abuild/rpmbuild/BUILD/gcc-13.2.1+git7813/obj-x86_64-suse-linux/x86_64-suse-linux/libphobos/libdruntime/../../../../libphobos/libdruntime/gcc/sections/elf.d:1095:(.text._D3gcc8sections3elf11getTLSRangeFNbNimmZAv+0x29):
undefined reference to `__tls_get_addr'
collect2: error: ld returned 1 exit status

that's libphobos/libdruntime/gcc/sections/elf.d:1095

void[] getTLSRange(size_t mod, size_t sz) nothrow @nogc
{
...
        else
            return (__tls_get_addr(&ti)-TLS_DTV_OFFSET)[0 .. sz];
    }
}

not using a TLS relocation but an explicit call.  A TLS relocation would
have been resolved/relaxed at static link time but an explicit call of
course prevails.

Linking the Hello World with -static-libphobos works (there is no
-static-libdruntime but libgdruntime.so.4 doesn't seem to be DT_NEEDED
on the executable?).

Maybe putting the TLS module helpers into a separate object (so not
statically linked when not needed) might help, implementing the helpers
in a way that allow static linking might be possible as well (by
using actual __tls declarations?).

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-03-10 20:29 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-19  7:49 [Bug d/113081] New: static linking does not work rguenth at gcc dot gnu.org
2023-12-19 17:59 ` [Bug d/113081] " pinskia at gcc dot gnu.org
2024-03-10 20:20 ` ibuclaw at gdcproject dot org
2024-03-10 20:29 ` ibuclaw at gdcproject dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).