Skip to content

[libc] update clock_gettime implementation with vDSO #91805

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

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 8 additions & 0 deletions libc/src/__support/OSUtil/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,11 @@ add_object_library(
DEPENDS
${target_os_util}
)

add_header_library(
vdso
HDRS
vdso.h
DEPENDS
.${LIBC_TARGET_OS}.vdso
)
12 changes: 12 additions & 0 deletions libc/src/__support/OSUtil/fuchsia/vdso.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//===------------- Fuchsia VDSO Header --------------------------*- 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_FUCHSIA_VDSO_H
#define LLVM_LIBC_SRC___SUPPORT_OSUTIL_FUCHSIA_VDSO_H
/// TODO: implement fuchsia VDSO
/// https://fuchsia.dev/fuchsia-src/concepts/kernel/vdso
#endif // LLVM_LIBC_SRC___SUPPORT_OSUTIL_FUCHSIA_VDSO_H
16 changes: 16 additions & 0 deletions libc/src/__support/OSUtil/linux/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,19 @@ add_object_library(
libc.src.__support.common
libc.src.__support.CPP.string_view
)

add_object_library(
vdso
HDRS
vdso.h
SRCS
vdso.cpp
DEPENDS
.${LIBC_TARGET_ARCHITECTURE}.vdso
libc.src.__support.CPP.array
libc.src.__support.CPP.string_view
libc.src.__support.threads.callonce
libc.src.__support.threads.linux.futex_word_type
libc.src.errno.errno
libc.src.sys.auxv.getauxval
)
9 changes: 9 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,12 @@ 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
)
50 changes: 50 additions & 0 deletions libc/src/__support/OSUtil/linux/aarch64/vdso.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//===---------- 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"
namespace LIBC_NAMESPACE {
namespace vdso {
// macro definitions
#define LIBC_VDSO_HAS_RT_SIGRETURN
#define LIBC_VDSO_HAS_GETTIMEOFDAY
#define LIBC_VDSO_HAS_CLOCK_GETTIME
#define LIBC_VDSO_HAS_CLOCK_GETRES

// list of VDSO symbols
enum class VDSOSym {
RTSigReturn,
GetTimeOfDay,
ClockGetTime,
ClockGetRes,
VDSOSymCount
};

// translate VDSOSym to symbol names
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
#endif // LLVM_LIBC_SRC___SUPPORT_OSUTIL_LINUX_AARCH64_VDSO_H
9 changes: 9 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,12 @@ 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
)
39 changes: 39 additions & 0 deletions libc/src/__support/OSUtil/linux/arm/vdso.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//===---------- 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"
namespace LIBC_NAMESPACE {
namespace vdso {
// macro definitions
#define LIBC_VDSO_HAS_GETTIMEOFDAY
#define LIBC_VDSO_HAS_CLOCK_GETTIME

// list of VDSO symbols
enum class VDSOSym {
GetTimeOfDay,
ClockGetTime,
};

// translate VDSOSym to symbol names
LIBC_INLINE constexpr cpp::string_view symbol_name(VDSOSym sym) {
switch (sym) {
case VDSOSym::GetTimeOfDay:
return "__vdso_gettimeofday";
case VDSOSym::ClockGetTime:
return "__vdso_clock_gettime";
}
}

// symbol versions
LIBC_INLINE constexpr cpp::string_view symbol_version(VDSOSym) {
return "LINUX_2.6";
}
} // namespace vdso
} // namespace LIBC_NAMESPACE
#endif // LLVM_LIBC_SRC___SUPPORT_OSUTIL_LINUX_ARM_VDSO_H
9 changes: 9 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,12 @@ 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
)
58 changes: 58 additions & 0 deletions libc/src/__support/OSUtil/linux/riscv/vdso.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
//===---------- 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"
namespace LIBC_NAMESPACE {
namespace vdso {
// macro definitions
#define LIBC_VDSO_HAS_RT_SIGRETURN
#define LIBC_VDSO_HAS_GETTIMEOFDAY
#define LIBC_VDSO_HAS_CLOCK_GETTIME
#define LIBC_VDSO_HAS_CLOCK_GETRES
#define LIBC_VDSO_HAS_GETCPU
#define LIBC_VDSO_HAS_FLUSH_ICACHE

// list of VDSO symbols
enum class VDSOSym {
RTSigReturn,
GetTimeOfDay,
ClockGetTime,
ClockGetRes,
GetCpu,
FlushICache,
VDSOSymCount
};

// translate VDSOSym to symbol names
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";
default:
return "";
}
}

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