diff --git a/libc/include/dlfcn.yaml b/libc/include/dlfcn.yaml index a8218b6780c2c..db2893aaff5d9 100644 --- a/libc/include/dlfcn.yaml +++ b/libc/include/dlfcn.yaml @@ -86,6 +86,8 @@ enums: standards: - gnu value: 11 +types: + - type_name: Dl_info functions: - name: dlclose standards: @@ -120,3 +122,10 @@ functions: - type: void *__restrict - type: int - type: void *__restrict + - name: dladdr + standards: + - POSIX + return_type: int + arguments: + - type: const void * + - type: Dl_info * diff --git a/libc/include/llvm-libc-types/Dl_info.h b/libc/include/llvm-libc-types/Dl_info.h new file mode 100644 index 0000000000000..b082e30549a02 --- /dev/null +++ b/libc/include/llvm-libc-types/Dl_info.h @@ -0,0 +1,19 @@ +//===-- Definition of Dl_info type ----------------------------------------===// +// +// 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_TYPES_DL_INFO_H +#define LLVM_LIBC_TYPES_DL_INFO_H + +typedef struct { + const char *dli_fname; + void *dli_fbase; + const char *dli_sname; + void *dli_saddr; +} Dl_info; + +#endif // LLVM_LIBC_TYPES_DL_INFO_H diff --git a/libc/src/dlfcn/CMakeLists.txt b/libc/src/dlfcn/CMakeLists.txt index 1ee05fc380c94..8ef0540c01a2e 100644 --- a/libc/src/dlfcn/CMakeLists.txt +++ b/libc/src/dlfcn/CMakeLists.txt @@ -49,3 +49,14 @@ add_entrypoint_object( libc.include.dlfcn libc.src.errno.errno ) + +add_entrypoint_object( + dladdr + SRCS + dladdr.cpp + HDRS + dladdr.h + DEPENDS + libc.include.dlfcn + libc.src.errno.errno +) diff --git a/libc/src/dlfcn/dladdr.cpp b/libc/src/dlfcn/dladdr.cpp new file mode 100644 index 0000000000000..61490fd9a64b5 --- /dev/null +++ b/libc/src/dlfcn/dladdr.cpp @@ -0,0 +1,21 @@ +//===-- Implementation of dladdr ------------------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#include "dladdr.h" + +#include "src/__support/common.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { + +// TODO: https:// github.com/llvm/llvm-project/issues/97929 +LLVM_LIBC_FUNCTION(int, dladdr, (const void *addr, Dl_info *info)) { + return -1; +} + +} // namespace LIBC_NAMESPACE_DECL diff --git a/libc/src/dlfcn/dladdr.h b/libc/src/dlfcn/dladdr.h new file mode 100644 index 0000000000000..346fc8dc27aed --- /dev/null +++ b/libc/src/dlfcn/dladdr.h @@ -0,0 +1,20 @@ +//===-- Implementation header of dladdr -------------------------*- 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_DLFCN_DLADDR_H +#define LLVM_LIBC_SRC_DLFCN_DLADDR_H + +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { + +int dladdr(const void *, Dl_info *); + +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC_DLFCN_DLADDR_H