authorgravatar for public+git@mearie.orgKang Seonghoon <public+git@mearie.org> 2023-08-24 18:26:27+09:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-01-04 17:12:07-07:00
log7dcf7412c474c28deee5deeb21f109096fd9ec9e
treebd9eec66e6e7d6961ecd724d65b6ccfcc96900cd
parentd3a163f86845bcc7d20e5fd54174e480d1a8ac33

glibc: get correct files compiled into libc_nonshared.a

The scope of libc_nonshared.a was greatly changed in glibc 2.33 and 2.34, but only the change from 2.34 was reflected so far. Glibc 2.33 finally switched to versioned symbols for stat functions, meaning that libc_nonshared.a no longer contains them since 2.33. Relevant files were therefore reverted to 2.32 versions and renamed accordingly. This commit also removes errno.c, which was probably added to libc_nonshared.a based on a wrong assumption that glibc/include/errno.h requires glibc/csu/errno.c. In reality errno.h should refer to __libc_errno (not to be confused with the public __errno_location), which should be imported from libc.so. The inclusion of errno.c resulted in wrong compile options as well; this commit fixes them as well. Fixes #16152

11 files changed, 579 insertions(+), 35 deletions(-)

lib/libc/glibc/io/fstat-2.32.c created+55
...@@ -0,0 +1,55 @@
1/* Copyright (C) 1996-2020 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 In addition to the permissions in the GNU Lesser General Public
10 License, the Free Software Foundation gives you unlimited
11 permission to link the compiled version of this file with other
12 programs, and to distribute those programs without any restriction
13 coming from the use of this file. (The GNU Lesser General Public
14 License restrictions do apply in other respects; for example, they
15 cover modification of the file, and distribution when not linked
16 into another program.)
17
18 Note that people who make modified versions of this file are not
19 obligated to grant this special exception for their modified
20 versions; it is their choice whether to do so. The GNU Lesser
21 General Public License gives permission to release a modified
22 version without this exception; this exception also makes it
23 possible to release a modified version which carries forward this
24 exception.
25
26 The GNU C Library is distributed in the hope that it will be useful,
27 but WITHOUT ANY WARRANTY; without even the implied warranty of
28 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
29 Lesser General Public License for more details.
30
31 You should have received a copy of the GNU Lesser General Public
32 License along with the GNU C Library; if not, see
33 <https://www.gnu.org/licenses/>. */
34
35#include <sys/stat.h>
36
37/* This definition is only used if inlining fails for this function; see
38 the last page of <sys/stat.h>. The real work is done by the `x'
39 function which is passed a version number argument. We arrange in the
40 makefile that when not inlined this function is always statically
41 linked; that way a dynamically-linked executable always encodes the
42 version number corresponding to the data structures it uses, so the `x'
43 functions in the shared library can adapt without needing to recompile
44 all callers. */
45
46#undef fstat
47#undef __fstat
48int
49attribute_hidden
50__fstat (int fd, struct stat *buf)
51{
52 return __fxstat (_STAT_VER, fd, buf);
53}
54
55weak_hidden_alias (__fstat, fstat)
lib/libc/glibc/io/fstat64-2.32.c created+52
...@@ -0,0 +1,52 @@
1/* Copyright (C) 1996-2020 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 In addition to the permissions in the GNU Lesser General Public
10 License, the Free Software Foundation gives you unlimited
11 permission to link the compiled version of this file with other
12 programs, and to distribute those programs without any restriction
13 coming from the use of this file. (The GNU Lesser General Public
14 License restrictions do apply in other respects; for example, they
15 cover modification of the file, and distribution when not linked
16 into another program.)
17
18 Note that people who make modified versions of this file are not
19 obligated to grant this special exception for their modified
20 versions; it is their choice whether to do so. The GNU Lesser
21 General Public License gives permission to release a modified
22 version without this exception; this exception also makes it
23 possible to release a modified version which carries forward this
24 exception.
25
26 The GNU C Library is distributed in the hope that it will be useful,
27 but WITHOUT ANY WARRANTY; without even the implied warranty of
28 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
29 Lesser General Public License for more details.
30
31 You should have received a copy of the GNU Lesser General Public
32 License along with the GNU C Library; if not, see
33 <https://www.gnu.org/licenses/>. */
34
35#include <sys/stat.h>
36
37/* This definition is only used if inlining fails for this function; see
38 the last page of <sys/stat.h>. The real work is done by the `x'
39 function which is passed a version number argument. We arrange in the
40 makefile that when not inlined this function is always statically
41 linked; that way a dynamically-linked executable always encodes the
42 version number corresponding to the data structures it uses, so the `x'
43 functions in the shared library can adapt without needing to recompile
44 all callers. */
45
46#undef fstat64
47int
48attribute_hidden
49fstat64 (int fd, struct stat64 *buf)
50{
51 return __fxstat64 (_STAT_VER, fd, buf);
52}
lib/libc/glibc/io/fstatat-2.32.c created+52
...@@ -0,0 +1,52 @@
1/* Copyright (C) 2005-2020 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 In addition to the permissions in the GNU Lesser General Public
10 License, the Free Software Foundation gives you unlimited
11 permission to link the compiled version of this file with other
12 programs, and to distribute those programs without any restriction
13 coming from the use of this file. (The GNU Lesser General Public
14 License restrictions do apply in other respects; for example, they
15 cover modification of the file, and distribution when not linked
16 into another program.)
17
18 Note that people who make modified versions of this file are not
19 obligated to grant this special exception for their modified
20 versions; it is their choice whether to do so. The GNU Lesser
21 General Public License gives permission to release a modified
22 version without this exception; this exception also makes it
23 possible to release a modified version which carries forward this
24 exception.
25
26 The GNU C Library is distributed in the hope that it will be useful,
27 but WITHOUT ANY WARRANTY; without even the implied warranty of
28 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
29 Lesser General Public License for more details.
30
31 You should have received a copy of the GNU Lesser General Public
32 License along with the GNU C Library; if not, see
33 <https://www.gnu.org/licenses/>. */
34
35#include <sys/stat.h>
36
37/* This definition is only used if inlining fails for this function; see
38 the last page of <sys/stat.h>. The real work is done by the `x'
39 function which is passed a version number argument. We arrange in the
40 makefile that when not inlined this function is always statically
41 linked; that way a dynamically-linked executable always encodes the
42 version number corresponding to the data structures it uses, so the `x'
43 functions in the shared library can adapt without needing to recompile
44 all callers. */
45
46#undef fstatat
47int
48attribute_hidden
49fstatat (int fd, const char *file, struct stat *buf, int flag)
50{
51 return __fxstatat (_STAT_VER, fd, file, buf, flag);
52}
lib/libc/glibc/io/fstatat64-2.32.c created+52
...@@ -0,0 +1,52 @@
1/* Copyright (C) 2005-2020 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 In addition to the permissions in the GNU Lesser General Public
10 License, the Free Software Foundation gives you unlimited
11 permission to link the compiled version of this file with other
12 programs, and to distribute those programs without any restriction
13 coming from the use of this file. (The GNU Lesser General Public
14 License restrictions do apply in other respects; for example, they
15 cover modification of the file, and distribution when not linked
16 into another program.)
17
18 Note that people who make modified versions of this file are not
19 obligated to grant this special exception for their modified
20 versions; it is their choice whether to do so. The GNU Lesser
21 General Public License gives permission to release a modified
22 version without this exception; this exception also makes it
23 possible to release a modified version which carries forward this
24 exception.
25
26 The GNU C Library is distributed in the hope that it will be useful,
27 but WITHOUT ANY WARRANTY; without even the implied warranty of
28 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
29 Lesser General Public License for more details.
30
31 You should have received a copy of the GNU Lesser General Public
32 License along with the GNU C Library; if not, see
33 <https://www.gnu.org/licenses/>. */
34
35#include <sys/stat.h>
36
37/* This definition is only used if inlining fails for this function; see
38 the last page of <sys/stat.h>. The real work is done by the `x'
39 function which is passed a version number argument. We arrange in the
40 makefile that when not inlined this function is always statically
41 linked; that way a dynamically-linked executable always encodes the
42 version number corresponding to the data structures it uses, so the `x'
43 functions in the shared library can adapt without needing to recompile
44 all callers. */
45
46#undef fstatat64
47int
48attribute_hidden
49fstatat64 (int fd, const char *file, struct stat64 *buf, int flag)
50{
51 return __fxstatat64 (_STAT_VER, fd, file, buf, flag);
52}
lib/libc/glibc/io/lstat-2.32.c created+55
...@@ -0,0 +1,55 @@
1/* Copyright (C) 1996-2020 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 In addition to the permissions in the GNU Lesser General Public
10 License, the Free Software Foundation gives you unlimited
11 permission to link the compiled version of this file with other
12 programs, and to distribute those programs without any restriction
13 coming from the use of this file. (The GNU Lesser General Public
14 License restrictions do apply in other respects; for example, they
15 cover modification of the file, and distribution when not linked
16 into another program.)
17
18 Note that people who make modified versions of this file are not
19 obligated to grant this special exception for their modified
20 versions; it is their choice whether to do so. The GNU Lesser
21 General Public License gives permission to release a modified
22 version without this exception; this exception also makes it
23 possible to release a modified version which carries forward this
24 exception.
25
26 The GNU C Library is distributed in the hope that it will be useful,
27 but WITHOUT ANY WARRANTY; without even the implied warranty of
28 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
29 Lesser General Public License for more details.
30
31 You should have received a copy of the GNU Lesser General Public
32 License along with the GNU C Library; if not, see
33 <https://www.gnu.org/licenses/>. */
34
35#include <sys/stat.h>
36
37/* This definition is only used if inlining fails for this function; see
38 the last page of <sys/stat.h>. The real work is done by the `x'
39 function which is passed a version number argument. We arrange in the
40 makefile that when not inlined this function is always statically
41 linked; that way a dynamically-linked executable always encodes the
42 version number corresponding to the data structures it uses, so the `x'
43 functions in the shared library can adapt without needing to recompile
44 all callers. */
45
46#undef lstat
47#undef __lstat
48int
49attribute_hidden
50__lstat (const char *file, struct stat *buf)
51{
52 return __lxstat (_STAT_VER, file, buf);
53}
54
55weak_hidden_alias (__lstat, lstat)
lib/libc/glibc/io/lstat64-2.32.c created+52
...@@ -0,0 +1,52 @@
1/* Copyright (C) 1996-2020 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 In addition to the permissions in the GNU Lesser General Public
10 License, the Free Software Foundation gives you unlimited
11 permission to link the compiled version of this file with other
12 programs, and to distribute those programs without any restriction
13 coming from the use of this file. (The GNU Lesser General Public
14 License restrictions do apply in other respects; for example, they
15 cover modification of the file, and distribution when not linked
16 into another program.)
17
18 Note that people who make modified versions of this file are not
19 obligated to grant this special exception for their modified
20 versions; it is their choice whether to do so. The GNU Lesser
21 General Public License gives permission to release a modified
22 version without this exception; this exception also makes it
23 possible to release a modified version which carries forward this
24 exception.
25
26 The GNU C Library is distributed in the hope that it will be useful,
27 but WITHOUT ANY WARRANTY; without even the implied warranty of
28 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
29 Lesser General Public License for more details.
30
31 You should have received a copy of the GNU Lesser General Public
32 License along with the GNU C Library; if not, see
33 <https://www.gnu.org/licenses/>. */
34
35#include <sys/stat.h>
36
37/* This definition is only used if inlining fails for this function; see
38 the last page of <sys/stat.h>. The real work is done by the `x'
39 function which is passed a version number argument. We arrange in the
40 makefile that when not inlined this function is always statically
41 linked; that way a dynamically-linked executable always encodes the
42 version number corresponding to the data structures it uses, so the `x'
43 functions in the shared library can adapt without needing to recompile
44 all callers. */
45
46#undef lstat64
47int
48attribute_hidden
49lstat64 (const char *file, struct stat64 *buf)
50{
51 return __lxstat64 (_STAT_VER, file, buf);
52}
lib/libc/glibc/io/mknod-2.32.c created+55
...@@ -0,0 +1,55 @@
1/* Copyright (C) 1995-2020 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 In addition to the permissions in the GNU Lesser General Public
10 License, the Free Software Foundation gives you unlimited
11 permission to link the compiled version of this file with other
12 programs, and to distribute those programs without any restriction
13 coming from the use of this file. (The GNU Lesser General Public
14 License restrictions do apply in other respects; for example, they
15 cover modification of the file, and distribution when not linked
16 into another program.)
17
18 Note that people who make modified versions of this file are not
19 obligated to grant this special exception for their modified
20 versions; it is their choice whether to do so. The GNU Lesser
21 General Public License gives permission to release a modified
22 version without this exception; this exception also makes it
23 possible to release a modified version which carries forward this
24 exception.
25
26 The GNU C Library is distributed in the hope that it will be useful,
27 but WITHOUT ANY WARRANTY; without even the implied warranty of
28 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
29 Lesser General Public License for more details.
30
31 You should have received a copy of the GNU Lesser General Public
32 License along with the GNU C Library; if not, see
33 <https://www.gnu.org/licenses/>. */
34
35
36#include <sys/types.h>
37#include <sys/stat.h>
38
39/* This definition is only used if inlining fails for this function; see
40 the last page of <sys/stat.h>. The real work is done by the `x'
41 function which is passed a version number argument. We arrange in the
42 makefile that when not inlined this function is always statically
43 linked; that way a dynamically-linked executable always encodes the
44 version number corresponding to the data structures it uses, so the `x'
45 functions in the shared library can adapt without needing to recompile
46 all callers. */
47
48int
49attribute_hidden
50__mknod (const char *path, mode_t mode, dev_t dev)
51{
52 return __xmknod (_MKNOD_VER, path, mode, &dev);
53}
54
55weak_hidden_alias (__mknod, mknod)
lib/libc/glibc/io/mknodat-2.32.c created+53
...@@ -0,0 +1,53 @@
1/* Copyright (C) 1995-2020 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 In addition to the permissions in the GNU Lesser General Public
10 License, the Free Software Foundation gives you unlimited
11 permission to link the compiled version of this file with other
12 programs, and to distribute those programs without any restriction
13 coming from the use of this file. (The GNU Lesser General Public
14 License restrictions do apply in other respects; for example, they
15 cover modification of the file, and distribution when not linked
16 into another program.)
17
18 Note that people who make modified versions of this file are not
19 obligated to grant this special exception for their modified
20 versions; it is their choice whether to do so. The GNU Lesser
21 General Public License gives permission to release a modified
22 version without this exception; this exception also makes it
23 possible to release a modified version which carries forward this
24 exception.
25
26 The GNU C Library is distributed in the hope that it will be useful,
27 but WITHOUT ANY WARRANTY; without even the implied warranty of
28 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
29 Lesser General Public License for more details.
30
31 You should have received a copy of the GNU Lesser General Public
32 License along with the GNU C Library; if not, see
33 <https://www.gnu.org/licenses/>. */
34
35
36#include <sys/types.h>
37#include <sys/stat.h>
38
39/* This definition is only used if inlining fails for this function; see
40 the last page of <sys/stat.h>. The real work is done by the `x'
41 function which is passed a version number argument. We arrange in the
42 makefile that when not inlined this function is always statically
43 linked; that way a dynamically-linked executable always encodes the
44 version number corresponding to the data structures it uses, so the `x'
45 functions in the shared library can adapt without needing to recompile
46 all callers. */
47
48int
49attribute_hidden
50mknodat (int fd, const char *path, mode_t mode, dev_t dev)
51{
52 return __xmknodat (_MKNOD_VER, fd, path, mode, &dev);
53}
lib/libc/glibc/io/stat-2.32.c created+54
...@@ -0,0 +1,54 @@
1/* Copyright (C) 1996-2020 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 In addition to the permissions in the GNU Lesser General Public
10 License, the Free Software Foundation gives you unlimited
11 permission to link the compiled version of this file with other
12 programs, and to distribute those programs without any restriction
13 coming from the use of this file. (The GNU Lesser General Public
14 License restrictions do apply in other respects; for example, they
15 cover modification of the file, and distribution when not linked
16 into another program.)
17
18 Note that people who make modified versions of this file are not
19 obligated to grant this special exception for their modified
20 versions; it is their choice whether to do so. The GNU Lesser
21 General Public License gives permission to release a modified
22 version without this exception; this exception also makes it
23 possible to release a modified version which carries forward this
24 exception.
25
26 The GNU C Library is distributed in the hope that it will be useful,
27 but WITHOUT ANY WARRANTY; without even the implied warranty of
28 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
29 Lesser General Public License for more details.
30
31 You should have received a copy of the GNU Lesser General Public
32 License along with the GNU C Library; if not, see
33 <https://www.gnu.org/licenses/>. */
34
35#include <sys/stat.h>
36
37/* This definition is only used if inlining fails for this function; see
38 the last page of <sys/stat.h>. The real work is done by the `x'
39 function which is passed a version number argument. We arrange in the
40 makefile that when not inlined this function is always statically
41 linked; that way a dynamically-linked executable always encodes the
42 version number corresponding to the data structures it uses, so the `x'
43 functions in the shared library can adapt without needing to recompile
44 all callers. */
45
46#undef stat
47int
48attribute_hidden
49__stat (const char *file, struct stat *buf)
50{
51 return __xstat (_STAT_VER, file, buf);
52}
53
54weak_hidden_alias (__stat, stat)
lib/libc/glibc/io/stat64-2.32.c created+52
...@@ -0,0 +1,52 @@
1/* Copyright (C) 1996-2020 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 In addition to the permissions in the GNU Lesser General Public
10 License, the Free Software Foundation gives you unlimited
11 permission to link the compiled version of this file with other
12 programs, and to distribute those programs without any restriction
13 coming from the use of this file. (The GNU Lesser General Public
14 License restrictions do apply in other respects; for example, they
15 cover modification of the file, and distribution when not linked
16 into another program.)
17
18 Note that people who make modified versions of this file are not
19 obligated to grant this special exception for their modified
20 versions; it is their choice whether to do so. The GNU Lesser
21 General Public License gives permission to release a modified
22 version without this exception; this exception also makes it
23 possible to release a modified version which carries forward this
24 exception.
25
26 The GNU C Library is distributed in the hope that it will be useful,
27 but WITHOUT ANY WARRANTY; without even the implied warranty of
28 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
29 Lesser General Public License for more details.
30
31 You should have received a copy of the GNU Lesser General Public
32 License along with the GNU C Library; if not, see
33 <https://www.gnu.org/licenses/>. */
34
35#include <sys/stat.h>
36
37/* This definition is only used if inlining fails for this function; see
38 the last page of <sys/stat.h>. The real work is done by the `x'
39 function which is passed a version number argument. We arrange in the
40 makefile that when not inlined this function is always statically
41 linked; that way a dynamically-linked executable always encodes the
42 version number corresponding to the data structures it uses, so the `x'
43 functions in the shared library can adapt without needing to recompile
44 all callers. */
45
46#undef stat64
47int
48attribute_hidden
49stat64 (const char *file, struct stat64 *buf)
50{
51 return __xstat64 (_STAT_VER, file, buf);
52}
src/glibc.zig+47-35
...@@ -172,6 +172,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr...@@ -172,6 +172,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr
172172
173 const target = comp.root_mod.resolved_target.result;173 const target = comp.root_mod.resolved_target.result;
174 const target_ver = target.os.version_range.linux.glibc;174 const target_ver = target.os.version_range.linux.glibc;
175 const nonshared_stat = target_ver.order(.{ .major = 2, .minor = 32, .patch = 0 }) != .gt;
175 const start_old_init_fini = target_ver.order(.{ .major = 2, .minor = 33, .patch = 0 }) != .gt;176 const start_old_init_fini = target_ver.order(.{ .major = 2, .minor = 33, .patch = 0 }) != .gt;
176177
177 // In all cases in this function, we add the C compiler flags to178 // In all cases in this function, we add the C compiler flags to
...@@ -276,54 +277,72 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr...@@ -276,54 +277,72 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr
276 },277 },
277 .libc_nonshared_a => {278 .libc_nonshared_a => {
278 const s = path.sep_str;279 const s = path.sep_str;
279 const linux_prefix = lib_libc_glibc ++
280 "sysdeps" ++ s ++ "unix" ++ s ++ "sysv" ++ s ++ "linux" ++ s;
281 const Flavor = enum { nonshared, shared };
282 const Dep = struct {280 const Dep = struct {
283 path: []const u8,281 path: []const u8,
284 flavor: Flavor = .shared,282 include: bool = true,
285 exclude: bool = false,
286 };283 };
287 const deps = [_]Dep{284 const deps = [_]Dep{
285 .{ .path = lib_libc_glibc ++ "stdlib" ++ s ++ "atexit.c" },
286 .{ .path = lib_libc_glibc ++ "stdlib" ++ s ++ "at_quick_exit.c" },
287 .{ .path = lib_libc_glibc ++ "sysdeps" ++ s ++ "pthread" ++ s ++ "pthread_atfork.c" },
288 .{ .path = lib_libc_glibc ++ "debug" ++ s ++ "stack_chk_fail_local.c" },
289
290 // libc_nonshared.a redirected stat functions to xstat until glibc 2.33,
291 // when they were finally versioned like other symbols.
292 .{
293 .path = lib_libc_glibc ++ "io" ++ s ++ "stat-2.32.c",
294 .include = nonshared_stat,
295 },
296 .{
297 .path = lib_libc_glibc ++ "io" ++ s ++ "fstat-2.32.c",
298 .include = nonshared_stat,
299 },
300 .{
301 .path = lib_libc_glibc ++ "io" ++ s ++ "lstat-2.32.c",
302 .include = nonshared_stat,
303 },
288 .{304 .{
289 .path = lib_libc_glibc ++ "stdlib" ++ s ++ "atexit.c",305 .path = lib_libc_glibc ++ "io" ++ s ++ "stat64-2.32.c",
290 .flavor = .nonshared,306 .include = nonshared_stat,
291 },307 },
292 .{308 .{
293 .path = lib_libc_glibc ++ "stdlib" ++ s ++ "at_quick_exit.c",309 .path = lib_libc_glibc ++ "io" ++ s ++ "fstat64-2.32.c",
294 .flavor = .nonshared,310 .include = nonshared_stat,
295 },311 },
296 .{312 .{
297 .path = lib_libc_glibc ++ "sysdeps" ++ s ++ "pthread" ++ s ++ "pthread_atfork.c",313 .path = lib_libc_glibc ++ "io" ++ s ++ "lstat64-2.32.c",
298 .flavor = .nonshared,314 .include = nonshared_stat,
299 },315 },
300 .{316 .{
301 .path = lib_libc_glibc ++ "debug" ++ s ++ "stack_chk_fail_local.c",317 .path = lib_libc_glibc ++ "io" ++ s ++ "fstatat-2.32.c",
302 .flavor = .nonshared,318 .include = nonshared_stat,
303 },319 },
304 .{ .path = lib_libc_glibc ++ "csu" ++ s ++ "errno.c" },320 .{
321 .path = lib_libc_glibc ++ "io" ++ s ++ "fstatat64-2.32.c",
322 .include = nonshared_stat,
323 },
324 .{
325 .path = lib_libc_glibc ++ "io" ++ s ++ "mknodat-2.32.c",
326 .include = nonshared_stat,
327 },
328 .{
329 .path = lib_libc_glibc ++ "io" ++ s ++ "mknod-2.32.c",
330 .include = nonshared_stat,
331 },
332
333 // __libc_start_main used to require statically linked init/fini callbacks
334 // until glibc 2.34 when they were assimilated into the shared library.
305 .{335 .{
306 .path = lib_libc_glibc ++ "csu" ++ s ++ "elf-init-2.33.c",336 .path = lib_libc_glibc ++ "csu" ++ s ++ "elf-init-2.33.c",
307 .exclude = !start_old_init_fini,337 .include = start_old_init_fini,
308 },338 },
309 .{ .path = linux_prefix ++ "stat.c" },
310 .{ .path = linux_prefix ++ "fstat.c" },
311 .{ .path = linux_prefix ++ "lstat.c" },
312 .{ .path = linux_prefix ++ "stat64.c" },
313 .{ .path = linux_prefix ++ "fstat64.c" },
314 .{ .path = linux_prefix ++ "lstat64.c" },
315 .{ .path = linux_prefix ++ "fstatat.c" },
316 .{ .path = linux_prefix ++ "fstatat64.c" },
317 .{ .path = linux_prefix ++ "mknodat.c" },
318 .{ .path = lib_libc_glibc ++ "io" ++ s ++ "mknod.c" },
319 .{ .path = linux_prefix ++ "stat_t64_cp.c" },
320 };339 };
321340
322 var files_buf: [deps.len]Compilation.CSourceFile = undefined;341 var files_buf: [deps.len]Compilation.CSourceFile = undefined;
323 var files_index: usize = 0;342 var files_index: usize = 0;
324343
325 for (deps) |dep| {344 for (deps) |dep| {
326 if (dep.exclude) continue;345 if (!dep.include) continue;
327346
328 var args = std.ArrayList([]const u8).init(arena);347 var args = std.ArrayList([]const u8).init(arena);
329 try args.appendSlice(&[_][]const u8{348 try args.appendSlice(&[_][]const u8{
...@@ -347,13 +366,6 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr...@@ -347,13 +366,6 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr
347 try args.append("-DCAN_USE_REGISTER_ASM_EBP");366 try args.append("-DCAN_USE_REGISTER_ASM_EBP");
348 }367 }
349368
350 const shared_def = switch (dep.flavor) {
351 .nonshared => "-DLIBC_NONSHARED=1",
352 // glibc passes `-DSHARED` for these. However, empirically if
353 // we do that here we will see undefined symbols such as `__GI_memcpy`.
354 // So we pass the same thing as for nonshared.
355 .shared => "-DLIBC_NONSHARED=1",
356 };
357 try args.appendSlice(&[_][]const u8{369 try args.appendSlice(&[_][]const u8{
358 "-D_LIBC_REENTRANT",370 "-D_LIBC_REENTRANT",
359 "-include",371 "-include",
...@@ -363,7 +375,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr...@@ -363,7 +375,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr
363 "-include",375 "-include",
364 try lib_path(comp, arena, lib_libc_glibc ++ "include" ++ path.sep_str ++ "libc-symbols.h"),376 try lib_path(comp, arena, lib_libc_glibc ++ "include" ++ path.sep_str ++ "libc-symbols.h"),
365 "-DPIC",377 "-DPIC",
366 shared_def,378 "-DLIBC_NONSHARED=1",
367 "-DTOP_NAMESPACE=glibc",379 "-DTOP_NAMESPACE=glibc",
368 });380 });
369 files_buf[files_index] = .{381 files_buf[files_index] = .{