Skip to content

Commit 1a92cc5

Browse files
authored
[libc] Implement 'getenv' on the GPU target (#102376)
Summary: This patch implements 'getenv'. I was torn on how to implement this, since realistically we only have access to this environment pointer in the "loader" interface. An alternative would be to use an RPC call every time, but I think that's overkill for what this will be used for. A better solution is just to emit a common `DataEnvironment` that contains all of the host visible resources to initialize. Right now this is the `env_ptr`, `clock_freq`, and `rpc_client`. I did this by making the `app.h` interface that Linux uses more general, could possibly move that into a separate patch, but I figured it's easier to see with the usage.
1 parent 8f0c865 commit 1a92cc5

File tree

22 files changed

+84
-26
lines changed

22 files changed

+84
-26
lines changed

libc/config/CMakeLists.txt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1-
#TODO: Properly select the correct subdirectory.
2-
3-
add_subdirectory(linux)
1+
add_header_library(
2+
app_h
3+
HDRS
4+
app.h
5+
DEPENDS
6+
libc.src.__support.common
7+
)

libc/config/app.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//===-- Classes to capture properites of applications -----------*- 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_CONFIG_APP_H
10+
#define LLVM_LIBC_CONFIG_APP_H
11+
12+
#include "src/__support/macros/properties/architectures.h"
13+
14+
#if defined(LIBC_TARGET_ARCH_IS_GPU)
15+
#include "gpu/app.h"
16+
#elif defined(__linux__)
17+
#include "linux/app.h"
18+
#endif
19+
20+
#endif // LLVM_LIBC_CONFIG_APP_H

libc/config/gpu/app.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//===-- Classes to capture properites of GPU applications -------*- 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_CONFIG_GPU_APP_H
10+
#define LLVM_LIBC_CONFIG_GPU_APP_H
11+
12+
#include "src/__support/macros/config.h"
13+
#include "src/__support/macros/properties/architectures.h"
14+
15+
#include <stdint.h>
16+
17+
namespace LIBC_NAMESPACE_DECL {
18+
19+
// TODO: Move other global values here and export them to the host.
20+
struct DataEnvironment {
21+
uintptr_t *env_ptr;
22+
};
23+
24+
extern DataEnvironment app;
25+
26+
} // namespace LIBC_NAMESPACE_DECL
27+
28+
#endif // LLVM_LIBC_CONFIG_GPU_APP_H

libc/config/gpu/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ set(TARGET_LIBC_ENTRYPOINTS
167167
libc.src.stdlib.strtoull
168168
libc.src.stdlib.at_quick_exit
169169
libc.src.stdlib.quick_exit
170+
libc.src.stdlib.getenv
170171

171172
# TODO: Implement these correctly
172173
libc.src.stdlib.aligned_alloc

libc/config/linux/CMakeLists.txt

Lines changed: 0 additions & 7 deletions
This file was deleted.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ add_object_library(
7777
thread.cpp
7878
DEPENDS
7979
.futex_utils
80-
libc.config.linux.app_h
80+
libc.config.app_h
8181
libc.include.sys_syscall
8282
libc.include.fcntl
8383
libc.src.errno.errno

libc/src/__support/threads/linux/thread.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "src/__support/threads/thread.h"
10-
#include "config/linux/app.h"
10+
#include "config/app.h"
1111
#include "src/__support/CPP/atomic.h"
1212
#include "src/__support/CPP/string_view.h"
1313
#include "src/__support/CPP/stringstream.h"

libc/src/stdlib/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ add_entrypoint_object(
6262
HDRS
6363
getenv.h
6464
DEPENDS
65-
libc.config.linux.app_h
65+
libc.config.app_h
6666
)
6767

6868
add_entrypoint_object(

libc/src/stdlib/getenv.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "src/stdlib/getenv.h"
10-
#include "config/linux/app.h"
10+
#include "config/app.h"
1111
#include "src/__support/CPP/string_view.h"
1212
#include "src/__support/common.h"
1313
#include "src/__support/macros/config.h"

libc/src/sys/auxv/linux/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ add_entrypoint_object(
1111
libc.src.__support.threads.callonce
1212
libc.src.__support.common
1313
libc.src.errno.errno
14-
libc.config.linux.app_h
14+
libc.config.app_h
1515
libc.src.fcntl.open
1616
libc.src.unistd.read
1717
libc.src.unistd.close

0 commit comments

Comments
 (0)