Home » Uncategorized » udev in x86_64-linux-musl

udev in x86_64-linux-musl

udev link error, just use eudev instead.

http://www.linuxfromscratch.org/lfs/view/development/chapter06/udev.html

vi /include/printf.h

enum

{

PA_INT,

PA_CHAR,

PA_WCHAR,

PA_STRING,

PA_WSTRING,

PA_POINTER,

PA_FLOAT,

PA_DOUBLE,

__PA_NOARG,

PA_LAST

};

#define PA_FLAG_MASK  (0xff00)

#define __PA_FLAG_CHAR (0x0100)

#define PA_FLAG_SHORT (0x0200)

#define PA_FLAG_LONG (0x0400)

#define PA_FLAG_LONG_LONG (0x0800)

#define PA_FLAG_LONG_DOUBLE (0x0800)

#define PA_FLAG_PTR (0x1000)

struct fh_ext_class

{

int magic;

const char *name;

void (*close) (struct file_handle *);

};

struct file_locator

{

const char *filename;

char *norm_fn;

char *fn;

struct file_locator where;

int recform;

size_t lrecl;

int mode;

struct fh_ext_class *class;

void *ext;

unsigned int handle_bytes;

};

vi /include/glob.h

+ #define GLOBE_BRACE (1<<10)

vi /include/bits/termios.h

+ #define IUTF8 0040000

vi systemd/udev-lfs-204-1/cfg.h

+ #define __WORDSIZE 64

+ #define __NEED_FILE

+ #define __NEED_mode_t

+ typedef int(* __compar_fn_t)(const void *, const void *);

curl -Ok https://www.kernel.org/pub/linux/utils/util-linux/v2.23/util-linux-2.23.tar.xz

[solved] NOTE: util-linux’s “mount” getting segmentation fault.

http://www.openwall.com/lists/musl/2013/05/30/3

munge-config-sub ./config/config.sub && ./configure –prefix=/usr –build=x86_64-linux-musl –disable-su –disable-sulogin –disable-utmpdump –disable-eject

vi /include/termios.h

+ #define TTYDEF_IFLAG    (BRKINT | ISTRIP | ICRNL | IMAXBEL | IXON | IXANY)
+ #define TTYDEF_OFLAG    (OPOST | ONLCR | XTABS)
+ #define TTYDEF_LFLAG    (ECHO | ICANON | ISIG | IEXTEN | ECHOE | ECHOKE | ECHOCTL)
+ #define TTYDEF_CFLAG    (CREAD | CS7 | PARENB | HUPCL)
+ #define TTYDEF_SPEED     (B9600)

+ #define CTRL(x)        (x&037)
+ #define CINTR        CTRL(‘c’)
+ #define CEOF        CTRL(‘d’)
+ #define CDISCARD    CTRL(‘o’)
+ #define CSTART        CTRL(‘q’)
+ #define CREPRINT    CTRL(‘r’)
+ #define CSTOP        CTRL(‘s’)
+ #define CKILL        CTRL(‘u’)
+ #define CLNEXT        CTRL(‘v’)
+ #define CWERASE    CTRL(‘w’)
+ #define CSUSP        CTRL(‘z’)
+ #define CQUIT        034
+ #define CERASE        0177

vi term-utils/setterm.c

+ #if 0
#if __GNU_LIBRARY__ < 5
#ifndef __alpha__
# include <linux/unistd.h>
#define __NR_klogctl __NR_syslog
_syscall3(int, klogctl, int, type, char*, buf, int, len);
#else /* __alpha__ */
#define klogctl syslog
#endif
#endif
+ #endif
extern int klogctl(int type, char *buf, int len);

vi term-utils/ttymsg.c
+ #include <sys/param.h>
--
add qsort_r.c and build musl again.
https://ccl.googlecode.com/svn/trunk/qsort_r.c

--
util-linux-2.23 build.log
make -k > build.log 2>&1

--
/include/bits/ioctl.h

- #define _IOR(a,b,c) _IOC(2,(a),(b),sizeof(c))
- #define _IOWR(a,b,c) _IOC(3,(a),(b),sizeof(c))

+ #define _IOR(a,b,c) _IOC(2U,(a),(b),sizeof(c))
+ #define _IOWR(a,b,c) _IOC(3U,(a),(b),sizeof(c))
--
/include/stdlib.h

typedef int cmp_t(const void*, const void*, void *);
void qsort_r (void *, size_t, size_t, cmp_t *, void *);

--
/musl/src/stdlib/qsort_r.c

/*-
 * Copyright (c) 1992, 1993
 *      The Regents of the University of California.  All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 4. Neither the name of the University nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * @(#)qsort.c  8.1 (Berkeley) 6/4/93
 * $FreeBSD: src/lib/libc/stdlib/qsort.c,v 1.15 2008/01/14 09:21:34 das Exp $
 * $DragonFly: src/lib/libc/stdlib/qsort.c,v 1.5 2005/11/20 12:37:49 swildner Exp $
 */

#include <stdlib.h>

//typedef int              cmp_t(void *, const void *, const void *);
typedef int              cmp_t(const void *, const void *, void *);
static inline char      *med3(char *, char *, char *, cmp_t *, void *);
static inline void       swapfunc(char *, char *, int, int);

#define min(a, b)       (a) < (b) ? a : b

/*
 * Qsort routine from Bentley & McIlroy's "Engineering a Sort Function".
 */
#define swapcode(TYPE, parmi, parmj, n) {               \
        long i = (n) / sizeof (TYPE);                   \
        TYPE *pi = (TYPE *) (parmi);            \
        TYPE *pj = (TYPE *) (parmj);            \
        do {                                            \
                TYPE    t = *pi;                \
                *pi++ = *pj;                            \
                *pj++ = t;                              \
        } while (--i > 0);                              \
}

#define SWAPINIT(a, es) swaptype = ((char *)a - (char *)0) % sizeof(long) || \
        es % sizeof(long) ? 2 : es == sizeof(long)? 0 : 1;

static inline void
swapfunc(char *a, char *b, int n, int swaptype)
{
        if(swaptype <= 1)
                swapcode(long, a, b, n)
        else
                swapcode(char, a, b, n)
}

#define swap(a, b)                                      \
        if (swaptype == 0) {                            \
                long t = *(long *)(a);                  \
                *(long *)(a) = *(long *)(b);            \
                *(long *)(b) = t;                       \
        } else                                          \
                swapfunc(a, b, es, swaptype)

#define vecswap(a, b, n)        if ((n) > 0) swapfunc(a, b, n, swaptype)

//#define CMP(t, x, y) (cmp((t), (x), (y)))
#define CMP(x, y, t) (cmp((x), (y), (t)))

static inline char *
med3(char *a, char *b, char *c, cmp_t *cmp, void *thunk)
{
        return CMP(a, b, thunk) < 0 ?
               (CMP(b, c, thunk) < 0 ? b : (CMP(a, c, thunk) < 0 ? c : a ))
              :(CMP(b, c, thunk) > 0 ? b : (CMP(a, c, thunk) < 0 ? a : c ));
}

void qsort_r(void *a, size_t n, size_t es, cmp_t *cmp, void *thunk)
{
        char *pa, *pb, *pc, *pd, *pl, *pm, *pn;
        size_t d, r;
        int cmp_result;
        int swaptype, swap_cnt;

loop:   SWAPINIT(a, es);
        swap_cnt = 0;
        if (n < 7) {
                for (pm = (char *)a + es; pm < (char *)a + n * es; pm += es)
                        for (pl = pm;
                             pl > (char *)a && CMP(pl - es, pl, thunk) > 0;
                             pl -= es)
                                swap(pl, pl - es);
                return;
        }
        pm = (char *)a + (n / 2) * es;
        if (n > 7) {
                pl = a;
                pn = (char *)a + (n - 1) * es;
                if (n > 40) {
                        d = (n / 8) * es;
                        pl = med3(pl, pl + d, pl + 2 * d, cmp, thunk);
                        pm = med3(pm - d, pm, pm + d, cmp, thunk);
                        pn = med3(pn - 2 * d, pn - d, pn, cmp, thunk);
                }
                pm = med3(pl, pm, pn, cmp, thunk);
        }
        swap(a, pm);
        pa = pb = (char *)a + es;

        pc = pd = (char *)a + (n - 1) * es;
        for (;;) {
                while (pb <= pc && (cmp_result = CMP(pb, a, thunk)) <= 0) {
                        if (cmp_result == 0) {
                                swap_cnt = 1;
                                swap(pa, pb);
                                pa += es;
                        }
                        pb += es;
                }
                while (pb <= pc && (cmp_result = CMP(pc, a, thunk)) >= 0) {
                        if (cmp_result == 0) {
                                swap_cnt = 1;
                                swap(pc, pd);
                                pd -= es;
                        }
                        pc -= es;
                }
                if (pb > pc)
                        break;
                swap(pb, pc);
                swap_cnt = 1;
                pb += es;
                pc -= es;
        }
        if (swap_cnt == 0) {  /* Switch to insertion sort */
                for (pm = (char *)a + es; pm < (char *)a + n * es; pm += es)
                        for (pl = pm;
                             pl > (char *)a && CMP(pl - es, pl, thunk) > 0;
                             pl -= es)
                                swap(pl, pl - es);
                return;
        }

        pn = (char *)a + n * es;
        r = min(pa - (char *)a, pb - pa);
        vecswap(a, pb - r, r);
        r = min(pd - pc, pn - pd - es);
        vecswap(pb, pn - r, r);
        if ((r = pb - pa) > es)
                qsort_r(a, r / es, es, thunk, cmp);
        if ((r = pd - pc) > es) {
                /* Iterate rather than recurse to save stack space */
                a = pn - r;
                n = r / es;
                goto loop;
        }
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s