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

Detect tool fails on OpenBSD: undefined symbol: __fe_dfl_env #12138

Closed
euantorano opened this issue Sep 5, 2019 · 6 comments · Fixed by #14672
Closed

Detect tool fails on OpenBSD: undefined symbol: __fe_dfl_env #12138

euantorano opened this issue Sep 5, 2019 · 6 comments · Fixed by #14672

Comments

@euantorano
Copy link
Contributor

euantorano commented Sep 5, 2019

The tools/detect/detect.nim tool fails on OpenBSD with the following output:

(note, egcc is in the logs rather than gcc as that's the name of the newer version GCC installed via ports on OpenBSD - I've manually modified the detect.nim file to reference this rather than the hard-coded gcc).

CMD egcc -o testh testh.c
testh.c:1:10: fatal error: aio.h: No such file or directory
 #include <aio.h>
          ^~~~~~~
compilation terminated.
Not found: <aio.h>
CMD egcc -o testh testh.c
Found: <dlfcn.h>
CMD egcc -o testh testh.c
Found: <errno.h>
CMD egcc -o testh testh.c
Found: <fcntl.h>
CMD egcc -o testh testh.c
Found: <fenv.h>
CMD egcc -o testh testh.c
testh.c:1:10: fatal error: fmtmsg.h: No such file or directory
 #include <fmtmsg.h>
          ^~~~~~~~~~
compilation terminated.
Not found: <fmtmsg.h>
CMD egcc -o testh testh.c
Found: <fnmatch.h>
CMD egcc -o testh testh.c
Found: <ftw.h>
CMD egcc -o testh testh.c
Found: <glob.h>
CMD egcc -o testh testh.c
Found: <langinfo.h>
CMD egcc -o testh testh.c
Found: <locale.h>
CMD egcc -o testh testh.c
Found: <netdb.h>
CMD egcc -o testh testh.c
Found: <net/if.h>
CMD egcc -o testh testh.c
Found: <netinet/in.h>
CMD egcc -o testh testh.c
In file included from testh.c:1:
/usr/include/netinet/tcp.h:42:9: error: unknown type name 'u_int32_t'
 typedef u_int32_t tcp_seq;
         ^~~~~~~~~
/usr/include/netinet/tcp.h:49:2: error: unknown type name 'u_int16_t'
  u_int16_t th_sport;  /* source port */
  ^~~~~~~~~
/usr/include/netinet/tcp.h:50:2: error: unknown type name 'u_int16_t'
  u_int16_t th_dport;  /* destination port */
  ^~~~~~~~~
/usr/include/netinet/tcp.h:54:2: error: unknown type name 'u_int32_t'
  u_int32_t th_x2:4,  /* (unused) */
  ^~~~~~~~~
/usr/include/netinet/tcp.h:58:2: error: unknown type name 'u_int32_t'
  u_int32_t th_off:4,  /* data offset */
  ^~~~~~~~~
/usr/include/netinet/tcp.h:61:2: error: unknown type name 'u_int8_t'
  u_int8_t  th_flags;
  ^~~~~~~~
/usr/include/netinet/tcp.h:70:2: error: unknown type name 'u_int16_t'
  u_int16_t th_win;   /* window */
  ^~~~~~~~~
/usr/include/netinet/tcp.h:71:2: error: unknown type name 'u_int16_t'
  u_int16_t th_sum;   /* checksum */
  ^~~~~~~~~
/usr/include/netinet/tcp.h:72:2: error: unknown type name 'u_int16_t'
  u_int16_t th_urp;   /* urgent pointer */
  ^~~~~~~~~
/usr/include/netinet/tcp.h:58:12: error: duplicate member 'th_off'
  u_int32_t th_off:4,  /* data offset */
            ^~~~~~
/usr/include/netinet/tcp.h:59:5: error: duplicate member 'th_x2'
     th_x2:4;  /* (unused) */
     ^~~~~
Not found: <netinet/tcp.h>
CMD egcc -o testh testh.c
Found: <nl_types.h>
CMD egcc -o testh testh.c
Found: <poll.h>
CMD egcc -o testh testh.c
Found: <pthread.h>
CMD egcc -o testh testh.c
Found: <sched.h>
CMD egcc -o testh testh.c
Found: <semaphore.h>
CMD egcc -o testh testh.c
Found: <signal.h>
CMD egcc -o testh testh.c
Found: <sys/ipc.h>
CMD egcc -o testh testh.c
Found: <sys/mman.h>
CMD egcc -o testh testh.c
Found: <sys/resource.h>
CMD egcc -o testh testh.c
Found: <sys/select.h>
CMD egcc -o testh testh.c
Found: <sys/socket.h>
CMD egcc -o testh testh.c
Found: <sys/stat.h>
CMD egcc -o testh testh.c
Found: <sys/statvfs.h>
CMD egcc -o testh testh.c
Found: <sys/wait.h>
CMD egcc -o testh testh.c
Found: <spawn.h>
CMD egcc -o testh testh.c
Found: <stdio.h>
CMD egcc -o testh testh.c
Found: <time.h>
CMD egcc -o testh testh.c
Found: <unistd.h>
CMD egcc -o genconsts genconsts.c
ld: error: undefined symbol: __fe_dfl_env
>>> referenced by genconsts.c
>>>               /tmp//cc8BjmtD.o:(main)
collect2: error: ld returned 1 exit status
Error: execution of an external program failed: '/home/administrator/build/Nim/tools/detect/detect '
@euantorano euantorano changed the title Detect tool fials on OpenBSD: undefined symbol: __fe_dfl_env Detect tool fails on OpenBSD: undefined symbol: __fe_dfl_env Sep 5, 2019
@j-bm
Copy link
Contributor

j-bm commented May 6, 2020

The missing symbol can be found in the math library - linking requires -lm.

Note: the correct compiler to use is cc. Most OpenBSD platforms (including amd64, arm64, mips64, sparc64) use clang and cc is clang.

I have a patch for this and once I can reliably do a pr (I'm new to git) I'll submit it.

@euantorano
Copy link
Contributor Author

Awesome, thanks @j-bm. I've since updated the Nim config to use clang as the compiler, but didn't re-visit this issue after doing so.

@lbartoletti
Copy link
Contributor

@euantorano I encountered a similar problem on FreeBSD (context: I can only compile nimterop with gcc which runs g++ because clang does not run clang++) I'm going to open a ticket (or on the forum, as the problem may be larger).

@euantorano
Copy link
Contributor Author

@lbartoletti Ah, since you're here could you please try just compiling and running detect on FreeBSD if you have a moment? I haven't tested that yet: nim c -r tools/detect/detect.nim. You should end up with some definition files (on OpenBSD these are named openbsd_amd64_consts.nim and other_consts.nim).

I've not played with nimterop at all, but that does sound like a problem. A forum thread may be easiest to try and track it down.

@lbartoletti
Copy link
Contributor

nim c -r tools/detect/detect.nim returns

CMD gcc -o testh testh.c
sh: gcc: not found

Because "gcc" doesn't exists it always suffixed with the major version number so it's gcc9 for me. But if I symlink gcc9 to gcc it returns:

Hint: 37162 LOC; 3.844 sec; 57.578MiB peakmem; Debug build; proj: /usr/home/lbartoletti/prog/nim/nim-lang/tools/detect/detect.nim; out: /usr/home/lbartoletti/prog/nim/nim-lang/tools/detect/detect [SuccessX]
Hint: /usr/home/lbartoletti/prog/nim/nim-lang/tools/detect/detect  [Exec]
CMD gcc -o testh testh.c
Found: <aio.h>
CMD gcc -o testh testh.c
Found: <dlfcn.h>
CMD gcc -o testh testh.c
Found: <errno.h>
CMD gcc -o testh testh.c
Found: <fcntl.h>
CMD gcc -o testh testh.c
Found: <fenv.h>
CMD gcc -o testh testh.c
Found: <fmtmsg.h>
CMD gcc -o testh testh.c
Found: <fnmatch.h>
CMD gcc -o testh testh.c
Found: <ftw.h>
CMD gcc -o testh testh.c
Found: <glob.h>
CMD gcc -o testh testh.c
Found: <langinfo.h>
CMD gcc -o testh testh.c
Found: <locale.h>
CMD gcc -o testh testh.c
Found: <netdb.h>
CMD gcc -o testh testh.c
Found: <net/if.h>
CMD gcc -o testh testh.c
Found: <netinet/in.h>
CMD gcc -o testh testh.c
Found: <netinet/tcp.h>
CMD gcc -o testh testh.c
Found: <nl_types.h>
CMD gcc -o testh testh.c
Found: <poll.h>
CMD gcc -o testh testh.c
Found: <pthread.h>
CMD gcc -o testh testh.c
Found: <sched.h>
CMD gcc -o testh testh.c
Found: <semaphore.h>
CMD gcc -o testh testh.c
Found: <signal.h>
CMD gcc -o testh testh.c
Found: <sys/ipc.h>
CMD gcc -o testh testh.c
Found: <sys/mman.h>
CMD gcc -o testh testh.c
Found: <sys/resource.h>
CMD gcc -o testh testh.c
Found: <sys/select.h>
CMD gcc -o testh testh.c
Found: <sys/socket.h>
CMD gcc -o testh testh.c
Found: <sys/stat.h>
CMD gcc -o testh testh.c
Found: <sys/statvfs.h>
CMD gcc -o testh testh.c
Found: <sys/wait.h>
CMD gcc -o testh testh.c
Found: <spawn.h>
CMD gcc -o testh testh.c
Found: <stdio.h>
CMD gcc -o testh testh.c
Found: <time.h>
CMD gcc -o testh testh.c
Found: <unistd.h>
CMD gcc -o genconsts genconsts.c
/usr/local/bin/ld : /tmp//ccdsfnVM.o : dans la fonction « main » :
genconsts.c:(.text+0xe78) : référence indéfinie vers « __fe_dfl_env »
collect2: error: ld returned 1 exit status
Error: execution of an external program failed: '/usr/home/lbartoletti/prog/nim/nim-lang/tools/detect/detect '

And if I change when defined(openbsd) to when defined(openbsd) or defined(freebsd):

CMD cc -o genconsts genconsts.c
genconsts.c:472:48: warning: format specifies type 'int' but the argument has type 'const fenv_t *' [-Wformat]
  fprintf(f, "const FE_DFL_ENV* = cint(%d)\n", FE_DFL_ENV);
                                       ~~      ^~~~~~~~~~
/usr/include/fenv.h:99:20: note: expanded from macro 'FE_DFL_ENV'
#define FE_DFL_ENV      (&__fe_dfl_env)
                        ^~~~~~~~~~~~~~~
genconsts.c:1208:58: warning: format specifies type 'int' but the argument has type '__sighandler_t *' (aka 'void (*)(int)') [-Wformat]
  fprintf(f, "const SIG_HOLD* = cast[Sighandler](%d)\n", SIG_HOLD);
                                                 ~~      ^~~~~~~~
/usr/include/sys/signal.h:143:25: note: expanded from macro 'SIG_HOLD'
#define SIG_HOLD        ((__sighandler_t *)3)
                        ^~~~~~~~~~~~~~~~~~~~~
genconsts.c:1211:57: warning: format specifies type 'int' but the argument has type '__sighandler_t *' (aka 'void (*)(int)') [-Wformat]
  fprintf(f, "const SIG_DFL* = cast[Sighandler](%d)\n", SIG_DFL);
                                                ~~      ^~~~~~~
/usr/include/sys/signal.h:139:18: note: expanded from macro 'SIG_DFL'
#define SIG_DFL         ((__sighandler_t *)0)
                        ^~~~~~~~~~~~~~~~~~~~~
genconsts.c:1214:57: warning: format specifies type 'int' but the argument has type '__sighandler_t *' (aka 'void (*)(int)') [-Wformat]
  fprintf(f, "const SIG_ERR* = cast[Sighandler](%d)\n", SIG_ERR);
                                                ~~      ^~~~~~~
/usr/include/sys/signal.h:141:18: note: expanded from macro 'SIG_ERR'
#define SIG_ERR         ((__sighandler_t *)-1)
                        ^~~~~~~~~~~~~~~~~~~~~~
genconsts.c:1217:57: warning: format specifies type 'int' but the argument has type '__sighandler_t *' (aka 'void (*)(int)') [-Wformat]
  fprintf(f, "const SIG_IGN* = cast[Sighandler](%d)\n", SIG_IGN);
                                                ~~      ^~~~~~~
/usr/include/sys/signal.h:140:18: note: expanded from macro 'SIG_IGN'
#define SIG_IGN         ((__sighandler_t *)1)
                        ^~~~~~~~~~~~~~~~~~~~~
genconsts.c:1230:49: warning: format specifies type 'int' but the argument has type 'key_t' (aka 'long') [-Wformat]
  fprintf(f, "const IPC_PRIVATE* = cint(%d)\n", IPC_PRIVATE);
                                        ~~      ^~~~~~~~~~~
                                        %ld
/usr/include/sys/ipc.h:110:21: note: expanded from macro 'IPC_PRIVATE'
#define IPC_PRIVATE     (key_t)0 /* private key */
                        ^~~~~~~~
genconsts.c:1582:54: warning: format specifies type 'long' but the argument has type 'int' [-Wformat]
  fprintf(f, "const CLOCKS_PER_SEC* = clong(%ld)\n", CLOCKS_PER_SEC);
                                            ~~~      ^~~~~~~~~~~~~~
                                            %d
/usr/include/time.h:59:24: note: expanded from macro 'CLOCKS_PER_SEC'
#define CLOCKS_PER_SEC  128
                        ^~~
7 warnings generated.
ld: error: undefined symbol: __fe_dfl_env
>>> referenced by genconsts.c
>>>               /tmp/genconsts-bbcb1a.o:(main)
cc: error: linker command failed with exit code 1 (use -v to see invocation)
Error: execution of an external program failed: '/usr/home/lbartoletti/prog/nim/nim-lang/tools/detect/detect '

@euantorano
Copy link
Contributor Author

Interesting, I'll have to open another issue for that and see if I can fix it. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants