Skip to content

Commit eb52173

Browse files
[libc] Add dlfcn.h placeholder
1 parent 3402a1a commit eb52173

File tree

19 files changed

+290
-0
lines changed

19 files changed

+290
-0
lines changed

libc/config/linux/aarch64/entrypoints.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ set(TARGET_LIBC_ENTRYPOINTS
1717
libc.src.ctype.tolower
1818
libc.src.ctype.toupper
1919

20+
# dlfcn.h entrypoints
21+
libc.src.dlfcn.dlopen
22+
libc.src.dlfcn.dlsym
23+
libc.src.dlfcn.dlclose
24+
libc.src.dlfcn.dlerror
25+
2026
# errno.h entrypoints
2127
libc.src.errno.errno
2228

libc/config/linux/aarch64/headers.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
set(TARGET_PUBLIC_HEADERS
22
libc.include.assert
33
libc.include.ctype
4+
libc.include.dlfcn
45
libc.include.errno
56
libc.include.features
67
libc.include.fenv

libc/config/linux/x86_64/entrypoints.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ set(TARGET_LIBC_ENTRYPOINTS
1717
libc.src.ctype.tolower
1818
libc.src.ctype.toupper
1919

20+
# dlfcn.h entrypoints
21+
libc.src.dlfcn.dlopen
22+
libc.src.dlfcn.dlsym
23+
libc.src.dlfcn.dlclose
24+
libc.src.dlfcn.dlerror
25+
2026
# errno.h entrypoints
2127
libc.src.errno.errno
2228

libc/config/linux/x86_64/headers.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ set(TARGET_PUBLIC_HEADERS
22
libc.include.assert
33
libc.include.ctype
44
libc.include.dirent
5+
libc.include.dlfcn
56
libc.include.errno
67
libc.include.fcntl
78
libc.include.features

libc/include/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,15 @@ add_gen_header(
5151
.llvm_libc_common_h
5252
)
5353

54+
add_gen_header(
55+
dlfcn
56+
DEF_FILE dlfcn.h.def
57+
GEN_HDR dlfcn.h
58+
DEPENDS
59+
.llvm-libc-macros.dlfcn_macros
60+
.llvm_libc_common_h
61+
)
62+
5463
add_gen_header(
5564
features
5665
DEF_FILE features.h.def

libc/include/dlfcn.h.def

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//===-- C standard library header dlfcn.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_DLFCN_H
10+
#define LLVM_LIBC_DLFCN_H
11+
12+
#include "__llvm-libc-common.h"
13+
#include "llvm-libc-macros/dlfcn-macros.h"
14+
15+
%%public_api()
16+
17+
#endif // LLVM_LIBC_DLFCN_H

libc/include/llvm-libc-macros/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,3 +277,9 @@ add_macro_header(
277277
HDR
278278
stdckdint-macros.h
279279
)
280+
281+
add_macro_header(
282+
dlfcn_macros
283+
HDR
284+
dlfcn-macros.h
285+
)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//===-- Definition of macros from dlfcn.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_MACROS_DLFCN_MACROS_H
10+
#define LLVM_LIBC_MACROS_DLFCN_MACROS_H
11+
12+
#define RTLD_LAZY 0x00001
13+
#define RTLD_NOW 0x00002
14+
#define RTLD_GLOBAL 0x00100
15+
#define RTLD_LOCAL 0
16+
17+
// Non-standard stuff here
18+
#define RTLD_BINDING_MASK 0x3
19+
#define RTLD_NOLOAD 0x00004
20+
#define RTLD_DEEPBIND 0x00008
21+
#define RTLD_NODELETE 0x01000
22+
23+
#endif // LLVM_LIBC_MACROS_DLFCN_MACROS_H

libc/spec/posix.td

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,40 @@ def POSIX : StandardSpec<"POSIX"> {
222222
[] // Functions
223223
>;
224224

225+
HeaderSpec DlFcn = HeaderSpec<
226+
"dlfcn.h",
227+
[
228+
Macro<"RTLD_LAZY">,
229+
Macro<"RTLD_NOW">,
230+
Macro<"RTLD_GLOBAL">,
231+
Macro<"RTLD_LOCAL">,
232+
],
233+
[], // Types
234+
[], // Enumerations
235+
[
236+
FunctionSpec<
237+
"dlclose",
238+
RetValSpec<IntType>,
239+
[ArgSpec<VoidPtr>]
240+
>,
241+
FunctionSpec<
242+
"dlerror",
243+
RetValSpec<CharPtr>,
244+
[]
245+
>,
246+
FunctionSpec<
247+
"dlopen",
248+
RetValSpec<VoidPtr>,
249+
[ArgSpec<ConstCharPtr>, ArgSpec<IntType>]
250+
>,
251+
FunctionSpec<
252+
"dlsym",
253+
RetValSpec<VoidPtr>,
254+
[ArgSpec<VoidRestrictedPtr>, ArgSpec<ConstCharRestrictedPtr>]
255+
>,
256+
]
257+
>;
258+
225259
HeaderSpec FCntl = HeaderSpec<
226260
"fcntl.h",
227261
[], // Macros
@@ -1690,6 +1724,7 @@ def POSIX : StandardSpec<"POSIX"> {
16901724
ArpaInet,
16911725
CType,
16921726
Dirent,
1727+
DlFcn,
16931728
Errno,
16941729
FCntl,
16951730
PThread,

libc/src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ add_subdirectory(stdio)
1111
add_subdirectory(stdlib)
1212
add_subdirectory(string)
1313
add_subdirectory(wchar)
14+
add_subdirectory(dlfcn)
1415

1516
if(${LIBC_TARGET_OS} STREQUAL "linux")
1617
add_subdirectory(dirent)

libc/src/dlfcn/CMakeLists.txt

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
add_entrypoint_object(
2+
dlclose
3+
SRCS
4+
dlclose.cpp
5+
HDRS
6+
dlclose.h
7+
DEPENDS
8+
libc.include.dlfcn
9+
libc.src.errno.errno
10+
)
11+
12+
add_entrypoint_object(
13+
dlerror
14+
SRCS
15+
dlerror.cpp
16+
HDRS
17+
dlerror.h
18+
DEPENDS
19+
libc.include.dlfcn
20+
libc.src.errno.errno
21+
)
22+
23+
add_entrypoint_object(
24+
dlopen
25+
SRCS
26+
dlopen.cpp
27+
HDRS
28+
dlopen.h
29+
DEPENDS
30+
libc.include.dlfcn
31+
libc.src.errno.errno
32+
)
33+
34+
add_entrypoint_object(
35+
dlsym
36+
SRCS
37+
dlsym.cpp
38+
HDRS
39+
dlsym.h
40+
DEPENDS
41+
libc.include.dlfcn
42+
libc.src.errno.errno
43+
)

libc/src/dlfcn/dlclose.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//===-- Implementation of dlclose -----------------------------------------===//
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+
#include "dlclose.h"
10+
11+
#include "src/__support/common.h"
12+
13+
namespace LIBC_NAMESPACE {
14+
15+
LLVM_LIBC_FUNCTION(int, dlclose, (void *)) { return -1; }
16+
17+
} // namespace LIBC_NAMESPACE

libc/src/dlfcn/dlclose.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//===-- Implementation header of dlclose ------------------------*- 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_DLFCN_DLCLOSE_H
10+
#define LLVM_LIBC_SRC_DLFCN_DLCLOSE_H
11+
12+
namespace LIBC_NAMESPACE {
13+
14+
int dlclose(void *);
15+
16+
} // namespace LIBC_NAMESPACE
17+
18+
#endif // LLVM_LIBC_SRC_DLFCN_DLCLOSE_H

libc/src/dlfcn/dlerror.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//===-- Implementation of delerror ----------------------------------------===//
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+
#include "dlerror.h"
10+
11+
#include "src/__support/common.h"
12+
13+
namespace LIBC_NAMESPACE {
14+
15+
LLVM_LIBC_FUNCTION(char *, dlerror, ()) {
16+
return const_cast<char *>("unsupported");
17+
}
18+
19+
} // namespace LIBC_NAMESPACE

libc/src/dlfcn/dlerror.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//===-- Implementation header of dlerror ------------------------*- 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_DLFCN_DLERROR_H
10+
#define LLVM_LIBC_SRC_DLFCN_DLERROR_H
11+
12+
namespace LIBC_NAMESPACE {
13+
14+
char *dlerror();
15+
16+
} // namespace LIBC_NAMESPACE
17+
18+
#endif // LLVM_LIBC_SRC_DLFCN_DLERROR_H

libc/src/dlfcn/dlopen.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//===-- Implementation of dlopen -----------------------------------------===//
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+
#include "dlopen.h"
10+
11+
#include "src/__support/common.h"
12+
13+
namespace LIBC_NAMESPACE {
14+
15+
LLVM_LIBC_FUNCTION(void *, dlopen, (const char *, int)) { return nullptr; }
16+
17+
} // namespace LIBC_NAMESPACE

libc/src/dlfcn/dlopen.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//===-- Implementation header of dlopen -------------------------*- 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_DLFCN_DLOPEN_H
10+
#define LLVM_LIBC_SRC_DLFCN_DLOPEN_H
11+
12+
namespace LIBC_NAMESPACE {
13+
14+
void *dlopen(const char *, int);
15+
16+
} // namespace LIBC_NAMESPACE
17+
18+
#endif // LLVM_LIBC_SRC_DLFCN_DLOPEN_H

libc/src/dlfcn/dlsym.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//===-- Implementation of dlsym ------------------------------------------===//
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+
#include "dlsym.h"
10+
11+
#include "src/__support/common.h"
12+
13+
namespace LIBC_NAMESPACE {
14+
15+
LLVM_LIBC_FUNCTION(void *, dlsym, (void *, const char *)) { return nullptr; }
16+
17+
} // namespace LIBC_NAMESPACE

libc/src/dlfcn/dlsym.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//===-- Implementation header of dlsym --------------------------*- 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_DLFCN_DLSYM_H
10+
#define LLVM_LIBC_SRC_DLFCN_DLSYM_H
11+
12+
namespace LIBC_NAMESPACE {
13+
14+
void *dlsym(void *, const char *);
15+
16+
} // namespace LIBC_NAMESPACE
17+
18+
#endif // LLVM_LIBC_SRC_DLFCN_DLSYM_H

0 commit comments

Comments
 (0)