Skip to content

Commit d8e124d

Browse files
[libc] implement vdso (#91572)
1 parent fa4a631 commit d8e124d

File tree

18 files changed

+861
-1
lines changed

18 files changed

+861
-1
lines changed

libc/hdr/CMakeLists.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,4 +143,22 @@ add_proxy_header_library(
143143
libc.include.llvm-libc-macros.limits_macros
144144
)
145145

146+
add_proxy_header_library(
147+
link_macros
148+
HDRS
149+
link_macros.h
150+
FULL_BUILD_DEPENDS
151+
libc.include.llvm-libc-macros.link_macros
152+
libc.include.link
153+
)
154+
155+
add_proxy_header_library(
156+
sys_auxv_macros
157+
HDRS
158+
sys_auxv_macros.h
159+
FULL_BUILD_DEPENDS
160+
libc.include.llvm-libc-macros.sys_auxv_macros
161+
libc.include.sys_auxv
162+
)
163+
146164
add_subdirectory(types)

libc/hdr/link_macros.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//===-- Definition of macros from link.h ----------------------------------===//
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_HDR_LINK_MACROS_H
10+
#define LLVM_LIBC_HDR_LINK_MACROS_H
11+
12+
#ifdef LIBC_FULL_BUILD
13+
14+
#include "include/llvm-libc-macros/link-macros.h"
15+
16+
#else // Overlay mode
17+
18+
#include <link.h>
19+
20+
#endif // LLVM_LIBC_FULL_BUILD
21+
22+
#endif // LLVM_LIBC_HDR_LINK_MACROS_H

libc/hdr/sys_auxv_macros.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//===-- Definition of macros from sys/auxv.h ------------------------------===//
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_HDR_SYS_AUXV_MACROS_H
10+
#define LLVM_LIBC_HDR_SYS_AUXV_MACROS_H
11+
12+
#ifdef LIBC_FULL_BUILD
13+
14+
#include "include/llvm-libc-macros/sys-auxv-macros.h"
15+
16+
#else // Overlay mode
17+
18+
#include <sys/auxv.h>
19+
20+
#endif // LLVM_LIBC_FULL_BUILD
21+
22+
#endif // LLVM_LIBC_HDR_SYS_AUXV_MACROS_H

libc/src/__support/OSUtil/linux/CMakeLists.txt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,33 @@ add_object_library(
2323
libc.hdr.types.struct_f_owner_ex
2424
libc.hdr.types.off_t
2525
)
26+
27+
add_header_library(
28+
vdso_sym
29+
HDRS
30+
vdso_sym.h
31+
DEPENDS
32+
libc.src.__support.common
33+
)
34+
35+
add_object_library(
36+
vdso
37+
HDRS
38+
vdso.h
39+
SRCS
40+
vdso.cpp
41+
DEPENDS
42+
.${LIBC_TARGET_ARCHITECTURE}.vdso
43+
libc.src.__support.CPP.array
44+
libc.src.__support.CPP.optional
45+
libc.src.__support.CPP.string_view
46+
libc.src.__support.threads.callonce
47+
libc.src.__support.threads.linux.futex_word_type
48+
libc.hdr.types.struct_timeval
49+
libc.hdr.types.struct_timespec
50+
libc.hdr.types.clockid_t
51+
libc.hdr.types.time_t
52+
libc.hdr.link_macros
53+
libc.src.errno.errno
54+
libc.src.sys.auxv.getauxval
55+
)

libc/src/__support/OSUtil/linux/aarch64/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,13 @@ add_header_library(
55
DEPENDS
66
libc.src.__support.common
77
)
8+
9+
add_header_library(
10+
vdso
11+
HDRS
12+
vdso.h
13+
DEPENDS
14+
libc.src.__support.common
15+
libc.src.__support.CPP.string_view
16+
libc.src.__support.OSUtil.linux.vdso_sym
17+
)
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//===---------- aarch64 vdso configuration ------------------------* 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+
#ifndef LLVM_LIBC_SRC___SUPPORT_OSUTIL_LINUX_AARCH64_VDSO_H
9+
#define LLVM_LIBC_SRC___SUPPORT_OSUTIL_LINUX_AARCH64_VDSO_H
10+
#include "src/__support/CPP/string_view.h"
11+
#include "src/__support/OSUtil/linux/vdso_sym.h"
12+
namespace LIBC_NAMESPACE_DECL {
13+
namespace vdso {
14+
// translate VDSOSym to symbol names
15+
// https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/arm64/kernel/vdso/vdso.lds.S
16+
LIBC_INLINE constexpr cpp::string_view symbol_name(VDSOSym sym) {
17+
switch (sym) {
18+
case VDSOSym::RTSigReturn:
19+
return "__kernel_rt_sigreturn";
20+
case VDSOSym::GetTimeOfDay:
21+
return "__kernel_gettimeofday";
22+
case VDSOSym::ClockGetTime:
23+
return "__kernel_clock_gettime";
24+
case VDSOSym::ClockGetRes:
25+
return "__kernel_clock_getres";
26+
default:
27+
return "";
28+
}
29+
}
30+
31+
// symbol versions
32+
LIBC_INLINE constexpr cpp::string_view symbol_version(VDSOSym) {
33+
return "LINUX_2.6.39";
34+
}
35+
} // namespace vdso
36+
} // namespace LIBC_NAMESPACE_DECL
37+
#endif // LLVM_LIBC_SRC___SUPPORT_OSUTIL_LINUX_AARCH64_VDSO_H

libc/src/__support/OSUtil/linux/arm/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,13 @@ add_header_library(
55
DEPENDS
66
libc.src.__support.common
77
)
8+
9+
add_header_library(
10+
vdso
11+
HDRS
12+
vdso.h
13+
DEPENDS
14+
libc.src.__support.common
15+
libc.src.__support.CPP.string_view
16+
libc.src.__support.OSUtil.linux.vdso_sym
17+
)
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//===---------- arm vdso configuration ----------------------------* 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+
#ifndef LLVM_LIBC_SRC___SUPPORT_OSUTIL_LINUX_ARM_VDSO_H
9+
#define LLVM_LIBC_SRC___SUPPORT_OSUTIL_LINUX_ARM_VDSO_H
10+
#include "src/__support/CPP/string_view.h"
11+
#include "src/__support/OSUtil/linux/vdso_sym.h"
12+
namespace LIBC_NAMESPACE_DECL {
13+
namespace vdso {
14+
// translate VDSOSym to symbol names
15+
// https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/arm/vdso/vdso.lds.S
16+
LIBC_INLINE constexpr cpp::string_view symbol_name(VDSOSym sym) {
17+
switch (sym) {
18+
case VDSOSym::ClockGetTime:
19+
return "__vdso_clock_gettime";
20+
case VDSOSym::GetTimeOfDay:
21+
return "__vdso_gettimeofday";
22+
case VDSOSym::ClockGetRes:
23+
return "__vdso_clock_getres";
24+
case VDSOSym::ClockGetTime64:
25+
return "__vdso_clock_gettime64";
26+
default:
27+
return "";
28+
}
29+
}
30+
31+
// symbol versions
32+
LIBC_INLINE constexpr cpp::string_view symbol_version(VDSOSym) {
33+
return "LINUX_2.6";
34+
}
35+
} // namespace vdso
36+
} // namespace LIBC_NAMESPACE_DECL
37+
#endif // LLVM_LIBC_SRC___SUPPORT_OSUTIL_LINUX_ARM_VDSO_H

libc/src/__support/OSUtil/linux/riscv/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,13 @@ add_header_library(
55
DEPENDS
66
libc.src.__support.common
77
)
8+
9+
add_header_library(
10+
vdso
11+
HDRS
12+
vdso.h
13+
DEPENDS
14+
libc.src.__support.common
15+
libc.src.__support.CPP.string_view
16+
libc.src.__support.OSUtil.linux.vdso_sym
17+
)
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//===---------- RISC-V vdso configuration -------------------------* 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+
#ifndef LLVM_LIBC_SRC___SUPPORT_OSUTIL_LINUX_RISCV_VDSO_H
9+
#define LLVM_LIBC_SRC___SUPPORT_OSUTIL_LINUX_RISCV_VDSO_H
10+
#include "src/__support/CPP/string_view.h"
11+
#include "src/__support/OSUtil/linux/vdso_sym.h"
12+
namespace LIBC_NAMESPACE_DECL {
13+
namespace vdso {
14+
// translate VDSOSym to symbol names
15+
// https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/riscv/kernel/vdso/vdso.lds.S
16+
LIBC_INLINE constexpr cpp::string_view symbol_name(VDSOSym sym) {
17+
switch (sym) {
18+
case VDSOSym::RTSigReturn:
19+
return "__vdso_rt_sigreturn";
20+
case VDSOSym::GetTimeOfDay:
21+
return "__vdso_gettimeofday";
22+
case VDSOSym::ClockGetTime:
23+
return "__vdso_clock_gettime";
24+
case VDSOSym::ClockGetRes:
25+
return "__vdso_clock_getres";
26+
case VDSOSym::GetCpu:
27+
return "__vdso_getcpu";
28+
case VDSOSym::FlushICache:
29+
return "__vdso_flush_icache";
30+
case VDSOSym::RiscvHwProbe:
31+
return "__vdso_riscv_hwprobe";
32+
default:
33+
return "";
34+
}
35+
}
36+
37+
// symbol versions
38+
LIBC_INLINE constexpr cpp::string_view symbol_version(VDSOSym) {
39+
return "LINUX_4.15";
40+
}
41+
} // namespace vdso
42+
} // namespace LIBC_NAMESPACE_DECL
43+
#endif // LLVM_LIBC_SRC___SUPPORT_OSUTIL_LINUX_RISCV_VDSO_H

0 commit comments

Comments
 (0)