Debugging toolchain internals

646 views
Skip to first unread message

Garrett Kajmowicz

unread,
Nov 12, 2021, 5:54:03 PM11/12/21
to bazel-discuss
I've been working on a slow project migration to bazel involving cross-compiling shenanigan. As far as I could tell, all of the Bazel toolchain stuff was working and was committed into source control.

A few months later I have time to pick the project up again. Unfortunately, things aren't working. My cc_toolchains still seem to be working and are being resolved. Yet the underlying binary which is being executed appears to be the standard host /usr/bin/gcc
even though the --toolchain_resolution_debug info shows the correct toolchain being selected. This obviously fails when you are trying to build for one architecture with a compiler which is targeting another. (On the off-chance bazel was being clever, I md5summed the in-sandbox /usr/bin/gcc binary and the host system gcc version and they were the same).

Is there a way to get intermediate toolchain debugging information?

bazel 4.1.0

-     Garrett

/var/tmp/gk/repo_bazel$ bazel --output_base=/var/tmp/gk/bazel_cache build --experimental_platforms_api //usfp-firewall/usfp/mflow/usfp_hash:usfp_hash  --verbose_failures --sandbox_debug --toolchain_resolution_debug --platforms=//usfp-firewall:armada
INFO: ToolchainResolution:   Type @bazel_tools//tools/cpp:toolchain_type: target platform //usfp-firewall:armada: execution @local_config_platform//:host: Selected toolchain //tools/build/nfp-firewall-build:marvell_armada_toolchain
INFO: ToolchainResolution:     Type @bazel_tools//tools/cpp:toolchain_type: target platform //usfp-firewall:armada: Rejected toolchain //tools/build/nfp-firewall-build:marvell_octeontx_toolchain; mismatching values: NPU_octeontx
INFO: ToolchainResolution:     Type @bazel_tools//tools/cpp:toolchain_type: target platform //usfp-firewall:armada: Rejected toolchain //tools/build/nfp-firewall-build:marvell_octeontx2_toolchain; mismatching values: NPU_octeontx2
INFO: ToolchainResolution:     Type @bazel_tools//tools/cpp:toolchain_type: target platform //usfp-firewall:armada: Rejected toolchain @local_config_cc//:cc-compiler-armeabi-v7a; mismatching values: arm, android
INFO: ToolchainResolution:     Type @bazel_tools//tools/cpp:toolchain_type: target platform //usfp-firewall:armada: Rejected toolchain @local_config_cc//:cc-compiler-k8; mismatching values: x86_64
INFO: ToolchainResolution: Target platform //usfp-firewall:armada: Selected execution platform @local_config_platform//:host, type @bazel_tools//tools/cpp:toolchain_type -> toolchain //tools/build/nfp-firewall-build:marvell_armada_toolchain
INFO: ToolchainResolution: Target platform @local_config_platform//:host: Selected execution platform @local_config_platform//:host, 
INFO: ToolchainResolution: Target platform //usfp-firewall:armada: Selected execution platform @local_config_platform//:host, 
INFO: ToolchainResolution: Target platform @local_config_platform//:host: Selected execution platform @local_config_platform//:host, 
INFO: Analyzed target //usfp-firewall/usfp/mflow/usfp_hash:usfp_hash (28 packages loaded, 802 targets configured).
INFO: Found 1 target...
ERROR: /var/tmp/gk/repo_bazel/usfp-firewall/usfp/mflow/usfp_hash/BUILD:24:11: Compiling usfp-firewall/usfp/mflow/usfp_hash/usfp_hash_cuckoo.c failed: (Exit 1): linux-sandbox failed: error executing command 
  (cd /var/tmp/gk/bazel_cache/sandbox/linux-sandbox/1336/execroot/__main__ && \
  exec env - \
    PATH=/home/garrettkajmowicz/bin:/opt/sophos/bin:/opt/marvell/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/storage/build_tools:/storage/pit-dev-lab \
    PWD=/proc/self/cwd \
    TMPDIR=/tmp \
  /home/garrettkajmowicz/.cache/bazel/_bazel_garrettkajmowicz/install/f95ca91ebc34d56aa0f8ad499de91220/linux-sandbox -t 15 -w /var/tmp/gk/bazel_cache/sandbox/linux-sandbox/1336/execroot/__main__ -w /tmp -w /dev/shm -D -- /usr/bin/gcc -U_FORTIFY_SOURCE -fstack-protector -Wall -Wunused-but-set-parameter -Wno-free-nonheap-object -fno-omit-frame-pointer -MD -MF bazel-out/k8-fastbuild/bin/usfp-firewall/usfp/mflow/usfp_hash/_objs/usfp_hash/usfp_hash_cuckoo.pic.d '-frandom-seed=bazel-out/k8-fastbuild/bin/usfp-firewall/usfp/mflow/usfp_hash/_objs/usfp_hash/usfp_hash_cuckoo.pic.o' -fPIC
<snip>

John Cater

unread,
Nov 15, 2021, 4:57:51 PM11/15/21
to Garrett Kajmowicz, bazel-discuss
Just to check: are you passing the `--incompatible_enable_cc_toolchain_resolution` flag? If not, you're using legacy cc toolchain selection (and the debugging work you've done isn't useful, because the results are ignored).

--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/5753a6c3-dc05-4197-9a24-4266bded6c1bn%40googlegroups.com.

Garrett Kajmowicz

unread,
Nov 19, 2021, 4:11:02 PM11/19/21
to bazel-discuss
That was it. Thank you.
I've created an internal document so I don't lose that again.
At the same time, it may be worthwhile for bazel to emit a warning message if it encounters a weird combination of things which suggests the user is trying to do one thing vs. what is found.

Reply all
Reply to author
Forward
0 new messages