Skip to content

Commit 62486c3

Browse files
committed
ability to build musl from source
bundles musl 1.1.21 See #514
1 parent 5734b7a commit 62486c3

File tree

1,801 files changed

+75395
-289
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,801 files changed

+75395
-289
lines changed

CMakeLists.txt

Lines changed: 2082 additions & 279 deletions
Large diffs are not rendered by default.

libc/musl/src/aio/aio.c

Lines changed: 400 additions & 0 deletions
Large diffs are not rendered by default.

libc/musl/src/aio/aio_suspend.c

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#include <aio.h>
2+
#include <errno.h>
3+
#include <time.h>
4+
#include "atomic.h"
5+
#include "pthread_impl.h"
6+
7+
int aio_suspend(const struct aiocb *const cbs[], int cnt, const struct timespec *ts)
8+
{
9+
int i, tid = 0, ret, expect = 0;
10+
struct timespec at;
11+
volatile int dummy_fut, *pfut;
12+
int nzcnt = 0;
13+
const struct aiocb *cb = 0;
14+
15+
pthread_testcancel();
16+
17+
if (cnt<0) {
18+
errno = EINVAL;
19+
return -1;
20+
}
21+
22+
for (i=0; i<cnt; i++) if (cbs[i]) {
23+
if (aio_error(cbs[i]) != EINPROGRESS) return 0;
24+
nzcnt++;
25+
cb = cbs[i];
26+
}
27+
28+
if (ts) {
29+
clock_gettime(CLOCK_MONOTONIC, &at);
30+
at.tv_sec += ts->tv_sec;
31+
if ((at.tv_nsec += ts->tv_nsec) >= 1000000000) {
32+
at.tv_nsec -= 1000000000;
33+
at.tv_sec++;
34+
}
35+
}
36+
37+
for (;;) {
38+
for (i=0; i<cnt; i++)
39+
if (cbs[i] && aio_error(cbs[i]) != EINPROGRESS)
40+
return 0;
41+
42+
switch (nzcnt) {
43+
case 0:
44+
pfut = &dummy_fut;
45+
break;
46+
case 1:
47+
pfut = (void *)&cb->__err;
48+
expect = EINPROGRESS | 0x80000000;
49+
a_cas(pfut, EINPROGRESS, expect);
50+
break;
51+
default:
52+
pfut = &__aio_fut;
53+
if (!tid) tid = __pthread_self()->tid;
54+
expect = a_cas(pfut, 0, tid);
55+
if (!expect) expect = tid;
56+
/* Need to recheck the predicate before waiting. */
57+
for (i=0; i<cnt; i++)
58+
if (cbs[i] && aio_error(cbs[i]) != EINPROGRESS)
59+
return 0;
60+
break;
61+
}
62+
63+
ret = __timedwait_cp(pfut, expect, CLOCK_MONOTONIC, ts?&at:0, 1);
64+
65+
switch (ret) {
66+
case ETIMEDOUT:
67+
ret = EAGAIN;
68+
case ECANCELED:
69+
case EINTR:
70+
errno = ret;
71+
return -1;
72+
}
73+
}
74+
}
75+
76+
weak_alias(aio_suspend, aio_suspend64);

libc/musl/src/aio/lio_listio.c

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
#include <aio.h>
2+
#include <errno.h>
3+
#include <unistd.h>
4+
#include <string.h>
5+
#include "pthread_impl.h"
6+
7+
struct lio_state {
8+
struct sigevent *sev;
9+
int cnt;
10+
struct aiocb *cbs[];
11+
};
12+
13+
static int lio_wait(struct lio_state *st)
14+
{
15+
int i, err, got_err = 0;
16+
int cnt = st->cnt;
17+
struct aiocb **cbs = st->cbs;
18+
19+
for (;;) {
20+
for (i=0; i<cnt; i++) {
21+
if (!cbs[i]) continue;
22+
err = aio_error(cbs[i]);
23+
if (err==EINPROGRESS)
24+
break;
25+
if (err) got_err=1;
26+
cbs[i] = 0;
27+
}
28+
if (i==cnt) {
29+
if (got_err) {
30+
errno = EIO;
31+
return -1;
32+
}
33+
return 0;
34+
}
35+
if (aio_suspend((void *)cbs, cnt, 0))
36+
return -1;
37+
}
38+
}
39+
40+
static void notify_signal(struct sigevent *sev)
41+
{
42+
siginfo_t si = {
43+
.si_signo = sev->sigev_signo,
44+
.si_value = sev->sigev_value,
45+
.si_code = SI_ASYNCIO,
46+
.si_pid = getpid(),
47+
.si_uid = getuid()
48+
};
49+
__syscall(SYS_rt_sigqueueinfo, si.si_pid, si.si_signo, &si);
50+
}
51+
52+
static void *wait_thread(void *p)
53+
{
54+
struct lio_state *st = p;
55+
struct sigevent *sev = st->sev;
56+
lio_wait(st);
57+
free(st);
58+
switch (sev->sigev_notify) {
59+
case SIGEV_SIGNAL:
60+
notify_signal(sev);
61+
break;
62+
case SIGEV_THREAD:
63+
sev->sigev_notify_function(sev->sigev_value);
64+
break;
65+
}
66+
return 0;
67+
}
68+
69+
int lio_listio(int mode, struct aiocb *restrict const *restrict cbs, int cnt, struct sigevent *restrict sev)
70+
{
71+
int i, ret;
72+
struct lio_state *st=0;
73+
74+
if (cnt < 0) {
75+
errno = EINVAL;
76+
return -1;
77+
}
78+
79+
if (mode == LIO_WAIT || (sev && sev->sigev_notify != SIGEV_NONE)) {
80+
if (!(st = malloc(sizeof *st + cnt*sizeof *cbs))) {
81+
errno = EAGAIN;
82+
return -1;
83+
}
84+
st->cnt = cnt;
85+
st->sev = sev;
86+
memcpy(st->cbs, (void*) cbs, cnt*sizeof *cbs);
87+
}
88+
89+
for (i=0; i<cnt; i++) {
90+
if (!cbs[i]) continue;
91+
switch (cbs[i]->aio_lio_opcode) {
92+
case LIO_READ:
93+
ret = aio_read(cbs[i]);
94+
break;
95+
case LIO_WRITE:
96+
ret = aio_write(cbs[i]);
97+
break;
98+
default:
99+
continue;
100+
}
101+
if (ret) {
102+
free(st);
103+
errno = EAGAIN;
104+
return -1;
105+
}
106+
}
107+
108+
if (mode == LIO_WAIT) {
109+
ret = lio_wait(st);
110+
free(st);
111+
return ret;
112+
}
113+
114+
if (st) {
115+
pthread_attr_t a;
116+
sigset_t set;
117+
pthread_t td;
118+
119+
if (sev->sigev_notify == SIGEV_THREAD) {
120+
if (sev->sigev_notify_attributes)
121+
a = *sev->sigev_notify_attributes;
122+
else
123+
pthread_attr_init(&a);
124+
} else {
125+
pthread_attr_init(&a);
126+
pthread_attr_setstacksize(&a, PAGE_SIZE);
127+
pthread_attr_setguardsize(&a, 0);
128+
}
129+
pthread_attr_setdetachstate(&a, PTHREAD_CREATE_DETACHED);
130+
sigfillset(&set);
131+
pthread_sigmask(SIG_BLOCK, &set, &set);
132+
if (pthread_create(&td, &a, wait_thread, st)) {
133+
free(st);
134+
errno = EAGAIN;
135+
return -1;
136+
}
137+
pthread_sigmask(SIG_SETMASK, &set, 0);
138+
}
139+
140+
return 0;
141+
}
142+
143+
weak_alias(lio_listio, lio_listio64);

libc/musl/src/complex/__cexp.c

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/* origin: FreeBSD /usr/src/lib/msun/src/k_exp.c */
2+
/*-
3+
* Copyright (c) 2011 David Schultz <[email protected]>
4+
* All rights reserved.
5+
*
6+
* Redistribution and use in source and binary forms, with or without
7+
* modification, are permitted provided that the following conditions
8+
* are met:
9+
* 1. Redistributions of source code must retain the above copyright
10+
* notice, this list of conditions and the following disclaimer.
11+
* 2. Redistributions in binary form must reproduce the above copyright
12+
* notice, this list of conditions and the following disclaimer in the
13+
* documentation and/or other materials provided with the distribution.
14+
*
15+
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18+
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21+
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24+
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25+
* SUCH DAMAGE.
26+
*/
27+
28+
#include "libm.h"
29+
30+
static const uint32_t k = 1799; /* constant for reduction */
31+
static const double kln2 = 1246.97177782734161156; /* k * ln2 */
32+
33+
/*
34+
* Compute exp(x), scaled to avoid spurious overflow. An exponent is
35+
* returned separately in 'expt'.
36+
*
37+
* Input: ln(DBL_MAX) <= x < ln(2 * DBL_MAX / DBL_MIN_DENORM) ~= 1454.91
38+
* Output: 2**1023 <= y < 2**1024
39+
*/
40+
static double __frexp_exp(double x, int *expt)
41+
{
42+
double exp_x;
43+
uint32_t hx;
44+
45+
/*
46+
* We use exp(x) = exp(x - kln2) * 2**k, carefully chosen to
47+
* minimize |exp(kln2) - 2**k|. We also scale the exponent of
48+
* exp_x to MAX_EXP so that the result can be multiplied by
49+
* a tiny number without losing accuracy due to denormalization.
50+
*/
51+
exp_x = exp(x - kln2);
52+
GET_HIGH_WORD(hx, exp_x);
53+
*expt = (hx >> 20) - (0x3ff + 1023) + k;
54+
SET_HIGH_WORD(exp_x, (hx & 0xfffff) | ((0x3ff + 1023) << 20));
55+
return exp_x;
56+
}
57+
58+
/*
59+
* __ldexp_cexp(x, expt) compute exp(x) * 2**expt.
60+
* It is intended for large arguments (real part >= ln(DBL_MAX))
61+
* where care is needed to avoid overflow.
62+
*
63+
* The present implementation is narrowly tailored for our hyperbolic and
64+
* exponential functions. We assume expt is small (0 or -1), and the caller
65+
* has filtered out very large x, for which overflow would be inevitable.
66+
*/
67+
double complex __ldexp_cexp(double complex z, int expt)
68+
{
69+
double x, y, exp_x, scale1, scale2;
70+
int ex_expt, half_expt;
71+
72+
x = creal(z);
73+
y = cimag(z);
74+
exp_x = __frexp_exp(x, &ex_expt);
75+
expt += ex_expt;
76+
77+
/*
78+
* Arrange so that scale1 * scale2 == 2**expt. We use this to
79+
* compensate for scalbn being horrendously slow.
80+
*/
81+
half_expt = expt / 2;
82+
INSERT_WORDS(scale1, (0x3ff + half_expt) << 20, 0);
83+
half_expt = expt - half_expt;
84+
INSERT_WORDS(scale2, (0x3ff + half_expt) << 20, 0);
85+
86+
return CMPLX(cos(y) * exp_x * scale1 * scale2, sin(y) * exp_x * scale1 * scale2);
87+
}

libc/musl/src/complex/__cexpf.c

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/* origin: FreeBSD /usr/src/lib/msun/src/k_expf.c */
2+
/*-
3+
* Copyright (c) 2011 David Schultz <[email protected]>
4+
* All rights reserved.
5+
*
6+
* Redistribution and use in source and binary forms, with or without
7+
* modification, are permitted provided that the following conditions
8+
* are met:
9+
* 1. Redistributions of source code must retain the above copyright
10+
* notice, this list of conditions and the following disclaimer.
11+
* 2. Redistributions in binary form must reproduce the above copyright
12+
* notice, this list of conditions and the following disclaimer in the
13+
* documentation and/or other materials provided with the distribution.
14+
*
15+
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18+
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21+
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24+
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25+
* SUCH DAMAGE.
26+
*/
27+
28+
#include "libm.h"
29+
30+
static const uint32_t k = 235; /* constant for reduction */
31+
static const float kln2 = 162.88958740F; /* k * ln2 */
32+
33+
/*
34+
* See __cexp.c for details.
35+
*
36+
* Input: ln(FLT_MAX) <= x < ln(2 * FLT_MAX / FLT_MIN_DENORM) ~= 192.7
37+
* Output: 2**127 <= y < 2**128
38+
*/
39+
static float __frexp_expf(float x, int *expt)
40+
{
41+
float exp_x;
42+
uint32_t hx;
43+
44+
exp_x = expf(x - kln2);
45+
GET_FLOAT_WORD(hx, exp_x);
46+
*expt = (hx >> 23) - (0x7f + 127) + k;
47+
SET_FLOAT_WORD(exp_x, (hx & 0x7fffff) | ((0x7f + 127) << 23));
48+
return exp_x;
49+
}
50+
51+
float complex __ldexp_cexpf(float complex z, int expt)
52+
{
53+
float x, y, exp_x, scale1, scale2;
54+
int ex_expt, half_expt;
55+
56+
x = crealf(z);
57+
y = cimagf(z);
58+
exp_x = __frexp_expf(x, &ex_expt);
59+
expt += ex_expt;
60+
61+
half_expt = expt / 2;
62+
SET_FLOAT_WORD(scale1, (0x7f + half_expt) << 23);
63+
half_expt = expt - half_expt;
64+
SET_FLOAT_WORD(scale2, (0x7f + half_expt) << 23);
65+
66+
return CMPLXF(cosf(y) * exp_x * scale1 * scale2,
67+
sinf(y) * exp_x * scale1 * scale2);
68+
}

libc/musl/src/complex/cabs.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include "libm.h"
2+
3+
double cabs(double complex z)
4+
{
5+
return hypot(creal(z), cimag(z));
6+
}

libc/musl/src/complex/cabsf.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include "libm.h"
2+
3+
float cabsf(float complex z)
4+
{
5+
return hypotf(crealf(z), cimagf(z));
6+
}

0 commit comments

Comments
 (0)