gdc: Fails to link any code using std.net.curl

Bug #1563861 reported by Matthias Klumpp
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
dub (Debian)
Fix Released
Unknown
dub (Ubuntu)
Fix Released
High
Unassigned
gcc-5 (Ubuntu)
Won't Fix
High
Unassigned

Bug Description

Hi!

The GDC D compiler in Ubuntu is currently unable to link anything using std.net.curl, likely due to an ordering issue in the linker command-line, since Ubuntus libcurl is compiled with --as-needed

To reproduce, take the following simple program:

test.d
```
import std.stdio;
import std.net.curl;

void main(string[] args)
{
    auto data = get ("ubuntu.com");
    writeln (data);
}
```

And compile with `gdc -lcurl -otest test.d`

Linking will file with lots of messages like
```
/usr/lib/gcc/x86_64-linux-gnu/5/libgphobos2.a(curl.o): In function `_D3std3net4curl4Curl18_sharedStaticCtor2FZv':
/build/gcc-5-hPAq_C/gcc-5-5.3.1/build/x86_64-linux-gnu/libphobos/src/../../../../src/libphobos/src/std/net/curl.d:3498: undefined reference to `curl_global_init'
```

A possible solution to this problem would be to link all D programs against libcurl, as has apparently been done in LDC: https://github.com/ldc-developers/ldc/pull/977
Maybe having GDC fix up the linker command line would also work.

Backporting the (massive) patch for Phobos for dynamically loading libcurl would also be an option, but I guess it wouldn't be an easy solution.

This being broken in Ubuntu means that Ubuntu can't compile several important tools, like the dub D package manager, which compiles fine in Debian ( https://packages.debian.org/source/stretch/dub ).

Since std.net is a part of the standard library, and it's kind of expected from a standard library to function, I've set the priority of this bug to "High".

Thanks in advance for the help! I am also thinking about reporting this bug upstream, but since compiling in other distros (e.g. Debian) works, I don't know how quickly one could expect people there to take care of this issue.

Matthias Klumpp (ximion)
affects: gcc-defaults (Ubuntu) → gcc-5 (Ubuntu)
summary: - Fails to link any code using std.net.curl
+ gdc: Fails to link any code using std.net.curl
Revision history for this message
Matthias Klose (doko) wrote :

you should link using:

  gdc -otest test.d -Wl,---pus-state,-no-as-needed -lcurl -Wl,--pop-state

Revision history for this message
Matthias Klumpp (ximion) wrote :

Oh, cool - I didn't know about --push-state, that's really cool and looks like a good workaround. Would be nice to make this more discoverable or - even better - work by default, but I guess that a workaround exists might reduce the urgency of this.

Matthias Klose (doko)
Changed in gcc-5 (Ubuntu):
status: New → Won't Fix
Revision history for this message
Matthias Klumpp (ximion) wrote :

Hmm, quick question: Does "Won't fix" mean this should be fixed in dub to pass this option to GDC? If so, I would formward this report to upstream dub, so they can apply it to every dub-using project (which means less project-specific fixes).
This would also mean that people not using dub should use that combination of flags if they want to link against Curl (I would fix that in the Debian package of dub then).

Or does won't fix mean that this thing should be fixed in upstream GDC, but you won't explicitly fix it in the Ubuntu package?

Revision history for this message
Matthias Klose (doko) wrote :

gdc probably should add some config binary to add these libs. And if it's built as a shared lib, then the library should be linked against it. But for now, from my point of view, users of these extra stuff should link with the required libs itself.

Revision history for this message
Matthias Klumpp (ximion) wrote :

Okay, thanks for the clarification!
Binutils should be new enough almost everywhere to support the --push-state flag, so using it is fine.

/me will take your patch against dub for Debian too, then :-)

Revision history for this message
Matthias Klumpp (ximion) wrote :

Fixed with 0.9.24-1ubuntu1

Changed in dub (Ubuntu):
importance: Undecided → High
status: New → Fix Released
Changed in dub (Debian):
status: Unknown → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.