authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-03-05 13:26:43-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-03-05 13:26:59-05:00
logc5fdea59d36dffcac95b71c20609a44d34b1935a
treebff5a583521b7384f626b91290f397c9caede1a0
parentaeb16010f37df3c702481c9bd98b8cc838418ee1
signature Commit is signed but in an unrecognized format.

building glibc from source


8 files changed, 363 insertions(+), 87 deletions(-)

CMakeLists.txt+3-1
......@@ -1270,7 +1270,6 @@ set(ZIG_LIBC_FILES
12701270 "glibc/csu/elf-init.c"
12711271 "glibc/csu/init.c"
12721272 "glibc/debug/stack_chk_fail_local.c"
1273 "glibc/debug/warning-nop.c"
12741273 "glibc/include/alloca.h"
12751274 "glibc/include/bits/types.h"
12761275 "glibc/include/bits/types/__locale_t.h"
......@@ -1399,6 +1398,9 @@ set(ZIG_LIBC_FILES
13991398 "glibc/bits/signum-generic.h"
14001399 "glibc/include/bits/types/sig_atomic_t.h"
14011400 "glibc/signal/bits/types/sig_atomic_t.h"
1401 "glibc/sysdeps/unix/sysv/linux/x86/bits/stat.h"
1402 "glibc/sysdeps/unix/sysv/linux/generic/bits/stat.h"
1403 "glibc/sysdeps/unix/sysv/linux/bits/stat.h"
14021404 "symbols.zig"
14031405)
14041406
libc/glibc/debug/warning-nop.c deleted-70
......@@ -1,70 +0,0 @@
1/* Dummy nop functions to elicit link-time warnings.
2 Copyright (C) 2005-2019 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 In addition to the permissions in the GNU Lesser General Public
11 License, the Free Software Foundation gives you unlimited
12 permission to link the compiled version of this file with other
13 programs, and to distribute those programs without any restriction
14 coming from the use of this file. (The GNU Lesser General Public
15 License restrictions do apply in other respects; for example, they
16 cover modification of the file, and distribution when not linked
17 into another program.)
18
19 Note that people who make modified versions of this file are not
20 obligated to grant this special exception for their modified
21 versions; it is their choice whether to do so. The GNU Lesser
22 General Public License gives permission to release a modified
23 version without this exception; this exception also makes it
24 possible to release a modified version which carries forward this
25 exception.
26
27 The GNU C Library is distributed in the hope that it will be useful,
28 but WITHOUT ANY WARRANTY; without even the implied warranty of
29 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
30 Lesser General Public License for more details.
31
32 You should have received a copy of the GNU Lesser General Public
33 License along with the GNU C Library; if not, see
34 <http://www.gnu.org/licenses/>. */
35
36#include <sys/cdefs.h>
37
38static void
39__attribute__ ((used))
40nop (void)
41{
42}
43
44/* Don't insert any other #include's before this #undef! */
45
46#undef __warndecl
47#define __warndecl(name, msg) \
48 extern void name (void) __attribute__ ((alias ("nop"))) attribute_hidden; \
49 link_warning (name, msg)
50
51#undef __USE_FORTIFY_LEVEL
52#define __USE_FORTIFY_LEVEL 99
53
54/* Following here we need an #include for each public header file
55 that uses __warndecl. */
56
57/* Define away to avoid warnings with compilers that do not have these
58 builtins. */
59#define __builtin___memcpy_chk(dest, src, len, bos) NULL
60#define __builtin___memmove_chk(dest, src, len, bos) NULL
61#define __builtin___mempcpy_chk(dest, src, len, bos) NULL
62#define __builtin___memset_chk(dest, ch, len, bos) NULL
63#define __builtin___stpcpy_chk(dest, src, bos) NULL
64#define __builtin___strcat_chk(dest, src, bos) NULL
65#define __builtin___strcpy_chk(dest, src, bos) NULL
66#define __builtin___strncat_chk(dest, src, len, bos) NULL
67#define __builtin___strncpy_chk(dest, src, len, bos) NULL
68#define __builtin_object_size(bos, level) 0
69
70#include <string.h>
libc/glibc/nptl/pthread_atfork.c+8-3
......@@ -33,9 +33,14 @@
3333 License along with the GNU C Library; if not, see
3434 <http://www.gnu.org/licenses/>. */
3535
36#include "pthreadP.h"
37#include <fork.h>
38#include <dso_handle.h>
36extern int __pthread_atfork (void (*prepare) (void), void (*parent) (void),
37 void (*child) (void));
38extern int __register_atfork (void (*__prepare) (void),
39 void (*__parent) (void),
40 void (*__child) (void),
41 void *dso_handle);
42libc_hidden_proto (__register_atfork)
43extern void *__dso_handle __attribute__ ((__visibility__ ("hidden")));
3944
4045
4146/* Hide the symbol so that no definition but the one locally in the
libc/glibc/stdlib/at_quick_exit.c+3-5
......@@ -32,14 +32,12 @@
3232 License along with the GNU C Library; if not, see
3333 <http://www.gnu.org/licenses/>. */
3434
35#include <stdlib.h>
36#include <dso_handle.h>
37#include "exit.h"
38
35extern void *__dso_handle __attribute__ ((__visibility__ ("hidden")));
36extern int __cxa_at_quick_exit (void (*func) (void *), void *d);
3937
4038/* Register FUNC to be executed by `quick_exit'. */
4139int
42attribute_hidden
40__attribute__ ((__visibility__ ("hidden")))
4341at_quick_exit (void (*func) (void))
4442{
4543 return __cxa_at_quick_exit ((void (*) (void *)) func, __dso_handle);
libc/glibc/stdlib/atexit.c+5-7
......@@ -32,16 +32,14 @@
3232 License along with the GNU C Library; if not, see
3333 <http://www.gnu.org/licenses/>. */
3434
35#include <stdlib.h>
36#include <dso_handle.h>
37#include "exit.h"
35extern int __cxa_atexit (void (*func) (void *), void *arg, void *d);
36libc_hidden_proto (__cxa_atexit);
37extern void *__dso_handle __attribute__ ((__visibility__ ("hidden")));
3838
3939/* Register FUNC to be executed by `exit'. */
4040int
41#ifndef atexit
42attribute_hidden
43#endif
41__attribute__ ((__visibility__ ("hidden")))
4442atexit (void (*func) (void))
4543{
46 return __cxa_atexit ((void (*) (void *)) func, NULL, __dso_handle);
44 return __cxa_atexit ((void (*) (void *)) func, 0, __dso_handle);
4745}
libc/glibc/sysdeps/unix/sysv/linux/bits/stat.h created+172
......@@ -0,0 +1,172 @@
1/* Copyright (C) 1992-2019 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <http://www.gnu.org/licenses/>. */
17
18#if !defined _SYS_STAT_H && !defined _FCNTL_H
19# error "Never include <bits/stat.h> directly; use <sys/stat.h> instead."
20#endif
21
22#ifndef _BITS_STAT_H
23#define _BITS_STAT_H 1
24
25/* Versions of the `struct stat' data structure. */
26#define _STAT_VER_LINUX_OLD 1
27#define _STAT_VER_KERNEL 1
28#define _STAT_VER_SVR4 2
29#define _STAT_VER_LINUX 3
30#define _STAT_VER _STAT_VER_LINUX /* The one defined below. */
31
32/* Versions of the `xmknod' interface. */
33#define _MKNOD_VER_LINUX 1
34#define _MKNOD_VER_SVR4 2
35#define _MKNOD_VER _MKNOD_VER_LINUX /* The bits defined below. */
36
37
38struct stat
39 {
40 __dev_t st_dev; /* Device. */
41 unsigned short int __pad1;
42#ifndef __USE_FILE_OFFSET64
43 __ino_t st_ino; /* File serial number. */
44#else
45 __ino_t __st_ino; /* 32bit file serial number. */
46#endif
47 __mode_t st_mode; /* File mode. */
48 __nlink_t st_nlink; /* Link count. */
49 __uid_t st_uid; /* User ID of the file's owner. */
50 __gid_t st_gid; /* Group ID of the file's group.*/
51 __dev_t st_rdev; /* Device number, if device. */
52 unsigned short int __pad2;
53#ifndef __USE_FILE_OFFSET64
54 __off_t st_size; /* Size of file, in bytes. */
55#else
56 __off64_t st_size; /* Size of file, in bytes. */
57#endif
58 __blksize_t st_blksize; /* Optimal block size for I/O. */
59
60#ifndef __USE_FILE_OFFSET64
61 __blkcnt_t st_blocks; /* Number 512-byte blocks allocated. */
62#else
63 __blkcnt64_t st_blocks; /* Number 512-byte blocks allocated. */
64#endif
65#ifdef __USE_XOPEN2K8
66 /* Nanosecond resolution timestamps are stored in a format
67 equivalent to 'struct timespec'. This is the type used
68 whenever possible but the Unix namespace rules do not allow the
69 identifier 'timespec' to appear in the <sys/stat.h> header.
70 Therefore we have to handle the use of this header in strictly
71 standard-compliant sources special. */
72 struct timespec st_atim; /* Time of last access. */
73 struct timespec st_mtim; /* Time of last modification. */
74 struct timespec st_ctim; /* Time of last status change. */
75# define st_atime st_atim.tv_sec /* Backward compatibility. */
76# define st_mtime st_mtim.tv_sec
77# define st_ctime st_ctim.tv_sec
78#else
79 __time_t st_atime; /* Time of last access. */
80 unsigned long int st_atimensec; /* Nscecs of last access. */
81 __time_t st_mtime; /* Time of last modification. */
82 unsigned long int st_mtimensec; /* Nsecs of last modification. */
83 __time_t st_ctime; /* Time of last status change. */
84 unsigned long int st_ctimensec; /* Nsecs of last status change. */
85#endif
86#ifndef __USE_FILE_OFFSET64
87 unsigned long int __glibc_reserved4;
88 unsigned long int __glibc_reserved5;
89#else
90 __ino64_t st_ino; /* File serial number. */
91#endif
92 };
93
94#ifdef __USE_LARGEFILE64
95struct stat64
96 {
97 __dev_t st_dev; /* Device. */
98 unsigned int __pad1;
99
100 __ino_t __st_ino; /* 32bit file serial number. */
101 __mode_t st_mode; /* File mode. */
102 __nlink_t st_nlink; /* Link count. */
103 __uid_t st_uid; /* User ID of the file's owner. */
104 __gid_t st_gid; /* Group ID of the file's group.*/
105 __dev_t st_rdev; /* Device number, if device. */
106 unsigned int __pad2;
107 __off64_t st_size; /* Size of file, in bytes. */
108 __blksize_t st_blksize; /* Optimal block size for I/O. */
109
110 __blkcnt64_t st_blocks; /* Number 512-byte blocks allocated. */
111# ifdef __USE_XOPEN2K8
112 /* Nanosecond resolution timestamps are stored in a format
113 equivalent to 'struct timespec'. This is the type used
114 whenever possible but the Unix namespace rules do not allow the
115 identifier 'timespec' to appear in the <sys/stat.h> header.
116 Therefore we have to handle the use of this header in strictly
117 standard-compliant sources special. */
118 struct timespec st_atim; /* Time of last access. */
119 struct timespec st_mtim; /* Time of last modification. */
120 struct timespec st_ctim; /* Time of last status change. */
121# else
122 __time_t st_atime; /* Time of last access. */
123 unsigned long int st_atimensec; /* Nscecs of last access. */
124 __time_t st_mtime; /* Time of last modification. */
125 unsigned long int st_mtimensec; /* Nsecs of last modification. */
126 __time_t st_ctime; /* Time of last status change. */
127 unsigned long int st_ctimensec; /* Nsecs of last status change. */
128# endif
129 __ino64_t st_ino; /* File serial number. */
130 };
131#endif
132
133/* Tell code we have these members. */
134#define _STATBUF_ST_BLKSIZE
135#define _STATBUF_ST_RDEV
136/* Nanosecond resolution time values are supported. */
137#define _STATBUF_ST_NSEC
138
139/* Encoding of the file mode. */
140
141#define __S_IFMT 0170000 /* These bits determine file type. */
142
143/* File types. */
144#define __S_IFDIR 0040000 /* Directory. */
145#define __S_IFCHR 0020000 /* Character device. */
146#define __S_IFBLK 0060000 /* Block device. */
147#define __S_IFREG 0100000 /* Regular file. */
148#define __S_IFIFO 0010000 /* FIFO. */
149#define __S_IFLNK 0120000 /* Symbolic link. */
150#define __S_IFSOCK 0140000 /* Socket. */
151
152/* POSIX.1b objects. Note that these macros always evaluate to zero. But
153 they do it by enforcing the correct use of the macros. */
154#define __S_TYPEISMQ(buf) ((buf)->st_mode - (buf)->st_mode)
155#define __S_TYPEISSEM(buf) ((buf)->st_mode - (buf)->st_mode)
156#define __S_TYPEISSHM(buf) ((buf)->st_mode - (buf)->st_mode)
157
158/* Protection bits. */
159
160#define __S_ISUID 04000 /* Set user ID on execution. */
161#define __S_ISGID 02000 /* Set group ID on execution. */
162#define __S_ISVTX 01000 /* Save swapped text after use (sticky). */
163#define __S_IREAD 0400 /* Read by owner. */
164#define __S_IWRITE 0200 /* Write by owner. */
165#define __S_IEXEC 0100 /* Execute by owner. */
166
167#ifdef __USE_ATFILE
168# define UTIME_NOW ((1l << 30) - 1l)
169# define UTIME_OMIT ((1l << 30) - 2l)
170#endif
171
172#endif /* bits/stat.h */
libc/glibc/sysdeps/unix/sysv/linux/generic/bits/stat.h created+171
......@@ -0,0 +1,171 @@
1/* Copyright (C) 2011-2019 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library. If not, see
17 <http://www.gnu.org/licenses/>. */
18
19#if !defined _SYS_STAT_H && !defined _FCNTL_H
20# error "Never include <bits/stat.h> directly; use <sys/stat.h> instead."
21#endif
22
23#ifndef _BITS_STAT_H
24#define _BITS_STAT_H 1
25
26#include <endian.h>
27#include <bits/wordsize.h>
28
29/* 64-bit libc uses the kernel's 'struct stat', accessed via the
30 stat() syscall; 32-bit libc uses the kernel's 'struct stat64'
31 and accesses it via the stat64() syscall. All the various
32 APIs offered by libc use the kernel shape for their struct stat
33 structure; the only difference is that 32-bit programs not
34 using __USE_FILE_OFFSET64 only see the low 32 bits of some
35 of the fields (specifically st_ino, st_size, and st_blocks). */
36#define _STAT_VER_KERNEL 0
37#define _STAT_VER_LINUX 0
38#define _STAT_VER _STAT_VER_KERNEL
39
40/* Versions of the `xmknod' interface. */
41#define _MKNOD_VER_LINUX 0
42
43#if defined __USE_FILE_OFFSET64
44# define __field64(type, type64, name) type64 name
45#elif __WORDSIZE == 64
46# define __field64(type, type64, name) type name
47#elif __BYTE_ORDER == __LITTLE_ENDIAN
48# define __field64(type, type64, name) \
49 type name __attribute__((__aligned__ (__alignof__ (type64)))); int __##name##_pad
50#else
51# define __field64(type, type64, name) \
52 int __##name##_pad __attribute__((__aligned__ (__alignof__ (type64)))); type name
53#endif
54
55struct stat
56 {
57 __dev_t st_dev; /* Device. */
58 __field64(__ino_t, __ino64_t, st_ino); /* File serial number. */
59 __mode_t st_mode; /* File mode. */
60 __nlink_t st_nlink; /* Link count. */
61 __uid_t st_uid; /* User ID of the file's owner. */
62 __gid_t st_gid; /* Group ID of the file's group.*/
63 __dev_t st_rdev; /* Device number, if device. */
64 __dev_t __pad1;
65 __field64(__off_t, __off64_t, st_size); /* Size of file, in bytes. */
66 __blksize_t st_blksize; /* Optimal block size for I/O. */
67 int __pad2;
68 __field64(__blkcnt_t, __blkcnt64_t, st_blocks); /* 512-byte blocks */
69#ifdef __USE_XOPEN2K8
70 /* Nanosecond resolution timestamps are stored in a format
71 equivalent to 'struct timespec'. This is the type used
72 whenever possible but the Unix namespace rules do not allow the
73 identifier 'timespec' to appear in the <sys/stat.h> header.
74 Therefore we have to handle the use of this header in strictly
75 standard-compliant sources special. */
76 struct timespec st_atim; /* Time of last access. */
77 struct timespec st_mtim; /* Time of last modification. */
78 struct timespec st_ctim; /* Time of last status change. */
79# define st_atime st_atim.tv_sec /* Backward compatibility. */
80# define st_mtime st_mtim.tv_sec
81# define st_ctime st_ctim.tv_sec
82#else
83 __time_t st_atime; /* Time of last access. */
84 unsigned long int st_atimensec; /* Nscecs of last access. */
85 __time_t st_mtime; /* Time of last modification. */
86 unsigned long int st_mtimensec; /* Nsecs of last modification. */
87 __time_t st_ctime; /* Time of last status change. */
88 unsigned long int st_ctimensec; /* Nsecs of last status change. */
89#endif
90 int __glibc_reserved[2];
91 };
92
93#undef __field64
94
95#ifdef __USE_LARGEFILE64
96struct stat64
97 {
98 __dev_t st_dev; /* Device. */
99 __ino64_t st_ino; /* File serial number. */
100 __mode_t st_mode; /* File mode. */
101 __nlink_t st_nlink; /* Link count. */
102 __uid_t st_uid; /* User ID of the file's owner. */
103 __gid_t st_gid; /* Group ID of the file's group.*/
104 __dev_t st_rdev; /* Device number, if device. */
105 __dev_t __pad1;
106 __off64_t st_size; /* Size of file, in bytes. */
107 __blksize_t st_blksize; /* Optimal block size for I/O. */
108 int __pad2;
109 __blkcnt64_t st_blocks; /* Nr. 512-byte blocks allocated. */
110#ifdef __USE_XOPEN2K8
111 /* Nanosecond resolution timestamps are stored in a format
112 equivalent to 'struct timespec'. This is the type used
113 whenever possible but the Unix namespace rules do not allow the
114 identifier 'timespec' to appear in the <sys/stat.h> header.
115 Therefore we have to handle the use of this header in strictly
116 standard-compliant sources special. */
117 struct timespec st_atim; /* Time of last access. */
118 struct timespec st_mtim; /* Time of last modification. */
119 struct timespec st_ctim; /* Time of last status change. */
120#else
121 __time_t st_atime; /* Time of last access. */
122 unsigned long int st_atimensec; /* Nscecs of last access. */
123 __time_t st_mtime; /* Time of last modification. */
124 unsigned long int st_mtimensec; /* Nsecs of last modification. */
125 __time_t st_ctime; /* Time of last status change. */
126 unsigned long int st_ctimensec; /* Nsecs of last status change. */
127#endif
128 int __glibc_reserved[2];
129 };
130#endif
131
132/* Tell code we have these members. */
133#define _STATBUF_ST_BLKSIZE
134#define _STATBUF_ST_RDEV
135/* Nanosecond resolution time values are supported. */
136#define _STATBUF_ST_NSEC
137
138/* Encoding of the file mode. */
139
140#define __S_IFMT 0170000 /* These bits determine file type. */
141
142/* File types. */
143#define __S_IFDIR 0040000 /* Directory. */
144#define __S_IFCHR 0020000 /* Character device. */
145#define __S_IFBLK 0060000 /* Block device. */
146#define __S_IFREG 0100000 /* Regular file. */
147#define __S_IFIFO 0010000 /* FIFO. */
148#define __S_IFLNK 0120000 /* Symbolic link. */
149#define __S_IFSOCK 0140000 /* Socket. */
150
151/* POSIX.1b objects. Note that these macros always evaluate to zero. But
152 they do it by enforcing the correct use of the macros. */
153#define __S_TYPEISMQ(buf) ((buf)->st_mode - (buf)->st_mode)
154#define __S_TYPEISSEM(buf) ((buf)->st_mode - (buf)->st_mode)
155#define __S_TYPEISSHM(buf) ((buf)->st_mode - (buf)->st_mode)
156
157/* Protection bits. */
158
159#define __S_ISUID 04000 /* Set user ID on execution. */
160#define __S_ISGID 02000 /* Set group ID on execution. */
161#define __S_ISVTX 01000 /* Save swapped text after use (sticky). */
162#define __S_IREAD 0400 /* Read by owner. */
163#define __S_IWRITE 0200 /* Write by owner. */
164#define __S_IEXEC 0100 /* Execute by owner. */
165
166#ifdef __USE_ATFILE
167# define UTIME_NOW ((1l << 30) - 1l)
168# define UTIME_OMIT ((1l << 30) - 2l)
169#endif
170
171#endif /* bits/stat.h */
src/link.cpp+1-1
......@@ -239,7 +239,6 @@ static const char *get_libc_crt_file(CodeGen *parent, const char *file) {
239239 {"mknod", "glibc" OS_SEP "io" OS_SEP "mknod.c"},
240240 {"mknodat", "glibc" OS_SEP "io" OS_SEP "mknodat.c"},
241241 {"pthread_atfork", "glibc" OS_SEP "nptl" OS_SEP "pthread_atfork.c"},
242 {"warning-nop", "glibc" OS_SEP "debug" OS_SEP "warning-nop.c"},
243242 {"stack_chk_fail_local", "glibc" OS_SEP "debug" OS_SEP "stack_chk_fail_local.c"},
244243 };
245244 for (size_t i = 0; i < array_length(deps); i += 1) {
......@@ -253,6 +252,7 @@ static const char *get_libc_crt_file(CodeGen *parent, const char *file) {
253252 c_file->args.append("-fno-stack-protector");
254253 c_file->args.append("-fmath-errno");
255254 c_file->args.append("-ftls-model=initial-exec");
255 c_file->args.append("-Wno-ignored-attributes");
256256 c_file->args.append("-I");
257257 c_file->args.append(path_from_libc(parent, "glibc" OS_SEP "include"));
258258 c_file->args.append("-I");