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

[racketcs] make cs does not work on FreeBSD #2344

Closed
abmclin opened this issue Oct 29, 2018 · 26 comments
Closed

[racketcs] make cs does not work on FreeBSD #2344

abmclin opened this issue Oct 29, 2018 · 26 comments
Labels
build Build failures, Makefiles, Zuo scripts, autoconf, building instructions, etc. platform:bsd BSD specific topics racket-cs Specific to Racket-on-Chez

Comments

@abmclin
Copy link
Contributor

abmclin commented Oct 29, 2018

Firstly, is it planned for Racket-on-Chez to be supported on BSD family operating systems?

If so here's a summary of all the issues I've found. I took make cs as far as I was able with my level of experience. It appears that the issues I ran into seem to be only arising from ChezScheme.

I'm running GhostBSD which is based on 64-bit FreeBSD kernel 11.1.

The first issue encountered is missing boot files for ta6fb architecture. As explained in cisco/ChezScheme#7 BSD boot files are not built by default. Following the recommended method in the issue comments, I cross-compiled and copied the missing boot files to my FreeBSD machine which allows make to continue.

Second issue is ChezScheme's makefiles are only compatible with GNU make, to work around that I aliased make with gmake

The third issue and this is as far as I got, is a compilation error occurring when compiling io.sls an attempt is made to load libc.so which fails with invalid file format error. In FreeBSD variants, libc.so is a linker script which resolves to libc.so.7 Apparently the linker doesn't know how to handle the FreeBSD case.

In case this is relevant, I see some code in ChezScheme/mats/foreign.ms which attempts to deal with loading libc.so on FreeBSD machines.

If RacketCS won't be supported on BSD family in the foreseeable future - which I hope won't be the case, then feel free to close this issue. Though I will continue to advocate for BSD support :-)

mflatt added a commit that referenced this issue Oct 30, 2018
Have the main Racket executable export a function to get errno, which
avoids portability problems trying to access it via the FFI.

Related to #2344
mflatt added a commit that referenced this issue Oct 30, 2018
@mflatt
Copy link
Member

mflatt commented Oct 30, 2018

Does b9c0423 let you use gmake cs (as opposed to having to globally redirect make to gmake), or is there still some other issue with gmake cs?

@abmclin
Copy link
Contributor Author

abmclin commented Oct 30, 2018

with the latest commits gmake cs continues some more but there's a new issue with ld not finding libiconv during a compilation step.

I've attached a file of the last 50 lines of gmake cs output. The entire output is a 183 MB file, let me know if you want all of it.
truncated_out.txt

@abmclin
Copy link
Contributor Author

abmclin commented Oct 30, 2018

As far as I can tell libiconv is installed on my system.

ldconfig -r | grep libiconv returns liconv.2 => /usr/local/lib/libiconv.so.2

@samth
Copy link
Member

samth commented Oct 30, 2018

From that output, it looks like Chez (or maybe Racket) is looking for libiconv without a version. Is there a package you can install that has the unversioned .so file?

@abmclin
Copy link
Contributor Author

abmclin commented Oct 30, 2018

I searched for the locations of libiconv and found below

-rw-r--r--  1 root  wheel  1137432 Oct 10  2017 /usr/local/lib/libiconv.a
lrwxr-xr-x  1 root  wheel       17 Oct 10  2017 /usr/local/lib/libiconv.so -> libiconv.so.2.5.1
lrwxr-xr-x  1 root  wheel       17 Oct 10  2017 /usr/local/lib/libiconv.so.2 -> libiconv.so.2.5.1
-rw-r--r--  1 root  wheel  1076457 Oct 10  2017 /usr/local/lib/libiconv.so.2.5.1

libiconv.so is in /usr/local/lib/ and soft linked to libiconv.so.2.5.1 I'm wondering if the problem is that the library isn't in /usr/lib/ which seems to be preferred location in GNU/Linux systems. Maybe a viable approach is to configure LD_LIBRARY_PATH with additional information?

@abmclin
Copy link
Contributor Author

abmclin commented Oct 30, 2018

When I manually edit racket/src/cs/c/Makefile.in to append -L /usr/local/lib -liconv to LIBS variable, gmake cs is able to proceed a bit further before hitting another error

cc -g -O2   -pthread -I/home/abm/Workspace/git/racket/racket/src/build/ChezScheme/ta6fb/boot/ta6fb -I../../cs/c/../../rktio -Irktio -I. -o raw_racketcs main.o boot.o /home/abm/Workspace/git/racket/racket/src/build/ChezScheme/ta6fb/boot/ta6fb/kernel.o rktio/librktio.a -pthread -lm  -L /usr/local/lib -liconv
main.o: In function `bytes_main':
/home/abm/Workspace/git/racket/racket/src/build/cs/../../cs/c/main.c:190: undefined reference to `get_self_path'
cc: error: linker command failed with exit code 1 (use -v to see invocation)
gmake[8]: *** [Makefile:145: raw_racketcs] Error 1
gmake[8]: Leaving directory '/usr/home/abm/Workspace/git/racket/racket/src/build/cs'
gmake[7]: *** [Makefile:50: cs] Error 2
gmake[7]: Leaving directory '/usr/home/abm/Workspace/git/racket/racket/src/build/cs'
gmake[6]: *** [Makefile:331: cs-after-racket-with-abs-paths] Error 2
gmake[6]: Leaving directory '/usr/home/abm/Workspace/git/racket'
gmake[5]: *** [Makefile:327: cs-after-racket-with-racket-and-scheme-src] Error 2
gmake[5]: Leaving directory '/usr/home/abm/Workspace/git/racket'
gmake[4]: *** [Makefile:321: cs-after-racket-with-racket] Error 2
gmake[4]: Leaving directory '/usr/home/abm/Workspace/git/racket'
gmake[3]: *** [Makefile:308: racket-configured-then-cs] Error 2
gmake[3]: Leaving directory '/usr/home/abm/Workspace/git/racket'
gmake[2]: *** [Makefile:302: racket-then-cs] Error 2
gmake[2]: Leaving directory '/usr/home/abm/Workspace/git/racket'
gmake[1]: *** [Makefile:275: plain-cs] Error 2
gmake[1]: Leaving directory '/usr/home/abm/Workspace/git/racket'
gmake: *** [Makefile:269: cs] Error 2

Looks like need to define get_self_path for FreeBSD, googling around shows a possible method for finding executable's own path on FreeBSD at this SlackOverflow URL https://stackoverflow.com/a/1024937

@abmclin
Copy link
Contributor Author

abmclin commented Oct 31, 2018

I have a proposed definition of get_self_path It seems to work in my obvious test cases.

I may be being too defensive in my code but here it is.

#if defined(__FreeBSD__)
# include <sys/sysctl.h>
# include <errno.h>
static char *get_self_path()
{
  int mib[4];
  char *s;
  size_t len;
  int r;

  mib[0] = CTL_KERN;
  mib[1] = KERN_PROC;
  mib[2] = KERN_PROC_PATHNAME;
  mib[3] = -1;

  r = sysctl(mib, 4, NULL, &len, NULL, 0);
  if (r < 0) {
      fprintf(stderr, "failed to get self (%d)\n", errno);
      exit(1);
  }
  s = malloc(len);
  r = sysctl(mib, 4, s, &len, NULL, 0);
  if (r < 0) {
      fprintf(stderr, "failed to get self (%d)\n", errno);
      exit(1);
  }
  return s;
}
#endif

With the above definition added to racket/src/cs/c/main.c gmake cs continues until racketcs tries to perform raco setup then it errors out with malformed fasl-object header in petite

gmake[11]: Entering directory '/usr/home/abm/Workspace/git/racket/racket/src/build'
if [ "" = "" ]; then \
  echo "/home/abm/Workspace/git/racket/racket/lib"; \
fi
/home/abm/Workspace/git/racket/racket/lib
gmake[11]: Leaving directory '/usr/home/abm/Workspace/git/racket/racket/src/build'
gmake[10]: Leaving directory '/usr/home/abm/Workspace/git/racket/racket/src/build'
cd cs; gmake setup-install
gmake[10]: Entering directory '/usr/home/abm/Workspace/git/racket/racket/src/build/cs'
/home/abm/Workspace/git/racket/racket/bin/racketcs -G /home/abm/Workspace/git/racket/racket/src/build -N raco -l- raco setup 
malformed fasl-object header in petite
gmake[10]: *** [Makefile:218: setup-install] Error 1
gmake[10]: Leaving directory '/usr/home/abm/Workspace/git/racket/racket/src/build/cs'
gmake[9]: *** [Makefile:258: install-cs-common] Error 2
gmake[9]: Leaving directory '/usr/home/abm/Workspace/git/racket/racket/src/build'
gmake[8]: *** [Makefile:262: install-racketcs] Error 2
gmake[8]: Leaving directory '/usr/home/abm/Workspace/git/racket/racket/src/build'
gmake[7]: *** [Makefile:268: install-cs] Error 2
gmake[7]: Leaving directory '/usr/home/abm/Workspace/git/racket/racket/src/build'
gmake[6]: *** [Makefile:333: cs-after-racket-with-abs-paths] Error 2
gmake[6]: Leaving directory '/usr/home/abm/Workspace/git/racket'
gmake[5]: *** [Makefile:327: cs-after-racket-with-racket-and-scheme-src] Error 2
gmake[5]: Leaving directory '/usr/home/abm/Workspace/git/racket'
gmake[4]: *** [Makefile:321: cs-after-racket-with-racket] Error 2
gmake[4]: Leaving directory '/usr/home/abm/Workspace/git/racket'
gmake[3]: *** [Makefile:308: racket-configured-then-cs] Error 2
gmake[3]: Leaving directory '/usr/home/abm/Workspace/git/racket'
gmake[2]: *** [Makefile:302: racket-then-cs] Error 2
gmake[2]: Leaving directory '/usr/home/abm/Workspace/git/racket'
gmake[1]: *** [Makefile:275: plain-cs] Error 2
gmake[1]: Leaving directory '/usr/home/abm/Workspace/git/racket'
gmake: *** [Makefile:269: cs] Error 2

@mflatt
Copy link
Member

mflatt commented Jun 12, 2019

Although there's a generic Unix get_self_path in place, now, I think it would be a good idea to use your specialization. Can you turn this into a PR? It may be as easy as pasting in your code with an exttra # undef USE_GENERIC_GET_SELF_PATH before the #endif.

The "malformed fasl-object header in petite" problem is probably because the strip operation on install moved the embedded boot files within the executable. I've adjusted the configure script to turn on ELF support for finding embedded boot files, so strip now works.

@mflatt
Copy link
Member

mflatt commented Jun 12, 2019

Also, in case you didn't know already: You won't have to build Chez Scheme boot files, anymore. They will be built automatically (via Racket running Chez Scheme's compiler).

@abmclin
Copy link
Contributor Author

abmclin commented Jun 12, 2019

Although there's a generic Unix get_self_path in place, now, I think it would be a good idea to use your specialization. Can you turn this into a PR? It may be as easy as pasting in your code with an exttra # undef USE_GENERIC_GET_SELF_PATH before the #endif.

Sure, I'd be happy to do that.

@abmclin
Copy link
Contributor Author

abmclin commented Jun 12, 2019

In addition, I also found that with gcc version 7 and above -Wextra now includes a new -Wimplicit-fallthrough raising warnings about implicit fallthroughs which stops compilation of schsig.c in ChezScheme codebase. It can be resolved by modifying the FreeBSD makefiles in the ChezScheme to include -Wno-implicit-fallthrough in the cc options which turns off the new check.

I don't know if this also affects OpenBSD and NetBSD, I imagine it probably does since the makefiles for those platforms doesn't have the new option.

I can open another PR with the above fix. It probably is better to open the PR against cisco\ChezScheme and it can be merged downstream into racket\ChezScheme, right?

@abmclin
Copy link
Contributor Author

abmclin commented Jun 12, 2019

Just to comment for the sake of the discussion, with the recent Makefile changes, racket\ChezScheme and the above -Wno-implicit-fallthrough fix for gcc v7+ make cs is successful on FreeBSD variants including TrueOS.

The malformed fasl-object header error has gone away too so your guess about its cause is probably correct.

@mflatt
Copy link
Member

mflatt commented Jun 12, 2019

Yes, if you post a PR to Chez Scheme, I can pick it up early for the Racket fork.

I think a better solution for GCC 7+ is to adjust the source instead of changing the warning flags. Of the options illustrated at https://developers.redhat.com/blog/2017/03/10/wimplicit-fallthrough-in-gcc-7/, the comment one looks most appealing to me — hacky, but simple and portable.

@abmclin
Copy link
Contributor Author

abmclin commented Jun 12, 2019

I like the idea of adding a comment to the source code. It should work automatically for wide variety of platform, making this approach more robust.

Just to make sure we're looking at the same comment, the one you have in mind is /* Falls through. */?

@mflatt
Copy link
Member

mflatt commented Jun 12, 2019

Yes — that comment or any accepted variant that looks nice to you.

@abmclin
Copy link
Contributor Author

abmclin commented Jun 12, 2019

Hmm, looking at the relevant lines in schsig.c under handle_signal https://github.com/cisco/ChezScheme/blob/master/c/schsig.c#L587-L610 that's causing the implicit fall through warning, I think adding fallthrough comments would be misleading because it appears that each case ends in non-returning function calls (I could be wrong about what those S_* functions are doing) so they don't actually fall through to the next case. It looks like a false positive gcc warning to me.

Looks like we're stuck with editing the makefiles instead. Thoughts?

@samth
Copy link
Member

samth commented Jun 12, 2019

If they don't return, could you add a break after them?

@abmclin
Copy link
Contributor Author

abmclin commented Jun 12, 2019

Yes that seems to work, I'll continue building and run some tests just to be sure.

@pmatos
Copy link
Collaborator

pmatos commented Jun 13, 2019

Hi... I need to intervene here since I am looking at something that looks potentially related. I think this is related to racket/ChezScheme#8

The functions that do not return should be marked with noreturn. That fixes at least part of the issues. Problem is that GCC8 (maybe 7 as well) something like this will happen with certain optimization flags:

scheme.c: In function ‘find_boot’:
scheme.c:637:8: error: ‘n’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
     if (n != scheme_version) {

That's warning is a false positive. GCC can't know that because it doesn't know that the previous call to S_abnormal_exit won't return. I would really like this to be fixed properly upstream since it sorts out a bunch of problems. The current issue is defining a macro that works for both GCC, Clang and MSVC. Both GCC and Clang support __attribute__((noreturn)). MSVC doesn't, as pointed out by Matthew. We need an alternative but I haven't had the time to research this yet.

At the moment I am working on JSC, the JavaScript compiler in WebKit and I see this code here:

/* NO_RETURN */

#if !defined(NO_RETURN) && COMPILER(GCC_COMPATIBLE)
#define NO_RETURN __attribute((__noreturn__))
#endif

#if !defined(NO_RETURN) && COMPILER(MSVC)
#define NO_RETURN __declspec(noreturn)
#endif

#if !defined(NO_RETURN)
#define NO_RETURN
#endif

Maybe for Racket/Chez we can do (untested):

#if !defined(NORETURN)
#if defined(__GNUC__) || defined(__clang__)
#define NORETURN __attribute__((noreturn))
#elif defined(_MSC_VER)
#define NORETURN __declspec(noreturn)
#else 
#define NORETURN
#endif /* defined(__GNUC__) || defined(__clang__) */
#endif /* !defined(NORETURN) */

@abmclin
Copy link
Contributor Author

abmclin commented Jun 13, 2019

I’ll be happy to give that a try, it does seem like a good approach to take here. I will report back soon.

Thank you.

@pmatos
Copy link
Collaborator

pmatos commented Jun 13, 2019

I should point out I haven't tested the above code or ensured it actually solves your problem. I just typed that from memory because it looked similar to a problem I was looking at a couple of days ago. Please confirm it actually solves this particular issue. :)

@abmclin
Copy link
Contributor Author

abmclin commented Jun 14, 2019

@pmatos your suggestion worked, all implicit-fallthrough warnings were removed by adding NORETURN to appropriate places. And turns out it was also necessary to add /* fall through */ in other places.

I've opened a PR against cisco/ChezScheme cisco/ChezScheme#437

mflatt added a commit to mflatt/ChezScheme that referenced this issue Jun 21, 2019
mflatt added a commit to mflatt/racket that referenced this issue Jul 27, 2020
@pmatos did all the work here in racket/ChezScheme#8 and
racket#2344.

original commit: 2e3a618b0072d547b6c5abe6dd8dbac36a98c10e
mflatt added a commit to racket/ChezScheme that referenced this issue Mar 24, 2021
@DavidAlphaFox
Copy link

config.log

Hi
I try to compile the Racket CS on FreeBSD machine.
I saw this config.log, but I pasted the test code in a file, built and ran it alone, it could give a correct value.

Thanks

@samth
Copy link
Member

samth commented Apr 2, 2021

@DavidAlphaFox It looks like your system can't find libiconv. Do you have that installed?

@DavidAlphaFox
Copy link

DavidAlphaFox commented Apr 2, 2021

@samth

Thanks for reply
I found the problem, I should use gmake instead of make.
And I installed Racket CS 8.0 on FreeBSD 12.2-RELEASE successfully.

@mflatt
Copy link
Member

mflatt commented Apr 27, 2021

I think we have CS build ok on FreeBSD (yes, with gmake), so I'll close this.

@mflatt mflatt closed this as completed Apr 27, 2021
mflatt added a commit to mflatt/ChezScheme that referenced this issue Oct 10, 2023
mflatt added a commit to mflatt/ChezScheme that referenced this issue Oct 10, 2023
@shhyou shhyou added racket-cs Specific to Racket-on-Chez build Build failures, Makefiles, Zuo scripts, autoconf, building instructions, etc. platform:bsd BSD specific topics labels Nov 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build Build failures, Makefiles, Zuo scripts, autoconf, building instructions, etc. platform:bsd BSD specific topics racket-cs Specific to Racket-on-Chez
Projects
None yet
Development

No branches or pull requests

6 participants