-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
Build: Support static linked executable #4152
Conversation
@@ -224,6 +224,10 @@ fi | |||
# so we need to link the c++ libraries staticly but not all. | |||
# @see https://stackoverflow.com/a/26107550 | |||
if [[ $SRS_STATIC == YES ]]; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why need SRS_STATIC_STD_CPP
? Maybe we should only support SRS_STATIC
which leads to -static-libstdc++ -static
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-static
will generate a static linked executer,
-static-libstdc++
only link the static libstdc++ library.
So -static
will cover -static-libstdc++
scope, I think it's no need to combine -static -static-libstdc++
together.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the output if use -static
without -static-libstdc++
? User only want a static binary without depends, majority of users can't understand the nuance of these two options.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On Linux:
-static
output:
docker run -it --rm -v `pwd`:/srs -w /srs ossrs/srs:ubuntu20 bash -c "./configure --static=on && make"
/usr/bin/ld: ./objs/src/kernel/srs_kernel_error.o: in function `parse_symbol_offset(char*)':
/srs/./src/kernel/srs_kernel_error.cpp:73: warning: Using 'dlopen' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/bin/ld: ./objs/src/kernel/srs_kernel_utility.o: in function `srs_dns_resolve(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, int&)':
/srs/./src/kernel/srs_kernel_utility.cpp:161: warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/bin/ld: ./objs/openssl/lib/libcrypto.a(b_sock.o): in function `BIO_gethostbyname':
b_sock.c:(.text+0x78): warning: Using 'gethostbyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
make[1]: Leaving directory '/srs'
The warning said: dlopen
, getaddrinfo
and gethostbyname
requires libc similar runtime shared library to support.
docker run -it --rm -v `pwd`:/srs -w /srs ossrs/srs:ubuntu20 bash -c "ldd ./objs/srs"
not a dynamic executable
with both -static -static-ibstdc++
same warning like -static
.
ldd ./objs/srs
same output: not a dynamic executable
.
git show 6314c27
on above commit, SRS_STATIC
use -static-libstdc++
to replace -static
.
But I think keep fully static linked exec can be an option, but not recommended.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Upon investigation, when we utilize certain functions such as dlopen and gethostbyname, we cannot achieve complete static linking, even though we use the -static flag; full static linking is not possible.
Only by removing the dependencies on these functions can we fully utilize the -static flag to create a version that truly does not depend on glibc.
Therefore, it is necessary to remove the dependencies on these functions. The dependency on dlopen comes from third-party libraries, which might be removed through compilation options. Functions like gethostbyname may require the use of different libraries or an implementation by the ST team itself.
https://www.reddit.com/r/haskell/comments/vqqq7x/comment/iez099a/
TRANS_BY_GPT4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To facilitate full static linking, we can only support the -static
option, rather than also having a -static-libstdc++
option, which users might not understand how to use.
Essentially, when we support -static
, a multitude of warnings are generated. These warnings actually indicate potential issues, hence our support for -static
is not robust and leaves underlying problems unresolved.
We absolutely cannot offer an option that carries potential risks, as it would make any arising issues even more difficult to address.
TRANS_BY_GPT4
related to #4148 : support static linked srs executable.
Only verified Linux and MacOS platform, Cygwin wait for verify.
How to use static linking option and verify the static linked executable?
if you just want the static linking the c++ std library, use option
--static-stdcpp=on
:MacOS platform
Mac OS X does not support statically linked executable binaries. The compiler exit with error for
-static
.@see https://developer.apple.com/library/archive/qa/qa1118/_index.html
for
-static-libstdc++
compiler option: MacOS didn't implement it, the compiler just give a unused warning.Linux platform
-static
,-static-libstdc++
and-static-libgcc
support them well.But this PR not include the
-static-libgcc
.Cygwin
Not yet verified.