Skip to content

Commit 3f96581

Browse files
author
Siva Chandra Reddy
committed
[libc] Add POSIX execv and execve functions.
The POSIX global variable environ has also been added. Reviewed By: michaelrj Differential Revision: https://reviews.llvm.org/D135351
1 parent eaa583c commit 3f96581

File tree

25 files changed

+454
-3
lines changed

25 files changed

+454
-3
lines changed

libc/cmake/modules/LLVMLibCTestRules.cmake

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,8 @@ function(add_integration_test test_name)
431431
APPEND fq_deps_list
432432
libc.src.__support.threads.thread
433433
libc.src.stdlib.atexit
434-
libc.src.stdlib.exit)
434+
libc.src.stdlib.exit
435+
libc.src.unistd.environ)
435436
list(REMOVE_DUPLICATES fq_deps_list)
436437

437438
# We don't want memory functions to be dependencies on integration tests.
@@ -533,7 +534,8 @@ function(add_integration_test test_name)
533534
add_dependencies(${fq_target_name}
534535
${fq_target_name}.__copy_loader__
535536
${fq_libc_target_name}
536-
libc.utils.IntegrationTest.test)
537+
libc.utils.IntegrationTest.test
538+
${INTEGRATION_TEST_DEPENDS})
537539

538540
add_custom_command(
539541
TARGET ${fq_target_name}

libc/config/linux/aarch64/entrypoints.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,9 @@ if(LLVM_LIBC_FULL_BUILD)
377377
libc.src.time.mktime
378378
libc.src.time.nanosleep
379379
libc.src.time.clock_gettime
380+
381+
# unistd.h entrypoints
382+
libc.src.unistd.environ
380383
)
381384
endif()
382385

libc/config/linux/api.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ def DirentAPI : PublicAPI<"dirent.h"> {
259259
}
260260

261261
def UniStdAPI : PublicAPI<"unistd.h"> {
262-
let Types = ["off_t", "pid_t", "size_t", "ssize_t", "uid_t"];
262+
let Types = ["__exec_argv_t", "__exec_envp_t", "off_t", "pid_t", "size_t", "ssize_t", "uid_t"];
263263
}
264264

265265
def SysResourceAPI : PublicAPI<"sys/resource.h"> {

libc/config/linux/x86_64/entrypoints.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ set(TARGET_LIBC_ENTRYPOINTS
143143
libc.src.unistd.dup
144144
libc.src.unistd.dup2
145145
libc.src.unistd.dup3
146+
libc.src.unistd.execve
146147
libc.src.unistd.fchdir
147148
libc.src.unistd.fsync
148149
libc.src.unistd.ftruncate
@@ -412,6 +413,8 @@ if(LLVM_LIBC_FULL_BUILD)
412413
libc.src.time.clock_gettime
413414

414415
# unistd.h entrypoints
416+
libc.src.unistd.environ
417+
libc.src.unistd.execv
415418
libc.src.unistd.fork
416419
libc.src.unistd.__llvm_libc_syscall
417420
)

libc/include/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ add_gen_header(
175175
.llvm_libc_common_h
176176
.llvm-libc-macros.file_seek_macros
177177
.llvm-libc-macros.unistd_macros
178+
.llvm-libc-types.__exec_argv_t
179+
.llvm-libc-types.__exec_envp_t
178180
.llvm-libc-types.off_t
179181
.llvm-libc-types.pid_t
180182
.llvm-libc-types.size_t

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ add_header(off64_t HDR off64_t.h)
22
add_header(size_t HDR size_t.h)
33
add_header(__bsearchcompare_t HDR __bsearchcompare_t.h)
44
add_header(__call_once_func_t HDR __call_once_func_t.h)
5+
add_header(__exec_argv_t HDR __exec_argv_t.h)
6+
add_header(__exec_envp_t HDR __exec_envp_t.h)
57
add_header(__futex_word HDR __futex_word.h)
68
add_header(__mutex_type HDR __mutex_type.h DEPENDS .__futex_word)
79
add_header(__pthread_once_func_t HDR __pthread_once_func_t.h)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//===-- Definition of type __exec_argv_t ----------------------------------===//
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_TYPES_EXEC_ARGV_T_H__
10+
#define __LLVM_LIBC_TYPES_EXEC_ARGV_T_H__
11+
12+
typedef char *const __exec_argv_t[];
13+
14+
#endif // __LLVM_LIBC_TYPES_EXEC_ARGV_T_H__
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//===-- Definition of type __exec_envp_t ----------------------------------===//
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_TYPES_EXEC_ENVP_T_H__
10+
#define __LLVM_LIBC_TYPES_EXEC_ENVP_T_H__
11+
12+
typedef char *const __exec_envp_t[];
13+
14+
#endif // __LLVM_LIBC_TYPES_EXEC_ENVP_T_H__

libc/loader/linux/aarch64/start.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <stdint.h>
2121
#include <sys/mman.h>
2222
#include <sys/syscall.h>
23+
#include <unistd.h>
2324

2425
extern "C" int main(int, char **, char **);
2526

@@ -147,6 +148,9 @@ __attribute__((noinline)) static void do_start() {
147148
while (*env_end_marker)
148149
++env_end_marker;
149150

151+
// Initialize the POSIX global declared in unistd.h
152+
environ = reinterpret_cast<char **>(env_ptr);
153+
150154
// After the env array, is the aux-vector. The end of the aux-vector is
151155
// denoted by an AT_NULL entry.
152156
Elf64_Phdr *programHdrTable = nullptr;

libc/loader/linux/x86_64/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ add_loader_object(
66
libc.config.linux.app_h
77
libc.include.sys_mman
88
libc.include.sys_syscall
9+
libc.include.unistd
910
libc.src.__support.threads.thread
1011
libc.src.__support.OSUtil.osutil
1112
libc.src.stdlib.exit
1213
libc.src.stdlib.atexit
1314
libc.src.string.memory_utils.memcpy_implementation
15+
libc.src.unistd.environ
1416
COMPILE_OPTIONS
1517
-fno-omit-frame-pointer
1618
-ffreestanding # To avoid compiler warnings about calling the main function.

0 commit comments

Comments
 (0)