From 4e89c037b23c9a65f85d56f68ce75dcf643023f6 Mon Sep 17 00:00:00 2001 From: Jasper Siepkes Date: Sun, 14 Aug 2022 13:31:04 +0200 Subject: [PATCH] Changes to make v1.22.10 build on SmartOS. --- .bazelrc | 22 +- BUILD | 19 ++ README.md | 212 ++++++++++++++++++ bazel/BUILD | 6 + bazel/dependency_imports.bzl | 9 +- bazel/envoy_binary.bzl | 16 +- bazel/envoy_internal.bzl | 3 +- bazel/foreign_cc/BUILD | 5 + bazel/foreign_cc/gperftools.patch | 68 ++++++ bazel/foreign_cc/zlib.patch | 2 +- bazel/illumos-bazel-gazelle.patch | 31 +++ bazel/illumos-boringssl.patch | 99 ++++++++ bazel/protobuf.patch | 38 ++-- bazel/repositories.bzl | 12 +- bazel/repository_locations.bzl | 84 ++++--- source/common/common/posix/thread_impl.cc | 2 + source/common/common/utility.cc | 2 +- source/common/network/address_impl.cc | 9 + source/common/network/connection_impl.cc | 3 +- source/common/signal/signal_action.cc | 28 ++- source/common/thread/terminate_thread.cc | 2 +- .../listener/proxy_protocol/proxy_protocol.cc | 5 + source/server/hot_restart_impl.cc | 6 + 23 files changed, 622 insertions(+), 61 deletions(-) create mode 100644 bazel/foreign_cc/gperftools.patch create mode 100644 bazel/illumos-bazel-gazelle.patch create mode 100644 bazel/illumos-boringssl.patch diff --git a/.bazelrc b/.bazelrc index 7e46a2b89fbc..bc3f236a816f 100644 --- a/.bazelrc +++ b/.bazelrc @@ -16,8 +16,9 @@ build --color=yes build --workspace_status_command="bash bazel/get_workspace_status" build --incompatible_strict_action_env build --host_force_python=PY3 -build --java_runtime_version=remotejdk_11 -build --tool_java_runtime_version=remotejdk_11 +# On Illumos we need to use the OpenJDK version installed locally. +#build --java_runtime_version=remotejdk_11 +#build --tool_java_runtime_version=remotejdk_11 build --platform_mappings=bazel/platform_mappings build --experimental_repository_downloader_retries=2 @@ -407,3 +408,20 @@ build:windows --dynamic_mode=off try-import %workspace%/clang.bazelrc try-import %workspace%/user.bazelrc try-import %workspace%/local_tsan.bazelrc + +# Illumos +build:illumos --cxxopt=-std=c++17 +build:illumos --define hot_restart=disabled +build:illumos --define wasm=disabled +# Disables gperftools. I (@siepkes) couldn't get 'libtcmalloc_and_profiler.a' to be built. +# Not because it doesn't build on Illumos but because I couldn't get Bazel -> foreign_cc +# -> autoconf to build the thing. And then Bazel complains about not finding it. +# When building the "vanilla" gperftools repo the 'libtcmalloc_and_profiler.a' artifact +# is build just fine. +build:illumos --define tcmalloc=disabled + +build:illumos --java_runtime_version=local_jdk +build:illumos --java_language_version=11 +build:illumos --tool_java_runtime_version=local_jdk +build:illumos --tool_java_language_version=11 +build:illumos --extra_toolchains=//:repository_default_toolchain_definition \ No newline at end of file diff --git a/BUILD b/BUILD index 0f77cbba9e19..124e8d4db74c 100644 --- a/BUILD +++ b/BUILD @@ -53,3 +53,22 @@ package_group( "//examples/...", ], ) + +load( + "@bazel_tools//tools/jdk:default_java_toolchain.bzl", + "default_java_toolchain", "DEFAULT_TOOLCHAIN_CONFIGURATION", "BASE_JDK9_JVM_OPTS", "DEFAULT_JAVACOPTS" +) + +# On Illumos this config gets activated. We use it to force Bazel to use the local (pkgsrc) JDK. If we don't +# it will try to use '@bazel_tools//tools/jdk:remote_jdk11'. Which won't work because there is no remote Illumos +# JDK which can be downloaded configured in the 'rules_java' project. +default_java_toolchain( + name = "repository_default_toolchain", + configuration = DEFAULT_TOOLCHAIN_CONFIGURATION, # One of predefined configurations + # Other parameters are from java_toolchain rule: + java_runtime = "@local_jdk//:jdk", # JDK to use for compilation and toolchain's tools execution + jvm_opts = BASE_JDK9_JVM_OPTS, # Additional JDK options + javacopts = DEFAULT_JAVACOPTS, # Additional javac options + source_version = "11", + target_version = "11", +) \ No newline at end of file diff --git a/README.md b/README.md index fa2ac8920ca4..a5f10ff4184c 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,215 @@ +# Envoy SmartOS / Illumos / Solaris port + +**(Scroll down for original Envoy readme.md)** + +This repo contains a SmartOS port for Envoy. It will probably also work on Solaris though it will probably require modifications since we assume the use of pkgsrc. + +To build this Envoy port you need Bazel. This requires a SmartOS / Illumos / Solaris port of Bazel since Bazel does not natively support these platforms. See the [bazel-smartos](https://github.com/siepkes/bazel-smartos) repo for a SmartOS port. My intention being to properly upstream the thing but that takes some work... Feel free to reach out to me if you encounter any issues. + +## Running Envoy on SmartOS + +**WARNING: When running set the environmental variable `EVENT_NOEVPORT=yes`.** + +Envoy uses libevent which uses event ports on Illumos (the native non-blocking IO implementation on Illumos). For some reason when using event ports libevent starts making a massive number of syscalls (as many as the CPU limits allow). Therefor we disable the event ports implementation in libevent for now. + +``` +$ export EVENT_NOEVPORT=yes +$ ./envoy-static --disable-hot-restart -c ./config.yaml +``` + +## Building Envoy on SmartOS + +Create a SmartOS container (`joyent` brand if your on Joyent's public cloud / Triton). Steps below are performed on a container running the `base-64-lts` image version `20.4.0` (`1d05e788-5409-11eb-b12f-037bd7fee4ee`). + +The following things are good to know: + +* As stated in the [bazel-smartos](https://github.com/siepkes/bazel-smartos) repo the Bazel binary depends on a specific GCC version (due to hardcoded version in some paths). +* When using `export NUM_CPUS=2` you probably require at least 16GB of RAM and 32 GB of swap in your VM to build Envoy. Trying to build with an 8GB VM led to an `ld: fatal: mmap anon failed: Resource temporarily unavailable` error while linking in my case. You can experiment with lowering `NUM_CPUS` if you run in to memory problems. + +Install required build packages. Envoy makes use of modern C++ so will only work with a modern C++ compiler. + +``` +# pkgin -y install go117 ninja-build gcc9 git-base zip unzip openjdk11 libtool cmake automake ninja-build autoconf gmake python39 py39-expat +``` + +Recent version of Bazel's `rules_pkg` run some tests which expect the ability to use UTF-8 characters in directory and file names. Modify `/etc/defaults/init` and add the following to enable UTF-8 support. Reboot the container after making these modifications: + +``` +CMASK=022 +# Specifies the locale to use for all purposes except as overridden by the variables below. +LANG=en_US.UTF-8 +# Determines the effect of character handling functions. +LC_CTYPE=en_US.UTF-8 +# Determines the decimal point character and thousands separator character. +LC_NUMERIC=en_US.UTF-8 +# Determines the date/time format. +LC_TIME=en_US.UTF-8 +# Determines the order in which the output is sorted. +LC_COLLATE=en_US.UTF-8 +# Determines the format for monetary symbols. +LC_MONETARY=en_US.UTF-8 +# Determines the format of standard operating system messages. +LC_MESSAGES=en_US.UTF-8 +# Used to set a single locale for all purposes, overrides all variables listed above. +# Not always supported by all applications. +LC_ALL=en_US.UTF-8 +``` + +Bazel will try to build the extensions that use Python (for example Kafka filter) for every Python version that is installed. Meaning you need to have the Python modules such as `py39-expat` installed for every installed Python version (for example `py37-expat` if Python 3.7 is also installed). When bumping Triton image version verify the package Python version. So beware that having other versions of Python installed in your build VM might complicate the build process. The same goes for Go; Having a more recent version or multiple versions of Go installed can lead to build issues. + +Configure the build environment: +``` +$ git clone https://github.com/siepkes/envoy-smartos.git +``` + +Build Envoy with clang (building with GCC might not work due to [issues](https://github.com/envoyproxy/envoy/issues/14788)): +``` +$ cd envoy-smartos +$ git checkout smartos-v1.22.10 +$ export NUM_CPUS=2 # Needed to prevent a CPU detection algorithm from going awry. +$ export JAVA_HOME="/opt/local/java/openjdk11" +$ bazel build -c opt --jobs=3 \ + --config=illumos \ + --define hot_restart=disabled \ + --verbose_failures \ + --subcommands \ + --sandbox_debug \ + --toolchain_resolution_debug \ + --//source/extensions/bootstrap/wasm:enabled=false \ + --//source/extensions/wasm_runtime/v8:enabled=false \ + --package_path %workspace%:/root/envoy-smartos/ \ + //source/exe:envoy-static +``` + +To troubleshoot build issues Bazel can be made more talkative by adding the following flags: + +``` +--sandbox_debug --verbose_failures --toolchain_resolution_debug +``` + +This will result in a statically linked binary of Envoy in `./bazel-bin/source/exe/envoy-static`. + +The binary will include debug symbols which you can strip to bring down the size of the binary substantially. Beware that this will make the backtrace library unusable (ie. stacktraces become hard to read): + +``` +$ strip --strip-debug ./bazel-bin/source/exe/envoy-static +``` + +## Known issues / TODO's / Remarks + +Below is a list of known issues of this port. These are mostly open issues because they represent functionality I didn't need right away and stood in the way of doing a sucessful build. I'm obviously open to any PR / help anyone can offer though! + +### Make webassembly runtime work + +We currently disable WASM in `.bazerc` when building. Reason for this is that the V8 WASM runtime currently doesn't build on Illumos. Envoy can be configured to use a different WASM runtime but for now WASM is just disabled. + +Additionally building the WASM extensions which GCC does not work. Leading to errors such as the one below. Apparantly these issues are not present when using clang instead of GCC (See [Envoy issue 14788](https://github.com/envoyproxy/envoy/issues/14788)). + +``` +external/com_google_absl/absl/time/internal/cctz/include/cctz/civil_time_detail.h: In function 'constexpr int absl::time_internal::cctz::detail::impl::days_per_month(absl::time_internal::cctz::year_t, absl::time_internal::cctz::detail::month_t)': +external/com_google_absl/absl/time/internal/cctz/include/cctz/civil_time_detail.h:104:28: warning: array subscript has type 'char' [-Wchar-subscripts] + return k_days_per_month[m] + (m == 2 && is_leap_year(y)); + ^ +external/com_google_cel_cpp/eval/eval/ternary_step.cc: In function 'absl::StatusOr > google::api::expr::runtime::CreateTernaryStep(int64_t)': +external/com_google_cel_cpp/eval/eval/ternary_step.cc:75:10: error: could not convert 'step' from 'std::unique_ptr' to 'absl::StatusOr >' + return step; + ^~~~ + +``` + +### Make event ports work + +Currently we disable event ports by using the environmental variable `EVENT_NOEVPORT=yes`. When using event ports Envoy (or more likely libevent) starts making a massive number of syscalls. I'm guessing this is because some (event) loop in libevent is going haywire. Probably need to take a look at `libevent_scheduler.cc` how libevent is configured. + +### Final binary requires GCC package + +Due to the way the linking is currently configured the final Envoy binary requires the GCC package to be installed in the container: + +``` +$ ldd bazel-bin/source/exe/envoy-static + librt.so.1 => /lib/64/librt.so.1 + libdl.so.1 => /lib/64/libdl.so.1 + libpthread.so.1 => /lib/64/libpthread.so.1 + libm.so.2 => /lib/64/libm.so.2 + libstdc++.so.6 => /opt/local/gcc7//lib/amd64/libstdc++.so.6 + libxnet.so.1 => /lib/64/libxnet.so.1 + libsocket.so.1 => /lib/64/libsocket.so.1 + libnsl.so.1 => /lib/64/libnsl.so.1 + libgcc_s.so.1 => /opt/local/gcc7//lib/amd64/libgcc_s.so.1 + libc.so.1 => /lib/64/libc.so.1 + libmp.so.2 => /lib/64/libmp.so.2 + libmd.so.1 => /lib/64/libmd.so.1 +``` + +### Get entire test suite to run + +Headline covers it. + +``` +$ export JAVA_HOME="/opt/local/java/openjdk11" +$ bazel test --host_javabase=@local_jdk//:jdk //test/... +``` + +### Hot restart disabled + +Currently we pass `--define hot_restart=disabled` via `.bazelrc` when building to disable Hot restart (ie. restart Envoy without client connections being closed). Hot restart is disabled because it didn't work without modifications and I didn't have a need for it. + +#### py37-expat package requirement. + +The `py37-expat` package must be installed otherwise the build dies with the output below. I (@siepkes) think this might actually be a bug in upstream since requiring manual install of the package is not really what Bazel is about? + +``` +[INFO 08:56:26.568 src/main/cpp/rc_file.cc:131] Skipped optional import of /root/envoy-smartos/local_tsan.bazelrc, the specified rc file either does not exist or is not readable. +[INFO 08:56:26.568 src/main/cpp/rc_file.cc:56] Parsing the RcFile /dev/null +[INFO 08:56:26.569 src/main/cpp/blaze.cc:1623] Debug logging requested, sending all client log statements to stderr +[INFO 08:56:26.570 src/main/cpp/blaze.cc:1506] Acquired the client lock, waited 0 milliseconds +[INFO 08:56:26.577 src/main/cpp/blaze.cc:1694] Trying to connect to server (timeout: 30 secs)... +[INFO 08:56:26.590 src/main/cpp/blaze_util_illumos.cc:126] PID: 658256 (/root/envoy-smartos). +[INFO 08:56:26.590 src/main/cpp/blaze.cc:1261] Connected (server pid=658256). +[INFO 08:56:26.590 src/main/cpp/blaze.cc:1971] Releasing client lock, let the server manage concurrent requests. +INFO: Repository config_validation_pip3 instantiated at: + no stack (--record_rule_instantiation_callstack not enabled) +Repository rule pip_import defined at: + /root/.cache/bazel/_bazel_root/7558a64af10a6eb79f74e70211660103/external/rules_python/python/pip.bzl:51:29: in +ERROR: An error occurred during the fetch of repository 'config_validation_pip3': + pip_import failed: (Traceback (most recent call last): + File "/opt/local/lib/python3.7/runpy.py", line 193, in _run_module_as_main + "__main__", mod_spec) + File "/opt/local/lib/python3.7/runpy.py", line 85, in _run_code + exec(code, run_globals) + File "/root/.cache/bazel/_bazel_root/7558a64af10a6eb79f74e70211660103/external/rules_python/tools/piptool.par/__main__.py", line 26, in + File "/root/.cache/bazel/_bazel_root/7558a64af10a6eb79f74e70211660103/external/rules_python/tools/piptool.par/piptool_deps_pypi__setuptools_44_0_0/pkg_resources/__init__.py", line 35, in + File "/opt/local/lib/python3.7/plistlib.py", line 65, in + from xml.parsers.expat import ParserCreate + File "/opt/local/lib/python3.7/xml/parsers/expat.py", line 4, in + from pyexpat import * +ModuleNotFoundError: No module named 'pyexpat' +) +ERROR: no such package '@config_validation_pip3//': pip_import failed: (Traceback (most recent call last): + File "/opt/local/lib/python3.7/runpy.py", line 193, in _run_module_as_main + "__main__", mod_spec) + File "/opt/local/lib/python3.7/runpy.py", line 85, in _run_code + exec(code, run_globals) + File "/root/.cache/bazel/_bazel_root/7558a64af10a6eb79f74e70211660103/external/rules_python/tools/piptool.par/__main__.py", line 26, in + File "/root/.cache/bazel/_bazel_root/7558a64af10a6eb79f74e70211660103/external/rules_python/tools/piptool.par/piptool_deps_pypi__setuptools_44_0_0/pkg_resources/__init__.py", line 35, in + File "/opt/local/lib/python3.7/plistlib.py", line 65, in + from xml.parsers.expat import ParserCreate + File "/opt/local/lib/python3.7/xml/parsers/expat.py", line 4, in + from pyexpat import * +ModuleNotFoundError: No module named 'pyexpat' +) +INFO: Elapsed time: 10.114s +INFO: 0 processes. +FAILED: Build did NOT complete successfully (0 packages loaded) + Fetching @headersplit_pip3; fetching 9s + Fetching @configs_pip3; fetching 9s + Fetching @kafka_pip3; fetching 9s + Fetching @thrift_pip3; fetching 9s + Fetching @protodoc_pip3; fetching 9s +``` + +# Original Envoy Readme + ![Envoy Logo](https://github.com/envoyproxy/artwork/blob/main/PNG/Envoy_Logo_Final_PANTONE.png) [Cloud-native high-performance edge/middle/service proxy](https://www.envoyproxy.io/) diff --git a/bazel/BUILD b/bazel/BUILD index 17319f4c35ef..5e4aab85b3fb 100644 --- a/bazel/BUILD +++ b/bazel/BUILD @@ -471,6 +471,11 @@ config_setting( values = {"cpu": "x64_windows"}, ) +config_setting( + name = "illumos_x86_64", + values = {"cpu": "x86_64"}, +) + # Configuration settings to make doing selects for Apple vs non-Apple platforms # easier. More details: https://docs.bazel.build/versions/master/configurable-attributes.html#config_settingaliasing config_setting( @@ -588,6 +593,7 @@ selects.config_setting_group( ":ios_x86_64", ":linux_x86_64", ":windows_x86_64", + "illumos_x86_64", ], ) diff --git a/bazel/dependency_imports.bzl b/bazel/dependency_imports.bzl index cf8e357e3233..2d33a425051a 100644 --- a/bazel/dependency_imports.bzl +++ b/bazel/dependency_imports.bzl @@ -12,13 +12,18 @@ load("@base_pip3//:requirements.bzl", pip_dependencies = "install_deps") load("@emsdk//:emscripten_deps.bzl", "emscripten_deps") # go version for rules_go -GO_VERSION = "1.17.5" +# Align the Go version with the version that is installed in Illumos since we added the +# 'go_register_toolchains(go_version = "host")' directive. +GO_VERSION = "1.17.6" def envoy_dependency_imports(go_version = GO_VERSION): # TODO: allow building of tools for easier onboarding rules_foreign_cc_dependencies(register_default_tools = False, register_built_tools = False) go_rules_dependencies() - go_register_toolchains(go_version) + # Using 'host' makes Bazel use the go installation on our host. This + # is needed because the 'io_bazel_rules_go' tries to download a GO + # installation. However it can't download one for Illumos / Solaris. + go_register_toolchains(go_version = "host") gazelle_dependencies() apple_rules_dependencies() pip_dependencies() diff --git a/bazel/envoy_binary.bzl b/bazel/envoy_binary.bzl index f744e60c82f0..c55eb08649fa 100644 --- a/bazel/envoy_binary.bzl +++ b/bazel/envoy_binary.bzl @@ -40,7 +40,8 @@ def envoy_cc_binary( linkstatic = 1, visibility = visibility, malloc = tcmalloc_external_dep(repository), - stamp = 1, + # FIXME: Solaris ld doesn't support build-ld. Fix more elegantly. + stamp = 0, deps = deps, tags = tags, features = features, @@ -74,14 +75,18 @@ def _envoy_linkopts(): "-pthread", "-lrt", "-ldl", - "-Wl,-z,relro,-z,now", - "-Wl,--hash-style=gnu", + # The 'relro'flag is not supported by the Illumos linker. + "-Wl,-z,now", + # FIXME: GNU LD supports this option but the Illumos linker doesn't. + #'-Wl,--hash-style=gnu', ], }) + select({ "@envoy//bazel:apple": [], "@envoy//bazel:boringssl_fips": [], "@envoy//bazel:windows_x86_64": [], - "//conditions:default": ["-pie"], + # FIXME: GCC on Illumos doesn't support position independent executables? + # "//conditions:default": ["-pie"], + "//conditions:default": [], }) + _envoy_select_exported_symbols(["-Wl,-E"]) def _envoy_stamped_deps(): @@ -112,6 +117,7 @@ def _envoy_stamped_linkopts(): # Note: assumes GNU GCC (or compatible) handling of `--build-id` flag. "//conditions:default": [ - "-Wl,@$(location @envoy//bazel:gnu_build_id.ldscript)", + # TODO: Ilumos ld doesn't support build-ld. Fix more elegantly. + # "-Wl,@$(location @envoy//bazel:gnu_build_id.ldscript)", ], }) diff --git a/bazel/envoy_internal.bzl b/bazel/envoy_internal.bzl index b942be424c1f..4a2a0529cc23 100644 --- a/bazel/envoy_internal.bzl +++ b/bazel/envoy_internal.bzl @@ -7,7 +7,8 @@ def envoy_copts(repository, test = False): posix_options = [ "-Wall", "-Wextra", - "-Werror", + # TODO: Doesn't work on Illumos. + #"-Werror", "-Wnon-virtual-dtor", "-Woverloaded-virtual", "-Wold-style-cast", diff --git a/bazel/foreign_cc/BUILD b/bazel/foreign_cc/BUILD index 6c59c4266db1..fe31ec4bdda7 100644 --- a/bazel/foreign_cc/BUILD +++ b/bazel/foreign_cc/BUILD @@ -19,10 +19,15 @@ configure_make( # TODO: Consider our own gperftools.BUILD file as we do with many other packages configure_make( name = "gperftools_build", + # Additional flags needed so 'libtcmalloc_and_profiler.a' gets created. configure_options = [ "--enable-shared=no", "--enable-frame-pointers", "--disable-libunwind", + "--enable-cpu-profiler", + "--enable-heap-profiler", + "--enable-heap-checker", + "--enable-debugalloc", ] + select({ "//bazel:apple": ["AR=/usr/bin/ar"], "//conditions:default": [], diff --git a/bazel/foreign_cc/gperftools.patch b/bazel/foreign_cc/gperftools.patch new file mode 100644 index 000000000000..c06b8fecd9f3 --- /dev/null +++ b/bazel/foreign_cc/gperftools.patch @@ -0,0 +1,68 @@ +From 4568af7a36e85274c9d15a873d235b518ef01b0c Mon Sep 17 00:00:00 2001 +From: Jasper Siepkes +Date: Wed, 7 Dec 2022 13:01:09 +0100 +Subject: [PATCH] Added Illumos / SmartOS support. + +--- + m4/pc_from_ucontext.m4 | 8 +++++++- + src/getpc.h | 3 +++ + src/profiler.cc | 3 +++ + 3 files changed, 13 insertions(+), 1 deletion(-) + +diff --git a/m4/pc_from_ucontext.m4 b/m4/pc_from_ucontext.m4 +index 159b01d..2aa04ca 100644 +--- a/m4/pc_from_ucontext.m4 ++++ b/m4/pc_from_ucontext.m4 +@@ -16,6 +16,9 @@ AC_DEFUN([AC_PC_FROM_UCONTEXT], + if grep "Red Hat Linux release 7" /etc/redhat-release >/dev/null 2>&1; then + AC_DEFINE(HAVE_SYS_UCONTEXT_H, 0, [ is broken on redhat 7]) + ac_cv_header_sys_ucontext_h=no ++ elif grep "SmartOS" /etc/release >/dev/null 2>&1; then ++ # SmartOS has but it doesn't work. does work. ++ AC_CHECK_HEADERS(ucontext.h) + else + AC_CHECK_HEADERS(sys/ucontext.h) # ucontext on OS X 10.6 (at least) + fi +@@ -69,7 +72,10 @@ AC_DEFUN([AC_PC_FROM_UCONTEXT], + pc_field_found=true) + elif test "x$ac_cv_header_sys_ucontext_h" = xyes; then + AC_TRY_COMPILE([#define _GNU_SOURCE 1 +- #include ], ++ #include , ++ #if defined(__sun) ++ #include ++ #endif], + [ucontext_t u; return u.$pc_field == 0;], + AC_DEFINE_UNQUOTED(PC_FROM_UCONTEXT, $pc_field, + How to access the PC from a struct ucontext) +diff --git a/src/getpc.h b/src/getpc.h +index 9605363..41ce862 100644 +--- a/src/getpc.h ++++ b/src/getpc.h +@@ -61,6 +61,9 @@ + #endif + #if defined(HAVE_SYS_UCONTEXT_H) + #include ++#if defined(__illumos__) ++#include ++#endif + #elif defined(HAVE_UCONTEXT_H) + #include // for ucontext_t (and also mcontext_t) + #elif defined(HAVE_CYGWIN_SIGNAL_H) +diff --git a/src/profiler.cc b/src/profiler.cc +index 227deb2..bed0a2e 100644 +--- a/src/profiler.cc ++++ b/src/profiler.cc +@@ -46,6 +46,9 @@ + #endif + #if defined(HAVE_SYS_UCONTEXT_H) + #include ++#if defined(__illumos__) ++#include ++#endif + #elif defined(HAVE_UCONTEXT_H) + #include + #elif defined(HAVE_CYGWIN_SIGNAL_H) +-- +2.38.1 + diff --git a/bazel/foreign_cc/zlib.patch b/bazel/foreign_cc/zlib.patch index aeeeed3147fd..4d5280f2235f 100644 --- a/bazel/foreign_cc/zlib.patch +++ b/bazel/foreign_cc/zlib.patch @@ -92,4 +92,4 @@ index e108c16..2cd82ef 100644 + target_link_libraries(minigzip64 zlib) + set_target_properties(minigzip64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64") + endif() - endif() + endif() \ No newline at end of file diff --git a/bazel/illumos-bazel-gazelle.patch b/bazel/illumos-bazel-gazelle.patch new file mode 100644 index 000000000000..624abfac1056 --- /dev/null +++ b/bazel/illumos-bazel-gazelle.patch @@ -0,0 +1,31 @@ +From 9a84657061207c1bb8e978e31042443c37520a54 Mon Sep 17 00:00:00 2001 +From: Jasper Siepkes +Date: Sun, 11 Jul 2021 10:12:21 +0200 +Subject: [PATCH] Added Illumos / Solaris support. + +--- + internal/go_repository_cache.bzl | 8 ++++++++ + 1 file changed, 8 insertions(+) + +diff --git a/internal/go_repository_cache.bzl b/internal/go_repository_cache.bzl +index 5f01ccc..73546e9 100644 +--- a/internal/go_repository_cache.bzl ++++ b/internal/go_repository_cache.bzl +@@ -133,6 +133,14 @@ def _detect_host_platform(ctx): + host = "windows_amd64" + elif ctx.os.name == "freebsd": + host = "freebsd_amd64" ++ elif ctx.os.name == "solaris" or ctx.os.name == "sunos": ++ res = ctx.execute(["uname", "-o"]) ++ if res.return_code == 0: ++ uname = res.stdout.strip() ++ if uname == "illumos": ++ host = "illumos_amd64" ++ else: ++ host = "solaris_amd64" + else: + fail("Unsupported operating system: " + ctx.os.name) + +-- +2.36.1 + diff --git a/bazel/illumos-boringssl.patch b/bazel/illumos-boringssl.patch new file mode 100644 index 000000000000..5df6c625a46d --- /dev/null +++ b/bazel/illumos-boringssl.patch @@ -0,0 +1,99 @@ +From 43f3f05f38dcf0e1b70bdad198b493c4a436de8b Mon Sep 17 00:00:00 2001 +From: Jasper Siepkes +Date: Wed, 7 Dec 2022 17:02:04 +0100 +Subject: [PATCH] Added Illumos / SmartOS support. + +Also includes the changes from the 'boringssl_static.patch' of Envoy. +--- + BUILD | 24 +++++++++++++++++++++++- + src/include/openssl/thread.h | 2 +- + 2 files changed, 24 insertions(+), 2 deletions(-) + +diff --git a/BUILD b/BUILD +index cfa695a44..d8ff5ca04 100644 +--- a/BUILD ++++ b/BUILD +@@ -75,6 +75,11 @@ config_setting( + ], + ) + ++config_setting( ++ name = "illumos_x86_64", ++ values = {"cpu": "illumos"}, ++) ++ + posix_copts = [ + # Assembler option --noexecstack adds .note.GNU-stack to each object to + # ensure that binaries can be built with non-executable stack. +@@ -98,9 +103,20 @@ linux_copts = posix_copts + [ + "-D_XOPEN_SOURCE=700", + ] + ++illumos_copts = posix_copts + [ ++ "-D_XOPEN_SOURCE=600", ++ "-D__EXTENSIONS__", ++ ++ # There is no assmebly code for Solaris in BoringSSL. While this is a ++ # performance hit it seems gRPC has it disabled by default as well: ++ # https://github.com/grpc/grpc/issues/9440 ++ "-DOPENSSL_NO_ASM", ++] ++ + boringssl_copts = select({ + "@platforms//os:linux": linux_copts, +- "@platforms//os:macos": posix_copts, ++ "@platforms//os:macos": illumos_copts, ++ "@platforms//os:illumos": posix_copts, + "@platforms//os:windows": ["-DWIN32_LEAN_AND_MEAN"], + "//conditions:default": [], + }) +@@ -134,6 +150,7 @@ posix_copts_c11 = [ + boringssl_copts_c11 = boringssl_copts + select({ + "@platforms//os:linux": posix_copts_c11, + "@platforms//os:macos": posix_copts_c11, ++ "@platforms//os:illumos": posix_copts_c11, + "//conditions:default": [], + }) + +@@ -146,6 +163,7 @@ posix_copts_cxx = [ + boringssl_copts_cxx = boringssl_copts + select({ + "@platforms//os:linux": posix_copts_cxx, + "@platforms//os:macos": posix_copts_cxx, ++ "@platforms//os:illumos": posix_copts_cxx, + "//conditions:default": [], + }) + +@@ -163,6 +181,8 @@ cc_library( + "@platforms//os:windows": ["-defaultlib:advapi32.lib"], + "//conditions:default": ["-lpthread"], + }), ++ # Imported from 'boringssl_static.patch' ++ linkstatic = True, + visibility = ["//visibility:public"], + ) + +@@ -171,6 +191,8 @@ cc_library( + srcs = ssl_sources + ssl_internal_headers, + hdrs = ssl_headers, + copts = boringssl_copts_cxx, ++ # Imported from 'boringssl_static.patch' ++ linkstatic = True, + includes = ["src/include"], + visibility = ["//visibility:public"], + deps = [ +diff --git a/src/include/openssl/thread.h b/src/include/openssl/thread.h +index 91706fec2..c5a69c42f 100644 +--- a/src/include/openssl/thread.h ++++ b/src/include/openssl/thread.h +@@ -77,7 +77,7 @@ typedef struct crypto_mutex_st { + typedef union crypto_mutex_st { + void *handle; + } CRYPTO_MUTEX; +-#elif defined(__MACH__) && defined(__APPLE__) ++#elif defined(__MACH__) && defined(__APPLE__) || defined(__illumos__) + typedef pthread_rwlock_t CRYPTO_MUTEX; + #else + // It is reasonable to include pthread.h on non-Windows systems, however the +-- +2.38.1 + diff --git a/bazel/protobuf.patch b/bazel/protobuf.patch index c34ac0ffe0de..a557657bb194 100644 --- a/bazel/protobuf.patch +++ b/bazel/protobuf.patch @@ -1,27 +1,35 @@ -diff --git a/BUILD b/BUILD -index 1690d4219..8a7f1bf14 100644 ---- a/BUILD -+++ b/BUILD -@@ -19,7 +19,7 @@ exports_files(["LICENSE"]) - # ZLIB configuration - ################################################################################ +diff -uar ../protobuf-all-21.11-orig/protobuf-21.11/BUILD.bazel protobuf-21.11/BUILD.bazel +--- ../protobuf-all-21.11-orig/protobuf-21.11/BUILD.bazel 2022-12-14 14:47:14.280134747 +0100 ++++ protobuf-21.11/BUILD.bazel 2022-12-14 14:49:18.376959691 +0100 +@@ -18,7 +18,7 @@ + + licenses(["notice"]) --ZLIB_DEPS = ["@zlib//:zlib"] -+ZLIB_DEPS = ["//external:zlib"] +-exports_files(["LICENSE"]) ++exports_files(["LICENSE", "zlib.BUILD"]) ################################################################################ # Protobuf Runtime Library -diff --git a/python/google/protobuf/__init__.py b/python/google/protobuf/__init__.py -index 9319c67f1..d85d53d4a 100644 ---- a/python/google/protobuf/__init__.py -+++ b/python/google/protobuf/__init__.py -@@ -31,3 +31,9 @@ +@@ -138,7 +138,7 @@ + visibility = ["//visibility:public"], + deps = [":protobuf_lite"] + select({ + "//build_defs:config_msvc": [], +- "//conditions:default": ["@zlib//:zlib"], ++ "//conditions:default": ["//external:zlib"], + }), + ) + +diff -uar ../protobuf-all-21.11-orig/protobuf-21.11/python/google/protobuf/__init__.py protobuf-21.11/python/google/protobuf/__init__.py +--- ../protobuf-all-21.11-orig/protobuf-21.11/python/google/protobuf/__init__.py 2022-12-14 14:47:14.283134753 +0100 ++++ protobuf-21.11/python/google/protobuf/__init__.py 2022-12-14 14:51:11.435723700 +0100 +@@ -31,3 +31,10 @@ # Copyright 2007 Google Inc. All Rights Reserved. - __version__ = '3.19.4' + __version__ = '4.21.11' + +if __name__ != '__main__': + try: + __import__('pkg_resources').declare_namespace(__name__) + except ImportError: + __path__ = __import__('pkgutil').extend_path(__path__, __name__) ++ diff --git a/bazel/repositories.bzl b/bazel/repositories.bzl index 676b79f4f30b..9c5764753fbb 100644 --- a/bazel/repositories.bzl +++ b/bazel/repositories.bzl @@ -121,8 +121,8 @@ def _go_deps(skip_targets): external_http_archive( name = "io_bazel_rules_go", # TODO(wrowe, sunjayBhatia): remove when Windows RBE supports batch file invocation - patch_args = ["-p1"], - patches = ["@envoy//bazel:rules_go.patch"], +# patch_args = ["-p1"], +# patches = ["@envoy//bazel:rules_go.patch"], ) external_http_archive("bazel_gazelle") @@ -223,6 +223,7 @@ def envoy_dependencies(skip_targets = []): external_http_archive("envoy_build_tools") external_http_archive("rules_cc") external_http_archive("rules_pkg") + external_http_archive("platforms") _com_github_fdio_vpp_vcl() # Unconditional, since we use this only for compiler-agnostic fuzzing utils. @@ -258,7 +259,8 @@ def _boringssl(): name = "boringssl", patch_args = ["-p1"], patches = [ - "@envoy//bazel:boringssl_static.patch", + # Removed 'boringssl_static.patch'. Changes have been added to the modifications to make BoringSSL + # build on Illumos. "@envoy//bazel:boringssl_CVE-2023-0286.patch", ], ) @@ -426,7 +428,7 @@ def _net_zlib(): name = "net_zlib", build_file_content = BUILD_ALL_CONTENT, patch_args = ["-p1"], - patches = ["@envoy//bazel/foreign_cc:zlib.patch"], + patches = ["@envoy//bazel/foreign_cc:zlib.patch"] ) native.bind( @@ -1063,6 +1065,8 @@ def _com_github_gperftools_gperftools(): external_http_archive( name = "com_github_gperftools_gperftools", build_file_content = BUILD_ALL_CONTENT, + patch_args = ["-p1"], + patches = ["@envoy//bazel/foreign_cc:gperftools.patch"], ) native.bind( name = "gperftools", diff --git a/bazel/repository_locations.bzl b/bazel/repository_locations.bzl index ab26210d0eaf..9231be88c22d 100644 --- a/bazel/repository_locations.bzl +++ b/bazel/repository_locations.bzl @@ -15,9 +15,11 @@ REPOSITORY_LOCATIONS_SPEC = dict( project_name = "Gazelle", project_desc = "Bazel BUILD file generator for Go projects", project_url = "https://github.com/bazelbuild/bazel-gazelle", - version = "0.24.0", - sha256 = "de69a09dc70417580aabf20a28619bb3ef60d038470c7cf8442fafcf627c21cb", - urls = ["https://github.com/bazelbuild/bazel-gazelle/releases/download/v{version}/bazel-gazelle-v{version}.tar.gz"], + # Fork of version 0.24.0 with Illumos support. + version = "9a84657061207c1bb8e978e31042443c37520a54", + sha256 = "9dce8407d96a438892a5426a100d256e1f1db4f3b44bcacc8293289fdf56f99f", + strip_prefix = "bazel-gazelle-{version}", + urls = ["https://github.com/siepkes/bazel-gazelle/archive/{version}.tar.gz"], release_date = "2021-10-11", use_category = ["build"], ), @@ -34,6 +36,21 @@ REPOSITORY_LOCATIONS_SPEC = dict( release_date = "2021-11-30", use_category = ["build"], ), + # Even though the Bazel Illumos port has Illumos defined in the 'platform' repo it gets overridden + # by Envoy. Therefor we need to make sure the modified platforms repo is in Envoy's Bazel build. + platforms = dict( + project_name = "platforms", + project_desc = "Constraint values for specifying platforms and toolchains", + project_url = "https://github.com/bazelbuild/bazel-toolchains", + version = "e2b0fddbd5f841432740a0029751168c054db622", + sha256 = "0333ae8fb930af48095b399f23fbd0e1994c23aa330793f804823295ca343b9e", + strip_prefix = "platforms-{version}", + urls = [ + "https://github.com/siepkes/platforms/archive/{version}.tar.gz", + ], + release_date = "2021-11-30", + use_category = ["build"], + ), build_bazel_rules_apple = dict( project_name = "Apple Rules for Bazel", project_desc = "Bazel rules for Apple platforms", @@ -81,13 +98,15 @@ REPOSITORY_LOCATIONS_SPEC = dict( # 3. Find a commit in BoringSSL's "master-with-bazel" branch that merges . # # chromium-100.0.4896.30 (linux/beta) - version = "cacb5526268191ab52e3a8b2d71f686115776646", - sha256 = "fd72798ee22beb9f052d792d6c701d3ea94183c2e5b94e737866a53152b46f41", + version = "bac527fa9d0f53ec099891c2981580cd0d479c30", + sha256 = "9da97beb995fabe5018acb87a8c68d2a833b33a175a917d826faac98b8ac9314", strip_prefix = "boringssl-{version}", - urls = ["https://github.com/google/boringssl/archive/{version}.tar.gz"], + urls = ["https://github.com/siepkes/boringssl/archive/{version}.tar.gz"], use_category = ["controlplane", "dataplane_core"], release_date = "2022-02-08", cpe = "cpe:2.3:a:google:boringssl:*", + #patch_args = ["-p1"], + #patches = ["@envoy//bazel:illumos-boringssl.patch"], ), boringssl_fips = dict( project_name = "BoringSSL (FIPS)", @@ -104,10 +123,10 @@ REPOSITORY_LOCATIONS_SPEC = dict( project_name = "Abseil", project_desc = "Open source collection of C++ libraries drawn from the most fundamental pieces of Google’s internal codebase", project_url = "https://abseil.io/", - version = "6f43f5bb398b6685575b36874e36cf1695734df1", - sha256 = "5ca73792af71ab962ee81cdf575f79480704b8fb87e16ca8f1dc1e9b6822611e", + version = "022ad185bd1c593c30016a1133a2ec8bbb504b0b", + sha256 = "7f5d03194db24eed29b852573de44354a9e6cb7f1c13ebf1f01bcf2566181ac4", strip_prefix = "abseil-cpp-{version}", - urls = ["https://github.com/abseil/abseil-cpp/archive/{version}.tar.gz"], + urls = ["https://github.com/siepkes/abseil-cpp/archive/{version}.tar.gz"], use_category = ["dataplane_core", "controlplane"], release_date = "2022-04-04", cpe = "N/A", @@ -278,10 +297,11 @@ REPOSITORY_LOCATIONS_SPEC = dict( project_name = "gRPC", project_desc = "gRPC C core library", project_url = "https://grpc.io", - version = "a3ae8e00a2c5553c806e83fae83e33f0198913f0", - sha256 = "1ccc2056b68b81ada8df61310e03dfa0541c34821fd711654d0590a7321db9c8", + # Forked version of 'a3ae8e00a2c5553c806e83fae83e33f0198913f0' with Illumos support. + version = "f6b659378fd431ddcbe26c88a5421d2cb5129356", + sha256 = "6fc6c708c44316fcc2a2be85d100e3897c9d6a4dbf1bc04e988a1ff1abf69ab3", strip_prefix = "grpc-{version}", - urls = ["https://github.com/grpc/grpc/archive/{version}.tar.gz"], + urls = ["https://github.com/siepkes/grpc/archive/{version}.tar.gz"], use_category = ["dataplane_core", "controlplane"], release_date = "2021-06-07", cpe = "cpe:2.3:a:grpc:grpc:*", @@ -669,16 +689,20 @@ REPOSITORY_LOCATIONS_SPEC = dict( project_name = "Protocol Buffers", project_desc = "Language-neutral, platform-neutral extensible mechanism for serializing structured data", project_url = "https://developers.google.com/protocol-buffers", - version = "3.19.4", + # We need this version bump on Illumos because the orignal version (3.19.4) fails to properly convert double + # values in YAML/JSON config files to protobuf. For example '0.90' becomes '-6.0659880001149178e+66'. + # This behavior was observed when configuring the overload manager with for example the + # 'envoy.resource_monitors.fixed_heap' action. + version = "21.11", # When upgrading the protobuf library, please re-run # test/common/json:gen_excluded_unicodes to recompute the ranges # excluded from differential fuzzing that are populated in # test/common/json/json_sanitizer_test_util.cc. - sha256 = "ba0650be1b169d24908eeddbe6107f011d8df0da5b1a5a4449a913b10e578faf", + sha256 = "f045f136e61e367a9436571b6676b94e5e16631a06c864146688c3aaf7df794b", strip_prefix = "protobuf-{version}", urls = ["https://github.com/protocolbuffers/protobuf/releases/download/v{version}/protobuf-all-{version}.tar.gz"], use_category = ["dataplane_core", "controlplane"], - release_date = "2022-01-28", + release_date = "2022-12-08", cpe = "cpe:2.3:a:google:protobuf:*", ), grpc_httpjson_transcoding = dict( @@ -698,9 +722,11 @@ REPOSITORY_LOCATIONS_SPEC = dict( project_name = "Go rules for Bazel", project_desc = "Bazel rules for the Go language", project_url = "https://github.com/bazelbuild/rules_go", - version = "0.31.0", - sha256 = "f2dcd210c7095febe54b804bb1cd3a58fe8435a909db2ec04e31542631cf715c", - urls = ["https://github.com/bazelbuild/rules_go/releases/download/v{version}/rules_go-v{version}.zip"], + # Fork of 0.31.0 with Illumos added. + version = "86cfe63b52f1c3ea4bafff399606d12860af87d4", + sha256 = "f31a91c78dfbf50aa94045e285489bbcb5e84a40c8571e21b97523e837a52d96", + strip_prefix = "rules_go-{version}", + urls = ["https://github.com/siepkes/rules_go/archive/{version}.tar.gz"], use_category = ["build", "api"], release_date = "2022-03-21", implied_untracked_deps = [ @@ -714,9 +740,11 @@ REPOSITORY_LOCATIONS_SPEC = dict( project_name = "C++ rules for Bazel", project_desc = "Bazel rules for the C++ language", project_url = "https://github.com/bazelbuild/rules_cc", - version = "0.0.1", - sha256 = "4dccbfd22c0def164c8f47458bd50e0c7148f3d92002cdb459c2a96a68498241", - urls = ["https://github.com/bazelbuild/rules_cc/releases/download/{version}/rules_cc-{version}.tar.gz"], + # Fork of version 0.0.1 with Illumos added. + version = "18b4a816bce5436073556368ddeccc3d830caaeb", + sha256 = "6e1db8131c07aa4b9d07ec283b08cde635f1157a9bc05c9b29dc6a6a8cd1600a", + strip_prefix = "rules_cc-{version}", + urls = ["https://github.com/siepkes/rules_cc//archive/{version}.tar.gz"], release_date = "2021-10-07", use_category = ["build"], ), @@ -724,10 +752,10 @@ REPOSITORY_LOCATIONS_SPEC = dict( project_name = "Rules for using foreign build systems in Bazel", project_desc = "Rules for using foreign build systems in Bazel", project_url = "https://github.com/bazelbuild/rules_foreign_cc", - version = "0.7.1", - sha256 = "bcd0c5f46a49b85b384906daae41d277b3dc0ff27c7c752cc51e43048a58ec83", + version = "0026fdab99d2ae36f1d8b5e35bf1f43a90013c2b", + sha256 = "3c461dd7650cd2f63e0766a9990fc7c72096f1e996cf12b127db6f08b4bcd663", strip_prefix = "rules_foreign_cc-{version}", - urls = ["https://github.com/bazelbuild/rules_foreign_cc/archive/{version}.tar.gz"], + urls = ["https://github.com/siepkes/rules_foreign_cc/archive/{version}.tar.gz"], release_date = "2022-01-03", use_category = ["build", "dataplane_core", "controlplane"], ), @@ -991,11 +1019,13 @@ REPOSITORY_LOCATIONS_SPEC = dict( project_name = "upb", project_desc = "A small protobuf implementation in C (gRPC dependency)", project_url = "https://github.com/protocolbuffers/upb", - version = "de76b31f9c56b28120580d53a6f8d7941fdb79eb", - sha256 = "487d84ce85065ff89ccde1c1ac2ea1515d2be411306e4adf1be6861dc4a4a86b", + # Building upb breaks the build because it pass both the '-Wall' and '-Werror' flags to GCC. + # However Google upb includes Google absl which generates warnings and thereby kills the build. + version = "231008fa571839db492b69341c724196c1f0fd3c", + sha256 = "f524c1ee1da46b1848a00ff805acfbc7399ac09a8831066de5f30a6e58e04d31", release_date = "2020-12-29", strip_prefix = "upb-{version}", - urls = ["https://github.com/protocolbuffers/upb/archive/{version}.tar.gz"], + urls = ["https://github.com/siepkes/upb/archive/{version}.tar.gz"], use_category = ["controlplane"], cpe = "N/A", ), diff --git a/source/common/common/posix/thread_impl.cc b/source/common/common/posix/thread_impl.cc index fae09194d8cc..9297f145c6cf 100644 --- a/source/common/common/posix/thread_impl.cc +++ b/source/common/common/posix/thread_impl.cc @@ -19,6 +19,8 @@ int64_t getCurrentThreadId() { uint64_t tid; pthread_threadid_np(nullptr, &tid); return tid; +#elif defined(__sun) + return (unsigned long)pthread_self(); #else #error "Enable and test pthread id retrieval code for you arch in pthread/thread_impl.cc" #endif diff --git a/source/common/common/utility.cc b/source/common/common/utility.cc index 82ad3dd520b0..9a20d2641f3f 100644 --- a/source/common/common/utility.cc +++ b/source/common/common/utility.cc @@ -604,7 +604,7 @@ bool Primes::isPrime(uint32_t x) { return false; // eliminates even numbers >2. } - uint32_t limit = sqrt(x); + uint32_t limit = sqrt((double)x); for (uint32_t factor = 3; factor <= limit; factor += 2) { if ((x % factor) == 0) { return false; diff --git a/source/common/network/address_impl.cc b/source/common/network/address_impl.cc index 330735fc100c..b5855ef29837 100644 --- a/source/common/network/address_impl.cc +++ b/source/common/network/address_impl.cc @@ -1,3 +1,8 @@ +#ifdef __sun +#include +#include +#endif + #include "source/common/network/address_impl.h" #include @@ -14,6 +19,10 @@ #include "source/common/common/utility.h" #include "source/common/network/socket_interface.h" +#ifdef __sun +#define s6_addr32 _S6_un._S6_u32 +#endif + namespace Envoy { namespace Network { namespace Address { diff --git a/source/common/network/connection_impl.cc b/source/common/network/connection_impl.cc index f8bfa2ef03e1..14f94e634fd2 100644 --- a/source/common/network/connection_impl.cc +++ b/source/common/network/connection_impl.cc @@ -289,10 +289,11 @@ void ConnectionImpl::noDelay(bool enable) { int new_value = enable; Api::SysCallIntResult result = socket_->setSocketOption(IPPROTO_TCP, TCP_NODELAY, &new_value, sizeof(new_value)); -#if defined(__APPLE__) +#if defined(__APPLE__) || defined(__sun) if (SOCKET_FAILURE(result.return_value_) && result.errno_ == SOCKET_ERROR_INVAL) { // Sometimes occurs when the connection is not yet fully formed. Empirically, TCP_NODELAY is // enabled despite this result. + // For Illumos see: https://github.com/joyent/illumos-joyent/issues/148 return; } #elif defined(WIN32) diff --git a/source/common/signal/signal_action.cc b/source/common/signal/signal_action.cc index cc2a18f6dfa9..e9026990b57d 100644 --- a/source/common/signal/signal_action.cc +++ b/source/common/signal/signal_action.cc @@ -1,5 +1,11 @@ #include "source/common/signal/signal_action.h" +#ifdef __sun +#include +#endif + +#include + #include #include @@ -13,6 +19,26 @@ namespace Envoy { constexpr int SignalAction::FATAL_SIGS[]; void SignalAction::sigHandler(int sig, siginfo_t* info, void* context) { + void* error_pc = 0; + + const ucontext_t* ucontext = reinterpret_cast(context); + if (ucontext != nullptr) { +#ifdef REG_RIP + // x86_64 + error_pc = reinterpret_cast(ucontext->uc_mcontext.gregs[REG_RIP]); +#elif defined(__APPLE__) && defined(__x86_64__) + error_pc = reinterpret_cast(ucontext->uc_mcontext->__ss.__rip); +#elif defined(__powerpc__) + error_pc = reinterpret_cast(ucontext->uc_mcontext.regs->nip); +#elif defined(__sun) + error_pc = reinterpret_cast(ucontext->uc_mcontext.gregs[REG_PC]); +#else +#warning "Please enable and test PC retrieval code for your arch in signal_action.cc" +// x86 Classic: reinterpret_cast(ucontext->uc_mcontext.gregs[REG_EIP]); +// ARM: reinterpret_cast(ucontext->uc_mcontext.arm_pc); +#endif + } + BackwardsTrace tracer; tracer.logFault(strsignal(sig), info->si_addr); @@ -95,7 +121,7 @@ void SignalAction::removeSigHandlers() { } } -#if defined(__APPLE__) && !defined(MAP_STACK) +#if defined(__APPLE__) || defined(__sun) && !defined(MAP_STACK) #define MAP_STACK (0) #endif diff --git a/source/common/thread/terminate_thread.cc b/source/common/thread/terminate_thread.cc index 8ddb9f20edf9..162fdcf3dd4a 100644 --- a/source/common/thread/terminate_thread.cc +++ b/source/common/thread/terminate_thread.cc @@ -9,7 +9,7 @@ namespace Envoy { namespace Thread { namespace { -#ifdef __linux__ +#if defined(__linux__) || defined(__sun) pid_t toPlatformTid(int64_t tid) { return static_cast(tid); } #elif defined(__APPLE__) uint64_t toPlatformTid(int64_t tid) { return static_cast(tid); } diff --git a/source/extensions/filters/listener/proxy_protocol/proxy_protocol.cc b/source/extensions/filters/listener/proxy_protocol/proxy_protocol.cc index ee9e0c53f025..c0308f8c0240 100644 --- a/source/extensions/filters/listener/proxy_protocol/proxy_protocol.cc +++ b/source/extensions/filters/listener/proxy_protocol/proxy_protocol.cc @@ -1,5 +1,10 @@ #include "source/extensions/filters/listener/proxy_protocol/proxy_protocol.h" +#ifdef __sun +// This is where the FIONREAD macro lives. +#include +#endif + #include #include #include diff --git a/source/server/hot_restart_impl.cc b/source/server/hot_restart_impl.cc index 347167217b95..16284664cff7 100644 --- a/source/server/hot_restart_impl.cc +++ b/source/server/hot_restart_impl.cc @@ -1,6 +1,8 @@ #include "source/server/hot_restart_impl.h" +#ifndef __sun #include +#endif #include #include @@ -102,10 +104,14 @@ HotRestartImpl::HotRestartImpl(uint32_t base_id, uint32_t restart_epoch, as_parent_(HotRestartingParent(scaled_base_id_, restart_epoch, socket_path, socket_mode)), shmem_(attachSharedMemory(scaled_base_id_, restart_epoch)), log_lock_(shmem_->log_lock_), access_log_lock_(shmem_->access_log_lock_) { +// FIXME: Solaris doesn't support 'prctl'. Find a POSIX compliant way to do this. See also: +// https://stackoverflow.com/questions/284325/how-to-make-child-process-die-after-parent-exits/284443 +#ifndef __sun // If our parent ever goes away just terminate us so that we don't have to rely on ops/launching // logic killing the entire process tree. We should never exist without our parent. int rc = prctl(PR_SET_PDEATHSIG, SIGTERM); RELEASE_ASSERT(rc != -1, ""); +#endif } void HotRestartImpl::drainParentListeners() {