Skip to content

[WIP] Enough to get libc to build clang on aarch64 #97231

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 44 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
31dc769
[libc]: add missing aarch64 headers
izaakschroeder Jun 30, 2024
a5f8ee2
[libunwind]: remove needless `sys/uio.h`
izaakschroeder Jun 30, 2024
1083aec
[libc]: function spec for `getauxval`
izaakschroeder Jun 30, 2024
e9628ce
[libc]: hack `ExitCallbackList` always public
izaakschroeder Jun 30, 2024
e3ed9aa
[libc]: add `Scrt1.o`
izaakschroeder Jun 30, 2024
1f98bd6
[libc]: `sys_time.utimes` placeholder
izaakschroeder Jul 1, 2024
346f424
[libc]: add missing `<sys/statvfs.h>` and friends
izaakschroeder Jul 1, 2024
570638e
[libc]: add basic `ioctl` function
izaakschroeder Jul 1, 2024
57bd786
[libc]: add `dlfcn.h` placeholder
izaakschroeder Jul 1, 2024
56c789f
[libc]: add `link.h`
izaakschroeder Jul 2, 2024
4207b20
[libc]: `dirent.h` for aarch64
izaakschroeder Jul 2, 2024
f98f594
fixup! fix `utimes` types
izaakschroeder Jul 2, 2024
bc7c5da
fixup! additional `dirent` entrypoints
izaakschroeder Jul 2, 2024
0c9c7c1
fixup! ioctl add missing def
izaakschroeder Jul 2, 2024
d142e13
[libc]: `<sys/resource.h>` on aarch64
izaakschroeder Jul 2, 2024
96b360a
[libc]: `<sys/types.h>` on aarch64
izaakschroeder Jul 2, 2024
f5b9c1b
[libc]: support `getrusage`
izaakschroeder Jul 2, 2024
c5ceed8
[libc]: add `<sys/prctl.h>` on aarch64
izaakschroeder Jul 2, 2024
3f7f620
[libc]: missing `prctl` export
izaakschroeder Jul 2, 2024
a987fe3
[libc]: add `locale.h` stubs
izaakschroeder Jul 2, 2024
8510d10
[libcxx]: allow default rune table as config
izaakschroeder Jul 2, 2024
598b782
[libcxx]: swap `__Fuchsia__` for `__LLVM_LIBC__`
izaakschroeder Jul 2, 2024
50c85f7
[libcxx]: no `catopen` for llvm libc
izaakschroeder Jul 2, 2024
b6219c9
wip! more locale stuff
izaakschroeder Jul 2, 2024
eecf663
fixup! locale type ref
izaakschroeder Jul 2, 2024
6c17d9f
fixup! locale recursive target
izaakschroeder Jul 2, 2024
1e04f9a
fixup! locale whoops
izaakschroeder Jul 2, 2024
a9b420c
fixup! locale lol forgot file
izaakschroeder Jul 2, 2024
eac2273
fixup! locale fix header def
izaakschroeder Jul 2, 2024
81391e6
fixup! locale add stdlib locale_t
izaakschroeder Jul 2, 2024
88f05c2
fixup! locale fn name
izaakschroeder Jul 2, 2024
1d00a3e
fixup! more locale funcs
izaakschroeder Jul 2, 2024
47aa763
fixup! locale MB_CUR_MAX macro
izaakschroeder Jul 2, 2024
09af310
[libc]: add `vsscanf` and `vaprintf`
izaakschroeder Jul 2, 2024
15ac0f0
fixup! locale _l typedef fixes
izaakschroeder Jul 2, 2024
91ad488
fixup! vaprintf -> vasprintf
izaakschroeder Jul 2, 2024
59e2b1d
[libcxx]: no `<langinfo.h>` in llvm libc
izaakschroeder Jul 2, 2024
3e9557c
fixup! more locale funcs
izaakschroeder Jul 2, 2024
5de914c
fixup! more locale stuff and strftime
izaakschroeder Jul 2, 2024
bfec5e7
fixup! strftime add size_t
izaakschroeder Jul 2, 2024
d690577
fixup! strftime final size_t dream
izaakschroeder Jul 2, 2024
ca27b8c
fixup! strftime locale_t
izaakschroeder Jul 2, 2024
b6916e3
fixup! strftime const ptr
izaakschroeder Jul 2, 2024
ad17b28
fixup! strftime call `LIBC_NAMESPACE::` version
izaakschroeder Jul 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions libc/config/linux/aarch64/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,54 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.unistd.unlink
libc.src.unistd.unlinkat
libc.src.unistd.write

# XXX
libc.src.string.strxfrm
libc.src.string.strcoll
libc.src.stdio.ungetc
libc.src.stdio.getc
libc.src.assert.__assert_fail
libc.src.sys.time.utimes
libc.src.sys.statvfs.fstatvfs
libc.src.sys.statvfs.statvfs
libc.src.sys.ioctl.ioctl
libc.src.dlfcn.dlopen
libc.src.dlfcn.dlsym
libc.src.dlfcn.dlclose
libc.src.dlfcn.dlerror
libc.src.dlfcn.dladdr
libc.src.link.dl_iterate_phdr
libc.src.dirent.closedir
libc.src.dirent.dirfd
libc.src.dirent.opendir
libc.src.dirent.readdir
libc.src.sys.resource.getrusage
libc.src.wchar.wctob
libc.src.locale.duplocale
libc.src.locale.freelocale
libc.src.locale.localeconv
libc.src.locale.newlocale
libc.src.locale.setlocale
libc.src.locale.uselocale
libc.src.stdio.scanf
libc.src.stdio.sscanf
libc.src.stdlib.strtof_l
libc.src.stdlib.strtod_l
libc.src.stdlib.strtold_l
libc.src.stdlib.strtoull_l
libc.src.stdlib.strtoll_l
libc.src.ctype.isdigit_l
libc.src.ctype.isxdigit_l
libc.src.ctype.islower_l
libc.src.ctype.isupper_l
libc.src.ctype.tolower_l
libc.src.ctype.toupper_l
libc.src.string.strxfrm_l
libc.src.string.strcoll_l
libc.src.stdio.vsscanf
libc.src.stdio.vasprintf
libc.src.time.strftime
libc.src.time.strftime_l
)

set(TARGET_LIBM_ENTRYPOINTS
Expand Down
15 changes: 15 additions & 0 deletions libc/config/linux/aarch64/headers.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,19 @@ set(TARGET_PUBLIC_HEADERS
libc.include.sys_ioctl
# Disabled due to epoll_wait syscalls not being available on this platform.
# libc.include.sys_epoll

# XXX
libc.include.sys_auxv
libc.include.sys_statvfs
libc.include.fcntl
libc.include.sched
libc.include.sys_stat
libc.include.dlfcn
libc.include.link
libc.include.elf
libc.include.dirent
libc.include.sys_resource
libc.include.sys_types
libc.include.sys_prctl
libc.include.locale
)
22 changes: 21 additions & 1 deletion libc/config/linux/api.td
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def SysSocketAPI : PublicAPI<"sys/socket.h"> {
}

def SysResourceAPI : PublicAPI<"sys/resource.h"> {
let Types = ["rlim_t", "struct rlimit"];
let Types = ["rlim_t", "struct rlimit", "struct rusage"];
}

def SysStatAPI : PublicAPI<"sys/stat.h"> {
Expand Down Expand Up @@ -308,3 +308,23 @@ def SearchAPI : PublicAPI<"search.h"> {
def SysStatvfsAPI : PublicAPI<"sys/statvfs.h"> {
let Types = ["fsblkcnt_t", "fsfilcnt_t", "struct statvfs"];
}

def LinkAPI : PublicAPI<"link.h"> {
let Types = [
"struct dl_phdr_info",
"__dl_iterate_phdr_callback_t"
];
}

def DlfcnAPI : PublicAPI<"dlfcn.h"> {
let Types = [
"Dl_info"
];
}

def LocaleAPI : PublicAPI<"locale.h"> {
let Types = [
"struct lconv",
"locale_t"
];
}
34 changes: 34 additions & 0 deletions libc/config/linux/x86_64/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,40 @@ set(TARGET_LIBC_ENTRYPOINTS

# wchar.h entrypoints
libc.src.wchar.wctob

# XXX
libc.src.sys.time.utimes
libc.src.sys.ioctl.ioctl
libc.src.dlfcn.dlopen
libc.src.dlfcn.dlsym
libc.src.dlfcn.dlclose
libc.src.dlfcn.dlerror
libc.src.dlfcn.dladdr
libc.src.link.dl_iterate_phdr
libc.src.sys.resource.getrusage
libc.src.locale.duplocale
libc.src.locale.freelocale
libc.src.locale.localeconv
libc.src.locale.newlocale
libc.src.locale.setlocale
libc.src.locale.uselocale
libc.src.stdlib.strtof_l
libc.src.stdlib.strtod_l
libc.src.stdlib.strtold_l
libc.src.stdlib.strtoull_l
libc.src.stdlib.strtoll_l
libc.src.ctype.isdigit_l
libc.src.ctype.isxdigit_l
libc.src.ctype.islower_l
libc.src.ctype.isupper_l
libc.src.ctype.tolower_l
libc.src.ctype.toupper_l
libc.src.string.strxfrm_l
libc.src.string.strcoll_l
libc.src.stdio.vsscanf
libc.src.stdio.vasprintf
libc.src.time.strftime
libc.src.time.strftime_l
)

set(TARGET_LIBM_ENTRYPOINTS
Expand Down
7 changes: 7 additions & 0 deletions libc/config/linux/x86_64/headers.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,11 @@ set(TARGET_PUBLIC_HEADERS
libc.include.sys_types
libc.include.sys_utsname
libc.include.sys_wait

# XXX
libc.include.sys_statvfs
libc.include.dlfcn
libc.include.link
libc.include.elf
libc.include.locale
)
43 changes: 43 additions & 0 deletions libc/include/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ add_gen_header(
.llvm_libc_common_h
)

add_gen_header(
dlfcn
DEF_FILE dlfcn.h.def
GEN_HDR dlfcn.h
DEPENDS
.llvm-libc-types.Dl_info
.llvm-libc-macros.dlfcn_macros
.llvm_libc_common_h
)

add_gen_header(
features
DEF_FILE features.h.def
Expand Down Expand Up @@ -199,6 +209,8 @@ add_gen_header(
.llvm-libc-types.struct_timespec
.llvm-libc-types.struct_timeval
.llvm-libc-types.clockid_t
.llvm-libc-types.size_t
.llvm-libc-types.locale_t
)

add_gen_header(
Expand Down Expand Up @@ -358,6 +370,36 @@ add_gen_header(
.llvm-libc-types.posix_spawn_file_actions_t
)

add_gen_header(
link
DEF_FILE link.h.def
GEN_HDR link.h
DEPENDS
.llvm_libc_common_h
.llvm-libc-types.struct_dl_phdr_info
.llvm-libc-types.__dl_iterate_phdr_callback_t
.llvm-libc-macros.link_macros
)

add_gen_header(
locale
DEF_FILE locale.h.def
GEN_HDR locale.h
DEPENDS
.llvm_libc_common_h
.llvm-libc-types.struct_lconv
.llvm-libc-types.locale_t
.llvm-libc-macros.locale_macros
)

add_gen_header(
elf
DEF_FILE elf.h.def
GEN_HDR elf.h
DEPENDS
.llvm-libc-macros.elf_macros
)

# TODO: Not all platforms will have a include/sys directory. Add the sys
# directory and the targets for sys/*.h files conditional to the OS requiring
# them.
Expand Down Expand Up @@ -441,6 +483,7 @@ add_gen_header(
.llvm-libc-macros.sys_resource_macros
.llvm-libc-types.rlim_t
.llvm-libc-types.struct_rlimit
.llvm-libc-types.struct_rusage
)

add_gen_header(
Expand Down
1 change: 1 addition & 0 deletions libc/include/ctype.h.def
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#define LLVM_LIBC_CTYPE_H

#include "__llvm-libc-common.h"
#include "llvm-libc-types/locale_t.h"

%%public_api()

Expand Down
17 changes: 17 additions & 0 deletions libc/include/dlfcn.h.def
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//===-- C standard library header dlfcn.h ---------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIBC_DLFCN_H
#define LLVM_LIBC_DLFCN_H

#include "__llvm-libc-common.h"
#include "llvm-libc-macros/dlfcn-macros.h"

%%public_api()

#endif // LLVM_LIBC_DLFCN_H
14 changes: 14 additions & 0 deletions libc/include/elf.h.def
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//===-- C standard library header elf.h -----------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIBC_ELF_H
#define LLVM_LIBC_ELF_H

#include "llvm-libc-macros/elf-macros.h"

#endif // LLVM_LIBC_ELF_H
16 changes: 16 additions & 0 deletions libc/include/link.h.def
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//===-- C standard library header link.h ----------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIBC_LINK_H
#define LLVM_LIBC_LINK_H

#include "llvm-libc-macros/link-macros.h"

%%public_api()

#endif // LLVM_LIBC_LINK_H
18 changes: 18 additions & 0 deletions libc/include/llvm-libc-macros/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -277,3 +277,21 @@ add_macro_header(
HDR
stdckdint-macros.h
)

add_macro_header(
dlfcn_macros
HDR
dlfcn-macros.h
)

add_macro_header(
elf_macros
HDR
elf-macros.h
)

add_macro_header(
locale_macros
HDR
locale-macros.h
)
23 changes: 23 additions & 0 deletions libc/include/llvm-libc-macros/dlfcn-macros.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//===-- Definition of macros from dlfcn.h ---------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIBC_MACROS_DLFCN_MACROS_H
#define LLVM_LIBC_MACROS_DLFCN_MACROS_H

#define RTLD_LAZY 0x00001
#define RTLD_NOW 0x00002
#define RTLD_GLOBAL 0x00100
#define RTLD_LOCAL 0

// Non-standard stuff here
#define RTLD_BINDING_MASK 0x3
#define RTLD_NOLOAD 0x00004
#define RTLD_DEEPBIND 0x00008
#define RTLD_NODELETE 0x01000

#endif // LLVM_LIBC_MACROS_DLFCN_MACROS_H
18 changes: 18 additions & 0 deletions libc/include/llvm-libc-macros/elf-macros.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//===-- Definition of macros from elf.h -----------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIBC_MACROS_ELF_MACROS_H
#define LLVM_LIBC_MACROS_ELF_MACROS_H

#if __has_include(<linux/elf.h>)
#include <linux/elf.h>
#else
#error "cannot use <sys/elf.h> without proper system headers."
#endif

#endif // LLVM_LIBC_MACROS_ELF_MACROS_H
26 changes: 24 additions & 2 deletions libc/include/llvm-libc-macros/link-macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,30 @@
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIBC_MACROS_LINK_MACROS_H
#define LLVM_LIBC_MACROS_LINK_MACROS_H

#include "elf-macros.h"

#ifdef __LP64__
#define ElfW(type) Elf64_ ## type
#define ElfW(type) Elf64_##type
#else
#define ElfW(type) Elf32_ ## type
#define ElfW(type) Elf32_##type
#endif

struct link_map {
ElfW(Addr) l_addr;
char *l_name;
ElfW(Dyn) * l_ld;
struct link_map *l_next, *l_prev;
};

struct r_debug {
int r_version;
struct link_map *r_map;
ElfW(Addr) r_brk;
enum { RT_CONSISTENT, RT_ADD, RT_DELETE } r_state;
ElfW(Addr) r_ldbase;
};

#endif
4 changes: 4 additions & 0 deletions libc/include/llvm-libc-macros/linux/sys-resource-macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,8 @@

#define RLIM_INFINITY (~0UL)

#define RUSAGE_SELF 0
#define RUSAGE_CHILDREN (~0UL)
#define RUSAGE_THREAD 1

#endif // LLVM_LIBC_MACROS_LINUX_SYS_RESOURCE_MACROS_H
Loading
Loading