Difficulties building Coco and liblua.so

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Difficulties building Coco and liblua.so

Jim Pryor-2-3
Hi I'm having some difficulties building Coco 1.1.5 against Lua 5.1.4 on
an x86_64 Linux machine, using gcc 4.4.1.

Actually, I _am_ able to get it to build and pass all the tests with the
stock Makefile + Coco patch.

But my distribution (ArchLinux) changes the Makefile as follows:


------- start of patch ---------
diff -ur lua-5.1.orig/src/Makefile lua-5.1/src/Makefile
--- lua-5.1.orig/src/Makefile 2006-03-21 11:51:53.000000000 +0100
+++ lua-5.1/src/Makefile 2006-03-21 11:52:09.000000000 +0100
@@ -23,6 +23,7 @@
 PLATS= aix ansi bsd generic linux macosx mingw posix solaris
 
 LUA_A= liblua.a
+LUA_SO= liblua.so
 CORE_O= lapi.o lcode.o ldebug.o ldo.o ldump.o lfunc.o lgc.o llex.o lmem.o \
  lobject.o lopcodes.o lparser.o lstate.o lstring.o ltable.o ltm.o  \
  lundump.o lvm.o lzio.o
@@ -36,7 +37,7 @@
 LUAC_O= luac.o print.o
 
 ALL_O= $(CORE_O) $(LIB_O) $(LUA_O) $(LUAC_O)
-ALL_T= $(LUA_A) $(LUA_T) $(LUAC_T)
+ALL_T= $(LUA_A) $(LUA_SO) $(LUA_T) $(LUAC_T)
 ALL_A= $(LUA_A)
 
 default: $(PLAT)
@@ -51,6 +52,10 @@
  $(AR) $@ $?
  $(RANLIB) $@
 
+$(LUA_SO): $(CORE_O) $(LIB_O)
+ $(CC) -shared -ldl -Wl,-soname,liblua.so -o $@.5.1 $? $(MYLDFLAGS)
+ ln -s $@.5.1 $@
+
 $(LUA_T): $(LUA_O) $(LUA_A)
  $(CC) -o $@ $(MYLDFLAGS) $(LUA_O) $(LUA_A) $(LIBS)
 
----- end of patch ----

and adds -fPIC to the CFLAGS. This is needed to be able to build
liblua.so on x86_64.

Now, if I build with those changes plus the Coco patch, then compilation is successful _but_
the lua executable I get gives a Segmentation Fault for all of the Coco
tests.

If I disable the building of liblua.so and remove -fPIC from the CFLAGS,
then the lua executable I get passes all the Coco tests.

I didn't set any COCCFLAGS, and building with a new GCC, so I'm guessing Coco is using the gccasm method.

I'm in over my head here. Is it possible to build a Lua shared library
with Coco and x86_64? If so, how should I do it? Do I need to change
some more compilation flags?

Here's the build line my distro uses (this is the version that tries to
build liblua.so):


  make INSTALL_DATA="cp -d" TO_LIB="liblua.a" LUA_SO=liblua.so  INSTALL_TOP=$startdir/pkg/usr INSTALL_MAN=$startdir/pkg/usr/share/man/man1 linux install

and here's the result if I change "make...linux install" to
"make...echo":

> These are the parameters currently set in src/Makefile to build Lua
> 5.1.4:

> PLAT = none
> CC = gcc
> CFLAGS = -march=native -mtune=generic -O2 -pipe -fPIC  
> AR = ar rcu
> RANLIB = ranlib
> RM = rm -f
> MYCFLAGS =
> MYLDFLAGS =
> MYLIBS =

> These are the parameters currently set in Makefile to install Lua 5.1.4:

> PLAT = none
> INSTALL_TOP = /var/cache/build/makepkg-tmp-jim/lua/pkg/usr
> INSTALL_BIN = /var/cache/build/makepkg-tmp-jim/lua/pkg/usr/bin
> INSTALL_INC = /var/cache/build/makepkg-tmp-jim/lua/pkg/usr/include
> INSTALL_LIB = /var/cache/build/makepkg-tmp-jim/lua/pkg/usr/lib
> INSTALL_MAN =
> /var/cache/build/makepkg-tmp-jim/lua/pkg/usr/share/man/man1
> INSTALL_LMOD =
> /var/cache/build/makepkg-tmp-jim/lua/pkg/usr/share/lua/5.1
> INSTALL_CMOD = /var/cache/build/makepkg-tmp-jim/lua/pkg/usr/lib/lua/5.1
> INSTALL_EXEC = install -p -m 0755
> INSTALL_DATA = cp -d


I'd be glad for any help.

--
Jim Pryor
[hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: Difficulties building Coco and liblua.so

Mike Pall-7
Jim Pryor wrote:
> [...] and adds -fPIC to the CFLAGS. This is needed to be able to build
> liblua.so on x86_64.

Looks like GCC treats references to assembler functions and static
C functions differently in PIC mode. Here's the fix:

Edit lcoco.c and replace the definition of coco_wrap_main plus the
assembler stuff immediately below it with this code:

static void coco_wrap_main(void)
{
  __asm__ __volatile__ ("\tmovq %r13, %rdi\n\tjmpq *%r12\n");
}

I'll release an update to Coco ASAP.

--Mike
Reply | Threaded
Open this post in threaded view
|

Difficulties building Coco and liblua.so (and also RVM)

Jim Pryor-2-3
Wow, terrific, thanks for the amazingly quick fix for Coco.

I'm also trying to build and try out the RVM patch. It doesn't patch
cleanly against the Lua 5.1.4 sources, so I'm going and cleaning it up
by hand. Mostly this is straightforward. There are a few spots where I'm
stuck though: the Lua 5.1.4 sources have changed
from what the RVM patch is trying to replace. I'm not familiar with
these sources yet, so don't know what's the right merge.

The wiki says that Greg Falcon aka VeLoSo has taken over maintenance of
the RVM patch. Is there any version floating around against the current
Lua sources? Is noone using this patch anymore? From what I've seen on
the mailing list it looks that, though there's no development happening
on it, it's still regarded as a solid and viable option?


On Tue, Sep 08, 2009 at 02:09:08AM +0200, Mike Pall wrote:

> Jim Pryor wrote:
> > [...] and adds -fPIC to the CFLAGS. This is needed to be able to build
> > liblua.so on x86_64.
>
> Looks like GCC treats references to assembler functions and static
> C functions differently in PIC mode. Here's the fix:
>
> Edit lcoco.c and replace the definition of coco_wrap_main plus the
> assembler stuff immediately below it with this code:
>
> static void coco_wrap_main(void)
> {
>   __asm__ __volatile__ ("\tmovq %r13, %rdi\n\tjmpq *%r12\n");
> }
>
> I'll release an update to Coco ASAP.
>
> --Mike

--
Jim Pryor
[hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: Difficulties building Coco and liblua.so (and also RVM)

Mike Pall-7
Jim Pryor wrote:
> I'm also trying to build and try out the RVM patch. It doesn't patch
> cleanly against the Lua 5.1.4 sources, so I'm going and cleaning it up
> by hand. Mostly this is straightforward. There are a few spots where I'm
> stuck though: the Lua 5.1.4 sources have changed
> from what the RVM patch is trying to replace. I'm not familiar with
> these sources yet, so don't know what's the right merge.

I think you need to undo some coroutine-related changes introduced
in Lua 5.1.3. Have a look at the Coco patch which does the same.

> The wiki says that Greg Falcon aka VeLoSo has taken over maintenance of
> the RVM patch. Is there any version floating around against the current
> Lua sources? Is noone using this patch anymore? From what I've seen on
> the mailing list it looks that, though there's no development happening
> on it, it's still regarded as a solid and viable option?

You'd have to ask Greg about the former. But it looks like RVM
will be resurrected (again): the basic concept of RVM will be used
to make the Lua 5.2 VM fully resumable:

  http://lua-users.org/lists/lua-l/2009-08/msg00540.html

--Mike
Reply | Threaded
Open this post in threaded view
|

Updated RVM patch against Lua5.1.4---needs review

Jim Pryor-2-3
In reply to this post by Jim Pryor-2-3
On Mon, Sep 07, 2009 at 09:18:41PM -0400, Jim Pryor wrote:

> Wow, terrific, thanks for the amazingly quick fix for Coco.
>
> I'm also trying to build and try out the RVM patch. It doesn't patch
> cleanly against the Lua 5.1.4 sources, so I'm going and cleaning it up
> by hand. Mostly this is straightforward. There are a few spots where I'm
> stuck though: the Lua 5.1.4 sources have changed
> from what the RVM patch is trying to replace. I'm not familiar with
> these sources yet, so don't know what's the right merge.
>
> The wiki says that Greg Falcon aka VeLoSo has taken over maintenance of
> the RVM patch. Is there any version floating around against the current
> Lua sources? Is noone using this patch anymore? From what I've seen on
> the mailing list it looks that, though there's no development happening
> on it, it's still regarded as a solid and viable option?
OK, I've done the grunt work of updating the Resumable VM patch against the
Lua5.1.4 sources. What I've ended up with compiles and runs the test/
directory in the Lua5.1.4 sources without crashing. But it needs some
code review! I'm new to Lua and in some places I had to make an educated
guess about how to merge the rvm patch against the Lua5.1->Lua5.1.4
changes. Someone who really understands the source should look this
over.

I've made it easy for you. Attached are three patches _against the
Lua5.1 rvm patch on the wiki_. That's right, they're patches against the
patch file at
http://lua-users.org/files/wiki_insecure/users/VeLoSo/lua5.1-rvm.patch.

The first patch just changes some line numbers. I'm sure this is
harmless.

The second patch, (*-safe.patch) are changes that I'm pretty sure are fine. Someone should look at this too, but it's probably ok.

The third patch are the changes that I feel less certain about. There's
one largish patch that I'm least certain of, and the others are probably
ok, but I put them here to be sure someone looks at them.

Pretty please?

--
Jim Pryor
[hidden email]

lua5.1.4-rvm-renumbering.patch (18K) Download Attachment
lua5.1.4-rvm-safe.patch (4K) Download Attachment
lua5.1.4-rvm-unsure.patch (4K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Updated RVM patch against Lua5.1.4---needs review

Jim Pryor-2-3
Here's an update. iFollowing a suggestion from Mike Pall, I changed the
patch so that now it reverts, rather than tries to merge, the
L->baseCcalls related changes introduced in Lua 5.1.3.

Attached now are _two_ patches against the original patch file:
http://lua-users.org/files/wiki_insecure/users/VeLoSo/lua5.1-rvm.patch.

The first just changes line numberings in the original patch, so can be
relied on to be harmless. The second contains all the other changes
needed. I think these are all straightforward, except for the
L->baseCcalls stuff. That still needs review.

Also, there was a

 if (L->nCcalls >= LUAI_MAXCCALLS)
    return resume_error(L, "C stack overflow");

introduced to ldo.c: resume_error in the changes between 5.1 and 5.1.4.
Following the lead of the Coco patch, I removed this too. But I'm really
not sure whether that's right.


On Tue, Sep 08, 2009 at 09:03:06AM -0400, Jim Pryor wrote:

> > I'm also trying to build and try out the RVM patch. It doesn't patch
> > cleanly against the Lua 5.1.4 sources, so I'm going and cleaning it up
> > by hand. Mostly this is straightforward. There are a few spots where I'm
> > stuck though: the Lua 5.1.4 sources have changed
> > from what the RVM patch is trying to replace. I'm not familiar with
> > these sources yet, so don't know what's the right merge.
> >
> > The wiki says that Greg Falcon aka VeLoSo has taken over maintenance of
> > the RVM patch. Is there any version floating around against the current
> > Lua sources? Is noone using this patch anymore? From what I've seen on
> > the mailing list it looks that, though there's no development happening
> > on it, it's still regarded as a solid and viable option?
>
> OK, I've done the grunt work of updating the Resumable VM patch against the
> Lua5.1.4 sources. What I've ended up with compiles and runs the test/
> directory in the Lua5.1.4 sources without crashing. But it needs some
> code review! I'm new to Lua and in some places I had to make an educated
> guess about how to merge the rvm patch against the Lua5.1->Lua5.1.4
> changes. Someone who really understands the source should look this
> over.
>
> I've made it easy for you. Attached are three patches _against the
> Lua5.1 rvm patch on the wiki_. That's right, they're patches against the
> patch file at
> http://lua-users.org/files/wiki_insecure/users/VeLoSo/lua5.1-rvm.patch.
>
> The first patch just changes some line numbers. I'm sure this is
> harmless.
>
> The second patch...
--
Jim Pryor
[hidden email]

lua5.1.4-rvm-renumbering.patch (24K) Download Attachment
lua5.1.4-rvm-changes.patch (8K) Download Attachment