Skip to content

Commit 3198018

Browse files
authored
Fix linux-sgx build error when libc-wasi is disabled (#2997)
Compilation error was reported when `cmake -DWAMR_BUILD_LIBC_WASI=0` on linux-sgx platform: ``` core/shared/platform/linux-sgx/sgx_socket.c:8:10: fatal error: libc_errno.h: No such file or directory 8 | #include "libc_errno.h" | ^~~~~~~~~~~~~~ ``` After fixing, both `cmake -DWAMR_BUILD_LIBC_WASI=1` and `WAMR_BUILD_LIBC_WASI=0` work good.
1 parent 9121db5 commit 3198018

File tree

6 files changed

+40
-6
lines changed

6 files changed

+40
-6
lines changed

core/shared/platform/linux-sgx/sgx_platform.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,18 @@ strcpy(char *dest, const char *src)
119119
return dest;
120120
}
121121

122+
#if WASM_ENABLE_LIBC_WASI == 0
123+
bool
124+
os_is_handle_valid(os_file_handle *handle)
125+
{
126+
assert(handle != NULL);
127+
128+
return *handle > -1;
129+
}
130+
#else
131+
/* implemented in posix_file.c */
132+
#endif
133+
122134
void *
123135
os_mmap(void *hint, size_t size, int prot, int flags, os_file_handle file)
124136
{

core/shared/platform/linux-sgx/sgx_socket.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55

66
#include "platform_api_vmcore.h"
77
#include "platform_api_extension.h"
8-
#include "libc_errno.h"
98

109
#ifndef SGX_DISABLE_WASI
1110

11+
#include "libc_errno.h"
12+
1213
#define TRACE_OCALL_FAIL() os_printf("ocall %s failed!\n", __FUNCTION__)
1314

1415
/** OCALLs prototypes **/

product-mini/platforms/linux-sgx/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,3 +164,15 @@ else()
164164
OUTPUT_VARIABLE cmdOutput
165165
)
166166
endif()
167+
168+
if (WAMR_BUILD_LIBC_WASI EQUAL 1)
169+
execute_process(
170+
COMMAND bash -c "sed -i -E 's/^WAMR_BUILD_LIBC_WASI = 0/WAMR_BUILD_LIBC_WASI = 1/g' ${CMAKE_CURRENT_SOURCE_DIR}/enclave-sample/Makefile"
171+
OUTPUT_VARIABLE cmdOutput
172+
)
173+
else()
174+
execute_process(
175+
COMMAND bash -c "sed -i -E 's/^WAMR_BUILD_LIBC_WASI = 1/WAMR_BUILD_LIBC_WASI = 0/g' ${CMAKE_CURRENT_SOURCE_DIR}/enclave-sample/Makefile"
176+
OUTPUT_VARIABLE cmdOutput
177+
)
178+
endif()

product-mini/platforms/linux-sgx/enclave-sample/Enclave/Enclave.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ handle_cmd_set_log_level(uint64 *args, uint32 argc)
510510
#endif
511511
}
512512

513-
#ifndef SGX_DISABLE_WASI
513+
#if WASM_ENABLE_LIBC_WASI != 0
514514
static void
515515
handle_cmd_set_wasi_args(uint64 *args, int32 argc)
516516
{
@@ -637,7 +637,7 @@ handle_cmd_set_wasi_args(uint64 *args, int32 argc)
637637
{
638638
*args = true;
639639
}
640-
#endif /* end of SGX_DISABLE_WASI */
640+
#endif /* end of WASM_ENABLE_LIBC_WASI != 0 */
641641

642642
static void
643643
handle_cmd_get_version(uint64 *args, uint32 argc)

product-mini/platforms/linux-sgx/enclave-sample/Makefile

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ WAMR_BUILD_LIB_RATS = 0
1616
WAMR_BUILD_GLOBAL_HEAP_POOL = 0
1717
WAMR_BUILD_GLOBAL_HEAP_SIZE = 10485760
1818
WAMR_BUILD_STATIC_PGO = 0
19+
WAMR_BUILD_LIBC_WASI = 1
1920

2021
VMLIB_BUILD_DIR ?= $(CURDIR)/../build
2122
LIB_RATS_SRC ?= $(VMLIB_BUILD_DIR)/_deps/librats-build
@@ -66,7 +67,9 @@ ifeq ($(WAMR_BUILD_LIB_RATS), 1)
6667
App_Include_Paths += -I$(LIB_RATS_INCLUDE_DIR)
6768
endif
6869

69-
App_C_Flags := $(SGX_COMMON_CFLAGS) -fPIC -Wno-attributes $(App_Include_Paths) -DWASM_ENABLE_STATIC_PGO=$(WAMR_BUILD_STATIC_PGO)
70+
App_C_Flags := $(SGX_COMMON_CFLAGS) -fPIC -Wno-attributes $(App_Include_Paths) \
71+
-DWASM_ENABLE_STATIC_PGO=$(WAMR_BUILD_STATIC_PGO) \
72+
-DWASM_ENABLE_LIBC_WASI=$(WAMR_BUILD_LIBC_WASI)
7073

7174
# Three configuration modes - Debug, prerelease, release
7275
# Debug - Macro DEBUG enabled.
@@ -135,7 +138,13 @@ ifeq ($(WAMR_BUILD_LIB_RATS), 1)
135138
Enclave_Include_Paths += -I$(LIB_RATS_INCLUDE_DIR) -I$(SGX_SSL)/include
136139
endif
137140

138-
Enclave_C_Flags := $(SGX_COMMON_CFLAGS) -nostdinc -fvisibility=hidden -fpie -fstack-protector $(Enclave_Include_Paths) -DWASM_GLOBAL_HEAP_SIZE=$(WAMR_BUILD_GLOBAL_HEAP_SIZE) -DWASM_ENABLE_GLOBAL_HEAP_POOL=$(WAMR_BUILD_GLOBAL_HEAP_POOL) -DWASM_ENABLE_LIB_RATS=$(WAMR_BUILD_LIB_RATS) -DWASM_ENABLE_STATIC_PGO=$(WAMR_BUILD_STATIC_PGO)
141+
Enclave_C_Flags := $(SGX_COMMON_CFLAGS) -nostdinc -fvisibility=hidden \
142+
-fpie -fstack-protector $(Enclave_Include_Paths) \
143+
-DWASM_GLOBAL_HEAP_SIZE=$(WAMR_BUILD_GLOBAL_HEAP_SIZE) \
144+
-DWASM_ENABLE_GLOBAL_HEAP_POOL=$(WAMR_BUILD_GLOBAL_HEAP_POOL) \
145+
-DWASM_ENABLE_LIB_RATS=$(WAMR_BUILD_LIB_RATS) \
146+
-DWASM_ENABLE_STATIC_PGO=$(WAMR_BUILD_STATIC_PGO) \
147+
-DWASM_ENABLE_LIBC_WASI=$(WAMR_BUILD_LIBC_WASI)
139148
ifeq ($(SPEC_TEST), 1)
140149
Enclave_C_Flags += -DWASM_ENABLE_SPEC_TEST=1
141150
else

product-mini/platforms/linux-sgx/enclave-sample/Makefile_minimal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ Enclave_Include_Paths := -IEnclave -I$(WAMR_ROOT)/core/iwasm/include \
102102
Enclave_C_Flags := $(SGX_COMMON_CFLAGS) -nostdinc -fvisibility=hidden -fpie -fstack-protector $(Enclave_Include_Paths)
103103

104104
# disable wasi
105-
Enclave_C_Flags += -DSGX_DISABLE_WASI
105+
Enclave_C_Flags += -DWASM_ENABLE_LIBC_WASI=0
106106

107107
ifeq ($(SPEC_TEST), 1)
108108
Enclave_C_Flags += -DWASM_ENABLE_SPEC_TEST=1

0 commit comments

Comments
 (0)