[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] Re: Pesky '#define current' in mini-os/sched.h



Ferenc Wagner, le Mon 27 Apr 2009 22:29:02 +0200, a écrit :
> Samuel Thibault <samuel.thibault@xxxxxxxxxxxx> writes:
> > Ferenc Wagner, le Mon 27 Apr 2009 21:42:42 +0200, a écrit :
> >
> >> Of course if I add -lncurses to the above command, I get lots of
> >> undefined references to the libc functions from ncurses.
> >
> > Which ones?
> 
> /home/wferi/xen/xen-3.3.1/stubdom/ncurses-x86_32/ncurses/../ncurses/./base/lib_color.c:265:
>  undefined reference to `calloc'
> etc.
> 
> No wonder, as the linker command originally had a single object
> (mini-os.o), and if I put -lncurses before it, it wasn't pulled in,
> and if I put -lncurses after it, then every single libc function
> became undefined.

Have you, like in the C example of stubdom/Makefile, propagated
TARGET_CPPFLAGS, TARGET_CFLAGS, and added a rule like is done for other
stubdom images in the "minios" paragraph of stubdom/Makefile?

> Yes, but I tried the crazy way first, which was bound to fail.  Setting
> 
> LDLIBS := -L/home/wferi/xen/xen-3.3.1/stubdom/ncurses-x86_32/lib -lncurses

That's not how it's supposed to be done. See the Cross-zlib paragraph
for instance: the cross-zlib target not only configures & builds libz,
but also installs it, the prefix being properly set during configuration
into the cross-chain directory.

> I couldn't track how it's done for libpci & libz for qemu-stubdom
> (ioemu?) yet.

It's all in stubdom/Makefile: they get installed within the
cross-root-$(GNU_TARGET_ARCH) hierarchy, where the linker finds it
thanks to the TARGET_LDFLAGS variable.

> This make magic is somewhat convoluted,

It's no magic, it's makefiles :)

> and I'm not too much into linker scripts et al.

You do not need to change any linker script.

> So, where should I add it for proper operation?

Just the same way as zlib & C stubdom examples.

> /home/wferi/xen/xen-3.3.1/stubdom/mini-os-x86_32-c/mini-os.o: In function 
> `grub_memalign':
> /home/wferi/xen/grub2/util/misc.c:263: undefined reference to `posix_memalign'

It should just be a matter of setting it as an alias for newlib's
memalign, by adding a macro into newlib/libc/include/malloc.h for
instance.  Ideally it should be reported to newlib's upstream actually.

> /home/wferi/xen/grub2/util/getroot.c:215: undefined reference to `lstat'
> /home/wferi/xen/xen-3.3.1/stubdom/ncurses-x86_32/ncurses/../ncurses/./tty/lib_tstp.c:159:
>  undefined reference to `tcgetpgrp'
> /home/wferi/xen/xen-3.3.1/stubdom/ncurses-x86_32/ncurses/../ncurses/./tty/lib_tstp.c:159:
>  undefined reference to `getpgrp'
> /home/wferi/xen/xen-3.3.1/stubdom/ncurses-x86_32/ncurses/../ncurses/./tinfo/lib_kernel.c:143:
>  undefined reference to `tcflush'

Should be fixed by the patch below.

> /home/wferi/xen/xen-3.3.1/stubdom/ncurses-x86_32/ncurses/../ncurses/./tinfo/lib_baudrate.c:244:
>  undefined reference to `cfgetospeed'

I'm a bit surprised you actually got code using cfgetospeed compiled in
the miniOS environment.  It's supposed to return something like B9600,
but that's not defined by newlib!

> /home/wferi/xen/xen-3.3.1/stubdom/ncurses-x86_32/ncurses/../ncurses/./tinfo/lib_kernel.c:67:
>  undefined reference to `fpathconf'

Same issue: how did you get that code to compile? _PC_VDISABLE is not
defined...  I believe you are not using the cross-chain flags.

> /home/wferi/xen/xen-3.3.1/stubdom/ncurses-x86_32/ncurses/../ncurses/./tinfo/access.c:112:
>  undefined reference to `access'
> /home/wferi/xen/xen-3.3.1/stubdom/ncurses-x86_32/ncurses/../ncurses/./tinfo/access.c:125:
>  undefined reference to `access'

Mmmm, the fsif protocol does not provide an access operation to
implement that properly. You could add a dummy implementation in
lib/sys.c that just open()/close() it and return proper error codes if
any and it should be fine for ncurses' use cases.

Samuel




Add tcgetpgrp getpgrp tcflush and lstat dummy implementations.

Signed-off-by: Samuel Thibault <samuel.thibault@xxxxxxxxxxxx>

diff -r 9fdcd3ab84b7 extras/mini-os/lib/sys.c
--- a/extras/mini-os/lib/sys.c  Mon Apr 27 15:40:09 2009 +0100
+++ b/extras/mini-os/lib/sys.c  Mon Apr 27 23:05:01 2009 +0200
@@ -148,6 +148,16 @@
     return 1;
 }
 
+pid_t tcgetpgrp(int fd)
+{
+    return 1;
+}
+
+pid_t getpgrp(void)
+{
+    return 1;
+}
+
 char *getcwd(char *buf, size_t size)
 {
     snprintf(buf, size, "/");
@@ -365,6 +375,20 @@
     return -1;
 }
 
+int tcflush(int fd, int queue_selector)
+{
+    switch (files[fd].type) {
+        case FTYPE_CONSOLE:
+            /* Already flushed */
+            return 0;
+        default:
+            break;
+    }
+    printk("tcflush(%d): Bad descriptor\n", fd);
+    errno = EBADF;
+    return -1;
+}
+
 int close(int fd)
 {
     printk("close(%d)\n", fd);
@@ -473,6 +497,8 @@
 out:
     return ret;
 }
+/* We do not have symlinks */
+int lstat(const char *path, struct stat *buf) __attribute__((alias("stat")));
 
 int fstat(int fd, struct stat *buf)
 {

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.