-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Adds support for OpenBSD #3326
Adds support for OpenBSD #3326
Conversation
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.
Thanks for porting Crystal to OpenBSD! This looks great overall. I just wrote a few notes here and there.
Could you explain how you generated the LibC bindings? Did you use the posix generator, or did you copy and adapted the FreeBSD bindings?
Could you explain how to configure an OpenBSD installation, or better provide an openbsd target to the Vagrantfile? I tried once to port to OpenBSD but failed at installing dependencies (I believe). This way I could test a few things, like why is crystal docs
segfaulting, why is Shards not compiling, ...
@@ -19,7 +21,7 @@ class OpenSSL::HMAC | |||
key_slice = key.to_slice | |||
data_slice = data.to_slice | |||
buffer = Slice(UInt8).new(128) | |||
LibCrypto.hmac(evp, key_slice, key_slice.size, data_slice, data_slice.size, buffer, out buffer_len) | |||
LibCrypto.hmac(evp.not_nil!, key_slice, key_slice.size, data_slice, data_slice.size, buffer, out buffer_len) |
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.
evp
should never be nil, because it was either assigned a value or an exception was raised.
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.
It shouldn't be, but I was getting a compiler error after adding the conditional macro code on line 11. I'll investigate further to confirm that this is a reproducable problem, if so it may indicate a bug in the compiler.
@@ -8,7 +8,9 @@ class OpenSSL::HMAC | |||
when :md4 then LibCrypto.evp_md4 | |||
when :md5 then LibCrypto.evp_md5 | |||
when :ripemd160 then LibCrypto.evp_ripemd160 | |||
{% if !flag?(:openbsd) %} | |||
when :sha then LibCrypto.evp_sha |
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.
EVP_sha
was removed in OpenSSL 1.1.0. Let's drop it altogether.
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.
Agreed
@@ -50,7 +50,9 @@ class Thread | |||
# All threads, so the GC can see them (GC doesn't scan thread locals) | |||
@@threads = Set(Thread).new | |||
|
|||
{% if !flag?(:openbsd) %} | |||
@[ThreadLocal] |
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.
How to access Thread.current
and be sure to always memoize the current Thread
without @[ThreadLocal]
? This i the only issue with ThreadLocal not being supported on OpenBSD.
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.
Maybe not memoizing @@current
on OpenBSD, then iterating @@threads
to find the current thread that matches the id returned by pthread_self
?
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.
That sounds like a viable idea. I'll give it a try
ONOCR = 0x00000040 | ||
ONLRET = 0x00000080 | ||
|
||
TABDLY = 0x00000004 |
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.
TABDLY is defined here, but not in the OutputMode
enum. Is this intended?
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.
No, not intended
An improvement (can be postponed):
|
Current status: I got an initial OpenBSD setup. I'm just missing an up to date boehm-gc (the very recent 7.6 release). |
@ysbaddaden Thanks for taking the time to look at this! Regarding your initial questions: I generated the LibC bindings by adapting the FreeBSD bindings. I wasn't aware of your posix generator, I will take a look at it soon. As for configuring OpenBSD, I installed the following packages: llvm boehm-gc libevent pcre gmake bash I listed the steps I took to build on a fresh OpenBSD install here: https://gist.github.com/wmoxam/d06f9ccc82e03f6fea64747d82caa421 |
Thanks! I cross-compiled a Crystal binary for OpenBSD which was indeed capable to build itself :-)
Compilation prints some warnings, that appear to be OpenBSD specific. For example libyaml prints "use snprintf instead of often misused sprintf" or "libevent: random() may return deterministic values". I believe they're harmless warnings. |
I adapted the pkg.sh script I use for building FreeBSD packages, and here comes an alpha OpenBSD tarball of 0.19.2 for testing: https://dl.dropboxusercontent.com/u/53345358/openbsd/index.html |
I was able to build crystal in release mode. I didn't do anything special to do so. @ysbaddaden What steps did you take to cross-compile crystal on OpenBSD itself? I would like to try to reproduce the problem. |
There is enough here to cross-compile an object file which can be used to complile a working compiler The ported compiler can then fully compile itself.
@ysbaddaden I believe all of the issues have been addressed. Let me know if you think there is anything else that should be addressed. |
{% end %} | ||
@@current = new | ||
|
||
def self.current | ||
{% if flag?(:openbsd) %} | ||
pthread_self_id = LibC.pthread_self().as(UInt64*).address |
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.
Wouldn't pthread_equal
be safer?
class Thread
{% if flag?(:openbsd) %}
def self.current
current_thread_id = LibC.pthread_self
@@threads.find { |thread| LibC.pthread_equal(thread.id, current_thread_id) != 0 }.not_nil!
end
{% else %}
@[ThreadLocal]
def self.current
@@current
end
{% end %}
def id
@th
end
end
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.
Oh, I didn't know about pthread_equal, that seems much better
@ysbaddaden Feel free to merge this whenever you think this is ready. I looked at the changed and they look fine :) (once travis passes, of course) |
I still can't build in release mode, Crystal crashes during "codegen (bc+obj)" with the following. It looks like an exception fails to raise in LLVM. Maybe compiling LLVM in debug mode (with assertions enabled) could help catch the issue.
|
I fixed a few issues. OpenBSD doesn't support keepalive configuration on a per socket basis. I also changed the |
@ysbaddaden I was able to build in release mode, the problem was in linking. See: https://gist.github.com/wmoxam/93120d51e3be3af2479f3842f75ebb49#file-success-txt |
That's good news! There must be an issue in my Vagrant box (kaorimatz/openbsd-6.0-amd64) or VirtualBox or something.
Yes, the LLVM package must have been compiled with |
Closed in favour of #3369 |
There is enough here to cross-compile an object file which can be used to compile a working compiler. The ported compiler can then fully compile itself.
Some notes:
crystal docs
command is brokencrystal deps
is broken