authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-12-15 17:53:29-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-12-15 18:34:27-07:00
loge977455f7c5693369d547c4d9b2e0b902f578d65
tree1a07981c76145e6eb265ab29e0fccc3d0d0a3b77
parent59a3a27a6828af96cf579417a194fd1ee35fa0c7

glibc: improve RISC-V support

* omit crti.o / crtn.o for this architecture * add missing entry.h header from upstream

7 files changed, 92 insertions(+), 11 deletions(-)

lib/libc/glibc/sysdeps/generic/entry.h created+5
...@@ -0,0 +1,5 @@
1#ifndef __ASSEMBLY__
2extern void _start (void) attribute_hidden;
3#endif
4
5#define ENTRY_POINT _start
lib/libc/glibc/sysdeps/hppa/entry.h created+13
...@@ -0,0 +1,13 @@
1#ifndef __ASSEMBLY__
2extern void _start (void);
3#endif
4
5/* Lives in libgcc.so and canonicalizes function pointers for comparison. */
6extern unsigned int __canonicalize_funcptr_for_compare (unsigned int fptr);
7
8/* The function's entry point is stored in the first word of the
9 function descriptor (plabel) of _start(). */
10#define ENTRY_POINT __canonicalize_funcptr_for_compare((unsigned int)_start)
11
12/* We have to provide a special declaration. */
13#define ENTRY_POINT_DECL(class) class void _start (void);
lib/libc/glibc/sysdeps/ia64/entry.h created+13
...@@ -0,0 +1,13 @@
1#include <link.h>
2#include <dl-fptr.h>
3
4#ifndef __ASSEMBLY__
5extern void _start (void);
6#endif
7
8/* The function's entry point is stored in the first word of the
9 function descriptor (plabel) of _start(). */
10#define ENTRY_POINT ELF_PTR_TO_FDESC (_start)->ip
11
12/* We have to provide a special declaration. */
13#define ENTRY_POINT_DECL(class) class void _start (void);
lib/libc/glibc/sysdeps/powerpc/powerpc64/entry.h created+37
...@@ -0,0 +1,37 @@
1/* Finding the entry point and start of text. PowerPC64 version.
2 Copyright (C) 2002-2021 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 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 <https://www.gnu.org/licenses/>. */
18
19
20#ifndef __ASSEMBLY__
21extern void _start (void);
22#endif
23
24#define ENTRY_POINT _start
25
26#if _CALL_ELF != 2
27/* We have to provide a special declaration. */
28#define ENTRY_POINT_DECL(class) class void _start (void);
29
30/* Use the address of ._start as the lowest address for which we need
31 to keep profiling records. We can't copy the ia64 scheme as our
32 entry poiny address is really the address of the function
33 descriptor, not the actual function entry. */
34#define TEXT_START \
35 ({ extern unsigned long int _start_as_data[] asm ("_start"); \
36 _start_as_data[0]; })
37#endif
lib/libc/glibc/sysdeps/unix/mips/entry.h created+5
...@@ -0,0 +1,5 @@
1#ifndef __ASSEMBLY__
2extern void __start (void);
3#endif
4
5#define ENTRY_POINT __start
src/Compilation.zig+11-11
...@@ -1586,7 +1586,17 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {...@@ -1586,7 +1586,17 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
1586 // If we need to build glibc for the target, add work items for it.1586 // If we need to build glibc for the target, add work items for it.
1587 // We go through the work queue so that building can be done in parallel.1587 // We go through the work queue so that building can be done in parallel.
1588 if (comp.wantBuildGLibCFromSource()) {1588 if (comp.wantBuildGLibCFromSource()) {
1589 try comp.addBuildingGLibCJobs();1589 if (glibc.needsCrtiCrtn(comp.getTarget())) {
1590 try comp.work_queue.write(&[_]Job{
1591 .{ .glibc_crt_file = .crti_o },
1592 .{ .glibc_crt_file = .crtn_o },
1593 });
1594 }
1595 try comp.work_queue.write(&[_]Job{
1596 .{ .glibc_crt_file = .scrt1_o },
1597 .{ .glibc_crt_file = .libc_nonshared_a },
1598 .{ .glibc_shared_objects = {} },
1599 });
1590 }1600 }
1591 if (comp.wantBuildMuslFromSource()) {1601 if (comp.wantBuildMuslFromSource()) {
1592 try comp.work_queue.ensureUnusedCapacity(6);1602 try comp.work_queue.ensureUnusedCapacity(6);
...@@ -4046,16 +4056,6 @@ pub fn get_libc_crt_file(comp: *Compilation, arena: Allocator, basename: []const...@@ -4046,16 +4056,6 @@ pub fn get_libc_crt_file(comp: *Compilation, arena: Allocator, basename: []const
4046 return full_path;4056 return full_path;
4047}4057}
40484058
4049fn addBuildingGLibCJobs(comp: *Compilation) !void {
4050 try comp.work_queue.write(&[_]Job{
4051 .{ .glibc_crt_file = .crti_o },
4052 .{ .glibc_crt_file = .crtn_o },
4053 .{ .glibc_crt_file = .scrt1_o },
4054 .{ .glibc_crt_file = .libc_nonshared_a },
4055 .{ .glibc_shared_objects = {} },
4056 });
4057}
4058
4059fn wantBuildLibCFromSource(comp: Compilation) bool {4059fn wantBuildLibCFromSource(comp: Compilation) bool {
4060 const is_exe_or_dyn_lib = switch (comp.bin_file.options.output_mode) {4060 const is_exe_or_dyn_lib = switch (comp.bin_file.options.output_mode) {
4061 .Obj => false,4061 .Obj => false,
src/glibc.zig+8
...@@ -1062,3 +1062,11 @@ fn buildSharedLib(...@@ -1062,3 +1062,11 @@ fn buildSharedLib(
10621062
1063 try sub_compilation.updateSubCompilation();1063 try sub_compilation.updateSubCompilation();
1064}1064}
1065
1066// Return true if glibc has crti/crtn sources for that architecture.
1067pub fn needsCrtiCrtn(target: std.Target) bool {
1068 return switch (target.cpu.arch) {
1069 .riscv32, .riscv64 => false,
1070 else => true,
1071 };
1072}