Skip to content

Commit 3cc2161

Browse files
author
Siva Chandra Reddy
committed
[libc] Move the x86_64 syscall functions to OSUtil.
Reviewed By: michaelrj, lntue Differential Revision: https://reviews.llvm.org/D116177
1 parent edf8e3e commit 3cc2161

38 files changed

+106
-88
lines changed

libc/config/linux/CMakeLists.txt

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,3 @@
1-
add_gen_header(
2-
linux_syscall_h
3-
DEF_FILE syscall.h.def
4-
GEN_HDR syscall.h
5-
PARAMS
6-
inline_syscalls=${LIBC_TARGET_ARCHITECTURE}/syscall.h.inc
7-
DATA_FILES
8-
${LIBC_TARGET_ARCHITECTURE}/syscall.h.inc
9-
DEPENDS
10-
libc.src.__support.common
11-
)
12-
131
add_header(
142
app_h
153
HDR

libc/loader/linux/x86_64/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ add_loader_object(
33
SRC
44
start.cpp
55
DEPENDS
6-
libc.config.linux.linux_syscall_h
76
libc.config.linux.app_h
87
libc.include.sys_syscall
8+
libc.src.__support.OSUtil.osutil
99
libc.src.string.memcpy
1010
libc.src.sys.mman.mmap
1111
COMPILE_OPTIONS

libc/loader/linux/x86_64/start.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "config/linux/app.h"
10-
#include "config/linux/syscall.h"
1110
#include "include/sys/mman.h"
1211
#include "include/sys/syscall.h"
12+
#include "src/__support/OSUtil/syscall.h"
1313
#include "src/string/memcpy.h"
1414
#include "src/sys/mman/mmap.h"
1515

libc/src/__support/OSUtil/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ add_header_library(
55
HDRS
66
io.h
77
quick_exit.h
8+
syscall.h
89
DEPENDS
910
libc.src.__support.OSUtil.linux.linux_util
1011
)
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
add_subdirectory(x86_64)
2+
13
add_header_library(
24
linux_util
35
HDRS
46
io.h
57
quick_exit.h
8+
syscall.h
69
DEPENDS
7-
libc.config.linux.linux_syscall_h
8-
libc.include.sys_syscall
9-
libc.src.string.string_utils
10+
.x86_64.linux_x86_64_util
11+
libc.src.__support.common
1012
)

libc/src/__support/OSUtil/linux/io.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
#ifndef LLVM_LIBC_SRC_SUPPORT_OSUTIL_LINUX_IO_H
1010
#define LLVM_LIBC_SRC_SUPPORT_OSUTIL_LINUX_IO_H
1111

12-
#include "config/linux/syscall.h" // For internal syscall function.
13-
#include "include/sys/syscall.h" // For syscall numbers.
12+
#include "include/sys/syscall.h" // For syscall numbers.
1413
#include "src/string/string_utils.h"
14+
#include "syscall.h" // For internal syscall function.
1515

1616
namespace __llvm_libc {
1717

libc/src/__support/OSUtil/linux/quick_exit.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
#ifndef LLVM_LIBC_SRC_SUPPORT_OSUTIL_LINUX_QUICK_EXIT_H
1010
#define LLVM_LIBC_SRC_SUPPORT_OSUTIL_LINUX_QUICK_EXIT_H
1111

12-
#include "config/linux/syscall.h" // For internal syscall function.
13-
#include "include/sys/syscall.h" // For syscall numbers.
12+
#include "include/sys/syscall.h" // For syscall numbers.
13+
#include "syscall.h" // For internal syscall function.
1414

1515
namespace __llvm_libc {
1616

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//===----------------------- Linux syscalls ---------------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_LIBC_SRC_SUPPORT_OSUTIL_LINUX_SYSCALL_H
10+
#define LLVM_LIBC_SRC_SUPPORT_OSUTIL_LINUX_SYSCALL_H
11+
12+
#include "src/__support/architectures.h"
13+
14+
#ifdef LLVM_LIBC_ARCH_X86_64
15+
#include "x86_64/syscall.h"
16+
#endif
17+
18+
#endif // LLVM_LIBC_SRC_SUPPORT_OSUTIL_LINUX_SYSCALL_H
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
add_header_library(
2+
linux_x86_64_util
3+
HDRS
4+
syscall.h
5+
DEPENDS
6+
libc.src.__support.common
7+
)

libc/config/linux/x86_64/syscall.h.inc renamed to libc/src/__support/OSUtil/linux/x86_64/syscall.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
//===------------ inline implementation of x86_64 syscalls ----------------===//
1+
//===---------- inline implementation of x86_64 syscalls ----------* C++ *-===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
77
//===----------------------------------------------------------------------===//
88

9-
%%begin()
9+
#ifndef LLVM_LIBC_SRC_SUPPORT_OSUTIL_LINUX_X86_64_SYSCALL_H
10+
#define LLVM_LIBC_SRC_SUPPORT_OSUTIL_LINUX_X86_64_SYSCALL_H
1011

1112
#include "src/__support/common.h"
1213

@@ -100,7 +101,8 @@ __attribute__((always_inline)) inline long syscall(long __number, Ts... ts) {
100101
return syscall(__number, (long)ts...);
101102
}
102103

103-
104104
#undef SYSCALL_CLOBBER_LIST
105105

106106
} // namespace __llvm_libc
107+
108+
#endif // LLVM_LIBC_SRC_SUPPORT_OSUTIL_LINUX_X86_64_SYSCALL_H

libc/config/linux/syscall.h.def renamed to libc/src/__support/OSUtil/syscall.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#ifndef LLVM_LIBC_CONFIG_LINUX_SYSCALL_H
10-
#define LLVM_LIBC_CONFIG_LINUX_SYSCALL_H
9+
#ifndef LLVM_LIBC_SRC_SUPPORT_OSUTIL_SYSCALL_H
10+
#define LLVM_LIBC_SRC_SUPPORT_OSUTIL_SYSCALL_H
1111

12-
%%include_file(${inline_syscalls})
12+
#ifdef __unix__
13+
#include "linux/syscall.h"
14+
#endif
1315

14-
#endif // LLVM_LIBC_CONFIG_LINUX_SYSCALL_H
16+
#endif // LLVM_LIBC_SRC_SUPPORT_OSUTIL_SYSCALL_H

libc/src/assert/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ add_entrypoint_object(
88
DEPENDS
99
# These two dependencies are temporary and should be replaced by fprintf
1010
# later.
11-
libc.config.linux.linux_syscall_h
11+
libc.src.__support.OSUtil.osutil
1212
libc.include.sys_syscall
1313
libc.src.stdlib.abort
1414
)

libc/src/assert/__assert_fail.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
#include "src/stdlib/abort.h"
1111

1212
// These includes are temporary.
13-
#include "config/linux/syscall.h" // For internal syscall function.
1413
#include "include/sys/syscall.h" // For syscall numbers.
14+
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
1515

1616
namespace __llvm_libc {
1717

libc/src/signal/linux/CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ add_entrypoint_object(
77
signal.h
88
../raise.h
99
DEPENDS
10-
libc.config.linux.linux_syscall_h
1110
libc.include.signal
1211
libc.include.sys_syscall
12+
libc.src.__support.OSUtil.osutil
1313
)
1414

1515
add_object_library(
@@ -25,8 +25,8 @@ add_object_library(
2525
# asan creates asan.module_ctor which uses stack space, causing warnings.
2626
-fno-sanitize=address
2727
DEPENDS
28-
libc.config.linux.linux_syscall_h
2928
libc.include.sys_syscall
29+
libc.src.__support.OSUtil.osutil
3030
)
3131

3232
add_entrypoint_object(
@@ -38,9 +38,9 @@ add_entrypoint_object(
3838
../sigaction.h
3939
DEPENDS
4040
.__restore
41-
libc.config.linux.linux_syscall_h
4241
libc.include.signal
4342
libc.include.sys_syscall
43+
libc.src.__support.OSUtil.osutil
4444
libc.src.errno.__errno_location
4545
)
4646

@@ -52,9 +52,9 @@ add_entrypoint_object(
5252
signal.h
5353
../sigprocmask.h
5454
DEPENDS
55-
libc.config.linux.linux_syscall_h
5655
libc.include.signal
5756
libc.include.sys_syscall
57+
libc.src.__support.OSUtil.osutil
5858
libc.src.errno.__errno_location
5959
)
6060

libc/src/signal/linux/__restore.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
// strongly control the options this file is compiled with. __restore_rt cannot
1111
// make any stack allocations so we must ensure this.
1212

13-
#include "config/linux/syscall.h"
1413
#include "include/sys/syscall.h"
14+
#include "src/__support/OSUtil/syscall.h"
1515

1616
namespace __llvm_libc {
1717

libc/src/signal/linux/signal.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
#ifndef LLVM_LIBC_SRC_SIGNAL_LINUX_SIGNAL_H
1010
#define LLVM_LIBC_SRC_SIGNAL_LINUX_SIGNAL_H
1111

12-
#include "config/linux/syscall.h" // For internal syscall function.
13-
#include "include/sys/syscall.h" // For syscall numbers.
12+
#include "include/sys/syscall.h" // For syscall numbers.
13+
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
1414

1515
#include "include/signal.h"
1616

libc/src/stdlib/linux/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ add_entrypoint_object(
66
../_Exit.h
77
DEPENDS
88
libc.include.sys_syscall
9-
libc.config.linux.linux_syscall_h
109
libc.include.stdlib
10+
libc.src.__support.OSUtil.osutil
1111
)

libc/src/stdlib/linux/_Exit.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#include "config/linux/syscall.h" // For internal syscall function.
10-
#include "include/sys/syscall.h" // For syscall numbers.
9+
#include "include/sys/syscall.h" // For syscall numbers.
10+
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
1111
#include "src/__support/common.h"
1212

1313
#include "src/stdlib/_Exit.h"

libc/src/sys/mman/linux/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ add_entrypoint_object(
55
HDRS
66
../mmap.h
77
DEPENDS
8-
libc.config.linux.linux_syscall_h
98
libc.include.sys_mman
109
libc.include.sys_syscall
10+
libc.src.__support.OSUtil.osutil
1111
libc.src.errno.__errno_location
1212
)
1313

@@ -18,8 +18,8 @@ add_entrypoint_object(
1818
HDRS
1919
../munmap.h
2020
DEPENDS
21-
libc.config.linux.linux_syscall_h
2221
libc.include.sys_mman
2322
libc.include.sys_syscall
23+
libc.src.__support.OSUtil.osutil
2424
libc.src.errno.__errno_location
2525
)

libc/src/sys/mman/linux/mmap.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
#include "src/sys/mman/mmap.h"
1010

11-
#include "config/linux/syscall.h" // For internal syscall function.
12-
#include "include/sys/syscall.h" // For syscall numbers.
11+
#include "include/sys/syscall.h" // For syscall numbers.
12+
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
1313
#include "src/__support/common.h"
1414
#include "src/errno/llvmlibc_errno.h"
1515

libc/src/sys/mman/linux/munmap.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
#include "src/sys/mman/munmap.h"
1010

11-
#include "config/linux/syscall.h" // For internal syscall function.
12-
#include "include/sys/syscall.h" // For syscall numbers.
11+
#include "include/sys/syscall.h" // For syscall numbers.
12+
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
1313
#include "src/__support/common.h"
1414
#include "src/errno/llvmlibc_errno.h"
1515

libc/src/threads/linux/CMakeLists.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ add_entrypoint_object(
1616
../call_once.h
1717
DEPENDS
1818
.threads_utils
19-
libc.config.linux.linux_syscall_h
2019
libc.include.sys_syscall
2120
libc.include.threads
21+
libc.src.__support.OSUtil.osutil
2222
)
2323

2424
add_header_library(
@@ -30,9 +30,9 @@ add_header_library(
3030
Thread.h
3131
DEPENDS
3232
.thread_start_args_h
33-
libc.config.linux.linux_syscall_h
3433
libc.include.sys_syscall
3534
libc.include.threads
35+
libc.src.__support.OSUtil.osutil
3636
)
3737

3838
add_entrypoint_object(
@@ -43,11 +43,11 @@ add_entrypoint_object(
4343
../thrd_create.h
4444
DEPENDS
4545
.threads_utils
46-
libc.config.linux.linux_syscall_h
4746
libc.include.errno
4847
libc.include.sys_syscall
4948
libc.include.threads
5049
libc.src.__support.common
50+
libc.src.__support.OSUtil.osutil
5151
libc.src.errno.__errno_location
5252
libc.src.sys.mman.mmap
5353
COMPILE_OPTIONS
@@ -64,11 +64,11 @@ add_entrypoint_object(
6464
../thrd_join.h
6565
DEPENDS
6666
.threads_utils
67-
libc.config.linux.linux_syscall_h
6867
libc.include.sys_syscall
6968
libc.include.threads
70-
libc.src.sys.mman.munmap
7169
libc.src.__support.common
70+
libc.src.__support.OSUtil.osutil
71+
libc.src.sys.mman.munmap
7272
)
7373

7474
add_entrypoint_object(

libc/src/threads/linux/CndVar.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
#include "Futex.h"
1313
#include "Mutex.h"
1414

15-
#include "config/linux/syscall.h" // For syscall functions.
16-
#include "include/sys/syscall.h" // For syscall numbers.
17-
#include "include/threads.h" // For values like thrd_success etc.
15+
#include "include/sys/syscall.h" // For syscall numbers.
16+
#include "include/threads.h" // For values like thrd_success etc.
17+
#include "src/__support/OSUtil/syscall.h" // For syscall functions.
1818

1919
#include <linux/futex.h> // For futex operations.
2020
#include <stdatomic.h> // For atomic operations

libc/src/threads/linux/Mutex.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111

1212
#include "Futex.h"
1313

14-
#include "config/linux/syscall.h" // For syscall functions.
15-
#include "include/sys/syscall.h" // For syscall numbers.
16-
#include "include/threads.h" // For values like thrd_success etc.
14+
#include "include/sys/syscall.h" // For syscall numbers.
15+
#include "include/threads.h" // For values like thrd_success etc.
16+
#include "src/__support/OSUtil/syscall.h" // For syscall functions.
1717

1818
#include <linux/futex.h> // For futex operations.
1919
#include <stdatomic.h>

libc/src/threads/linux/call_once.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "src/threads/call_once.h"
10-
#include "config/linux/syscall.h" // For syscall functions.
11-
#include "include/sys/syscall.h" // For syscall numbers.
12-
#include "include/threads.h" // For call_once related type definition.
10+
#include "include/sys/syscall.h" // For syscall numbers.
11+
#include "include/threads.h" // For call_once related type definition.
12+
#include "src/__support/OSUtil/syscall.h" // For syscall functions.
1313
#include "src/__support/common.h"
1414
#include "src/threads/linux/Futex.h"
1515

0 commit comments

Comments
 (0)