occlum/tools/toolchains/golang/build.sh
Tate, Hongliang Tian 5e8f997d4d Make PIE the default mode for Go toolchain
Occlum-compatible executable binaries must be Position-Independent
Executable (PIE). Previously, to build such binaries, the users need to
explicitly give `-buildmode=pie` flag to `occlum-go`. Apparently, this
is error-prone. This commit sets `-buildmode=pie` by default for `occlum-go`.

In addition, this commit upgrades the Go version to 1.13.7.
2020-08-11 05:35:43 +00:00

38 lines
935 B
Bash
Executable File

#!/bin/bash
THIS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
BUILD_DIR=/tmp/occlum_golang_toolchain
INSTALL_DIR=/opt/occlum/toolchains/golang
# Exit if any command fails
set -e
# Clean previous build and installation if any
rm -rf ${BUILD_DIR}
rm -rf ${INSTALL_DIR}
# Create the build directory
mkdir -p ${BUILD_DIR}
cd ${BUILD_DIR}
# Download Golang
git clone https://github.com/golang/go .
# Swtich to Golang 1.13.7
git checkout -b go1.13.7 tags/go1.13.7
# Apply the patch to adapt Golang to Occlum
git apply ${THIS_DIR}/0001-adapt-golang-to-occlum-libos.patch
# Build Golang
cd src
./make.bash
mv ${BUILD_DIR} ${INSTALL_DIR}
# Generate the wrappers for Go
cat > ${INSTALL_DIR}/bin/occlum-go <<EOF
#!/bin/bash
OCCLUM_GCC="\$(which occlum-gcc)"
OCCLUM_GOFLAGS="-buildmode=pie \$GOFLAGS"
CC=\$OCCLUM_GCC GOFLAGS=\$OCCLUM_GOFLAGS ${INSTALL_DIR}/bin/go "\$@"
EOF
chmod +x ${INSTALL_DIR}/bin/occlum-go