Add Glibc as an optional libc and fix test cases
This commit is contained in:
parent
1a00884e1c
commit
22b02850a3
3
Makefile
3
Makefile
@ -56,6 +56,9 @@ src:
|
||||
test:
|
||||
@$(MAKE) --no-print-directory -C test test
|
||||
|
||||
test-glibc:
|
||||
@$(MAKE) --no-print-directory -C test test-glibc
|
||||
|
||||
OCCLUM_PREFIX ?= /opt/occlum
|
||||
install: $(OCCLUM_PREFIX)/sgxsdk-tools/lib64/libsgx_uae_service_sim.so
|
||||
@# Install both libraries for HW mode and SIM mode
|
||||
|
@ -66,6 +66,9 @@ postbuild:
|
||||
# Test targets
|
||||
#############################################################################
|
||||
|
||||
test-glibc:
|
||||
@OCCLUM_TEST_GLIBC=1 $(MAKE) test
|
||||
|
||||
test: build pretest $(TEST_TARGETS) posttest
|
||||
|
||||
pretest:
|
||||
|
@ -2,13 +2,13 @@
|
||||
"resource_limits": {
|
||||
"kernel_space_heap_size": "40MB",
|
||||
"kernel_space_stack_size": "1MB",
|
||||
"user_space_size": "128MB",
|
||||
"user_space_size": "224MB",
|
||||
"max_num_of_threads": 32
|
||||
},
|
||||
"process": {
|
||||
"default_stack_size": "4MB",
|
||||
"default_heap_size": "8MB",
|
||||
"default_mmap_size": "32MB"
|
||||
"default_mmap_size": "80MB"
|
||||
},
|
||||
"entry_points": [
|
||||
"/bin"
|
||||
|
@ -1,3 +1,4 @@
|
||||
#define _GNU_SOURCE
|
||||
#include <sys/stat.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
|
@ -1,5 +1,5 @@
|
||||
include ../test_common.mk
|
||||
|
||||
EXTRA_C_FLAGS := -Wno-incompatible-pointer-types-discards-qualifiers
|
||||
EXTRA_LINK_FLAGS :=
|
||||
EXTRA_LINK_FLAGS := -lpthread
|
||||
BIN_ARGS :=
|
||||
|
@ -1,5 +1,5 @@
|
||||
include ../test_common.mk
|
||||
|
||||
EXTRA_C_FLAGS :=
|
||||
EXTRA_LINK_FLAGS :=
|
||||
EXTRA_LINK_FLAGS := -lpthread
|
||||
BIN_ARGS :=
|
||||
|
@ -1,3 +1,4 @@
|
||||
#define _LARGEFILE64_SOURCE
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include "test_fs.h"
|
||||
@ -5,9 +6,14 @@
|
||||
// ============================================================================
|
||||
// Helper macro
|
||||
// ============================================================================
|
||||
#ifdef __GLIBC__
|
||||
#define TMPFILE_FLAG __O_TMPFILE
|
||||
#else
|
||||
#define TMPFILE_FLAG O_TMPFILE
|
||||
#endif
|
||||
|
||||
#define CREATION_FLAGS_MASK (O_CLOEXEC | O_CREAT| O_DIRECTORY | O_EXCL | \
|
||||
O_NOCTTY | O_NOFOLLOW | O_TMPFILE | O_TRUNC)
|
||||
O_NOCTTY | O_NOFOLLOW | TMPFILE_FLAG | O_TRUNC)
|
||||
|
||||
// ============================================================================
|
||||
// Test cases for fcntl
|
||||
|
@ -1,3 +1,4 @@
|
||||
#define _GNU_SOURCE
|
||||
#include <sys/stat.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
|
@ -1,8 +1,10 @@
|
||||
#define _GNU_SOURCE
|
||||
#include <errno.h>
|
||||
#include <sys/epoll.h>
|
||||
#include <sys/select.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <sys/wait.h>
|
||||
#include <sys/time.h>
|
||||
#include <fcntl.h>
|
||||
#include <poll.h>
|
||||
#include <unistd.h>
|
||||
|
@ -1,5 +1,5 @@
|
||||
include ../test_common.mk
|
||||
|
||||
EXTRA_C_FLAGS := -Wno-stringop-truncation
|
||||
EXTRA_LINK_FLAGS :=
|
||||
EXTRA_LINK_FLAGS := -lpthread
|
||||
BIN_ARGS :=
|
||||
|
@ -1,5 +1,5 @@
|
||||
include ../test_common.mk
|
||||
|
||||
EXTRA_C_FLAGS :=
|
||||
EXTRA_LINK_FLAGS :=
|
||||
EXTRA_LINK_FLAGS := -lpthread
|
||||
BIN_ARGS :=
|
||||
|
@ -45,8 +45,10 @@ static int getdents_with_big_enough_buffer(bool use_explicit_syscall) {
|
||||
while (1) {
|
||||
if (use_explicit_syscall) {
|
||||
len = syscall(__NR_getdents, fd, buf, sizeof(buf));
|
||||
#ifndef __GLIBC__
|
||||
} else {
|
||||
len = getdents(fd, (struct dirent *)buf, sizeof(buf));
|
||||
#endif
|
||||
}
|
||||
if (len < 0) {
|
||||
close(fd);
|
||||
@ -60,10 +62,12 @@ static int getdents_with_big_enough_buffer(bool use_explicit_syscall) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifndef __GLIBC__
|
||||
static int test_getdents_with_big_enough_buffer() {
|
||||
bool use_explicit_syscall = false;
|
||||
return getdents_with_big_enough_buffer(use_explicit_syscall);
|
||||
}
|
||||
#endif
|
||||
|
||||
static int test_getdents_via_explicit_syscall_with_big_enough_buffer() {
|
||||
bool use_explicit_syscall = true;
|
||||
@ -80,8 +84,10 @@ static int getdents_with_too_small_buffer(bool use_explicit_syscall) {
|
||||
}
|
||||
if (use_explicit_syscall) {
|
||||
len = syscall(__NR_getdents, fd, buf, sizeof(buf));
|
||||
#ifndef __GLIBC__
|
||||
} else {
|
||||
len = getdents(fd, (struct dirent *)buf, sizeof(buf));
|
||||
#endif
|
||||
}
|
||||
if (len >= 0 || errno != EINVAL) {
|
||||
close(fd);
|
||||
@ -91,10 +97,12 @@ static int getdents_with_too_small_buffer(bool use_explicit_syscall) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifndef __GLIBC__
|
||||
static int test_getdents_with_too_small_buffer() {
|
||||
bool use_explicit_syscall = false;
|
||||
return getdents_with_too_small_buffer(use_explicit_syscall);
|
||||
}
|
||||
#endif
|
||||
|
||||
static int test_getdents_via_explicit_syscall_with_too_small_buffer() {
|
||||
bool use_explicit_syscall = true;
|
||||
@ -107,9 +115,13 @@ static int test_getdents_via_explicit_syscall_with_too_small_buffer() {
|
||||
|
||||
static test_case_t test_cases[] = {
|
||||
TEST_CASE(test_readdir),
|
||||
#ifndef __GLIBC__
|
||||
TEST_CASE(test_getdents_with_big_enough_buffer),
|
||||
#endif
|
||||
TEST_CASE(test_getdents_via_explicit_syscall_with_big_enough_buffer),
|
||||
#ifndef __GLIBC__
|
||||
TEST_CASE(test_getdents_with_too_small_buffer),
|
||||
#endif
|
||||
TEST_CASE(test_getdents_via_explicit_syscall_with_too_small_buffer),
|
||||
};
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
#define _GNU_SOURCE
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <netdb.h>
|
||||
|
@ -1,5 +1,5 @@
|
||||
include ../test_common.mk
|
||||
|
||||
EXTRA_C_FLAGS := -Wno-return-stack-address -Wno-unused-but-set-variable
|
||||
EXTRA_LINK_FLAGS :=
|
||||
EXTRA_LINK_FLAGS := -lpthread
|
||||
BIN_ARGS :=
|
||||
|
@ -1,6 +1,8 @@
|
||||
#define _GNU_SOURCE
|
||||
#include <sys/stat.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include "test_fs.h"
|
||||
|
||||
// ============================================================================
|
||||
|
@ -77,7 +77,7 @@ static int __test_readlink_from_proc_self_fd(const char *file_path) {
|
||||
}
|
||||
|
||||
static int __test_realpath(const char *file_path) {
|
||||
char buf[128] = { 0 };
|
||||
char buf[PATH_MAX] = { 0 };
|
||||
char dir_buf[PATH_MAX] = { 0 };
|
||||
char base_buf[PATH_MAX] = { 0 };
|
||||
char *dir_name, *file_name, *res;
|
||||
|
@ -17,8 +17,13 @@ CXX_OBJS := $(addprefix $(BUILD_DIR)/test/obj/$(TEST_NAME)/,$(CXX_SRCS:%.cc=%.o)
|
||||
|
||||
ALL_BUILD_SUBDIRS := $(sort $(patsubst %/,%,$(dir $(BIN) $(C_OBJS) $(CXX_OBJS))))
|
||||
|
||||
CC := occlum-gcc
|
||||
CXX := occlum-g++
|
||||
ifeq ($(OCCLUM_TEST_GLIBC), 1)
|
||||
CC = gcc
|
||||
CXX = g++
|
||||
else
|
||||
CC = occlum-gcc
|
||||
CXX = occlum-g++
|
||||
endif
|
||||
|
||||
C_FLAGS = -Wall -Wno-return-local-addr -I../include -O2 -fPIC $(EXTRA_C_FLAGS)
|
||||
ifeq ($(SGX_MODE), SIM)
|
||||
|
@ -12,6 +12,7 @@ RUN yum install epel-release -y && \
|
||||
dnf group install 'Development Tools' -y && \
|
||||
dnf --enablerepo=PowerTools install -y \
|
||||
astyle \
|
||||
bison \
|
||||
boost-devel \
|
||||
cmake \
|
||||
createrepo \
|
||||
@ -19,6 +20,7 @@ RUN yum install epel-release -y && \
|
||||
expect \
|
||||
fuse-devel \
|
||||
fuse-libs \
|
||||
gawk \
|
||||
gmp-devel \
|
||||
golang \
|
||||
jq \
|
||||
@ -67,11 +69,16 @@ RUN curl https://sh.rustup.rs -sSf | \
|
||||
cargo install sccache
|
||||
|
||||
# Install Occlum toolchain
|
||||
COPY toolchains/gcc /tmp/gcc
|
||||
COPY toolchains/musl-gcc /tmp/musl-gcc
|
||||
WORKDIR /tmp
|
||||
RUN cd gcc && ./build.sh && ./install_zlib.sh && rm -rf /tmp/gcc
|
||||
RUN cd musl-gcc && ./build.sh && ./install_zlib.sh && rm -rf /tmp/musl-gcc
|
||||
ENV PATH="/opt/occlum/build/bin:/usr/local/occlum/bin:$PATH"
|
||||
|
||||
# Install glibc
|
||||
COPY toolchains/glibc /tmp/glibc
|
||||
WORKDIR /tmp
|
||||
RUN cd glibc && ./build.sh && rm -rf /tmp/glibc
|
||||
|
||||
# Install Occlum Golang toolchain
|
||||
COPY toolchains/golang /tmp/golang
|
||||
WORKDIR /tmp
|
||||
@ -83,7 +90,7 @@ COPY toolchains/rust /tmp/rust
|
||||
WORKDIR /tmp
|
||||
RUN cd rust && ./build.sh && rm -rf /tmp/rust
|
||||
ENV PATH="/opt/occlum/toolchains/rust/bin:$PATH"
|
||||
ENV LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/opt/intel/sgxsdk/sdk_libs"
|
||||
ENV LD_LIBRARY_PATH="/opt/intel/sgxsdk/sdk_libs"
|
||||
|
||||
# Install Occlum Java toolchain (JDK 11)
|
||||
ARG JDK11_PATH=/opt/occlum/toolchains/jvm/java-11-openjdk
|
||||
|
@ -14,6 +14,7 @@ RUN apt-get update && DEBIAN_FRONTEND="noninteractive" apt-get install -y --no-i
|
||||
astyle \
|
||||
autoconf \
|
||||
automake \
|
||||
bison \
|
||||
build-essential \
|
||||
ca-certificates \
|
||||
cmake \
|
||||
@ -21,6 +22,7 @@ RUN apt-get update && DEBIAN_FRONTEND="noninteractive" apt-get install -y --no-i
|
||||
debhelper \
|
||||
expect \
|
||||
g++ \
|
||||
gawk \
|
||||
gdb \
|
||||
git-core \
|
||||
golang-go \
|
||||
@ -79,11 +81,16 @@ RUN curl https://sh.rustup.rs -sSf | \
|
||||
cargo install sccache
|
||||
|
||||
# Install Occlum toolchain
|
||||
COPY toolchains/gcc /tmp/gcc
|
||||
COPY toolchains/musl-gcc /tmp/musl-gcc
|
||||
WORKDIR /tmp
|
||||
RUN cd gcc && ./build.sh && ./install_zlib.sh && rm -rf /tmp/gcc
|
||||
RUN cd musl-gcc && ./build.sh && ./install_zlib.sh && rm -rf /tmp/musl-gcc
|
||||
ENV PATH="/opt/occlum/build/bin:/usr/local/occlum/bin:$PATH"
|
||||
|
||||
# Install glibc
|
||||
COPY toolchains/glibc /tmp/glibc
|
||||
WORKDIR /tmp
|
||||
RUN cd glibc && ./build.sh && rm -rf /tmp/glibc
|
||||
|
||||
# Install Occlum Golang toolchain
|
||||
COPY toolchains/golang /tmp/golang
|
||||
WORKDIR /tmp
|
||||
@ -95,7 +102,7 @@ COPY toolchains/rust /tmp/rust
|
||||
WORKDIR /tmp
|
||||
RUN cd rust && ./build.sh && rm -rf /tmp/rust
|
||||
ENV PATH="/opt/occlum/toolchains/rust/bin:$PATH"
|
||||
ENV LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/opt/intel/sgxsdk/sdk_libs"
|
||||
ENV LD_LIBRARY_PATH="/opt/intel/sgxsdk/sdk_libs"
|
||||
|
||||
# Install Occlum Java toolchain (JDK 11)
|
||||
ARG JDK11_PATH=/opt/occlum/toolchains/jvm/java-11-openjdk
|
||||
|
35
tools/occlum
35
tools/occlum
@ -129,20 +129,43 @@ cmd_init() {
|
||||
mkdir -p image
|
||||
mkdir -p image/bin
|
||||
mkdir -p image/lib
|
||||
mkdir -p image/lib64
|
||||
mkdir -p image/root
|
||||
mkdir -p image/host
|
||||
mkdir -p image/tmp
|
||||
local occlum_glibc_lib=/opt/occlum/glibc/lib
|
||||
local cpu_lib=/sys/devices/system/cpu
|
||||
if [ -d "$occlum_glibc_lib" ]; then
|
||||
mkdir -p "image/$occlum_glibc_lib"
|
||||
mkdir -p "image/$cpu_lib"
|
||||
fi
|
||||
# add default /etc/hosts
|
||||
mkdir -p image/etc
|
||||
echo "127.0.0.1 localhost" > image/etc/hosts
|
||||
|
||||
local occlum_gcc_lib=/usr/local/occlum/x86_64-linux-musl/lib
|
||||
cp -t image/lib/ \
|
||||
# add musl
|
||||
local occlum_musl_lib=/usr/local/occlum/x86_64-linux-musl/lib
|
||||
cp -t image/lib \
|
||||
/lib/ld-musl-x86_64.so.1 \
|
||||
"$occlum_gcc_lib/libc.so" \
|
||||
"$occlum_gcc_lib/libstdc++.so.6" \
|
||||
"$occlum_gcc_lib/libgcc_s.so.1" \
|
||||
"$occlum_gcc_lib/libgomp.so.1"
|
||||
"$occlum_musl_lib/libc.so" \
|
||||
"$occlum_musl_lib/libstdc++.so.6" \
|
||||
"$occlum_musl_lib/libgcc_s.so.1" \
|
||||
"$occlum_musl_lib/libgomp.so.1"
|
||||
|
||||
# add glibc
|
||||
if [ -d "$occlum_glibc_lib" ]; then
|
||||
cp -t image/lib64 \
|
||||
"$occlum_glibc_lib/ld-linux-x86-64.so.2"
|
||||
ln -sf /lib64/ld-linux-x86-64.so.2 "image/$occlum_glibc_lib/ld-linux-x86-64.so.2"
|
||||
cp -t "image/$occlum_glibc_lib" \
|
||||
"$occlum_glibc_lib/libc.so.6" \
|
||||
"$occlum_glibc_lib/libpthread.so.0" \
|
||||
"$occlum_glibc_lib/libm.so.6" \
|
||||
"/usr/lib/x86_64-linux-gnu/libstdc++.so.6" \
|
||||
"/usr/lib/gcc/x86_64-linux-gnu/7/libgcc_s.so.1"
|
||||
cp -t "image/$cpu_lib" \
|
||||
"$cpu_lib/online"
|
||||
fi
|
||||
|
||||
cp "$occlum_dir"/etc/template/Occlum.json "$instance_dir"/
|
||||
chmod 644 "$instance_dir"/Occlum.json
|
||||
|
27
tools/toolchains/glibc/build.sh
Executable file
27
tools/toolchains/glibc/build.sh
Executable file
@ -0,0 +1,27 @@
|
||||
#!/bin/bash
|
||||
SRC_DIR=/tmp/glibc/glibc
|
||||
BUILD_DIR=/tmp/glibc/glibc_build
|
||||
INSTALL_DIR=/opt/occlum/glibc
|
||||
|
||||
# Exit if any command fails
|
||||
set -e
|
||||
|
||||
# Clean previous build and installation if any
|
||||
rm -rf ${SRC_DIR}
|
||||
rm -rf ${BUILD_DIR}
|
||||
rm -rf ${INSTALL_DIR}
|
||||
|
||||
mkdir -p ${SRC_DIR}
|
||||
cd ${SRC_DIR}
|
||||
# Download glibc
|
||||
git clone -b occlum-glibc-2.27 https://github.com/occlum/glibc .
|
||||
|
||||
mkdir -p ${BUILD_DIR}
|
||||
cd ${BUILD_DIR}
|
||||
# Build and install glibc
|
||||
unset LD_LIBRARY_PATH
|
||||
CFLAGS="-O2 -g" ${SRC_DIR}/configure \
|
||||
--prefix=${INSTALL_DIR} --with-tls --without-selinux \
|
||||
--enable-stack-protector=strong --disable-nscd
|
||||
make
|
||||
make install
|
Loading…
Reference in New Issue
Block a user