Build fails on FreeBSD and NetBSD

Bug #159181 reported by Wolfram Fenske
4
Affects Status Importance Assigned to Milestone
Ikarus Scheme
Fix Released
Medium
Abdulaziz Ghuloum

Bug Description

On both FreeBSD 6.2 and NetBSD 3.1, the build fails with this error message:

====================================
Making all in scheme
../src/ikarus -b ./ikarus.boot.orig --r6rs-script makefile.ss
looking for foreign name ik_foreign_call
failed to find foreign name ik_foreign_call: Undefined symbol "ik_foreign_call"
*** Error code 255
====================================

$ uname -a

on those systems returns

====================================
NetBSD aix 3.1 NetBSD 3.1 (GENERIC.MPACPI) #0: Tue Oct 31 04:47:22 UTC 2006 <email address hidden>:/home/builds/ab/netbsd-3-1-RELEASE/i386/200610302053Z-obj/home/builds/ab/netbsd-3-1-RELEASE/src/sys/arch/i386/compile/GENERIC.MPACPI i386 i386 i386 NetBSD
====================================

and

====================================
FreeBSD hondo 6.2-STABLE FreeBSD 6.2-STABLE #0: Sun Sep 16 04:17:59 CEST 2007 wfenske@hondo:/usr/obj/usr/src/sys/WF_RELENG_6 i386
====================================

The message comes from src/ikarus-fasl.c. function ik_relocate_code().
Apparently the call dlsym(RTLD_DEFAULT, name) fails. I inserted another
debug message and it seems like "ik_foreign_call" is the first symbol dlsym
tries to locate. That means this piece of code doesn't work at all on FreeBSD
or NetBSD.

For comparison I built Ikarus on a Linux system and everything worked just
fine, as I expected.

Revision history for this message
Abdulaziz Ghuloum (aghuloum) wrote : Re: [Bug 159181] Build fails on FreeBSD and NetBSD

There is a flag that must be passed to gcc in order to make functions
in the executable visible to dlsym. On linux, it's "-rdynamic", and
on Mac OS, you don't need to do anything. I don't know what it is
for the bsds. If you know how to get gcc to compile the following
program such that the two printed lines show the same address, then
you'd have solved the problem. Otherwise, I'd have to look around
for a bsd machine to try to figure it out. Keep me posted.

Aziz,,,

#include <stdio.h>
#include <dlfcn.h>

int foo(int x){
   return x*x;
}

int main(int args, char** argv){
   printf("foo=0x%08x\n", (int)foo);
   printf("foo=0x%08x\n", (int)dlsym(RTLD_DEFAULT, "foo"));
   return 0;
}

Revision history for this message
Abdulaziz Ghuloum (aghuloum) wrote :

Googling around, it seems that you need to call gcc passing -Wl,-E
Try ./configure LDFLAGS=-Wl,-E
then make and see what happens.

Revision history for this message
Abdulaziz Ghuloum (aghuloum) wrote :
Revision history for this message
Wolfram Fenske (wolfram-fenske) wrote :

Hello!

Wow, that was fast!

Abdulaziz Ghuloum <email address hidden> schreibt:

> There is a flag that must be passed to gcc in order to make
> functions in the executable visible to dlsym. On linux, it's
> "-rdynamic", and

As it turns out it's the same on FreeBSD and NetBSD. Not too
surprising, though--after all the system cc on these systems is
gcc. :-)

I rebuilt Ikarus with CFLAGS set to '-rdynamic' and this time it went
through. Yeah! I don't know if you have a test suite or something,
but I get a REPL and typing in some basic expressions works as
expected. (This whole paragraph goes for both NetBSD and FreeBSD.)

Please, feel free to contact me if you ever want to test anything on
those OSes.

Also, congratulations on the release! And a native code compiler,
too!

I'm curious: is this part of a PhD thesis? Or is it something you do
in your free time? The reason I ask is this: I find programming
languages and compiler construction quite fascinating, and I
especially like Lispy languages (duh!). After finishing my master's
thesis I was thinking about doing a doctorate in that area, but I have
no clue what's currently going on there. The one thing I do know is
that somebody already did the "Erlang-style multiprocessing in Lisp"
thing[1], so that idea is pretty much gone. Since there is nobody at
my university that does research in that area, there aren't a whole
lot of people I can ask.

Greetings
Wolfram

Footnotes:
[1] Termite, see <http://lambda-the-ultimate.org/node/841>

Revision history for this message
Wolfram Fenske (wolfram-fenske) wrote : Re: [Bug 159181] Re: Build fails on FreeBSD and NetBSD

Abdulaziz Ghuloum <email address hidden> schreibt:

> Googling around, it seems that you need to call gcc passing -Wl,-E
> Try ./configure LDFLAGS=-Wl,-E
> then make and see what happens.

Yes, that works too (on both FreeBSD and NetBSD). In fact, it should
work on Linux as well. The manpages for ld say the same thing about
the `-E' (`--export-dynamic') option.

At least on the two BSDs, LDFLAGS="-Wl,-E" is probably better than
CFLAGS="-rdynamic". Both methods work, but `-rdynamic' isn't
documented in the gcc manpages on FreeBSD or NetBSD (it is on Linux).

Revision history for this message
Abdulaziz Ghuloum (aghuloum) wrote :

Would the fix shown in
http://codebrowse.launchpad.net/~aghuloum/ikarus/ikarus.main/revision/967
allow you to compile on the *bsd*s without having to pass the LDFLAGS?

Changed in ikarus:
assignee: nobody → aghuloum
importance: Undecided → Medium
status: New → Fix Committed
Revision history for this message
Wolfram Fenske (wolfram-fenske) wrote :

Abdulaziz Ghuloum <email address hidden> schreibt:

> Would the fix shown in
> http://codebrowse.launchpad.net/~aghuloum/ikarus/ikarus.main/revision/967
> allow you to compile on the *bsd*s without having to pass the
> LDFLAGS?

Yes, that works. No manual setting of LDFLAGS necessary anymore.
Tested on both NetBSD 3.1 and FreeBSD 6.2 with the system
compiler/linker. IMO this ticket should be closed. Thanks a lot!

Wolfram

Revision history for this message
Abdulaziz Ghuloum (aghuloum) wrote :

Will close with the next (0.0.2) release. Thanks a bunch.

Aziz,,,

Revision history for this message
Abdulaziz Ghuloum (aghuloum) wrote :

This bug report is about to be closed as the fix comitted previously
will be incorporated in the next 0.0.2 release of Ikarus Scheme,
scheduled for November 28, 2007.
A release candidate tarball is available for download from:
  http://www.cs.indiana.edu/~aghuloum/ikarus/ikarus-0.0.2-rc1.tar.gz
Please do test it if you have the time and report any issues you
might encounter. Thank you very much for your support. Aziz,,,
(Sorry for the duplicates; I'm updating every open bug.)

Changed in ikarus:
milestone: none → 0.0.2
Revision history for this message
Wolfram Fenske (wolfram-fenske) wrote :
Download full text (4.0 KiB)

Abdulaziz Ghuloum <email address hidden> writes:

[...]

> A release candidate tarball is available for download from:
> http://www.cs.indiana.edu/~aghuloum/ikarus/ikarus-0.0.2-rc1.tar.gz
> Please do test it if you have the time and report any issues you
> might encounter.

The build goes through on NetBSD. No special compiler flags are
needed.

On FreeBSD, however, it fails. The last lines of the build log are as
follows:

--8<---------------cut here---------------start------------->8---
gcc -I/opt/gmp-4.2.1/include -DNDEBUG -O3 -Wl,-E -L/opt/gmp-4.2.1/lib -Wl,-rpath,/opt/gmp-4.2.1/lib -o ikarus ikarus-collect.o ikarus-exec.o ikarus-fasl.o ikarus-flonums.o ikarus-main.o ikarus-numerics.o ikarus-print.o ikarus-runtime.o ikarus-symbol-table.o ikarus-verify-integrity.o ikarus-weak-pairs.o ikarus-winmmap.o ikarus-enter.o -lgmp -lgmp -lm
echo "#!/bin/sh" > scheme-script
echo "exec /opt/ikarus-0.0.2-rc1/bin/ikarus --r6rs-script \$@" >> scheme-script
Making all in scheme
echo "" >last-revision
echo '(define ikarus-version "0.0.2-rc1")' >ikarus.config.ss
echo '(define ikarus-revision "")' >>ikarus.config.ss
echo '(define ikarus-lib-dir "/opt/ikarus-0.0.2-rc1/lib/ikarus")' >>ikarus.config.ss
../src/ikarus -b ./ikarus.boot.orig --r6rs-script makefile.ss
*** Signal 11

Stop in /tmp/wfenske/build/ikarus-0.0.2-rc1/scheme.
*** Error code 1

Stop in /tmp/wfenske/build/ikarus-0.0.2-rc1.
*** Error code 1

Stop in /tmp/wfenske/build/ikarus-0.0.2-rc1.
--8<---------------cut here---------------end--------------->8---

Output of GDB:

--8<---------------cut here---------------start------------->8---
$ gdb src/ikarus scheme/ikarus.core
GNU gdb 6.1.1 [FreeBSD]
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "i386-marcel-freebsd"...(no debugging symbols found).
..
Core was generated by `ikarus'.
Program terminated with signal 11, Segmentation fault.

warning: current_sos: Can't read pathname for load map: Input/output error

Cannot access memory at address 0x468b075f
#0 0x2805c960 in ?? ()
(gdb) backtrace
#0 0x2805c960 in ?? ()
#1 0x00000b21 in ?? ()
#2 0x01bfddf4 in ?? ()
#3 0x2805c56a in ?? ()
#4 0x28082060 in ?? ()
#5 0x00000001 in ?? ()
#6 0x2807a8e0 in ?? ()
#7 0x281bc898 in ?? ()
#8 0x00000183 in ?? ()
#9 0x28081295 in ?? ()
#10 0xbfbfde28 in ?? ()
#11 0x2805ab29 in ?? ()
#12 0x28081000 in ?? ()
#13 0x00000018 in ?? ()
#14 0x280812a8 in ?? ()
#15 0x281bca60 in ?? ()
#16 0x00000002 in ?? ()
#17 0x00000216 in ?? ()
#18 0x28081000 in ?? ()
#19 0x00000018 in ?? ()
#20 0x0804dc87 in ik_relocate_code ()
Previous frame inner to this frame (corrupt stack?)
(gdb)
--8<---------------cut here---------------end--------------->8---

Configuration of this machine:

--8<---------------cut here---------------start------------->8---
$ uname -a
FreeBSD bsd62 6.2-RELEASE FreeBSD 6.2-RELEASE #0: Fri Jan 12 10:40:27 UTC 2007 <email address hidden>:/usr...

Read more...

Revision history for this message
Abdulaziz Ghuloum (aghuloum) wrote :

I've had no luck installing freebsd on vmware fusion so far. I'm still trying.

In the meanwhile, can you try a few things. I don't think this is a gmp problem, so we need to look elsewhere.

In configure.ac, comment out the line that says
CFLAGS="$CFLAGS -DNDEBUG -O3"
then make clean and make. This will generate lots of output but hopefully it might tell us more about where the problem lies. You can open a new bug report with the output.

Revision history for this message
Abdulaziz Ghuloum (aghuloum) wrote :

Okay, got it installed and figured out (kinda).

ikarus crashes inside the ld-elf.so library when it calls ldsym. I haven't figured out why yet but the problem here is actually related to this bug. I managed to get it to build by doing:

$ ./configure
$ LD_BIND_NOW=yes make

But I need to figure out why this is happening and how to get rid of it.

Changed in ikarus:
status: Fix Committed → In Progress
Revision history for this message
Abdulaziz Ghuloum (aghuloum) wrote :

Hey, launchpad is down so I'm emailing you directly.

I fixed the problem with FreeBSD, which was not fun and all my fault.
The fix is in revision 1128 in the master repository. Please do
check it out at your convenience. Thanks!

Aziz,,,

Revision history for this message
Abdulaziz Ghuloum (aghuloum) wrote :

Fixed again in revision 1028.

Changed in ikarus:
status: In Progress → Fix Committed
Revision history for this message
Wolfram Fenske (wolfram-fenske) wrote :

Abdulaziz Ghuloum <email address hidden> schreibt:

[...]

> I fixed the problem with FreeBSD, which was not fun and all my
> fault. The fix is in revision 1128 in the master repository.
> Please do check it out at your convenience.

I checked out revision 1131 yesterday and it builds without problems.
Happy happy, joy joy! :-) This version continues to work on NetBSD,
too. Good job!

Wolfram

Changed in ikarus:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.