Giter VIP home page Giter VIP logo

Comments (6)

0intro avatar 0intro commented on July 18, 2024 3

undefined reference to swapcontext' undefined reference tolibthread_getmcontext'
undefined reference to makecontext' undefined reference toswapcontext'

These functions are indeed deprecated in POSIX. I think one of the reason
is because the POSIX people considered the threads to be a replacement
for them, while it's not the same thing at all.

These functions are still very useful, but easy to implement locally.
I think the right way would be to implement them conditionally, like
it was done for Linux/sparc64 and other architectures.

You can also take a look to libtask, where Russ already did most of the code
for Linux/x86_64.

https://github.com/0intro/libtask

from plan9port.

huglovefan avatar huglovefan commented on July 18, 2024 3

i found this library that implements the ucontext functions for musl:

https://code.foxkit.us/adelie/libucontext/

i was able to build plan9port on void x86_64-musl with the library (xbps-install libucontext-devel) and just these changes:

diff --git a/bin/9l b/bin/9l
index 6195815f..d1a980cc 100755
--- a/bin/9l
+++ b/bin/9l
@@ -38,9 +38,9 @@ case "$tag" in
 *Linux*)
 	ld=${CC9:-gcc}
 	userpath=true
-	extralibs="$extralibs -lutil -lresolv"
+	extralibs="$extralibs -lutil -lresolv -lucontext"
 	case "${SYSVERSION:-`uname -r`}" in
-	2.6.* | 3.* | 4.*)
+	2.6.* | [3-9].* | [1-9][0-9].*)
 		extralibs="$extralibs -lpthread"
 		;;
 	esac
diff --git a/lib/linux-isnptl.c b/lib/linux-isnptl.c
index e4c23c63..c44d97ad 100644
--- a/lib/linux-isnptl.c
+++ b/lib/linux-isnptl.c
@@ -1,3 +1,4 @@
+#include <sys/types.h>
 #include <pthread.h>
 #include <unistd.h>
 #include <stdlib.h>
diff --git a/src/lib9/dirread.c b/src/lib9/dirread.c
index 40fbe3c7..b13803e6 100644
--- a/src/lib9/dirread.c
+++ b/src/lib9/dirread.c
@@ -10,13 +10,7 @@ extern int _p9dir(struct stat*, struct stat*, char*, Dir*, char**, char*);
 static int
 mygetdents(int fd, struct dirent *buf, int n)
 {
-	off_t off;
-	int nn;
-
-	/* This doesn't match the man page, but it works in Debian with a 2.2 kernel */
-	off = p9seek(fd, 0, 1);
-	nn = getdirentries(fd, (void*)buf, n, &off);
-	return nn;
+	return getdents(fd, (void*)buf, n);
 }
 #elif defined(__APPLE__) 
 static int

from plan9port.

bhuntsman avatar bhuntsman commented on July 18, 2024 1

This issue is resolved by commit 1857120.

from plan9port.

pcoutin avatar pcoutin commented on July 18, 2024

I get the following when trying to compile on Alpine:

>>> cd /usr/local/plan9/src/cmd; mk all  
9l -o o.9import 9import.o 
/usr/local/plan9/src/libthread/thread.c:130: undefined reference to `getcontext'
/usr/local/plan9/src/libthread/thread.c:154: undefined reference to `makecontext'
/usr/local/plan9/src/libthread/thread.c:308: undefined reference to `swapcontext'
/usr/local/plan9/src/libthread/thread.c:308: undefined reference to `swapcontext'
collect2: error: ld returned 1 exit status

It turns out that musl does not implement those functions. "Legacy functions operating on ucontext_t (getcontext, setcontext, makecontext, swapcontext) are not implemented. They are no longer part of POSIX, but cooperative multi-tasking applications use them. ucontext_t also appears as an argument to sigaction handlers which cannot be used portably." http://wiki.musl-libc.org/wiki/Open_Issues

This is similar to how OS X is lacking such functions as explained in /usr/local/plan9/src/libthread/threadimpl.h, so I just added #include "x86_64-ucontext.h" to that file and I am hoping that everything I need (Venti) compiles fine. I also removed the #include <ucontext.h> to stop errors about redefinitions.

Now I'm stuck with

/usr/lib/gcc/x86_64-alpine-linux-musl/4.9.2/../../../../x86_64-alpine-linux-musl/bin/ld: cannot find -lthread

libthread didn't compile?!?!?!!?!

x86_64-ucontext.h:3:25: error: conflicting types for 'mcontext_t'
 typedef struct mcontext mcontext_t;
                         ^
/usr/include/bits/signal.h:61:3: note: previous declaration of 'mcontext_t' was here
 } mcontext_t;
   ^

I add a #define mcontext_t right above that line in x86_64-ucon, and it compiled, but

9l -o o.9import 9import.o 
/usr/local/plan9/src/libthread/thread.c:308: undefined reference to `swapcontext'
/usr/local/plan9/src/libthread/thread.c:130: undefined reference to `libthread_getmcontext'
/usr/local/plan9/src/libthread/thread.c:154: undefined reference to `makecontext'
/usr/local/plan9/src/libthread/thread.c:308: undefined reference to `swapcontext'

They're implemented for other platforms in that directory, but not for 64-bit x86 Linux.

from plan9port.

xerz-one avatar xerz-one commented on July 18, 2024

Any progress on this? I'm getting similar errors on a current Void x86_64-musl

>>> cd /builddir/plan9port-df2d9ec9d169626cdc2a23829bb2831738215722/src/cmd; mk all
9l -o o.9import 9import.o -Wl,-z,relro -Wl,-z,now -Wl,--as-needed    
/bin/ld: /builddir/plan9port-df2d9ec9d169626cdc2a23829bb2831738215722/lib/libthread.a(thread.o): in function `threadalloc':
/builddir/plan9port-df2d9ec9d169626cdc2a23829bb2831738215722/src/libthread/thread.c:130: undefined reference to `getcontext'
/bin/ld: /builddir/plan9port-df2d9ec9d169626cdc2a23829bb2831738215722/src/libthread/thread.c:154: undefined reference to `makecontext'
/bin/ld: /builddir/plan9port-df2d9ec9d169626cdc2a23829bb2831738215722/lib/libthread.a(thread.o): in function `contextswitch':
/builddir/plan9port-df2d9ec9d169626cdc2a23829bb2831738215722/src/libthread/thread.c:308: undefined reference to `swapcontext'
/bin/ld: /builddir/plan9port-df2d9ec9d169626cdc2a23829bb2831738215722/src/libthread/thread.c:308: undefined reference to `swapcontext'
collect2: error: ld returned 1 exit status
mk: 9l -o o.9import ...  : exit status=exit(1)
mk: for i in ...  : exit status=exit(1)

from plan9port.

gottaeat avatar gottaeat commented on July 18, 2024

same here, on musl-1.1.24 and gcc-9.2.1-20200215:

>>> cd /mss/work/table/plan9port/src/cmd; mk all
9l -o o.9import 9import.o
/usr/bin/ld: /mss/work/table/plan9port/lib/libthread.a(thread.o): in function `threadalloc':
/mss/work/table/plan9port/src/libthread/thread.c:135: undefined reference to `getcontext'
/usr/bin/ld: /mss/work/table/plan9port/src/libthread/thread.c:165: undefined reference to `makecontext'
/usr/bin/ld: /mss/work/table/plan9port/lib/libthread.a(thread.o): in function `contextswitch':
/mss/work/table/plan9port/src/libthread/thread.c:324: undefined reference to `swapcontext'
/usr/bin/ld: /mss/work/table/plan9port/src/libthread/thread.c:324: undefined reference to `swapcontext'
collect2: error: ld returned 1 exit status
mk: 9l -o o.9import ...  : exit status=exit(1)
mk: for i in ...  : exit status=exit(1)

tried applying the patch that @huglovefan posted to the version that is in the repo as i'm writing this but it failed due to modifications and lack of a linux-isnptl.c under lib/. modifying their patch to this got plan9port built:

 bin/9l             | 2 +-
 src/lib9/dirread.c | 8 +-------
 2 files changed, 2 insertions(+), 8 deletions(-)

diff --git a/bin/9l b/bin/9l
index a10aab7..103fd54 100755
--- a/bin/9l
+++ b/bin/9l
@@ -25,7 +25,7 @@ case "$tag" in
 *Linux*)
        ld=${CC9:-gcc}
        userpath=true
-       extralibs="$extralibs -lutil -lresolv -lpthread"
+       extralibs="$extralibs -lutil -lresolv -lpthread -lucontext"
        ;;
 *Darwin*x86_64*)
        ld="${CC9:-gcc} -m64"
diff --git a/src/lib9/dirread.c b/src/lib9/dirread.c
index c232eb8..7c8d48d 100644
--- a/src/lib9/dirread.c
+++ b/src/lib9/dirread.c
@@ -10,13 +10,7 @@ extern int _p9dir(struct stat*, struct stat*, char*, Dir*, char**, char*);
 static int
 mygetdents(int fd, struct dirent *buf, int n)
 {
-       off_t off;
-       int nn;
-
-       /* This doesn't match the man page, but it works in Debian with a 2.2 kernel */
-       off = p9seek(fd, 0, 1);
-       nn = getdirentries(fd, (void*)buf, n, &off);
-       return nn;
+       return getdents(fd, (void*)buf, n);
 }
 #elif defined(__APPLE__)
 static int

from plan9port.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.