From d21796fe74e3bb014304dcced0549d9c87f931e0 Mon Sep 17 00:00:00 2001 From: Jasper Siepkes Date: Wed, 10 Jul 2024 14:29:37 +0200 Subject: [PATCH] Changes to make v1.29.4 build on SmartOS. --- .bazelrc | 25 ++- BUILD | 19 ++ README.md | 198 ++++++++++++++++++ api/bazel/repository_locations.bzl | 8 +- bazel/BUILD | 6 + bazel/dependency_imports.bzl | 7 +- bazel/envoy_binary.bzl | 30 ++- 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/python_dependencies.bzl | 7 +- bazel/repositories.bzl | 9 +- bazel/repositories_extra.bzl | 11 +- bazel/repository_locations.bzl | 59 ++++-- .../http/test/test_data/access_log/go.mod | 2 +- .../filters/http/test/test_data/basic/go.mod | 2 +- .../filters/http/test/test_data/dummy/go.mod | 2 +- .../filters/http/test/test_data/metric/go.mod | 2 +- .../http/test/test_data/passthrough/go.mod | 2 +- .../filters/network/test/test_data/go.mod | 2 +- 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 + 31 files changed, 595 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 ffd0b37c0f5c..52f8212a3386 100644 --- a/.bazelrc +++ b/.bazelrc @@ -17,8 +17,9 @@ build --color=yes build --jobs=HOST_CPUS-1 build --workspace_status_command="bash bazel/get_workspace_status" build --incompatible_strict_action_env -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 # silence absl logspam. build --copt=-DABSL_MIN_LOG_LEVEL=4 @@ -548,3 +549,23 @@ common:debug --config=debug-tests 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 +# The DataDog extension pulls in Google Abseil, which enables `-Werror` (i.e. treat warnings as errors). +# When using GCC 12 on illumos this fails to build. +build:illumos --@envoy//source/extensions/tracers/datadog:enabled=false + +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 e7f90fcd9ea7..aea652a2782a 100644 --- a/BUILD +++ b/BUILD @@ -81,3 +81,22 @@ package_group( "//mobile/...", ], ) + +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 8be85d8fbeac..20cb4abac3b3 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,201 @@ +# Envoy SmartOS / illumos / Solaris port + +**(Scroll down for original Envoy readme.md)** + +This repo contains a SmartOS / illumos 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 Triton / SmartOS + +Wheter you are on Triton or on SmartOSS you need to create a native (`joyent` brand) container for the build. Steps below are performed on a container running the `base-64` image version `23.4.0` (`8adac45a-aca7-11ee-b53e-00151714048c`). + +The following things are good to know: + +* As stated in the [bazel-smartos](https://github.com/siepkes/bazel-smartos) repo the Bazel and Envoy binaries depend on the specific GCC version used due to hardcoded versions in some paths. +* For this guide a container with 32 GB RAM and 64 GB swap was used in order to built using `export NUM_CPUS=2`. You can experiment with lowering `NUM_CPUS` if you run in to memory problems or changing the amount of RAM and swap of the container. When the linker runs out of memory I've seen the following errors (some cryptic) which all meant "not enough memory" in my case: +** `ld: fatal: mmap anon failed: Resource temporarily unavailable` +** `collect2: error: ld returned 1 exit status` can mean "out of memory" if there is no other error in the output. + +Install required build packages: + +``` +# pkgin -y install go119 ninja-build gcc12 git-base zip unzip openjdk11 libtool cmake automake ninja-build autoconf gmake python311 py311-expat +``` + +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 `py311-expat` installed for every installed Python version (for example `py311-expat` if Python 3.11 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. + +Prepare the build environment: +``` +$ git clone https://github.com/siepkes/envoy-smartos.git +$ cd envoy-smartos +$ git checkout smartos-v1.29.2 +``` + +Build Envoy: +``` +$ export LANG=en_US.UTF-8 +$ export NUM_CPUS=2 # Needed to prevent a CPU detection algorithm from seeing all CPU's in the hypervisor and spawning too many threads. +$ export JAVA_HOME="/opt/local/java/openjdk11" +$ bazel build -c opt --jobs=4 \ + --config=illumos \ + --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 --subcommands +``` + +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 support 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. + +### DataDog tracing extension disabled + +During the build the DataDog tracing extension is disabled via `.bazelrc`. This is because the DataDog extension pulls in it's own Google Abseil (not our patched version) which enables `-Werror` (i.e. treat warnings as errors). When using GCC 12 on illumos this fails to build: + +``` +/opt/local/gcc12/lib/gcc/x86_64-sun-solaris2.11/12.2.0/../../../../include/c++/12.2.0/bits/new_allocator.h:158:33: error: 'void operator delete(void*, size_t)' called on a pointer to an unallocated object '1' [-Werror=free-nonheap-object] +158 | _GLIBCXX_OPERATOR_DELETE(_GLIBCXX_SIZED_DEALLOC(__p, __n)); +| ^ +cc1plus: all warnings being treated as errors +``` + +This could be remedied by forking DataDog's [dd-trace-cpp](https://github.com/DataDog/dd-trace-cpp/) library and ensuring this flag isn't set but since I (@siepkes) have no need for it I disabled building the extension. + +### 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/api/bazel/repository_locations.bzl b/api/bazel/repository_locations.bzl index 7d0bda841e9f..c07e241f4c60 100644 --- a/api/bazel/repository_locations.bzl +++ b/api/bazel/repository_locations.bzl @@ -155,10 +155,10 @@ REPOSITORY_LOCATIONS_SPEC = dict( project_name = "envoy_toolshed", project_desc = "Tooling, libraries, runners and checkers for Envoy proxy's CI", project_url = "https://github.com/envoyproxy/toolshed", - version = "0.1.3", - sha256 = "ee6d0b08ae3d9659f5fc34d752578af195147b153f8ca68eb4f8530aceb764d9", - strip_prefix = "toolshed-bazel-v{version}/bazel", - urls = ["https://github.com/envoyproxy/toolshed/archive/bazel-v{version}.tar.gz"], + version = "ad6ef2576db35e8d4e9deec5fb229b0ebb120f0b", + sha256 = "6dba7c5a5fafdbdf2caa06984872e6b32826356b1356392b33b4ab9b2c82f9d0", + strip_prefix = "toolshed-{version}/bazel", + urls = ["https://github.com/siepkes/toolshed/archive/{version}.tar.gz"], use_category = ["build"], release_date = "2024-04-16", cpe = "N/A", diff --git a/bazel/BUILD b/bazel/BUILD index 919e49f23ec5..8894db2cec2b 100644 --- a/bazel/BUILD +++ b/bazel/BUILD @@ -582,6 +582,11 @@ config_setting( values = {"cpu": "x64_windows"}, ) +config_setting( + name = "illumos", + 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( @@ -757,6 +762,7 @@ selects.config_setting_group( ":ios_x86_64", ":linux_x86_64", ":windows_x86_64", + ":illumos", ], ) diff --git a/bazel/dependency_imports.bzl b/bazel/dependency_imports.bzl index 2bd87a371771..ebf2621aa485 100644 --- a/bazel/dependency_imports.bzl +++ b/bazel/dependency_imports.bzl @@ -18,7 +18,7 @@ load("@com_google_cel_cpp//bazel:deps.bzl", "parser_deps") load("@com_github_chrusty_protoc_gen_jsonschema//:deps.bzl", protoc_gen_jsonschema_go_dependencies = "go_dependencies") # go version for rules_go -GO_VERSION = "1.20" +GO_VERSION = "1.19" JQ_VERSION = "1.7" YQ_VERSION = "4.24.4" @@ -26,7 +26,10 @@ YQ_VERSION = "4.24.4" def envoy_dependency_imports(go_version = GO_VERSION, jq_version = JQ_VERSION, yq_version = YQ_VERSION): rules_foreign_cc_dependencies() 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") envoy_download_go_sdks(go_version) gazelle_dependencies(go_sdk = "go_sdk") apple_rules_dependencies() diff --git a/bazel/envoy_binary.bzl b/bazel/envoy_binary.bzl index 58343f8bb322..1d52942034e1 100644 --- a/bazel/envoy_binary.bzl +++ b/bazel/envoy_binary.bzl @@ -20,7 +20,8 @@ def envoy_cc_binary( visibility = None, external_deps = [], repository = "", - stamp = 1, + # TODO: illumos ld doesn't support build-ld. Fix more elegantly. + stamp = 0, stamped = False, deps = [], linkopts = [], @@ -46,7 +47,8 @@ def envoy_cc_binary( linkstatic = 1, visibility = visibility, malloc = tcmalloc_external_dep(repository), - stamp = stamp, + # FIXME: Solaris ld doesn't support build-ld. Fix more elegantly. + stamp = 0, deps = deps, tags = tags, features = features, @@ -74,18 +76,31 @@ def _envoy_linkopts(): "-DEFAULTLIB:shell32.lib", "-WX", ], + "@envoy//bazel:illumos": [ + "-pthread", + "-lrt", + "-ldl", + # The 'relro'flag is not supported by the illumos linker. + "-Wl,-z,now", + ], "//conditions:default": [ "-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"], + # GCC on illumos doesn't support position independent executables ('-pie')? + "@envoy//bazel:illumos": [], + # 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(): @@ -106,6 +121,8 @@ def _envoy_stamped_linkopts(): # /usr/bin/ld.gold: internal error in write_build_id, at ../../gold/layout.cc:5419 "@envoy//bazel:coverage_build": [], "@envoy//bazel:windows_x86_64": [], + # illumos ld doesn't support build-ld. Fix more elegantly. + "@envoy//bazel:illumos": [], # macOS doesn't have an official equivalent to the `.note.gnu.build-id` # ELF section, so just stuff the raw ID into a new text section. @@ -116,6 +133,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 a1f8f1dc6e50..31b3637e6402 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 9ba87ee44e10..5e74b9223a3b 100644 --- a/bazel/foreign_cc/BUILD +++ b/bazel/foreign_cc/BUILD @@ -31,10 +31,15 @@ envoy_cc_library( # 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..5d2a59a0e2eb --- /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 64484e08f7ff..5477bc54f6b5 100644 --- a/bazel/foreign_cc/zlib.patch +++ b/bazel/foreign_cc/zlib.patch @@ -86,4 +86,4 @@ index b412dc7..658a109 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..de7c4f146d80 --- /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..eff8081f384d --- /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/python_dependencies.bzl b/bazel/python_dependencies.bzl index c3af1865cad0..0b71b348fc73 100644 --- a/bazel/python_dependencies.bzl +++ b/bazel/python_dependencies.bzl @@ -1,6 +1,5 @@ -load("@rules_python//python:pip.bzl", "pip_parse") -load("@python3_11//:defs.bzl", "interpreter") load("@envoy_toolshed//:packages.bzl", "load_packages") +load("@rules_python//python:pip.bzl", "pip_parse") def envoy_python_dependencies(): # TODO(phlax): rename base_pip3 -> pip3 and remove this @@ -17,21 +16,17 @@ def envoy_python_dependencies(): "sphinxcontrib-applehelp", ], }, - python_interpreter_target = interpreter, requirements_lock = "@envoy//tools/base:requirements.txt", extra_pip_args = ["--require-hashes"], ) pip_parse( name = "dev_pip3", - python_interpreter_target = interpreter, requirements_lock = "@envoy//tools/dev:requirements.txt", - extra_pip_args = ["--require-hashes"], ) pip_parse( name = "fuzzing_pip3", - python_interpreter_target = interpreter, requirements_lock = "@rules_fuzzing//fuzzing:requirements.txt", extra_pip_args = ["--require-hashes"], ) diff --git a/bazel/repositories.bzl b/bazel/repositories.bzl index aa93c9c838d8..4c872e1ccbce 100644 --- a/bazel/repositories.bzl +++ b/bazel/repositories.bzl @@ -242,8 +242,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") @@ -355,6 +355,7 @@ def envoy_dependencies(skip_targets = []): external_http_archive("bazel_toolchains") external_http_archive("bazel_compdb") external_http_archive("envoy_build_tools") + external_http_archive("platforms") _com_github_maxmind_libmaxminddb() # TODO(keith): Remove patch when we update rules_pkg @@ -632,7 +633,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( @@ -1321,6 +1322,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/repositories_extra.bzl b/bazel/repositories_extra.bzl index a5bc2d527769..9c41a1241f21 100644 --- a/bazel/repositories_extra.bzl +++ b/bazel/repositories_extra.bzl @@ -1,8 +1,10 @@ +# Modified to use illumos system Python instead of a Bazel hermetic Python binary. + load("@aspect_bazel_lib//lib:repositories.bzl", "aspect_bazel_lib_dependencies") load("@com_github_rules_proto_grpc//:repositories.bzl", "rules_proto_grpc_toolchains") load("@emsdk//:deps.bzl", emsdk_deps = "deps") load("@proxy_wasm_cpp_host//bazel/cargo/wasmtime:crates.bzl", "wasmtime_fetch_remote_crates") -load("@rules_python//python:repositories.bzl", "py_repositories", "python_register_toolchains") +load("@rules_python//python:repositories.bzl", "py_repositories") load("//bazel/external/cargo:crates.bzl", "raze_fetch_remote_crates") def _python_minor_version(python_version): @@ -22,11 +24,4 @@ def envoy_dependencies_extra( rules_proto_grpc_toolchains() py_repositories() - # Registers underscored Python minor version - eg `python3_10` - python_register_toolchains( - name = "python%s" % _python_minor_version(python_version), - python_version = python_version, - ignore_root_user_error = ignore_root_user_error, - ) - aspect_bazel_lib_dependencies() diff --git a/bazel/repository_locations.bzl b/bazel/repository_locations.bzl index 73c2b114aff1..a86393306bd8 100644 --- a/bazel/repository_locations.bzl +++ b/bazel/repository_locations.bzl @@ -33,9 +33,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.31.1", - sha256 = "b8b6d75de6e4bf7c41b7737b183523085f56283f6db929b86c5e7e1f09cf59c9", - urls = ["https://github.com/bazelbuild/bazel-gazelle/releases/download/v{version}/bazel-gazelle-v{version}.tar.gz"], + # Fork of version 0.31.1 with illumos support. + version = "83d37fa4b33748f6249e8d92de51cbc7c92f96a4", + sha256 = "8bb63e756a7e06a6d83ab59bf8d3a2350674048fede1815011aea9b7c9e2b8c9", + strip_prefix = "bazel-gazelle-{version}", + urls = ["https://github.com/siepkes/bazel-gazelle/archive/{version}.tar.gz"], release_date = "2023-06-13", use_category = ["build"], license = "Apache-2.0", @@ -56,6 +58,22 @@ REPOSITORY_LOCATIONS_SPEC = dict( license = "Apache-2.0", license_url = "https://github.com/bazelbuild/bazel-toolchains/blob/v{version}/LICENSE", ), + # 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 = "b2adb960759a3dc93505953357109d78503b0bd9", + sha256 = "dbb1e347cf7016ef8b1fa92999d45711c806c1d491510555cb2b82bddbf0b356", + strip_prefix = "platforms-{version}", + urls = [ + # Commit 'b2adb960759a3dc93505953357109d78503b0bd9' is a fork of 0.0.5 with 'illumos' added as OS. + "https://github.com/siepkes/platforms/archive/{version}.zip", + ], + 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", @@ -121,10 +139,10 @@ REPOSITORY_LOCATIONS_SPEC = dict( # 3. Find a commit in BoringSSL's "master-with-bazel" branch that merges . # # chromium-118.0.5993.54 (linux/beta) - version = "45cf810dbdbd767f09f8cb0b0fcccd342c39041f", - sha256 = "f1f421738e9ba39dd88daf8cf3096ddba9c53e2b6b41b32fff5a3ff82f4cd162", + version = "d9717238f5e73ba9f3e954c9b45bef610125d58e", + sha256 = "8e827ae6eef9f55b8e0e4609c184e7ef383e98fd0d44d78101a5592ad94feeb1", 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 = "2023-08-28", cpe = "cpe:2.3:a:google:boringssl:*", @@ -162,10 +180,11 @@ 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 = "20230802.1", - sha256 = "987ce98f02eefbaf930d6e38ab16aa05737234d7afbab2d5c4ea7adbe50c28ed", + # Fork of version 20230802.1 with illumos compatibility added. + version = "2aa06d2a9a540c1a9da8590d307f01af72cbd8b6", + sha256 = "6e9effdfb977edaf3eec52992449fa3f41a9e3597530313b10e556be6977beff", 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 = "2023-09-18", cpe = "N/A", @@ -376,10 +395,11 @@ REPOSITORY_LOCATIONS_SPEC = dict( project_name = "gRPC", project_desc = "gRPC C core library", project_url = "https://grpc.io", - version = "1.59.4", - sha256 = "6edc67c2ad200c5b618c421f6e8c1b734a4aa3e741975e683491da03390ebf63", + # Forked version of 1.59.4 with illumos support. + version = "481ca39731267a90d6be5d830414950ce2ef7628", + sha256 = "4a08296e560484372cc6dd162ab609137b802323a1ab7a4ad6bbcf88604a060e", strip_prefix = "grpc-{version}", - urls = ["https://github.com/grpc/grpc/archive/v{version}.tar.gz"], + urls = ["https://github.com/siepkes/grpc/archive/{version}.tar.gz"], use_category = ["dataplane_core", "controlplane"], release_date = "2024-02-05", cpe = "cpe:2.3:a:grpc:grpc:*", @@ -957,9 +977,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.39.1", - sha256 = "6dc2da7ab4cf5d7bfc7c949776b1b7c733f05e56edc4bcd9022bb249d2e2a996", - urls = ["https://github.com/bazelbuild/rules_go/releases/download/v{version}/rules_go-v{version}.zip"], + # Fork of 0.39.1 with illumos support added. + version = "43ec7595624f7d32af11989dc85164883488baec", + sha256 = "b47e80f2f514826c5ccc1bcbfb682cf799de3c35cffef8756818722415c6aca3", + strip_prefix = "rules_go-{version}", + urls = ["https://github.com/siepkes/rules_go/archive/{version}.tar.gz"], use_category = ["build", "api"], release_date = "2023-04-20", implied_untracked_deps = [ @@ -975,10 +997,11 @@ 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.9.0", - sha256 = "2a4d07cd64b0719b39a7c12218a3e507672b82a97b98c6a89d38565894cf7c51", + # Fork of version 0.9.0 with illumos support. + version = "bfca3db669f8de20416842a1d0cf1c0d9ba4410e", + sha256 = "3ff802dc981dc8dd1e4878818bde611181087fe1a10114a7e8db75225379137f", 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-08-02", use_category = ["build", "dataplane_core", "controlplane"], license = "Apache-2.0", diff --git a/contrib/golang/filters/http/test/test_data/access_log/go.mod b/contrib/golang/filters/http/test/test_data/access_log/go.mod index 01693aa92cd2..7884841faa1e 100644 --- a/contrib/golang/filters/http/test/test_data/access_log/go.mod +++ b/contrib/golang/filters/http/test/test_data/access_log/go.mod @@ -4,6 +4,6 @@ go 1.20 require github.com/envoyproxy/envoy v1.24.0 -require google.golang.org/protobuf v1.30.0 // indirect +require google.golang.org/protobuf v1.32.0 // indirect replace github.com/envoyproxy/envoy => ../../../../../../../ diff --git a/contrib/golang/filters/http/test/test_data/basic/go.mod b/contrib/golang/filters/http/test/test_data/basic/go.mod index b70054d4863a..61399db661d8 100644 --- a/contrib/golang/filters/http/test/test_data/basic/go.mod +++ b/contrib/golang/filters/http/test/test_data/basic/go.mod @@ -4,6 +4,6 @@ go 1.20 require github.com/envoyproxy/envoy v1.24.0 -require google.golang.org/protobuf v1.30.0 // indirect +require google.golang.org/protobuf v1.32.0 // indirect replace github.com/envoyproxy/envoy => ../../../../../../../ diff --git a/contrib/golang/filters/http/test/test_data/dummy/go.mod b/contrib/golang/filters/http/test/test_data/dummy/go.mod index beaf9d59c743..c3ad0d1f40d8 100644 --- a/contrib/golang/filters/http/test/test_data/dummy/go.mod +++ b/contrib/golang/filters/http/test/test_data/dummy/go.mod @@ -4,6 +4,6 @@ go 1.20 require github.com/envoyproxy/envoy v1.24.0 -require google.golang.org/protobuf v1.30.0 // indirect +require google.golang.org/protobuf v1.32.0 // indirect replace github.com/envoyproxy/envoy => ../../../../../../../ diff --git a/contrib/golang/filters/http/test/test_data/metric/go.mod b/contrib/golang/filters/http/test/test_data/metric/go.mod index b70054d4863a..61399db661d8 100644 --- a/contrib/golang/filters/http/test/test_data/metric/go.mod +++ b/contrib/golang/filters/http/test/test_data/metric/go.mod @@ -4,6 +4,6 @@ go 1.20 require github.com/envoyproxy/envoy v1.24.0 -require google.golang.org/protobuf v1.30.0 // indirect +require google.golang.org/protobuf v1.32.0 // indirect replace github.com/envoyproxy/envoy => ../../../../../../../ diff --git a/contrib/golang/filters/http/test/test_data/passthrough/go.mod b/contrib/golang/filters/http/test/test_data/passthrough/go.mod index d6c620393300..f25d4ad58729 100644 --- a/contrib/golang/filters/http/test/test_data/passthrough/go.mod +++ b/contrib/golang/filters/http/test/test_data/passthrough/go.mod @@ -4,6 +4,6 @@ go 1.20 require github.com/envoyproxy/envoy v1.24.0 -require google.golang.org/protobuf v1.30.0 // indirect +require google.golang.org/protobuf v1.32.0 // indirect replace github.com/envoyproxy/envoy => ../../../../../../../ diff --git a/contrib/golang/filters/network/test/test_data/go.mod b/contrib/golang/filters/network/test/test_data/go.mod index 8c20e9bd14f6..872406f09beb 100644 --- a/contrib/golang/filters/network/test/test_data/go.mod +++ b/contrib/golang/filters/network/test/test_data/go.mod @@ -4,6 +4,6 @@ go 1.18 require github.com/envoyproxy/envoy v1.24.0 -require google.golang.org/protobuf v1.30.0 // indirect +require google.golang.org/protobuf v1.32.0 // indirect replace github.com/envoyproxy/envoy => ../../../../../../ diff --git a/source/common/common/posix/thread_impl.cc b/source/common/common/posix/thread_impl.cc index e935ac53c11b..906ae6f8639a 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 144d57f69a12..b27116713e26 100644 --- a/source/common/common/utility.cc +++ b/source/common/common/utility.cc @@ -605,7 +605,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 ca18dc9a34af..bcac08a1767f 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 @@ -15,6 +20,10 @@ #include "source/common/network/socket_interface.h" #include "source/common/runtime/runtime_features.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 b6858939f517..eef399d07060 100644 --- a/source/common/network/connection_impl.cc +++ b/source/common/network/connection_impl.cc @@ -333,10 +333,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 265eb570a0b3..59b3f41989c1 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 417bb4a5f2f3..43c141622578 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() {