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

Fix compilation on FreeBSD. #3625

Merged
merged 10 commits into from Dec 22, 2023
Merged

Conversation

alexdupre
Copy link
Contributor

This patch allows to successfully run sandbox3/run on FreeBSD.

This is not enough to have a fully working scala-native setup, but many applications will work.

There are at least a couple of additional issues that I've found:

  • when the boehm GC is used with multithreading, FreeBSD requires linking with gc-threaded instead of just gc. I'm not sure how to change that. Moreover, the documentation should be updated unconditionally to require the boehm-gc-threaded package instead of boehm-gc (regardless the runtime use of multithreading)
  • any jdk >= 11 on FreeBSD has the system param java.net.preferIPv4Stack set to true by default, and the IPv4-mapped IPv6 addresses are disabled by default. Many tests won't work unless the net.inet6.ip6.v6only sysctl is set to zero and java.net.preferIPv4Stack is set to false

@ekrich
Copy link
Member

ekrich commented Dec 19, 2023

FreeBSD requires linking with gc-threaded instead of just gc

If this will work on all platforms, you could just change it here.
https://github.com/scala-native/scala-native/blob/main/tools/src/main/scala/scala/scalanative/build/GC.scala#L41

any jdk >= 11 on FreeBSD

I am not sure here but it should be in the javadocs and should be true on all JVMs, not just FreeBSD for "write once run anywhere". If this is the case then I think an issue specific to this problem should be added. Others more familiar should weigh in.

@alexdupre
Copy link
Contributor Author

I don't think the change to link togc-threaded will work on all platforms. My understanding is that FreeBSD provides a boehm-gc package without threads support, and a separate boehm-gc-threaded package with the multi-thread support that can both be installed concurrently, and for this reason the latter library has been renamed gc-threaded. I'm not sure what Linux distros do, I suppose they just provide a threaded library with the gc name. Can you confirm that?

I'll post another comment later about the networking issue. Anyway, these comments are just to let everyone be aware that there are still things to improve/fix, but they are independent from what this PR fixes.

@ekrich
Copy link
Member

ekrich commented Dec 19, 2023

I don't think the change to link togc-threaded will work on all platforms.

Yes, this does not work on macOS so I am guessing Linux as well. Maybe it can be installed differently or built easily for better instructions/docs?

@LeeTibbert
Copy link
Contributor

@alexdupre Thank you for the FreeBSD work here. It would be nice to get FreeBSD
building and passing unit-tests.

TL; DR - There may be a fire here, but I believe it is not a barn fire.

The problems you report sound strange.

In January or so of 2023(?) I had FreeBSD building and passing almost all of the
unit-tests. A few javalib network related tests did not pass (NetworkInterface etc.)
because the default configuration on FreeBSD differs from Linux & macOS.

Two or so months ago, I had a private FreeBSD building on, I think FreeBSD 13.0 (on AMD) (13.2?).
I bypassed the known failing network tests and made edits to a number of other files.
Unfortunately, I was never able to flush this work back to mainline (IIRC, a Scala version change
was two weeks away and I did not want to introduce churn.)

I would have to review my work, but to my memory, no special linking was required.

I will have to re-check my now FreeBSD 14.0 system to see which JDK I was using, probably
Java 8.

I will read thru the changes of this PR.

@@ -1,5 +1,5 @@

#if defined(__x86_64__) && (defined(__linux__) || defined(__APPLE__))
#if defined(__x86_64__) && (defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I concur with this change.

I never tried running on 32 bit FreeBSD. If the intent is
to support and & test such (which I doubt SN should be doing in the absence of a champion/advocate). does the
corresponding setjmp_amd32.s need a corresponding change?

Copy link
Contributor

@LeeTibbert LeeTibbert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI failures
  1. Needs scripts/clangfmt to be executed, so that the lint-check is happy.

  2. Two Windows runs are not happy.

    • one is still running after many hours, probably hung in a broken exception handler.
      Later: the test finally finished with a "timeout", looks like a socket read hung for some reason,

    • the other one has a hard failure in what appears to be Safepoint.c. On first reading of the log
      I do not know if that failure is related to this PR or preexisting. (Changes of this PR look
      innocent enough, but that is why we run CI).

Fixing the first problem will cause a new, full CI to run. We can monitor the fresh run and see what happens with
the Windows tests.

Once CI passes

Otherwise the changes of this PR Looks Good To Me (LGTM).

This PR contains the changes non-Test changes I made in private code in October, 2023 to get FreeBSD (13.2?) running on AMD hardware (well, VM on AMD hardware).

I expect the 13 or so Test files (unit-tests and ./tools/src/test/scala/scala/scalanative/linker/MinimalRequiredSymbolsTest.scala.original) to continue to fail.
Having this PR merged will make feeding fixed FreeBSD 14 versions of those tests
back into mainline, perhaps a few at a time.

There are a couple of point suggestions, not requirements. They should
not keep this PR from moving forward.

Because SN CI does not exercise FreeBSD (long story), it would be handy if the
base PR description described exactly which FreeBSD versions and architectures
were tested.

@LeeTibbert
Copy link
Contributor

LeeTibbert commented Dec 19, 2023

The failure of these tests should not keep this PR from progressing.

To co-ordinate work:

I expect at least the following tests to continue to fail. I have fixed copies of many of these and will try
to peck away at creating PRs for them, perhaps a few at a time.

./tools/src/test/scala/scala/scalanative/linker/MinimalRequiredSymbolsTest.scala.original
./unit-tests/native/src/test/scala/org/scalanative/testsuite/posixlib/LocaleTest.scala.original
./unit-tests/native/src/test/scala/org/scalanative/testsuite/posixlib/MonetaryTest.scala.original
./unit-tests/native/src/test/scala/org/scalanative/testsuite/posixlib/LocaleTest.scala.original~
./unit-tests/native/src/test/scala/org/scalanative/testsuite/posixlib/sys/ResourceTest.scala.original
./unit-tests/native/src/test/scala/org/scalanative/testsuite/posixlib/sys/StatTest.scala.original
./unit-tests/shared/src/test/scala/org/scalanative/testsuite/javalib/net/InterfaceAddressTest.scala.original
./unit-tests/shared/src/test/scala/org/scalanative/testsuite/javalib/net/NetworkInterfaceTest.scala.original
./unit-tests/shared/src/test/scala/org/scalanative/testsuite/javalib/net/SocketTest.scala.original
./scripted-tests/run/build-library-dynamic/src/main/c/testlib.cpp.original
./scripted-tests/run/java-net-server-socket/tests/ServerTest.scala.original
./scripted-tests/run/java-net-socket/tests/EchoClientTest.scala.original
./scripted-tests/run/java-net-socket/test.original

Least I forget my manners, @alexdupre, which tests would be most useful to you first (after this PR?)

@LeeTibbert
Copy link
Contributor

LeeTibbert commented Dec 19, 2023

There are at least a couple of additional issues that I've found:

    when the boehm GC is used with multithreading, FreeBSD requires linking with gc-threaded instead of just gc. I'm not sure how to change that. Moreover, the documentation should be updated unconditionally to require the boehm-gc-threaded package instead of boehm-gc (regardless the runtime use of multithreading)

    any jdk >= 11 on FreeBSD has the system param java.net.preferIPv4Stack set to true by default, and the IPv4-mapped IPv6 addresses are disabled by default. Many tests won't work unless the net.inet6.ip6.v6only sysctl is set to zero and java.net.preferIPv4Stack is set to false

Could you create seperate Issues for each of these so that they do not get lost? That will also make it easier
to get this PR merged (which will help in getting the tests, especially IPv6, working).

Each will require focused study. The first issue deals with multithreading, which a whole other box.

Is the FreeBSD boehm-gc-thread package smart enough to fall back to (no-lock) straight line code when running
in a single-threaded process? Performance impacts? Gotta love extended configuration matrices.

@alexdupre
Copy link
Contributor Author

alexdupre commented Dec 20, 2023

Some additional context:

  1. I've been able to successfully run sandbox3/run on FreeBSD 13.2 amd64, FreeBSD 14.0 amd64 and FreeBSD 14.0 aarch64

  2. I've tried to run sandbox2_12/run on FreeBSD 12.x i386, but it failed. I haven't a real i386 machine, so I tried within a jail. As you noted, to make it compile I had to add the defined(__FreeBSD__) into setjmp_amd32.S as well, but then it failed with:

[info] Generating intermediate code (with debug metadata) (1727 ms)
[info] Compiling to native code (565 ms)
[info] Linking native code (immix gc, none lto) (81 ms)
[info] Postprocessing (0 ms)
[info] Total (5583 ms)
Unexpected signal 11 when accessing memory at address 0x4000
        at _lh_get_sp
        at _lh_get_sp
        at _pthread_sigmask
        at _pthread_getspecific
[error] java.lang.RuntimeException: Nonzero exit code: 139
[error]         at scala.sys.package$.error(package.scala:30)
[error]         at scala.scalanative.sbtplugin.ScalaNativePluginInternal$.$anonfun$scalaNativeConfigSettings$18(ScalaNativePluginInternal.scala:276)
[error]         at scala.Option.foreach(Option.scala:407)
[error]         at scala.scalanative.sbtplugin.ScalaNativePluginInternal$.$anonfun$scalaNativeConfigSettings$16(ScalaNativePluginInternal.scala:276)
[error]         at scala.scalanative.sbtplugin.ScalaNativePluginInternal$.$anonfun$scalaNativeConfigSettings$16$adapted(ScalaNativePluginInternal.scala:253)
[error]         at scala.Function1.$anonfun$compose$1(Function1.scala:49)
[error] stack trace is suppressed; run last sandbox2_12 / Compile / run for the full output
[error] (sandbox2_12 / Compile / run) Nonzero exit code: 139

so I guess FreeBSD/i386 is not actually supported. I don't see it as a problem, since it's now a tier2 platform and I don't think anyone will ever want to run scala-native on it, so we should probably create a separate branch which errors out in this scenario.

  1. I couldn't run tests3/test on FreeBSD 14 aarch64 because of the following error, but I'm not sure why it happens:
[error] ld: error: undefined symbol: feraiseexcept
[error] >>> referenced by FenvTest.scala:59
[error] >>>               /home/ec2-user/scala-native/unit-tests/native/.3/target/scala-3.3.1/native-test/generated/6907d14c.ll.o:(_SM31scala.scalanative.libc.FEnvTestD46raiseCheckClearException$$anonfun$1$$anonfun$1L31scala.collection.immutable.ListuEpT31scala.scalanative.libc.FEnvTest)
[error] clang++: error: linker command failed with exit code 1 (use -v to see invocation)
  1. on am64 I can start the unit tests, but some of them never terminate (CPU at 100% for hours on the same tests)

  2. the sandbox program has been compiled with java 8 and java 21, the tests can be started only with java 8 because of the network differences between java 8 and 11+, specific to *BSD. In particular this logic is not correct anymore for java 11+: https://github.com/scala-native/scala-native/blob/main/test-interface/src/main/scala/scala/scalanative/testinterface/TestMain.scala#L34

  3. I've successfully compiled and run the sandbox program with all GC (none, boehm, immix, commix). The two only issues are:

  • boehm in conjunction with withMultithreadingSupport(true)
[error] In file included from /home/ale/scala-native/sandbox/.3/target/scala-3.3.1/native/dependencies/nativelib_native0.5.0-SNAPSHOT_3-0.5.0-SNAPSHOT-0/scala-native/gc/boehm/gc.c:7:
[error] /usr/local/include/gc/gc.h:1807:11: fatal error: 'gc_pthread_redirects.h' file not found
[error] # include "gc_pthread_redirects.h"
[error]           ^~~~~~~~~~~~~~~~~~~~~~~~
[error] 1 error generated.

This is due to the missing boehm-gc-threaded package, and after installation it fails because of wrong linked library:

[error] ld: error: undefined symbol: GC_pthread_create
[error] >>> referenced by gc.c:74 (dependencies/nativelib_native0.5.0-SNAPSHOT_3-0.5.0-SNAPSHOT-0/scala-native/gc/boehm/gc.c:74)
[error] >>>              /home/ale/scala-native/sandbox/.3/target/scala-3.3.1/native/dependencies/nativelib_native0.5.0-SNAPSHOT_3-0.5.0-SNAPSHOT-0/scala-native/gc/boehm/gc.c.o:(scalanative_pthread_create)
[error] clang++: error: linker command failed with exit code 1 (use -v to see invocation)

Linking it with the correct library make it working, I'll get in touch with the FreeBSD port maintainer to understand the reason of this separation between non-threaded and threaded.

  • experimental
[error] ld: error: undefined symbol: scalanative_alloc_small
[error] >>> referenced by AbstractQueuedSynchronizer.scala:343
[error] >>>               /home/ale/scala-native/sandbox/.3/target/scala-3.3.1/native/generated/c957210c.ll.o:(_SM53java.util.concurrent.locks.AbstractQueuedSynchronizerD10tryAcquireizEO)
[error] >>> referenced by AbstractQueuedSynchronizer.scala:133
[error] >>>               /home/ale/scala-native/sandbox/.3/target/scala-3.3.1/native/generated/c957210c.ll.o:(_SM53java.util.concurrent.locks.AbstractQueuedSynchronizerD17tryInitializeHeaduEPT53java.util.concurrent.locks.AbstractQueuedSynchronizer)
[error] >>> referenced by AbstractQueuedSynchronizer.scala:400
[error] >>>               /home/ale/scala-native/sandbox/.3/target/scala-3.3.1/native/generated/c957210c.ll.o:(_SM53java.util.concurrent.locks.AbstractQueuedSynchronizerD26acquireSharedInterruptiblyiuEO)
[error] >>> referenced 560 more times
[error] ld: error: undefined symbol: scalanative_init
[error] >>> referenced by unknown:1
[error] >>>               /home/ale/scala-native/sandbox/.3/target/scala-3.3.1/native/generated/494ee56d.ll.o:(main)
[error] ld: error: undefined symbol: scalanative_alloc_atomic
[error] >>> referenced by Arrays.scala:201
[error] >>>               /home/ale/scala-native/sandbox/.3/target/scala-3.3.1/native/generated/f1a3c5d6.ll.o:(_SM39scala.scalanative.runtime.BooleanArray$D5allociL38scala.scalanative.runtime.BooleanArrayEO)
[error] >>> referenced by Arrays.scala:333
[error] >>>               /home/ale/scala-native/sandbox/.3/target/scala-3.3.1/native/generated/f1a3c5d6.ll.o:(_SM36scala.scalanative.runtime.ByteArray$D5allociL35scala.scalanative.runtime.ByteArrayEO)
[error] >>> referenced by Arrays.scala:267
[error] >>>               /home/ale/scala-native/sandbox/.3/target/scala-3.3.1/native/generated/f1a3c5d6.ll.o:(_SM36scala.scalanative.runtime.CharArray$D5allociL35scala.scalanative.runtime.CharArrayEO)
[error] >>> referenced 5 more times
[error] ld: error: undefined symbol: scalanative_alloc
[error] >>> referenced by Arrays.scala:714
[error] >>>               /home/ale/scala-native/sandbox/.3/target/scala-3.3.1/native/generated/f1a3c5d6.ll.o:(_SM37scala.scalanative.runtime.ObjectArrayD5cloneL37scala.scalanative.runtime.ObjectArrayEO)
[error] >>> referenced by Arrays.scala:729
[error] >>>               /home/ale/scala-native/sandbox/.3/target/scala-3.3.1/native/generated/f1a3c5d6.ll.o:(_SM38scala.scalanative.runtime.ObjectArray$D5allociL37scala.scalanative.runtime.ObjectArrayEO)
[error] ld: error: undefined symbol: scalanative_add_roots
[error] >>> referenced by MemoryPool.c:50 (dependencies/nativelib_native0.5.0-SNAPSHOT_3-0.5.0-SNAPSHOT-0/scala-native/zone/MemoryPool.c:50)
[error] >>>               /home/ale/scala-native/sandbox/.3/target/scala-3.3.1/native/dependencies/nativelib_native0.5.0-SNAPSHOT_3-0.5.0-SNAPSHOT-0/scala-native/zone/MemoryPool.c.o:(MemoryPool_claim)
[error] >>> referenced by LargeMemoryPool.c:56 (dependencies/nativelib_native0.5.0-SNAPSHOT_3-0.5.0-SNAPSHOT-0/scala-native/zone/LargeMemoryPool.c:56)
[error] >>>               /home/ale/scala-native/sandbox/.3/target/scala-3.3.1/native/dependencies/nativelib_native0.5.0-SNAPSHOT_3-0.5.0-SNAPSHOT-0/scala-native/zone/LargeMemoryPool.c.o:(LargeMemoryPool_claim)
[error] ld: error: undefined symbol: scalanative_remove_roots
[error] >>> referenced by MemoryPool.c:58 (dependencies/nativelib_native0.5.0-SNAPSHOT_3-0.5.0-SNAPSHOT-0/scala-native/zone/MemoryPool.c:58)
[error] >>>               /home/ale/scala-native/sandbox/.3/target/scala-3.3.1/native/dependencies/nativelib_native0.5.0-SNAPSHOT_3-0.5.0-SNAPSHOT-0/scala-native/zone/MemoryPool.c.o:(MemoryPool_reclaim)
[error] >>> referenced by LargeMemoryPool.c:64 (dependencies/nativelib_native0.5.0-SNAPSHOT_3-0.5.0-SNAPSHOT-0/scala-native/zone/LargeMemoryPool.c:64)
[error] >>>               /home/ale/scala-native/sandbox/.3/target/scala-3.3.1/native/dependencies/nativelib_native0.5.0-SNAPSHOT_3-0.5.0-SNAPSHOT-0/scala-native/zone/LargeMemoryPool.c.o:(LargeMemoryPool_reclaim)
[error] clang++: error: linker command failed with exit code 1 (use -v to see invocation)

@ekrich
Copy link
Member

ekrich commented Dec 20, 2023

Given the differences in Java 8 vs Java 11, 17, and 21 I would document that FreeBSD should use Java 11+. Most projects are dropping Java 8 and there is no sense in trying to support old stuff any way. Scala Native still uses Java 8 in CI but I would be for dropping it entirely.

I am sure you are doing clean between the builds of different configurations but thought I'd mention it just in case.

@alexdupre
Copy link
Contributor Author

I'm fine with requiring java 11+, but we need to find a good/agreed solution for the TestMain. The issue is that TestMain tries to connect to ::1 while the server is listening on tcp4 only. Simply removing the custom logic for FreeBSD, and trying to connect to 127.0.0.1 won't work either, because scala-native opens an AF_INET6 socket and BSD has disabled ipv6 mapped ipv4 addresses.

I see two solutions:

  1. remove the custom logic and set the java.net.preferIPv4Stack system property instead (for FreeBSD only), so that scala-native will open a AF_INET socket to connect to 127.0.0.1
  2. remove the custom logic and require the user to set sysctl net.inet6.ip6.v6only=0

I think the former is better, since it doesn't require any action by the user. It might break on an IPv6-only machine, though (not quite common).

@LeeTibbert
Copy link
Contributor

@alexdupre You have been busy & productive. Good to see.

There are a number of topic or work-items in this discussion so far. I think we need some way of
sorting them out and getting them inline (of priority).

My time is limited right now, but let me give some quick, and I hope helpful & encouraging, thoughts.

  1. I concur that FreeBSD could drop 32 bit support. This, and other FreeBSD restrictions and options,
    should be described in the ReadTheDocs documentation for supported operating systems. I think
    the FreeBSD section was previously left vague on purpose because the edges of the FreeBSD world
    were not known.

  2. re: restricting to JDK 11. If it has to be on FreeBSD, then fine. javalib does not have more
    partially complete (50%, 60%) Java 8 support. There are some Java > 8 parts implemented,
    but they are almost useless even further from completion. Requiring Java 11 (or better yet 17) across the board
    would almost certainly lead to many well-deserved complaints about "missing methods".

  3. I was waiting for this PR to merge before I started fixing unit-tests for FreeBSD.
    I had them running in October. I believe that was with Java 8 and IPv6.

    My suggestion is that we get this PR merged for Java 8, then correct the unit-tests on Java 8,
    then run them on Java > 8 (probably 21, because most of my systems have that). Because
    there is currently no FreeBSD CI, this PR can be merged even if not everything is fixed at once.

    That would allow me to look at the TestMain code for FreeBSD in action on my systems
    and "one problem at a time".

    It would also restore some working FreeBSD support whilst we work on other FreeBSD
    complexity.

  4. If FreeBSD is setting java.net.preferIPv4Stack=true on JDK > mumble, that is more than passing
    strange. I read/hear the report, but I need to understand the conditions (and possible FreeBSD discussions
    about the change.) I'd like to understand this better before we make strategic decisions.

@alexdupre
Copy link
Contributor Author

I think to have addressed all your concerns/suggestions in my latest commits.

The change to TestMain should make it working OOTB on FreeBSD with stock config and any java version.

For the records, with these changes and the boehm-threaded hack I was able to successfully run all tests of https://github.com/lampepfl/gears

As noted in another github issue some native tests don't currently terminate on FreeBSD.

The reason to have "java.net.preferIPv4Stack=true" by default on BSD derives from the fact that IPv4-mapped IPv6 addresses are disabled by default for security reasons (https://datatracker.ietf.org/doc/html/draft-cmetz-v6ops-v4mapped-api-harmful-01). On OpenBSD there isn't even the ability to re-enable them, AFAIK.
The comment in this commit will give you some very useful insight: battleblow/jdk11u@e1615c2
Later it was extended to all BSD platforms and not just to OpenBSD: battleblow/jdk11u@6e4f1d3
I'm not fully sure about the rationale behind such decision, but I think it's related to the fact that even when a dual mode socket was used, IPv4-mapped IPv6 addresses are still forbidden.

@ekrich
Copy link
Member

ekrich commented Dec 21, 2023

Please refer to our contributing docs for info about Java source code. https://scala-native.org/en/stable/contrib/contributing.html

docs/user/setup.rst Outdated Show resolved Hide resolved
docs/user/setup.rst Outdated Show resolved Hide resolved
@alexdupre
Copy link
Contributor Author

Please refer to our contributing docs for info about Java source code.

If you are referring to the Scala CLA I think I already signed it in the past. Anyway, I just signed it again.

@ekrich
Copy link
Member

ekrich commented Dec 21, 2023

I was mostly referring to the links supplied which seem to be pointing to OpenJDK code.

@alexdupre
Copy link
Contributor Author

I was mostly referring to the links supplied which seem to be pointing to OpenJDK code.

Well, those links have just the purpose to show the jdk code running on BSD platforms, no code has been brought into this PR.

@@ -31,53 +31,27 @@ object TestMain {
final val iPv4Loopback = "127.0.0.1"
final val iPv6Loopback = "::1"

private def getFreeBSDLoopbackAddr(): String = {
private def setFreeBSDWorkaround(): Unit = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "not allowing IPv4 mapped IPv6 addresses," does not match my memory of what was working for me circa 2023-10-15. When I take a run, hopefully soon, at fixing
unit-tests for FreeBSD, I will have to refresh my memory.

I believe I was running most unit-tests with an unmodified
TestMain on IPv6. If that was and continues to be true, this section may need to be re-worked in another PR.

I believe this edit can proceed because my only evidence is two month old memory.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fact that you had to introduce iPv6Loopback and use it on FreeBSD (even if openjdk8 on FreeBSD has dual mode sockets) was exactly because IPv4 mapped IPv6 addresses are forbidden, so using 127.0.0.1 on an AF_INET6 socket wasn't working.
If you enable them, then on Java8 there isn't anything else to do, but on java 11+ the server will continue to listen only on tcp4, unless java.net.preferIPv4Stack is explicitely set to false on sbt. Manually adjusting both settings seems much more complex than automatically push SN to use an IPv4 socket.

scripts/scalafmt Outdated Show resolved Hide resolved

*Note 3:* Using the boehm GC with multi-threaded binaries doesn't work
out-of-the-box yet.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that a number of Tests, primarily unit-tests, are known to not execute, it may be worthwhile to add a "Note 4" which says something like:
"
A number of Tests, primarily unit-tests, are known to fail
on FreeBSD. It is believed that the code-under-test is correct and that the defect is in the Test itself.

Work is underway to fix these tests. See PR 3625 for a list of tests known to fail at that time."

I/we could create an Issue, with checkboxes, which lists
the known failing tests (Java 8) and substitute that URL into the text above.

That way, we are saying what we are doing and doing what
we say.

The last PR in the series which fixes these tests would delete this Note. I usually dislike creating work items which have to be deleted later, but this work is in flux.

Your thoughts?

@alexdupre
Copy link
Contributor Author

I've pushed some other improvements, I think I'm done.

@LeeTibbert
Copy link
Contributor

LeeTibbert commented Dec 21, 2023

@alexdupre

Thank you for the info about FreeBSD dual stack.

Later: I read the referenced draft RFC from the turn of the century. I then read
thru a series of later proposed RFCs over the next decade or so dealing with IPv4-mapped-IPv6
addresses. None of them suggested deprecating such addresses.

       I think the next step is to see if one or more Java 21 JDK implementions do not handle such
       addresses on {Linux, macOS}. Do the C libraries?  I would expect the C libraries to do so.

For reference, the Java 20 (Networking Properties)[https://docs.oracle.com/en/java/javase/20/docs/api/java.base/java/net/doc-files/net-properties.html] says:

java.net.preferIPv4Stack (default: false)
If IPv6 is available on the operating system the underlying native socket will be, by default, an IPv6 socket which lets applications connect to, and accept connections from, both IPv4 and IPv6 hosts. However, in the case an application would rather use IPv4 only sockets, then this property can be set to true. The implication is that it will not be possible for the application to communicate with IPv6 only hosts.

Java 20 was the latest I found with a 20 second google search for Java 21. The quoted text is substantially
the same as the Java 8 text.

FreeBSD (and other BSD?) may be setting some OS properties outside of the JDK to force IPv4.
Guess this is complexity why networking people get paid the big bucks/euros.

@LeeTibbert
Copy link
Contributor

LeeTibbert commented Dec 21, 2023

I think this PR is almost done. The work you have put into evolutions shows.

I'd like to give Wojciech, who will probably be the one doing the merge,
a clear "Yes, this is ready" in a final reply here. That would mean that Wojciech would only have to
lightly read a productive but long conversation trail. I find that making things easier for the person
doing the merge means that the PR gets accepted sooner.

To move it towards conclusion and capture unresolved concerns, I suggest creating at least two formal
Issues (in addition to the "hanging unit-tests" report you yesterday-ish).
That will allow focused attention on each.

  1. One which says something like:
mumble
FreeBSD 12.4+
java > 11
IPv4-only, dual-stack?
mumble.  
  1. multi-thread boehm-gc link failure on BSD.

Your thoughts?

@alexdupre
Copy link
Contributor Author

Why do you think the IPv4/dual-stack issue is still unresolved? What would be the purpose of the new github issue?

I've contacted the boehm-gc maintainer today and I hope he'll change the package to install the threaded libraries with the standard name, as done by other OS, so no change will be needed by SN. I'm waiting for his feedback.

@LeeTibbert
Copy link
Contributor

Why do you think the IPv4/dual-stack issue is still unresolved? What would be the purpose of the new github issue?

The idea is to convince the person doing the merge is that "due diligence" has been done.

If there is an OS specific hack necessary, I would like to understand it. Not the least because such will
probably come back to haunt me.

I have read the reports of dual-stack dragon encounters and believe them. Forewarned is forearmed.

Having an Issue, from a person other than me, would help keep the issue from falling off the bottom of my
"I'd like to fix that" priority list. I am suggesting a 5-minutes-work place holder, probably referring to this PR,
not a three-day effort. I can create it if you like.

I've contacted the boehm-gc maintainer today and I hope he'll change the package to install the threaded libraries with the standard name, as done by other OS, so no change will be needed by SN. I'm waiting for his feedback.

Thank you for doing that. Please keep posted. It would be nice to not have to do anything here.

@@ -3,7 +3,7 @@
set -e

HERE="`dirname $0`"
VERSION=$(sed -nre "s#version[^0-9]+([0-9.]+)#\1#p" $HERE/../.scalafmt.conf)
VERSION=$(sed -nre "s#[[:space:]]*version[^0-9]+([0-9.]+)#\1#p" $HERE/../.scalafmt.conf)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry to repeat myself. Has this been run manually on Windows?
We, you & I, are going to win no friends if we break SN development on
Windows.

CI runs on Ubuntu Linux. Unless we know that this has been successfully manually run on Windows, we should assume it broken.

As mentioned, I can run this on Windows if such would be hard for you.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what's the build env on windows. I've tried on mingw64 and it worked, I don't know what exact sed implementation uses SN on Windows. To be 100% sure it's better if you try yourself.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that I look at this more closely, I realize that I am a goat, the barnyard critter, not the
"Greatest of all time" kind.

This is obviously a bash script, which will not run on plain Windows to begin with. Arrgh! 🤦
It might be run on WSL (linux on Windows), but any sed there should handle the POSIX
[[:space:]]

Sorry for the false trigger.

@alexdupre
Copy link
Contributor Author

#3629
#3630

@LeeTibbert
Copy link
Contributor

CI failure summary

TL;DR I believe the two failures and the several multi-arch warnings on Windows are unrelated to
the content of this PR.

The following breakage in this also occurs in merged PR #3626. Breakage may have entered
the main branch.

3 Multiarch warnings
"Exception calling "SetPageFileSize" with "3" argument(s): "The operation completed successfully"

2 runtime failures, TestMain loopback connection failing, but only on Scala 2 & Windows.

Exception in thread "main"java.net.SocketException: read failed, errno: 10054
	at java.net.AbstractPlainSocketImpl.read(Unknown Source)
	at java.net.SocketInputStream.read(Unknown Source)
Exception in thread "main"java.net.SocketException: read failed, errno: 10054
	at java.net.AbstractPlainSocketImpl.read(Unknown Source)

@LeeTibbert
Copy link
Contributor

@WojciechMazur

I believe this PR is ready for review & merge at your convenience.

There is a long & complicted conversation trail for this PR. The issues raised and not resolved in
the current PR are FreeBSD or BSD (possibly macOS) specific and should not affect Linux & Windows.
A formal SN Issue has been created for each, so they are not lost.

A number of unit-tests are known to fail on FreeBSD. That has an issue and is described
as a limitation in the setup.rst documentation for FreeBSD. From prior private work,
I believe these are failures in the Tests themselves, and not the underlying code.
Such things as OS specific device names and such.

When this PR is merged, I will peck away at merging my private unit-test fixes.

Copy link
Contributor

@WojciechMazur WojciechMazur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. The remaining CI failures have nothing to deal with this PR, I'm working on getting rid of them. It's great to see restored balance in the FreeBSD support. Hopefully one day we're be able to set up a CI to guard it continuously.

@WojciechMazur WojciechMazur merged commit 963666d into scala-native:main Dec 22, 2023
59 of 61 checks passed
WojciechMazur pushed a commit that referenced this pull request Jan 17, 2024
* Fix compilation on FreeBSD.
* Explicitly error out on unsupported platforms.
* Make the MAP_NORESERVE change specific for FreeBSD.
* Fix the sed expression to run on FreeBSD, too.
* Make the TestMain to run on all java versions on FreeBSD.
* Update the documentation for FreeBSD.
* Restore the ability to skip leading whitespaces in a more portable way.
* Add a note about failing tests.

(cherry picked from commit 963666d)
WojciechMazur pushed a commit that referenced this pull request Jan 19, 2024
* Fix compilation on FreeBSD.
* Explicitly error out on unsupported platforms.
* Make the MAP_NORESERVE change specific for FreeBSD.
* Fix the sed expression to run on FreeBSD, too.
* Make the TestMain to run on all java versions on FreeBSD.
* Update the documentation for FreeBSD.
* Restore the ability to skip leading whitespaces in a more portable way.
* Add a note about failing tests.

(cherry picked from commit 963666d)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants