Xla_client_test failed to build

Hello, I built TensorFlow from source with the following command:

bazel build --config=dbg //tensorflow/tools/pip_package:build_pip_package

which succeeds.

Then I tried to build xla_client_test as follows, but failed:

$ bazel test --config=dbg //tensorflow/compiler/xla/python:xla_client_test  --verbose_failures
WARNING: Output base '/home/u89062/.cache/bazel/_bazel_u89062/6b391d355745daa7c7ecd1cfa522ceb7' is on NFS. This may lead to surprising failures and undetermined behavior.
INFO: Options provided by the client:
  Inherited 'common' options: --isatty=1 --terminal_columns=172
INFO: Reading rc options for 'test' from /home/u89062/tensorflow/.bazelrc:
  Inherited 'common' options: --experimental_repo_remote_exec
INFO: Reading rc options for 'test' from /home/u89062/tensorflow/.bazelrc:
  Inherited 'build' options: --define framework_shared_object=true --define=use_fast_cpp_protos=true --define=allow_oversize_protos=true --spawn_strategy=standalone -c opt --announce_rc --define=grpc_no_ares=true --noincompatible_remove_legacy_whole_archive --enable_platform_specific_config --define=with_xla_support=true --config=short_logs --config=v2 --define=no_aws_support=true --define=no_hdfs_support=true --experimental_cc_shared_library
INFO: Reading rc options for 'test' from /home/u89062/tensorflow/.tf_configure.bazelrc:
  Inherited 'build' options: --action_env PYTHON_BIN_PATH=/home/u89062/.conda/envs/xla/bin/python3 --action_env PYTHON_LIB_PATH= /home/u89062/.conda/envs/xla/lib/python3.9/site-packages --python_path=/home/u89062/.conda/envs/xla/bin/python3
INFO: Reading rc options for 'test' from /home/u89062/tensorflow/.bazelrc:
  Inherited 'build' options: --deleted_packages=tensorflow/compiler/mlir/tfrt,tensorflow/compiler/mlir/tfrt/benchmarks,tensorflow/compiler/mlir/tfrt/jit/python_binding,tensorflow/compiler/mlir/tfrt/jit/transforms,tensorflow/compiler/mlir/tfrt/python_tests,tensorflow/compiler/mlir/tfrt/tests,tensorflow/compiler/mlir/tfrt/tests/analysis,tensorflow/compiler/mlir/tfrt/tests/jit,tensorflow/compiler/mlir/tfrt/tests/lhlo_to_tfrt,tensorflow/compiler/mlir/tfrt/tests/tf_to_corert,tensorflow/compiler/mlir/tfrt/tests/tf_to_tfrt_data,tensorflow/compiler/mlir/tfrt/tests/saved_model,tensorflow/compiler/mlir/tfrt/transforms/lhlo_gpu_to_tfrt_gpu,tensorflow/core/runtime_fallback,tensorflow/core/runtime_fallback/conversion,tensorflow/core/runtime_fallback/kernel,tensorflow/core/runtime_fallback/opdefs,tensorflow/core/runtime_fallback/runtime,tensorflow/core/runtime_fallback/util,tensorflow/core/tfrt/common,tensorflow/core/tfrt/eager,tensorflow/core/tfrt/eager/backends/cpu,tensorflow/core/tfrt/eager/backends/gpu,tensorflow/core/tfrt/eager/core_runtime,tensorflow/core/tfrt/eager/cpp_tests/core_runtime,tensorflow/core/tfrt/gpu,tensorflow/core/tfrt/run_handler_thread_pool,tensorflow/core/tfrt/runtime,tensorflow/core/tfrt/saved_model,tensorflow/core/tfrt/graph_executor,tensorflow/core/tfrt/saved_model/tests,tensorflow/core/tfrt/tpu,tensorflow/core/tfrt/utils
INFO: Reading rc options for 'test' from /home/u89062/tensorflow/.tf_configure.bazelrc:
  'test' options: --flaky_test_attempts=3 --test_size_filters=small,medium
INFO: Found applicable config definition build:short_logs in file /home/u89062/tensorflow/.bazelrc: --output_filter=DONT_MATCH_ANYTHING
INFO: Found applicable config definition build:v2 in file /home/u89062/tensorflow/.bazelrc: --define=tf_api_version=2 --action_env=TF2_BEHAVIOR=1
INFO: Found applicable config definition test:v2 in file /home/u89062/tensorflow/.tf_configure.bazelrc: --test_tag_filters=-benchmark-test,-no_oss,-gpu,-oss_serial,-v1only --build_tag_filters=-benchmark-test,-no_oss,-gpu,-v1only
INFO: Found applicable config definition build:dbg in file /home/u89062/tensorflow/.bazelrc: -c dbg --per_file_copt=+.*,-tensorflow.*@-g0 --per_file_copt=+tensorflow/core/kernels.*@-g0 --cxxopt -DTF_LITE_DISABLE_X86_NEON --copt -DDEBUG_BUILD
INFO: Found applicable config definition build:linux in file /home/u89062/tensorflow/.bazelrc: --copt=-w --host_copt=-w --define=PREFIX=/usr --define=LIBDIR=$(PREFIX)/lib --define=INCLUDEDIR=$(PREFIX)/include --define=PROTOBUF_INCLUDE_PATH=$(PREFIX)/include --cxxopt=-std=c++14 --host_cxxopt=-std=c++14 --config=dynamic_kernels --distinct_host_configuration=false --experimental_guard_against_concurrent_changes
INFO: Found applicable config definition build:dynamic_kernels in file /home/u89062/tensorflow/.bazelrc: --define=dynamic_loaded_kernels=true --copt=-DAUTOLOAD_DYNAMIC_KERNELS
INFO: Build options --copt, --cxxopt, and --per_file_copt have changed, discarding analysis cache.
INFO: Analyzed target //tensorflow/compiler/xla/python:xla_client_test (0 packages loaded, 15394 targets configured).
INFO: Found 1 target and 0 test targets...
ERROR: /home/u89062/tensorflow/tensorflow/compiler/xla/python/BUILD:633:17: Linking tensorflow/compiler/xla/python/xla_extension.so failed: (Exit 1): gcc failed: error executing command
  (cd /home/u89062/.cache/bazel/_bazel_u89062/6b391d355745daa7c7ecd1cfa522ceb7/execroot/org_tensorflow && \
  exec env - \
    LD_LIBRARY_PATH=/glob/development-tools/versions/oneapi/2022.1.2/oneapi/vpl/2022.0.0/lib:/glob/development-tools/versions/oneapi/2022.1.2/oneapi/tbb/2021.5.1/env/../lib/intel64/gcc4.8:/glob/development-tools/versions/oneapi/2022.1.2/oneapi/rkcommon/1.8.0/lib:/glob/development-tools/versions/oneapi/2022.1.2/oneapi/ospray_studio/0.9.0/lib:/glob/development-tools/versions/oneapi/2022.1.2/oneapi/ospray/2.8.0/lib:/glob/development-tools/versions/oneapi/2022.1.2/oneapi/openvkl/1.1.0/lib:/glob/development-tools/versions/oneapi/2022.1.2/oneapi/oidn/1.4.2/lib:/glob/development-tools/versions/oneapi/2022.1.2/oneapi/mpi/2021.5.1//libfabric/lib:/glob/development-tools/versions/oneapi/2022.1.2/oneapi/mpi/2021.5.1//lib/release:/glob/development-tools/versions/oneapi/2022.1.2/oneapi/mpi/2021.5.1//lib:/glob/development-tools/versions/oneapi/2022.1.2/oneapi/mkl/2022.0.2/lib/intel64:/glob/development-tools/versions/oneapi/2022.1.2/oneapi/itac/2021.5.0/slib:/glob/development-tools/versions/oneapi/2022.1.2/oneapi/ipp/2021.5.2/lib/intel64:/glob/development-tools/versions/oneapi/2022.1.2/oneapi/ippcp/2021.5.1/lib/intel64:/glob/development-tools/versions/oneapi/2022.1.2/oneapi/ipp/2021.5.2/lib/intel64:/glob/development-tools/versions/oneapi/2022.1.2/oneapi/embree/3.13.2/lib:/glob/development-tools/versions/oneapi/2022.1.2/oneapi/dnnl/2022.0.2/cpu_dpcpp_gpu_dpcpp/lib:/glob/development-tools/versions/oneapi/2022.1.2/oneapi/debugger/2021.5.0/gdb/intel64/lib:/glob/development-tools/versions/oneapi/2022.1.2/oneapi/debugger/2021.5.0/libipt/intel64/lib:/glob/development-tools/versions/oneapi/2022.1.2/oneapi/debugger/2021.5.0/dep/lib:/glob/development-tools/versions/oneapi/2022.1.2/oneapi/dal/2021.5.3/lib/intel64:/glob/development-tools/versions/oneapi/2022.1.2/oneapi/compiler/2022.0.2/linux/lib:/glob/development-tools/versions/oneapi/2022.1.2/oneapi/compiler/2022.0.2/linux/lib/x64:/glob/development-tools/versions/oneapi/2022.1.2/oneapi/compiler/2022.0.2/linux/lib/oclfpga/host/linux64/lib:/glob/development-tools/versions/oneapi/2022.1.2/oneapi/compiler/2022.0.2/linux/compiler/lib/intel64_lin:/glob/development-tools/versions/oneapi/2022.1.2/oneapi/ccl/2021.5.1/lib/cpu_gpu_dpcpp \
    PATH=/home/u89062/.cache/bazelisk/downloads/bazelbuild/bazel-5.0.0-linux-x86_64/bin:/home/u89062/.conda/envs/xla/bin:/glob/intel-python/python2/bin:/glob/development-tools/versions/ispc/ispc-v1.13.0-linux/bin:/glob/development-tools/versions/oneapi/2022.1.2/oneapi/vtune/2022.0.0/bin64:/glob/development-tools/versions/oneapi/2022.1.2/oneapi/vpl/2022.0.0/bin:/glob/development-tools/versions/oneapi/2022.1.2/oneapi/ospray_studio/0.9.0/bin:/glob/development-tools/versions/oneapi/2022.1.2/oneapi/ospray/2.8.0/bin:/glob/development-tools/versions/oneapi/2022.1.2/oneapi/openvkl/1.1.0/bin:/glob/development-tools/versions/oneapi/2022.1.2/oneapi/oidn/1.4.2/bin:/glob/development-tools/versions/oneapi/2022.1.2/oneapi/mpi/2021.5.1/libfabric/bin:/glob/development-tools/versions/oneapi/2022.1.2/oneapi/mpi/2021.5.1/bin:/glob/development-tools/versions/oneapi/2022.1.2/oneapi/mkl/2022.0.2/bin/intel64:/glob/development-tools/versions/oneapi/2022.1.2/oneapi/itac/2021.5.0/bin:/glob/development-tools/versions/oneapi/2022.1.2/oneapi/ispc/1.16.1/bin:/glob/development-tools/versions/oneapi/2022.1.2/oneapi/intelpython/latest/bin:/glob/development-tools/versions/oneapi/2022.1.2/oneapi/inspector/2022.0.0/bin64:/glob/development-tools/versions/oneapi/2022.1.2/oneapi/embree/3.13.2/bin:/glob/development-tools/versions/oneapi/2022.1.2/oneapi/dpcpp-ct/2022.0.0/bin:/glob/development-tools/versions/oneapi/2022.1.2/oneapi/dev-utilities/2021.5.2/bin:/glob/development-tools/versions/oneapi/2022.1.2/oneapi/debugger/2021.5.0/gdb/intel64/bin:/glob/development-tools/versions/oneapi/2022.1.2/oneapi/compiler/2022.0.2/linux/lib/oclfpga/bin:/glob/development-tools/versions/oneapi/2022.1.2/oneapi/compiler/2022.0.2/linux/bin/intel64:/glob/development-tools/versions/oneapi/2022.1.2/oneapi/compiler/2022.0.2/linux/bin:/glob/development-tools/versions/oneapi/2022.1.2/oneapi/clck/2021.5.0/bin/intel64:/glob/development-tools/versions/oneapi/2022.1.2/oneapi/advisor/2022.0.0/bin64:/glob/development-tools/versions/oneapi/beta05/inteloneapi/intelpython/latest/bin:/home/u89062/bazel:/home/u89062/plaidml/plaidml/build-x86_64/Debug/_deps/llvm-project-build/bin:/home/u89062/plaidml/plaidml/build-x86_64/Debug/bin:/home/u89062/plaidml/miniconda3/condabin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/bin:/home/u89062/.local/bin:/home/u89062/bin:/bin \
    PWD=/proc/self/cwd \
    PYTHON_BIN_PATH=/home/u89062/.conda/envs/xla/bin/python3 \
    PYTHON_LIB_PATH=' /home/u89062/.conda/envs/xla/lib/python3.9/site-packages' \
    TF2_BEHAVIOR=1 \
  /usr/bin/gcc @bazel-out/k8-dbg/bin/tensorflow/compiler/xla/python/xla_extension.so-2.params)
# Configuration: 84951eb3fcef79cf0eb391bd1183cd070f245fa6361a21993ad5230f628ef5cf
# Execution platform: @local_execution_config_platform//:platform
/usr/bin/ld.gold: error: bazel-out/k8-dbg/bin/tensorflow/compiler/xla/python/_objs/jax_jit/jax_jit.pic.o: requires dynamic R_X86_64_PC32 reloc against '_ZN3jax12_GLOBAL__N_121CompiledFunctionCache16kDefaultCapacityE' which may overflow at runtime; recompile with -fPIC
collect2: error: ld returned 1 exit status
Target //tensorflow/compiler/xla/python:xla_client_test failed to build
INFO: Elapsed time: 68.150s, Critical Path: 61.05s
INFO: 2 processes: 2 internal.
FAILED: Build did NOT complete successfully

My environment is:

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.4 LTS
Release:        20.04
Codename:       focal

$ gcc --version
gcc (Ubuntu 9.4.0-1ubuntu1~20.04) 9.4.0

$python --version
Python 3.9.7 :: Intel Corporation

$ bazel --version
bazel 5.0.0

Any idea?
Thanks!
Hongbo

The static const int CompiledFunctionCache::kDefaultCapacity is the problem. I manually replaced all occurrences of it with its value 4096 in jax_jit.cc, and now the build succeeds. However, this is only a workaround. The problem is still open.