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

Fails to compile on OpenSSL 1.1.0 #4204

Closed
zatherz opened this issue Mar 28, 2017 · 15 comments · Fixed by #4215 or #4230
Closed

Fails to compile on OpenSSL 1.1.0 #4204

zatherz opened this issue Mar 28, 2017 · 15 comments · Fixed by #4215 or #4230

Comments

@zatherz
Copy link
Contributor

zatherz commented Mar 28, 2017

https://mta.openssl.org/pipermail/openssl-dev/2016-February/005494.html
SSL_library_init was removed (in favor of OPENSSL_init_ssl).

OPENSSL_init_ssl also replaces other things like SSL_load_error_strings: https://www.openssl.org/docs/man1.1.0/ssl/OPENSSL_init_ssl.html

_main.o: In function `__crystal_main':
/usr/lib/crystal/openssl/lib_ssl.cr:192: undefined reference to `SSL_library_init'
/usr/lib/crystal/openssl/lib_ssl.cr:193: undefined reference to `SSL_load_error_strings'
/usr/lib/crystal/openssl/lib_ssl.cr:194: undefined reference to `OPENSSL_add_all_algorithms_noconf'
/usr/lib/crystal/openssl/lib_ssl.cr:195: undefined reference to `ERR_load_crypto_strings'
O-penS-S-L-5858S-S-L-5858C-ontext5858C-lient.o: In function `initialize':
/usr/lib/crystal/openssl/ssl/context.cr:66: undefined reference to `SSLv23_method'
collect2: error: ld returned 1 exit status
Error: execution of command failed with code: 1: `cc -o "/home/zatherz/.cache/crystal/crystal-run-pipebot.tmp" "${@}"  -rdynamic  -lyaml -lz `command -v pkg-config > /dev/null && pkg-config --libs libssl || printf %s '-lssl -lcrypto'` `command -v pkg-config > /dev/null && pkg-config --libs libcrypto || printf %s '-lcrypto'` -lpcre -lm -lgc -lpthread /usr/lib/crystal/ext/libcrystal.a -levent -lrt -ldl -L/usr/lib -L/usr/local/lib`

@anatol
Copy link
Contributor

anatol commented Mar 29, 2017

I see the same issue...

@zatherz
Copy link
Contributor Author

zatherz commented Mar 29, 2017

Are you using Arch Linux? OpenSSL 1.1.0 got into the testing repo recently.
As a workaround, install the openssl-1.0 package, and then run/build with these commands:

crystal run --link-flags "-L/usr/lib/openssl-1.0" <file> -- <args>
crystal build --link-flags "-L/usr/lib/openssl-1.0" <file> -- <args>

For example:

crystal run --link-flags "-L/usr/lib/openssl-1.0" src/pipebot.cr -- pipe

@anatol
Copy link
Contributor

anatol commented Mar 29, 2017

Yes, I am at Arch. @zatherz I have a few questions:

  • How to compile Crystal with openssl 1.0? Currently I compile Crystal as
  make release=1 \
       PATH="$srcdir/$pkgname-$pkgver-$_binary_rel/bin:$PATH" \
       CRYSTAL_PATH="$srcdir/$pkgname-$pkgver/src" \
       CRYSTAL_CONFIG_VERSION="$pkgver" \
       CRYSTAL_CONFIG_PATH="lib:/usr/lib/crystal" \
       CRYSTAL_CACHE_DIR="/tmp/crystal"

but would like to specify version of openssl to be used.

  • How to make openssl link flag default so users don't need to set them manually?

@zatherz
Copy link
Contributor Author

zatherz commented Mar 29, 2017

I'm pretty sure you'd have to modify the Makefile to call .bin/crystal with the arguments above.

Crystal should allow using OpenSSL 1.1.0. To maintain compatibility, OpenSSL 1.1.0 support could be enabled through some sort of compiletime flag.

@ysbaddaden
Copy link
Contributor

ysbaddaden commented Mar 30, 2017

Crystal itself isn't compiled against OpenSSL... Running make release should call bin/crystal -Dwithout_openssl already. Errata: the repository Makefile doesn't have -Dwithout_openssl. Maybe it should, for consistency.

@jhass
Copy link
Member

jhass commented Mar 30, 2017

Well, -Dwithout_openssl was meant as a temporary workaround instead of fixing the omnibus project iirc, so that feels like going into the wrong direction...

@ysbaddaden
Copy link
Contributor

Why should the compiler be linked against OpenSSL? The playground? it's only loaded over HTTP and on localhost...

@jhass
Copy link
Member

jhass commented Mar 30, 2017

It probably shouldn't but it shouldn't need to disable it with a flag either, so this becomes rather a question of dead code elimination, no?

@bcardiff
Copy link
Member

The playground use websockets and for those there are some {% if !flag?(:without_openssl) %} here

@zatherz
Copy link
Contributor Author

zatherz commented Mar 30, 2017

Sorry, it's not only the Crystal compiler that doesn't compile due to this issue. Nothing compiles, as it's an issue in the standard lib (openssl/lib_ssl.cr).

@anatol
Copy link
Contributor

anatol commented Apr 1, 2017

Thank you. I applied the patch on top of 0.21.1 release and now compilation is fine. Unfortunately running tests fails with:

Using /usr/bin/llvm-config [version=4.0.0]
./bin/crystal build  -o .build/all_spec spec/all_spec.cr
Using compiled compiler at .build/crystal
_main.o: In function `~procProc(Pointer(Void), Nil)@src/openssl/ssl/hostname_validation.cr:66':
main_module:(.text+0x4efec2): undefined reference to `sk_free'
_main.o: In function `~proc2Proc(Pointer(Void), Nil)@src/openssl/ssl/hostname_validation.cr:66':
main_module:(.text+0x4eff52): undefined reference to `sk_free'
_main.o: In function `~proc3Proc(Pointer(Void), Nil)@src/openssl/ssl/hostname_validation.cr:66':
main_module:(.text+0x4effa2): undefined reference to `sk_free'
_main.o: In function `~proc4Proc(Pointer(Void), Nil)@src/openssl/ssl/hostname_validation.cr:66':
main_module:(.text+0x4efff2): undefined reference to `sk_free'
_main.o: In function `~proc5Proc(Pointer(Void), Nil)@src/openssl/ssl/hostname_validation.cr:66':
main_module:(.text+0x4f0002): undefined reference to `sk_free'
_main.o:main_module:(.text+0x4f0052): more undefined references to `sk_free' follow
O-penS-S-L-5858H-M-A-C-.o: In function `digest':
/build/crystal/src/crystal-0.21.1/src/openssl/hmac.cr:6: undefined reference to `EVP_dss'
/build/crystal/src/crystal-0.21.1/src/openssl/hmac.cr:7: undefined reference to `EVP_dss1'
O-penS-S-L-5858D-igest.o: In function `create_evp_mt_ctx':
/build/crystal/src/crystal-0.21.1/src/openssl/digest/digest.cr:23: undefined reference to `EVP_MD_CTX_create'
O-penS-S-L-5858D-igest.o: In function `finalize':
/build/crystal/src/crystal-0.21.1/src/openssl/digest/digest.cr:38: undefined reference to `EVP_MD_CTX_destroy'
O-penS-S-L-5858D-igest.o: In function `clone':
/build/crystal/src/crystal-0.21.1/src/openssl/digest/digest.cr:42: undefined reference to `EVP_MD_CTX_create'
/build/crystal/src/crystal-0.21.1/src/openssl/digest/digest.cr:44: undefined reference to `EVP_MD_CTX_destroy'
O-penS-S-L-5858S-S-L-5858H-ostnameV-alidation.o: In function `matches_subject_alternative_name':
/build/crystal/src/crystal-0.21.1/src/openssl/ssl/hostname_validation.cr:66: undefined reference to `sk_pop_free'
/build/crystal/src/crystal-0.21.1/src/openssl/ssl/hostname_validation.cr:66: undefined reference to `sk_pop_free'
/build/crystal/src/crystal-0.21.1/src/openssl/ssl/hostname_validation.cr:34: undefined reference to `sk_num'
/build/crystal/src/crystal-0.21.1/src/openssl/ssl/hostname_validation.cr:35: undefined reference to `sk_value'
/build/crystal/src/crystal-0.21.1/src/openssl/ssl/hostname_validation.cr:66: undefined reference to `sk_pop_free'
/build/crystal/src/crystal-0.21.1/src/openssl/ssl/hostname_validation.cr:66: undefined reference to `sk_pop_free'
/build/crystal/src/crystal-0.21.1/src/openssl/ssl/hostname_validation.cr:66: undefined reference to `sk_pop_free'
/build/crystal/src/crystal-0.21.1/src/openssl/ssl/hostname_validation.cr:66: undefined reference to `sk_pop_free'
/build/crystal/src/crystal-0.21.1/src/openssl/ssl/hostname_validation.cr:66: undefined reference to `sk_pop_free'
collect2: error: ld returned 1 exit status
Error: execution of command failed with code: 1: `cc -o "/build/crystal/src/crystal-0.21.1/.build/all_spec" "${@}"  -rdynamic  -lreadline -lgmp -lyaml -lz `command -v pkg-config > /dev/null && pkg-config --libs libssl || printf %s '-lssl -lcrypto'` `command -v pkg-config > /dev/null && pkg-config --libs libcrypto || printf %s '-lcrypto'` /build/crystal/src/crystal-0.21.1/src/llvm/ext/llvm_ext.o `/usr/bin/llvm-config --libs --system-libs --ldflags 2> /dev/null` -lstdc++ -lxml2 -lpcre -lm -lgc -lpthread /build/crystal/src/crystal-0.21.1/src/ext/libcrystal.a -levent -lrt -ldl -L/usr/lib -L/usr/local/lib`
make: *** [Makefile:102: .build/all_spec] Error 1

@anatol
Copy link
Contributor

anatol commented Apr 4, 2017

I applied the patches, ran it at Arch Linux and got following test failures. Not 100% that it because the openssl upgrate. Here is the test output

Failures:

  1) OpenSSL::SSL::Context new for client
     Failure/Error: context.options.should eq(OpenSSL::SSL::Options.flags(

       Expected: 2199456767
            got: 0

     # spec/std/openssl/ssl/context_spec.cr:7

  2) OpenSSL::SSL::Context new for server
     Failure/Error: context.options.should eq(OpenSSL::SSL::Options.flags(

       Expected: 2203651071
            got: 0

     # spec/std/openssl/ssl/context_spec.cr:18

  3) OpenSSL::SSL::Context adds options
     Failure/Error: context.add_options(OpenSSL::SSL::Options::ALL).should eq(default_options | OpenSSL::SSL::Options::ALL)

       Expected: ALL
            got: 0

     # spec/std/openssl/ssl/context_spec.cr:84

  4) OpenSSL::SSL::Context removes options
     Failure/Error: context.remove_options(OpenSSL::SSL::Options::NO_TLSV1).should eq(default_options | OpenSSL::SSL::Options::NO_SSLV2)

       Expected: NO_SSLV2
            got: 0

     # spec/std/openssl/ssl/context_spec.cr:93

  5) OpenSSL::SSL::Context returns options
     Failure/Error: context.options.should eq(default_options | OpenSSL::SSL::Options.flags(ALL, NO_SSLV2))

       Expected: 2164263935
            got: 0

     # spec/std/openssl/ssl/context_spec.cr:100

Finished in 5:43 minutes
12121 examples, 5 failures, 0 errors, 13 pending

Failed examples:

crystal spec spec/std/openssl/ssl/context_spec.cr:5 # OpenSSL::SSL::Context new for client
crystal spec spec/std/openssl/ssl/context_spec.cr:16 # OpenSSL::SSL::Context new for server
crystal spec spec/std/openssl/ssl/context_spec.cr:80 # OpenSSL::SSL::Context adds options
crystal spec spec/std/openssl/ssl/context_spec.cr:89 # OpenSSL::SSL::Context removes options
crystal spec spec/std/openssl/ssl/context_spec.cr:96 # OpenSSL::SSL::Context returns options
make: *** [Makefile:77: spec] Error 1

@ysbaddaden
Copy link
Contributor

Should be fixed now.

I miss a detailed list of changes between OpenSSL 1.0 and 1.1.

@joshuamzm
Copy link

Hi @anatol, I saw you uploaded a patched version of 0.21.1's PKGBUILD to ArchLinux repo. May I ask why the package isn't available for pacman and still out-of-date flag remains? I'm curious because I'm unable to compile the package by myself since after 3GB of memory allocation, fork is unable to use more memory in spite of having plenty of it... Meanwhile, I'll try to figure that out.

@anatol
Copy link
Contributor

anatol commented Apr 16, 2017

@jomendoz will look at the Arch package in ~10 days when I get back to my workstation.

I'm unable to compile the package by myself since after 3GB of memory allocation, fork is unable to use more memory in spite of having plenty of it

I confirm that Crystal package compilation is very slow and resource hungry process. It takes several hours at my computer to build the package.

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

Successfully merging a pull request may close this issue.

6 participants