Thread overview
a mysterious linking error introduced by import a library
Oct 14
Johann
Oct 14
Johann
Oct 14
Johann
Oct 14
Johann
October 14

The following is a project created by dub init.

dub.json

{
	"authors": [
		"john"
	],
	"dependencies": {
		"squiz-box": {
			"repository": "git+https://github.com/rtbo/squiz-box.git",
			"version": "6a10caaa01f7cefbe83c65b5a939bee2e0296250"
		}
	},
	"description": "Demo program",
	"license": "BSD 2 clause",
	"name": "gdc_curl"
}

app.d

import std.net.curl : get, download;

import squiz_box;

void main()
{
    immutable jsonURL = "https://ziglang.org/download/index.json";
    auto jsonStr = get(jsonURL);
}

squiz_box is a dlang library for compression and decompression.

I am able to compile this ldc2 and dmd, but not gdc. The error appears to be related to the line import squiz_box, removing of which causes the program to compile successfully, as the main function doesn't call the squiz_box library at all.

dub build --compiler=gdc --verbose

Using dub registry url 'https://code.dlang.org/'
Note: Failed to determine version of package gdc_curl at .. Assuming ~master.
  Version selection for dependency squiz-box (squiz-box) of gdc_curl is missing.
Scanning local packages...
Determined package version using GIT: squiz-box 0.2.1+commit.51.ga962211
Determined package version using GIT: squiz-box 0.2.1+commit.87.gf0ba9db
Determined package version using GIT: squiz-box 0.3.0+commit.15.g6a10caa
  Found dependency squiz-box git+https://github.com/rtbo/squiz-box.git
Generating using build
Configuring dependent gdc_curl, deps:"squiz-box"
  Configuring dependent squiz-box, deps:
    Starting Performing "debug" build using gdc for x86_64.
  Up-to-date squiz-box 0.3.0+commit.15.g6a10caa: target for configuration [library] is up to date.
Using existing build in /home/john/.dub/cache/squiz-box/0.3.0+commit.15.g6a10caa/build/library-debug-8Bi8iTVskbYwwEp3wicUsw.
Copying target from /home/john/.dub/cache/squiz-box/0.3.0+commit.15.g6a10caa/build/library-debug-8Bi8iTVskbYwwEp3wicUsw/libsquiz-box.a to /home/john/.dub/packages/squiz-box/6a10caaa01f7cefbe83c65b5a939bee2e0296250/squiz-box
Target '/home/john/.dub/cache/gdc_curl/~master/build/application-debug-G0CAYx5HyZ1UeOgA779Diw/gdc_curl' doesn't exist, need rebuild.
    Building gdc_curl ~master: building configuration [application]
Using pkg-config to resolve library flags for liblzma, libzstd.
Using direct -l... flags for bz2.
gdc -o /home/john/.dub/cache/gdc_curl/~master/build/application-debug-G0CAYx5HyZ1UeOgA779Diw/gdc_curl -fdebug -g -Werror -Wall -fversion=Have_gdc_curl -fversion=Have_squiz_box -fversion=HaveSquizBzip2 -fversion=HaveSquizLzma -fversion=HaveSquizZstandard -Isource/ -I/home/john/.dub/packages/squiz-box/6a10caaa01f7cefbe83c65b5a939bee2e0296250/squiz-box/src/ source/app.d /home/john/.dub/cache/squiz-box/0.3.0+commit.15.g6a10caa/build/library-debug-8Bi8iTVskbYwwEp3wicUsw/libsquiz-box.a -lbz2 -Xlinker -llzma -Xlinker -lzstd
/usr/bin/ld: /tmp/ccPUp96p.o: in function `_D3std6format8internal5write__T8getWidthTAyaZQoFNaNfQlZl':
/usr/lib/gcc/x86_64-redhat-linux/13/include/d/std/format/internal/write.d:3639: undefined reference to `_D3std9algorithm9searching__T3allSQBg6format8internal5write__T8getWidthTAyaZQoFQhZ9__lambda2Z__TQCpTQBcZQCxMFNaNfQBpZb'
/usr/bin/ld: /tmp/ccPUp96p.o: in function `_D3std6format8internal5write__T20formatValueImplUlongTSQCb5array__T8AppenderTAyaZQoTaZQCdFNaNfKQBpmIbMKxSQDzQDy4spec__T10FormatSpecTaZQpZv':
/usr/lib/gcc/x86_64-redhat-linux/13/include/d/std/format/internal/write.d:262: undefined reference to `_D3std9algorithm9searching__T3allSQBg6format8internal5write__T20formatValueImplUlongTSQDg5array__T8AppenderTAyaZQoTaZQCdFKQBlmIbMKxSQFaQDu4spec__T10FormatSpecTaZQpZ10__lambda16Z__TQFvTAaZQGcMFNaNfQmZb'
/usr/bin/ld: /usr/lib/gcc/x86_64-redhat-linux/13/include/d/std/format/internal/write.d:268: undefined reference to `_D3std9algorithm9searching__T3allSQBg6format8internal5write__T20formatValueImplUlongTSQDg5array__T8AppenderTAyaZQoTaZQCdFKQBlmIbMKxSQFaQDu4spec__T10FormatSpecTaZQpZ10__lambda17Z__TQFvTAaZQGcMFNaNfQmZb'
collect2: error: ld returned 1 exit status
FAIL /home/john/.dub/cache/gdc_curl/~master/build/application-debug-G0CAYx5HyZ1UeOgA779Diw gdc_curl executable
Error gdc failed with exit code 1.

I cannot figure out this error is caused by squiz_box libray, gdc or dub. My apologies to you if I should have filed this bug in other places. Thanks for your attention.

October 15
This may be a simple case of template emission eliding.

Did you try ``-fall-instantiations`` inside of a dflags directive?
October 14
On Saturday, 14 October 2023 at 17:58:27 UTC, Richard (Rikki) Andrew Cattermole wrote:
> This may be a simple case of template emission eliding.
>
> Did you try ``-fall-instantiations`` inside of a dflags directive?

Yeah, that works perfectly, thank you a lot.

> This may be a simple case of template emission eliding.

So is this a bug in gdc? And what is a template emission eliding? I have never heard of it before.
October 15
The frontend will attempt to not emit all template instantiations if it thinks that the instantiation isn't used. However it sometimes get this wrong, so you have to override it and tell it to emit them all anyway and let the linker do the eliding instead.

This is a known problem of all the compilers since its done by the shared frontend, rather than the glue layer.

It is a bug, but given how complex and time consuming it can be to minimize it to a small reproducible example, its not always worth the time to try and report it.
October 14
On Saturday, 14 October 2023 at 18:15:11 UTC, Richard (Rikki) Andrew Cattermole wrote:
> The frontend will attempt to not emit all template instantiations if it thinks that the instantiation isn't used. However it sometimes get this wrong, so you have to override it and tell it to emit them all anyway and let the linker do the eliding instead.
>
> This is a known problem of all the compilers since its done by the shared frontend, rather than the glue layer.
>
> It is a bug, but given how complex and time consuming it can be to minimize it to a small reproducible example, its not always worth the time to try and report it.

Thanks again for your lucid explanation. I will save `-fall-instantiations` flag in my main memory.
October 14

On Saturday, 14 October 2023 at 17:53:01 UTC, Johann wrote:

>

I cannot figure out this error is caused by squiz_box libray, gdc or dub. My apologies to you if I should have filed this bug in other places. Thanks for your attention.

Based on the symbol names, it could be this PR, which was fixed as of gdc versions 13.2 and 12.3

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

October 14

On Saturday, 14 October 2023 at 19:01:53 UTC, Iain Buclaw wrote:

>

On Saturday, 14 October 2023 at 17:53:01 UTC, Johann wrote:

>

I cannot figure out this error is caused by squiz_box libray, gdc or dub. My apologies to you if I should have filed this bug in other places. Thanks for your attention.

Based on the symbol names, it could be this PR, which was fixed as of gdc versions 13.2 and 12.3

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

Sorry somehow I forget to attach the version of gdc in the post,

gdc --version
gdc (GCC) 13.2.1 20230918 (Red Hat 13.2.1-3)

cat /etc/redhat-release
Fedora release 39 (Thirty Nine)
October 17

On Saturday, 14 October 2023 at 19:28:59 UTC, Johann wrote:

>

On Saturday, 14 October 2023 at 19:01:53 UTC, Iain Buclaw wrote:

>

On Saturday, 14 October 2023 at 17:53:01 UTC, Johann wrote:

>

I cannot figure out this error is caused by squiz_box libray, gdc or dub. My apologies to you if I should have filed this bug in other places. Thanks for your attention.

Based on the symbol names, it could be this PR, which was fixed as of gdc versions 13.2 and 12.3

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

Sorry somehow I forget to attach the version of gdc in the post,

gdc --version
gdc (GCC) 13.2.1 20230918 (Red Hat 13.2.1-3)

cat /etc/redhat-release
Fedora release 39 (Thirty Nine)

Thanks.

One potential reduction seems to suggest gdc is emitting too much, rather than too little.

dmd 2.103.1

--- dmd -v
function  D main
function  app._d_cmain!().main
function  curl.get!().get
function  std.format.format!().format
function  std.format.formattedWrite!string.formattedWrite
function  std.format.internal.write.formatValueImpl!int.formatValueImpl
--- nm app.o
W _Dmain
W main
W _D4curl__T3getZQfFNaNbAxaZv
W _D3std6format__TQkZQnFNaNbAyaQdZQg
W _D3std6format__T14formattedWriteTAyaZQvFNaNbQlZk
W _D3std6format8internal5write__T15formatValueImplTiZQuFNaNfxiZv
U _D3std6format8internal5write__T8getWidthTAyaZQoFNaNfQlZl

gdc 13.2

--- gdc -v
function  D main
function  app._d_cmain!().main
function  curl.get!().get
function  std.format.format!().format
function  std.format.formattedWrite!string.formattedWrite
function  std.format.internal.write.formatValueImpl!int.formatValueImpl
function  std.format.internal.write.getWidth!string.getWidth
--- nm app.o
T _Dmain
T main
W _D4curl__T3getZQfFNaNbAxaZv
W _D3std6format__TQkZQnFNaNbAyaQdZQg
W _D3std6format__T14formattedWriteTAyaZQvFNaNbQlZk
W _D3std6format8internal5write__T15formatValueImplTiZQuFNaNfxiZv
W _D3std6format8internal5write__T8getWidthTAyaZQoFNaNfQlZl
U _D3std9algorithm9searching__T3allSQBg6format8internal5write__T8getWidthTAyaZQoFQhZ9__lambda2Z__TQCpTQBcZQCxMFNaNfQBpZb