Skip to content

[libc] implement vdso #91572

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

Merged
merged 36 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
9673650
[libc] implement vdso
SchrodingerZhu May 9, 2024
fad0a8e
[libc] add simple tests for vDSO symbols
SchrodingerZhu May 9, 2024
7975840
[libc] fix header
SchrodingerZhu May 9, 2024
fce9d12
[libc] add missing header guards
SchrodingerZhu May 9, 2024
9c0668d
[libc] fix overlay build problems
SchrodingerZhu May 9, 2024
2a43d7e
[libc] remove toplevel vdso and non-linux vdso
SchrodingerZhu May 10, 2024
4d93cc0
wrap vDSO parsing utilities in unnamed namespace
SchrodingerZhu May 13, 2024
a575ca9
use `auto` after explicit casting
SchrodingerZhu May 22, 2024
5dc4737
error on failure of arch resolution.
SchrodingerZhu May 22, 2024
9852d54
remove extra brace
SchrodingerZhu May 26, 2024
ad62a03
restructure vdso initialization routine
May 26, 2024
4aead1e
adjust vDSO definitions
May 26, 2024
347c1f7
add more tests
May 26, 2024
16f7426
address CRs
May 29, 2024
1614d0f
[libc] add comment for x86 vdso
Jun 1, 2024
6e90bcd
[libc] fix
Jun 1, 2024
66a7e5b
[libc] fix
Jun 1, 2024
a0110ea
[libc] fix
Jun 1, 2024
4baa641
[libc] fix
Jun 1, 2024
b0462dd
[libc] undo extra changes
Jun 1, 2024
4e48674
address CRs and improve inlining of fastpaths
Jun 9, 2024
6705345
add back links to kernel sources
Jun 9, 2024
37644c9
fix silly bugs
Jun 9, 2024
6478047
remove extra friend
Jun 9, 2024
3fefec5
fix riscv
Jun 9, 2024
a275cb8
fix typo
Jun 9, 2024
db4ccf5
add typed symbol
Jun 9, 2024
2e158fc
address CR and latest changes
SchrodingerZhu Sep 10, 2024
cca6647
address CR and latest changes
SchrodingerZhu Sep 10, 2024
9017884
simplify dispatcher
SchrodingerZhu Sep 10, 2024
56fe811
fix format
SchrodingerZhu Sep 10, 2024
18b0fd9
fix format
SchrodingerZhu Sep 10, 2024
df58616
fix format
SchrodingerZhu Sep 10, 2024
fc42ae6
[libc] address CRs
SchrodingerZhu Sep 10, 2024
f5ec229
[libc] address CRs
SchrodingerZhu Sep 10, 2024
3031d4a
address more
SchrodingerZhu Sep 11, 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
18 changes: 18 additions & 0 deletions libc/hdr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,22 @@ add_proxy_header_library(
libc.include.llvm-libc-macros.limits_macros
)

add_proxy_header_library(
link_macros
HDRS
link_macros.h
FULL_BUILD_DEPENDS
libc.include.llvm-libc-macros.link_macros
libc.include.link
)

add_proxy_header_library(
sys_auxv_macros
HDRS
sys_auxv_macros.h
FULL_BUILD_DEPENDS
libc.include.llvm-libc-macros.sys_auxv_macros
libc.include.sys_auxv
)

add_subdirectory(types)
22 changes: 22 additions & 0 deletions libc/hdr/link_macros.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//===-- Definition of macros from 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_HDR_LINK_MACROS_H
#define LLVM_LIBC_HDR_LINK_MACROS_H

#ifdef LIBC_FULL_BUILD

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

#else // Overlay mode

#include <link.h>

#endif // LLVM_LIBC_FULL_BUILD

#endif // LLVM_LIBC_HDR_LINK_MACROS_H
22 changes: 22 additions & 0 deletions libc/hdr/sys_auxv_macros.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//===-- Definition of macros from sys/auxv.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_HDR_SYS_AUXV_MACROS_H
#define LLVM_LIBC_HDR_SYS_AUXV_MACROS_H

#ifdef LIBC_FULL_BUILD

#include "include/llvm-libc-macros/sys-auxv-macros.h"

#else // Overlay mode

#include <sys/auxv.h>

#endif // LLVM_LIBC_FULL_BUILD

#endif // LLVM_LIBC_HDR_SYS_AUXV_MACROS_H
30 changes: 30 additions & 0 deletions libc/src/__support/OSUtil/linux/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,33 @@ add_object_library(
libc.hdr.types.struct_f_owner_ex
libc.hdr.types.off_t
)

add_header_library(
vdso_sym
HDRS
vdso_sym.h
DEPENDS
libc.src.__support.common
)

add_object_library(
vdso
HDRS
vdso.h
SRCS
vdso.cpp
DEPENDS
.${LIBC_TARGET_ARCHITECTURE}.vdso
libc.src.__support.CPP.array
libc.src.__support.CPP.optional
libc.src.__support.CPP.string_view
libc.src.__support.threads.callonce
libc.src.__support.threads.linux.futex_word_type
libc.hdr.types.struct_timeval
libc.hdr.types.struct_timespec
libc.hdr.types.clockid_t
libc.hdr.types.time_t
libc.hdr.link_macros
libc.src.errno.errno
libc.src.sys.auxv.getauxval
)
10 changes: 10 additions & 0 deletions libc/src/__support/OSUtil/linux/aarch64/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,13 @@ add_header_library(
DEPENDS
libc.src.__support.common
)

add_header_library(
vdso
HDRS
vdso.h
DEPENDS
libc.src.__support.common
libc.src.__support.CPP.string_view
libc.src.__support.OSUtil.linux.vdso_sym
)
37 changes: 37 additions & 0 deletions libc/src/__support/OSUtil/linux/aarch64/vdso.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//===---------- aarch64 vdso configuration ------------------------* C++ *-===//
//
// 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_SRC___SUPPORT_OSUTIL_LINUX_AARCH64_VDSO_H
#define LLVM_LIBC_SRC___SUPPORT_OSUTIL_LINUX_AARCH64_VDSO_H
#include "src/__support/CPP/string_view.h"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should also include the top level vdso header (src/__support/OSUtil/linux/vdso.h). Each header should be able to build on its own.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would make a recursive include chain, which is not good. (it wouldn't actually infinitely recurse because of header guards, but it's still a bad idea).

Perhaps instead these arch/vdso.h files should be renamed to ".inc" and be without header guards, to show that they're not intended to be standalone headers?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or we can refactor VDSOSym to its own header file vdsosym.h to be included in all targets and the main vdso.h.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in 3031d4a

#include "src/__support/OSUtil/linux/vdso_sym.h"
namespace LIBC_NAMESPACE_DECL {
namespace vdso {
// translate VDSOSym to symbol names
// https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/arm64/kernel/vdso/vdso.lds.S
LIBC_INLINE constexpr cpp::string_view symbol_name(VDSOSym sym) {
switch (sym) {
case VDSOSym::RTSigReturn:
return "__kernel_rt_sigreturn";
case VDSOSym::GetTimeOfDay:
return "__kernel_gettimeofday";
case VDSOSym::ClockGetTime:
return "__kernel_clock_gettime";
case VDSOSym::ClockGetRes:
return "__kernel_clock_getres";
default:
return "";
}
}

// symbol versions
LIBC_INLINE constexpr cpp::string_view symbol_version(VDSOSym) {
return "LINUX_2.6.39";
}
} // namespace vdso
} // namespace LIBC_NAMESPACE_DECL
#endif // LLVM_LIBC_SRC___SUPPORT_OSUTIL_LINUX_AARCH64_VDSO_H
10 changes: 10 additions & 0 deletions libc/src/__support/OSUtil/linux/arm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,13 @@ add_header_library(
DEPENDS
libc.src.__support.common
)

add_header_library(
vdso
HDRS
vdso.h
DEPENDS
libc.src.__support.common
libc.src.__support.CPP.string_view
libc.src.__support.OSUtil.linux.vdso_sym
)
37 changes: 37 additions & 0 deletions libc/src/__support/OSUtil/linux/arm/vdso.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//===---------- arm vdso configuration ----------------------------* C++ *-===//
//
// 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_SRC___SUPPORT_OSUTIL_LINUX_ARM_VDSO_H
#define LLVM_LIBC_SRC___SUPPORT_OSUTIL_LINUX_ARM_VDSO_H
#include "src/__support/CPP/string_view.h"
#include "src/__support/OSUtil/linux/vdso_sym.h"
namespace LIBC_NAMESPACE_DECL {
namespace vdso {
// translate VDSOSym to symbol names
// https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/arm/vdso/vdso.lds.S
LIBC_INLINE constexpr cpp::string_view symbol_name(VDSOSym sym) {
switch (sym) {
case VDSOSym::ClockGetTime:
return "__vdso_clock_gettime";
case VDSOSym::GetTimeOfDay:
return "__vdso_gettimeofday";
case VDSOSym::ClockGetRes:
return "__vdso_clock_getres";
case VDSOSym::ClockGetTime64:
return "__vdso_clock_gettime64";
default:
return "";
}
}

// symbol versions
LIBC_INLINE constexpr cpp::string_view symbol_version(VDSOSym) {
return "LINUX_2.6";
}
} // namespace vdso
} // namespace LIBC_NAMESPACE_DECL
#endif // LLVM_LIBC_SRC___SUPPORT_OSUTIL_LINUX_ARM_VDSO_H
10 changes: 10 additions & 0 deletions libc/src/__support/OSUtil/linux/riscv/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,13 @@ add_header_library(
DEPENDS
libc.src.__support.common
)

add_header_library(
vdso
HDRS
vdso.h
DEPENDS
libc.src.__support.common
libc.src.__support.CPP.string_view
libc.src.__support.OSUtil.linux.vdso_sym
)
43 changes: 43 additions & 0 deletions libc/src/__support/OSUtil/linux/riscv/vdso.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//===---------- RISC-V vdso configuration -------------------------* C++ *-===//
//
// 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_SRC___SUPPORT_OSUTIL_LINUX_RISCV_VDSO_H
#define LLVM_LIBC_SRC___SUPPORT_OSUTIL_LINUX_RISCV_VDSO_H
#include "src/__support/CPP/string_view.h"
#include "src/__support/OSUtil/linux/vdso_sym.h"
namespace LIBC_NAMESPACE_DECL {
namespace vdso {
// translate VDSOSym to symbol names
// https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/riscv/kernel/vdso/vdso.lds.S
LIBC_INLINE constexpr cpp::string_view symbol_name(VDSOSym sym) {
switch (sym) {
case VDSOSym::RTSigReturn:
return "__vdso_rt_sigreturn";
case VDSOSym::GetTimeOfDay:
return "__vdso_gettimeofday";
case VDSOSym::ClockGetTime:
return "__vdso_clock_gettime";
case VDSOSym::ClockGetRes:
return "__vdso_clock_getres";
case VDSOSym::GetCpu:
return "__vdso_getcpu";
case VDSOSym::FlushICache:
return "__vdso_flush_icache";
case VDSOSym::RiscvHwProbe:
return "__vdso_riscv_hwprobe";
default:
return "";
}
}

// symbol versions
LIBC_INLINE constexpr cpp::string_view symbol_version(VDSOSym) {
return "LINUX_4.15";
}
} // namespace vdso
} // namespace LIBC_NAMESPACE_DECL
#endif // LLVM_LIBC_SRC___SUPPORT_OSUTIL_LINUX_RISCV_VDSO_H
Loading