Skip to content

Commit

Permalink
Add support for building on illumos
Browse files Browse the repository at this point in the history
  • Loading branch information
citrus-it committed Nov 28, 2024
1 parent b22093d commit 0e9e460
Show file tree
Hide file tree
Showing 6 changed files with 213 additions and 2 deletions.
2 changes: 1 addition & 1 deletion BaseTools/Conf/build_rule.template
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@
"$(DLINK)" /OUT:${dst} $(DLINK_FLAGS) $(DLINK_SPATH) @$(STATIC_LIBRARY_FILES_LIST) $(DLINK2_FLAGS)

<Command.GCC>
"$(DLINK)" -o ${dst} $(DLINK_FLAGS) -Wl,--start-group,@$(STATIC_LIBRARY_FILES_LIST),--end-group $(CC_FLAGS) $(DLINK2_FLAGS)
"$(DLINK)" -o ${dst} $(DLINK_FLAGS) --start-group @$(STATIC_LIBRARY_FILES_LIST) --end-group $(DLINK2_FLAGS)
"$(OBJCOPY)" $(OBJCOPY_FLAGS) ${dst}

<Command.XCODE>
Expand Down
6 changes: 6 additions & 0 deletions BaseTools/Conf/illumos.specs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

%rename cpp old_cpp

*cpp:
%(cpp_subtarget)

65 changes: 64 additions & 1 deletion BaseTools/Conf/tools_def.template
Original file line number Diff line number Diff line change
Expand Up @@ -1029,7 +1029,70 @@ DEFINE GCC5_LOONGARCH64_ASLDLINK_FLAGS = DEF(GCC_LOONGARCH64_ASLDLINK_FLAGS)
DEFINE GCC5_LOONGARCH64_ASM_FLAGS = -x assembler-with-cpp -mabi=lp64d -march=loongarch64 -fno-builtin -c -Wall -mno-explicit-relocs
DEFINE GCC5_LOONGARCH64_PP_FLAGS = -mabi=lp64d -march=loongarch64 DEF(GCC_PP_FLAGS)

####################################################################################
#############################################################################
#
# ILLGCC -- illumos
# This configuration is used to compile under illumos to produce
# PE/COFF binaries using GCC 7
#
#############################################################################


DEFINE ILLGCC_PREFIX = ENV(ILLGCC_BIN)
DEFINE ILLGCC_CC = DEF(ILLGCC_PREFIX)/gcc
DEFINE ILLGCC_AR = ENV(GAR)
# OmniOS gcc uses the illumos linker so we need to explicitly specify
# the GNU linker
DEFINE ILLGCC_LD = ENV(GLD)
DEFINE ILLGCC_OBJCOPY = ENV(GOBJCOPY)
DEFINE ILLGCC_MAKE = ENV(GMAKE)

*_ILLGCC_*_*_FAMILY = GCC

*_ILLGCC_*_ASL_PATH = DEF(UNIX_IASL_BIN)
*_ILLGCC_*_MAKE_PATH = DEF(ILLGCC_MAKE)
*_ILLGCC_*_CC_PATH = DEF(ILLGCC_CC)
*_ILLGCC_*_ASM_PATH = DEF(ILLGCC_CC)
*_ILLGCC_*_PP_PATH = DEF(ILLGCC_CC)
*_ILLGCC_*_VFRPP_PATH = DEF(ILLGCC_CC)
*_ILLGCC_*_ASLCC_PATH = DEF(ILLGCC_CC)
*_ILLGCC_*_ASLPP_PATH = DEF(ILLGCC_CC)
*_ILLGCC_*_SLINK_PATH = DEF(ILLGCC_AR)
*_ILLGCC_*_DLINK_PATH = DEF(ILLGCC_LD)
*_ILLGCC_*_ASLDLINK_PATH = DEF(ILLGCC_LD)
*_ILLGCC_*_RC_PATH = DEF(ILLGCC_OBJCOPY)
*_ILLGCC_*_OBJCOPY_PATH = DEF(ILLGCC_OBJCOPY)

*_ILLGCC_*_ASLPP_FLAGS = DEF(GCC_ASLPP_FLAGS)
*_ILLGCC_*_ASLCC_FLAGS = DEF(GCC_ASLCC_FLAGS)
*_ILLGCC_*_VFRPP_FLAGS = DEF(GCC_VFRPP_FLAGS)
*_ILLGCC_*_APP_FLAGS =
*_ILLGCC_*_ASL_FLAGS = DEF(IASL_FLAGS)
*_ILLGCC_*_ASL_OUTFLAGS = DEF(IASL_OUTFLAGS)

# Specify an alternative specs file that doesn't remove line number information
# when pre-processing assembly language files.
*_ILLGCC_*_PP_FLAGS = DEF(GCC_PP_FLAGS) -specs=ENV(WORKSPACE)/BaseTools/Conf/illumos.specs

########################
# illumos X64 definitions
########################

# Since we are not using gcc as a wrapper for the linker and the pre-defined
# arguments use "-Wl", we need to explicitly state the required options
# longhand.
*_ILLGCC_X64_ASLDLINK_FLAGS = -melf_x86_64_sol2 -nostdlib -n -q --gc-sections -z common-page-size=0x40 --defsym=PECOFF_HEADER_SIZE=0 --script=$(EDK_TOOLS_PATH)/Scripts/GccBase.lds --entry ReferenceAcpiTable -u ReferenceAcpiTable
*_ILLGCC_X64_DLINK_FLAGS = -nostdlib -n -q --gc-sections -z common-page-size=0x40 --entry $(IMAGE_ENTRY_POINT) -u $(IMAGE_ENTRY_POINT) -Map $(DEST_DIR_DEBUG)/$(BASE_NAME).map --whole-archive -flto -Os
*_ILLGCC_X64_DLINK2_FLAGS = -melf_x86_64_sol2 --oformat=elf64-x86-64-sol2 --defsym=PECOFF_HEADER_SIZE=0x228 --script=$(EDK_TOOLS_PATH)/Scripts/GccBase.lds

*_ILLGCC_X64_ASLCC_FLAGS = DEF(GCC5_ASLCC_FLAGS) -m64
*_ILLGCC_X64_ASM_FLAGS = DEF(GCC5_ASM_FLAGS) -m64 -melf_x86_64_sol2
*_ILLGCC_X64_RC_FLAGS = DEF(GCC_X64_RC_FLAGS) -O elf64-x86-64-sol2
*_ILLGCC_X64_OBJCOPY_FLAGS =
*_ILLGCC_X64_NASM_FLAGS = -f elf64
*_ILLGCC_X64_CC_FLAGS = DEF(GCC5_X64_CC_FLAGS) -flto -DUSING_LTO -Os -Wno-unused-but-set-variable -Wno-unused-const-variable -Wno-maybe-uninitialized

#################################################################################
#
# GCC 4.8 - This configuration is used to compile under Linux to produce
# PE/COFF binaries using GCC 4.8.
Expand Down
10 changes: 10 additions & 0 deletions BaseTools/Source/C/Makefiles/header.makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ endif
CYGWIN:=$(findstring CYGWIN, $(shell uname -s))
LINUX:=$(findstring Linux, $(shell uname -s))
DARWIN:=$(findstring Darwin, $(shell uname -s))
SUNOS:=$(findstring SunOS, $(shell uname -s))
CLANG:=$(shell $(CC) --version | grep clang)
ifneq ($(CLANG),)
CC ?= $(CLANG_BIN)clang
Expand Down Expand Up @@ -131,6 +132,15 @@ endif
CFLAGS += $(BUILD_OPTFLAGS)
CXXFLAGS += $(BUILD_OPTFLAGS)

ifeq ($(ARCH), X64)
ifeq ($(SUNOS),SunOS)
BUILD_CFLAGS += -Wno-pointer-to-int-cast -Wno-int-to-pointer-cast
CFLAGS += -m64
CPPFLAGS += -m64
LFLAGS += -m64
endif
endif

# keep EXTRA_LDFLAGS last
LDFLAGS += $(EXTRA_LDFLAGS)

Expand Down
120 changes: 120 additions & 0 deletions build
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
#!/bin/bash

# Copyright 2021 OmniOS Community Edition (OmniOSce) Association.

usage() {
cat <<- EOM
Usage: $0 [-bov] [-j <jobs>] <clean|RELEASE|DEBUG>
-b - Build BHYVE firmware (default)
-o - Build OVMF firmware (for Propolis)
-p - Apply patches and exit
-j jobs - Set parallelism - jobs defaults to 1 or the value of \$JOBS
-v - Verbose output
'clean' will clean up the directory any remove old build remnants
RELEASE|DEBUG specify the firmware variant to be built
EOM
exit 1
}

: "${GCCVER:=14}"
: "${GCCPATH:=/opt/gcc-$GCCVER}"
: "${GCC:=$GCCPATH/bin/gcc}"
: "${GXX:=$GCCPATH/bin/g++}"
: "${GMAKE:=/usr/bin/gmake}"
: "${GPATCH:=/usr/bin/gpatch}"
: "${GAS:=/usr/bin/gas}"
: "${GAR:=/usr/bin/gar}"
: "${GLD:=/usr/bin/gld}"
: "${GOBJCOPY:=/usr/bin/gobjcopy}"

export GCCVER GCCPATH GCC GXX GMAKE GPATCH GAS GAR GLD GOBJCOPY

verbose=0
stock=0
patch=0
: "${JOBS:=1}"

while [[ "$1" = -* ]]; do
case "$1" in
-csm)
echo "This branch does not support building the CSM variant"
exit 1
;;
-v) verbose=1 ;;
-b) stock=0 ;;
-o) stock=1 ;;
-p) patch=1 ;;
-j)
[ $# -ge 2 ] || usage
JOBS="$2"
shift
;;
*) usage ;;
esac
shift
done

for p in patches/*; do
[[ -f "$p" ]] || continue
$GPATCH --force --forward --strip=1 < $p
done

((patch)) && exit 0

clean=0
case "$1" in
DEBUG) flavour=DEBUG
;;
RELEASE) flavour=RELEASE
;;
clean) clean=1 ;;
*) usage ;;
esac
shift
[ -n "$1" ] && usage


MAKE_ARGS="
AS=$GAS
AR=$GAR
LD=$GLD
OBJCOPY=$GOBJCOPY
CC=$GCC BUILD_CC=$GCC
CXX=$GXX BUILD_CXX=$GXX
GCCPATH=$GCCPATH
"

((stock)) && platform=OvmfPkg/OvmfPkgX64.dsc \
|| platform=OvmfPkg/Bhyve/BhyveX64.dsc

ILLGCC_BIN=$GCCPATH/bin/
BUILD_ARGS="-DDEBUG_ON_SERIAL_PORT=TRUE -DNETWORK_HTTP_BOOT_ENABLE=TRUE"
BUILD_ARGS+=" -DFD_SIZE_2MB"
PYTHON3_ENABLE=TRUE
[ $verbose -eq 1 ] && BUILD_ARGS+=" -v"

export MAKE_ARGS ILLGCC_BIN BUILD_ARGS PYTHON3_ENABLE

rm -rf Conf/{target,build_rule,tools_def}.txt Conf/.cache

if ((clean)); then
gmake -j$JOBS $MAKE_ARGS HOST_ARCH=X64 ARCH=X64 -C BaseTools clean
rm -rf Build/
exit 0
fi

set -e

gmake -j$JOBS $MAKE_ARGS HOST_ARCH=X64 ARCH=X64 -C BaseTools

source edksetup.sh

./BaseTools/BinWrappers/PosixLike/build \
-n $JOBS \
-p $platform \
-a X64 \
-b $flavour \
-t ILLGCC \
$BUILD_ARGS

12 changes: 12 additions & 0 deletions patches/01-openssl.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
diff --git a/CryptoPkg/Library/OpensslLib/openssl/crypto/threads_pthread.c b/CryptoPkg/Library/OpensslLib/openssl/crypto/threads_pthread.c
index 801855c930..6a5ed91023 100644
--- a/CryptoPkg/Library/OpensslLib/openssl/crypto/threads_pthread.c
+++ b/CryptoPkg/Library/OpensslLib/openssl/crypto/threads_pthread.c
@@ -13,7 +13,7 @@
#include <openssl/crypto.h>
#include "internal/cryptlib.h"

-#if defined(__sun)
+#if defined(__sun) && !defined(__illumos__)
# include <atomic.h>
# #endif

0 comments on commit 0e9e460

Please sign in to comment.