ldc-developers / ldc

The LLVM-based D Compiler.
http://wiki.dlang.org/LDC
Other
1.22k stars 262 forks source link

`-defaultlib=phobos2-ldc-lto,druntime-ldc-lto` fails on ubuntu with `ldc-1.29.0` #4289

Open MrSmith33 opened 1 year ago

MrSmith33 commented 1 year ago

To reproduce:

> ldc2 -O -flto=full -defaultlib=phobos2-ldc-lto,druntime-ldc-lto ./test.d

The error is

/usr/bin/ld: /tmp/lto-llvm-42ff39.o:(.data._D3etc1c4curl12__ModuleInfoZ+0x10): undefined reference to `_D3std6socket12__ModuleInfoZ'
collect2: error: ld returned 1 exit status
Error: /usr/bin/cc failed with status: 1

The code is

// test.d
int main(string[] args) { return 0; }

Removing -defaultlib=phobos2-ldc-lto,druntime-ldc-lto fixes the compilation on Ubuntu ldc-1.29.0

kinke commented 1 year ago

This is most likely your default linker's fault, since LDC doesn't default to ld.gold since v1.29 anymore. So depends on what your ld is, otherwise play with -linker to select a working one (lld or gold). CI tests that such trivial stuff works.

MrSmith33 commented 1 year ago

TL;DR gold worked

> -link-internally
lld: error: unable to find library -lrt
lld: error: unable to find library -ldl
lld: error: unable to find library -lpthread
lld: error: unable to find library -lm
> -linker=lld-link
cc: error: unrecognized command line option ‘-fuse-ld=lld-link’; did you mean ‘-fuse-ld=lld’?
> -linker=lld
collect2: fatal error: cannot find ‘ld’
> -linker=gold
success

I had cc --version -> cc (Ubuntu 9.3.0-10ubuntu2) 9.3.0

But what I really want is to run ldc on github CI runners

kinke commented 1 year ago

Looks like you've been using default bfd then. - lld probably needs to be installed first.