Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhancement: please ignore the empty -J [was] grpc-dlang build failure with ldc2 #3723

Closed
mw66 opened this issue May 16, 2021 · 16 comments
Closed

Comments

@mw66
Copy link

mw66 commented May 16, 2021

dub build --compiler=ldc2 fails with many undefined reference errors.

See build log here: huntlabs/hunt#89

...
Performing "debug" build using ldc2 for x86_64.
grpc 0.4.0-beta.1: building configuration "library"...
/usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/Scrt1.o:function _start: error: undefined reference to 'main'
/home/user/grpc-dlang/source/grpc/GrpcStream.d:85: error: undefined reference to '_D4hunt2io11BufferUtilsQn8toStringFCQBiQBg10ByteBufferQmZAya'
/home/user/grpc-dlang/../.dub/packages/hunt-1.7.7/hunt/source/hunt/logging/Logger.d-mixin-584:584: error: undefined reference to '_D4hunt7logging6Logger8g_loggerCQBeQBcQxQz'
...

Following instructions on

https://github.com/huntlabs/grpc-dlang

readme, dub build i.e. DMD works fine. The build file is very simple, nothing suspicious:

https://github.com/huntlabs/grpc-dlang/blob/master/dub.json

Could this be ldc problem?

@JohanEngelen
Copy link
Member

Please distill down to the essence of this problem within the grpc-dlang project first. It could just as well be a dub bug. (the dlang forums may also be able to help)

@kinke
Copy link
Member

kinke commented May 22, 2021

It might be worth trying dub build --compiler=ldmd2 - if ldmd2 works, it's a dub thing. Running dub with -v shows the compiler command-lines, which can be compared across dmd and ldc2. That 'no main()' error sounds a bit like https://forum.dlang.org/post/s895he$1mbm$1@digitalmars.com, so make sure to use the same dub version when testing with dmd.

@mw66
Copy link
Author

mw66 commented May 22, 2021

Tried, same error:

$ dub build --compiler=ldmd2
Performing "debug" build using ldmd2 for x86_64.
grpc 0.4.0-beta.1: building configuration "library"...
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o:function _start: error: undefined reference to 'main'
...

Also tried ldc2's dub

$ ~/project/ldc2/bin/dub build --compiler=ldmd2
Performing "debug" build using ldmd2 for x86_64.
grpc 0.4.0-beta.1: building configuration "library"...
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o:function _start: error: undefined reference to 'main'
...

@mw66
Copy link
Author

mw66 commented May 22, 2021

and I also compared the exact cmd with -v:

~/project/ldc2/bin/dub build -v --compiler=ldmd2  // same build error above
~/project/ldc2/bin/dub build -v --compiler=dmd   //  successful build

except the output file name i.e -of..., there is no difference:

ldmd2 -J -lib -of.dub/build/library-debug-linux.posix-x86_64-ldc_v1.26.0-C3E1A3C9CD32A6FC331A53471EAF68DB/libgrpc.a -debug -g -w -version=Have_grpc -version=Have_hunt_http -version=Have_protobuf -version=Have_hunt_net -version=Have_hunt_extra -version=Have_hunt -version=HAVE_EPOLL -Isource/ -I../../../.dub/packages/hunt-http-0.7.3/hunt-http/source/ -I../../../.dub/packages/hunt-net-0.6.6/hunt-net/source/ -I../../../.dub/packages/hunt-extra-1.1.3/hunt-extra/source/ -I../../../.dub/packages/hunt-1.7.7/hunt/source/ -I../../../.dub/packages/protobuf-0.6.2/protobuf/src/ -J../../../.dub/packages/hunt-extra-1.1.3/hunt-extra/resources source/grpc/EvBuffer.d source/grpc/GrpcClient.d source/grpc/GrpcCode.d source/grpc/GrpcException.d source/grpc/GrpcServer.d source/grpc/GrpcService.d source/grpc/GrpcStream.d source/grpc/Status.d source/grpc/StatusCode.d source/grpc/package.d source/grpc/stream/ClientReader.d source/grpc/stream/ClientReaderWriter.d source/grpc/stream/ClientWriter.d source/grpc/stream/ServerReader.d source/grpc/stream/ServerReaderWriter.d source/grpc/stream/ServerWriter.d -vcolumns

dmd -J -lib -of.dub/build/library-debug-linux.posix-x86_64-dmd_v2.095.1-70FB875C140F8BEFB2515B2EEE9739D1/libgrpc.a -debug -g -w -version=Have_grpc -version=Have_hunt_http -version=Have_protobuf -version=Have_hunt_net -version=Have_hunt_extra -version=Have_hunt -version=HAVE_EPOLL -Isource/ -I../../../.dub/packages/hunt-http-0.7.3/hunt-http/source/ -I../../../.dub/packages/hunt-net-0.6.6/hunt-net/source/ -I../../../.dub/packages/hunt-extra-1.1.3/hunt-extra/source/ -I../../../.dub/packages/hunt-1.7.7/hunt/source/ -I../../../.dub/packages/protobuf-0.6.2/protobuf/src/ -J../../../.dub/packages/hunt-extra-1.1.3/hunt-extra/resources source/grpc/EvBuffer.d source/grpc/GrpcClient.d source/grpc/GrpcCode.d source/grpc/GrpcException.d source/grpc/GrpcServer.d source/grpc/GrpcService.d source/grpc/GrpcStream.d source/grpc/Status.d source/grpc/StatusCode.d source/grpc/package.d source/grpc/stream/ClientReader.d source/grpc/stream/ClientReaderWriter.d source/grpc/stream/ClientWriter.d source/grpc/stream/ServerReader.d source/grpc/stream/ServerReaderWriter.d source/grpc/stream/ServerWriter.d -vcolumns

So, could this be a LDC bug? @kinke

@kinke
Copy link
Member

kinke commented May 22, 2021

This is the wrong command - this creates a static library with -lib, no linking happening yet.

@mw66
Copy link
Author

mw66 commented May 22, 2021

What do you mean by "wrong command"?

It is building a library: (I specifically added: "targetType": "library" to the dub.json)

~/project/contrib/grpc-dlang 16:22:36$ cat dub.json 
{
    "name": "grpc",
    "targetType": "library",
    "license": "Apache-2.0",
    "copyright": "Copyright (C) 2018-2021 HuntLabs",
    "homepage": "https://www.huntlabs.net",
    "description": "gRPC implementation for D programming language",
    "dependencies": {
        "hunt-http": "~>0.7.0",
        "protobuf": "~>0.6.2"
    }
}

with this same dub.json file,

~/project/ldc2/bin/dub build -v --compiler=ldmd2  // same build error above
~/project/ldc2/bin/dub build -v --compiler=dmd   //  successful build

This is what the build errors I showed above.

Can you try it yourself?

@kinke
Copy link
Member

kinke commented May 22, 2021

Can you try it yourself?

Sorry but no, looks too time-consuming and hardly LDC's fault.

What do you mean by "wrong command"?

The error is emitted by the linker. The linker isn't invoked by LDC with -lib. So either dub isn't printing the actual failing command-line, or you've just missed it.

@mw66
Copy link
Author

mw66 commented May 22, 2021

I don't think I missed it, and I copied the 1 line before the command (it says: building configuration "library"), and 1 line after the command (it's the error: undefined reference to 'main')

I didn't see any linker command:

grpc 0.4.0-beta.1: building configuration "library"...
ldmd2 -J -lib -of.dub/build/library-debug-linux.posix-x86_64-ldc_v1.26.0-C3E1A3C9CD32A6FC331A53471EAF68DB/libgrpc.a -debug -g -w -version=Have_grpc -version=Have_hunt_http -version=Have_protobuf -version=Have_hunt_net -version=Have_hunt_extra -version=Have_hunt -version=HAVE_EPOLL -Isource/ -I../../../.dub/packages/hunt-http-0.7.3/hunt-http/source/ -I../../../.dub/packages/hunt-net-0.6.6/hunt-net/source/ -I../../../.dub/packages/hunt-extra-1.1.3/hunt-extra/source/ -I../../../.dub/packages/hunt-1.7.7/hunt/source/ -I../../../.dub/packages/protobuf-0.6.2/protobuf/src/ -J../../../.dub/packages/hunt-extra-1.1.3/hunt-extra/resources source/grpc/EvBuffer.d source/grpc/GrpcClient.d source/grpc/GrpcCode.d source/grpc/GrpcException.d source/grpc/GrpcServer.d source/grpc/GrpcService.d source/grpc/GrpcStream.d source/grpc/Status.d source/grpc/StatusCode.d source/grpc/package.d source/grpc/stream/ClientReader.d source/grpc/stream/ClientReaderWriter.d source/grpc/stream/ClientWriter.d source/grpc/stream/ServerReader.d source/grpc/stream/ServerReaderWriter.d source/grpc/stream/ServerWriter.d -vcolumns
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o:function _start: error: undefined reference to 'main'

@mw66
Copy link
Author

mw66 commented May 22, 2021

@kinke Hi, I realized that I have that exact command line, so I just run that ldmd2 command directly (without using dub):

"""
$ ldmd2 -J -lib -of.dub/build/library-debug-linux.posix-x86_64-ldc_v1.26.0-C3E1A3C9CD32A6FC331A53471EAF68DB/libgrpc.a -debug -g -w -version=Have_grpc -version=Have_hunt_http -version=Have_protobuf -version=Have_hunt_net -version=Have_hunt_extra -version=Have_hunt -version=HAVE_EPOLL -Isource/ -I../../../.dub/packages/hunt-http-0.7.3/hunt-http/source/ -I../../../.dub/packages/hunt-net-0.6.6/hunt-net/source/ -I../../../.dub/packages/hunt-extra-1.1.3/hunt-extra/source/ -I../../../.dub/packages/hunt-1.7.7/hunt/source/ -I../../../.dub/packages/protobuf-0.6.2/protobuf/src/ -J../../../.dub/packages/hunt-extra-1.1.3/hunt-extra/resources source/grpc/EvBuffer.d source/grpc/GrpcClient.d source/grpc/GrpcCode.d source/grpc/GrpcException.d source/grpc/GrpcServer.d source/grpc/GrpcService.d source/grpc/GrpcStream.d source/grpc/Status.d source/grpc/StatusCode.d source/grpc/package.d source/grpc/stream/ClientReader.d source/grpc/stream/ClientReaderWriter.d source/grpc/stream/ClientWriter.d source/grpc/stream/ServerReader.d source/grpc/stream/ServerReaderWriter.d source/grpc/stream/ServerWriter.d -vcolumns

/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o:function _start: error: undefined reference to 'main'

...
"""

Same error!

So it is LDC with -lib who is invoking the linker!

Can you check!

@mw66
Copy link
Author

mw66 commented May 22, 2021

I also tried to run the exact command generated by $ ~/project/ldc2/bin/dub build -v --compiler=ldc2, directly without using dub,

Same error:

$ ldc2 -J -lib -of.dub/build/library-debug-linux.posix-x86_64-ldc_v1.26.0-9DDFB54AD65F3A8BD307F1E232CC37B2/libgrpc.a -d-debug -g -w --oq -od=.dub/build/library-debug-linux.posix-x86_64-ldc_v1.26.0-9DDFB54AD65F3A8BD307F1E232CC37B2//obj -d-version=Have_grpc -d-version=Have_hunt_http -d-version=Have_protobuf -d-version=Have_hunt_net -d-version=Have_hunt_extra -d-version=Have_hunt -d-version=HAVE_EPOLL -Isource/ -I../../../.dub/packages/hunt-http-0.7.3/hunt-http/source/ -I../../../.dub/packages/hunt-net-0.6.6/hunt-net/source/ -I../../../.dub/packages/hunt-extra-1.1.3/hunt-extra/source/ -I../../../.dub/packages/hunt-1.7.7/hunt/source/ -I../../../.dub/packages/protobuf-0.6.2/protobuf/src/ -J../../../.dub/packages/hunt-extra-1.1.3/hunt-extra/resources source/grpc/EvBuffer.d source/grpc/GrpcClient.d source/grpc/GrpcCode.d source/grpc/GrpcException.d source/grpc/GrpcServer.d source/grpc/GrpcService.d source/grpc/GrpcStream.d source/grpc/Status.d source/grpc/StatusCode.d source/grpc/package.d source/grpc/stream/ClientReader.d source/grpc/stream/ClientReaderWriter.d source/grpc/stream/ClientWriter.d source/grpc/stream/ServerReader.d source/grpc/stream/ServerReaderWriter.d source/grpc/stream/ServerWriter.d -vcolumns
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o:function _start: error: undefined reference to 'main'
...

@kinke
Copy link
Member

kinke commented May 23, 2021

Thx for testing further - after a 2nd look, it looks like -J -lib is the problem. LDC accepts -Jmy/dir as well as -J my/dir, so an empty/invalid -J swallows the consecutive -lib arg.

@mw66
Copy link
Author

mw66 commented May 23, 2021

Ha! Great to find the problem!

@mw66
Copy link
Author

mw66 commented May 23, 2021

@kinke

I've update the dub ticket: dlang/dub#2133, and hopefully dub will fix it not to pass empty -J.

On the other hand, IIRC LDC share the same front end code with DMD, so looks like DMD choose to ignore the empty -J, I'm wondering if LDC can use this same defensive approach too? this will make the LDC compiler more robust.

Thanks.

@mw66 mw66 changed the title grpc-dlang build failure with ldc2 enhancement: please ignore the empty -J [was] grpc-dlang build failure with ldc2 Jun 4, 2021
@kinke
Copy link
Member

kinke commented Jun 27, 2021

DMD doesn't ignore an empty -J, it then adds an empty entry to its string import paths - I suspect with semantics being identical to -J. (include current working dir): https://github.com/dlang/dmd/blob/904360af0edeb894f2ecc1c49770874885d400fd/src/dmd/mars.d#L2295-L2300

We cannot alter this behavior for ldc2, because this is how LLVM cmdline options work (and would be a breaking change), but we could make ldmd2 compatible with DMD, translating -J to -J. (and probably the same for -I).

@mw66
Copy link
Author

mw66 commented Jun 27, 2021

That will be fine. Thanks.

@mw66
Copy link
Author

mw66 commented Apr 4, 2023

Since dlang/dub#2133 is fixed, and closed.

Gonna close this, feel free to reopen if you have another reproduction case.

@mw66 mw66 closed this as completed Apr 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants