uNetworking / uSockets

Miniscule cross-platform eventing, networking & crypto for async applications
Apache License 2.0
1.29k stars 267 forks source link

option to disable lto, enabled by default to avoid regression #93

Closed ng5 closed 4 years ago

ng5 commented 4 years ago

Trying to build static executable in linux using clang, but certain third party libraries are gcc compiled and running into random issues related to LTO issues(undefined reference). this flag will provide option to disable lto if not required.

Steps to reproduce: (With in new factory installed redhat 8 container)

da09 ➜ ~ docker pull centos da09 ➜ ~ docker run -it --rm centos
[root@05386def3fe3 /]# yum update && yum group install "Development Tools" [root@05386def3fe3 /]# git clone https://github.com/uNetworking/uSockets [root@05386def3fe3 /]# cd uSockets/ [root@05386def3fe3 uSockets]# make examples rm -f .o cc -DLIBUS_NO_SSL -std=c11 -Isrc -flto -O3 -c src/.c src/eventing/.c src/crypto/.c ar rvs uSockets.a .o ar: creating uSockets.a a - context.o a - epoll_kqueue.o a - gcd.o a - libuv.o a - loop.o a - openssl.o a - socket.o a - wolfssl.o ar: context.o: plugin needed to handle lto object ar: epoll_kqueue.o: plugin needed to handle lto object ar: gcd.o: plugin needed to handle lto object ar: libuv.o: plugin needed to handle lto object ar: loop.o: plugin needed to handle lto object ar: openssl.o: plugin needed to handle lto object ar: socket.o: plugin needed to handle lto object ar: wolfssl.o: plugin needed to handle lto object for f in examples/.c; do cc -flto -O3 -DLIBUS_NO_SSL -std=c11 -Isrc -o $(basename "$f" ".c") "$f" uSockets.a; done /tmp/ccAd3JMz.ltrans0.ltrans.o: In function `on_echo_socket_open':

:(.text+0x3d): undefined reference to `us_socket_ext' :(.text+0x5d): undefined reference to `us_socket_timeout'
ng5 commented 4 years ago

Ubuntu seems to work, but doesn't seem to work on alpine linux either.

docker pull alpine docker run -it --rm alpine

apk add --update alpine-sdk git clone https://github.com/uNetworking/uSockets.git cd uSockets/ /uSockets # make examples rm -f .o cc -DLIBUS_NO_SSL -std=c11 -Isrc -flto -O3 -c src/.c src/eventing/.c src/crypto/.c ar rvs uSockets.a .o ar: creating uSockets.a a - context.o a - epoll_kqueue.o a - gcd.o a - libuv.o a - loop.o a - openssl.o a - socket.o a - wolfssl.o ar: context.o: plugin needed to handle lto object for f in examples/.c; do cc -flto -O3 -DLIBUS_NO_SSL -std=c11 -Isrc -o $(basename "$f" ".c") "$f" uSockets.a; done /usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: /tmp/echo_server.aGhfpi.ltrans0.ltrans.o: in function `on_echo_socket_open':

:(.text+0x3e): undefined reference to `us_socket_ext' /usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: :(.text+0x5e): undefined reference to `us_socket_timeout' /usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: /tmp/echo_server.aGhfpi.ltrans0.ltrans.o: in function `on_echo_socket_close': :(.text+0x93): undefined reference to `us_socket_ext'
epsilon-0 commented 4 years ago

I second this option as well, as Gentoo passes the lto and -O3 flags on a per package basis.

ghost commented 4 years ago

plugin needed to handle lto object

ng5 commented 4 years ago

thanks.

switching default AR from ar to gcc-ar works fine in redhat.

[root@dfa483506e8b uSockets]# g++ --version g++ (GCC) 8.3.1 20190507 (Red Hat 8.3.1-4) Copyright (C) 2018 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

[root@dfa483506e8b uSockets]# uname -a Linux dfa483506e8b 5.4.0-29-generic #33-Ubuntu SMP Wed Apr 29 14:32:27 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux [root@dfa483506e8b uSockets]# export AR=gcc-ar [root@dfa483506e8b uSockets]# make examples/ make: Nothing to be done for 'examples/'. [root@dfa483506e8b uSockets]# make clean rm -f .o rm -f .a rm -rf .certs [root@dfa483506e8b uSockets]# make examples rm -f .o cc -DLIBUS_NO_SSL -std=c11 -Isrc -flto -O3 -c src/.c src/eventing/.c src/crypto/.c gcc-ar rvs uSockets.a .o /usr/bin/ar: creating uSockets.a a - context.o a - epoll_kqueue.o a - gcd.o a - libuv.o a - loop.o a - openssl.o a - socket.o a - wolfssl.o for f in examples/.c; do cc -flto -O3 -DLIBUS_NO_SSL -std=c11 -Isrc -o $(basename "$f" ".c") "$f" uSockets.a; done [root@dfa483506e8b uSockets]#