Can't build tools/jdk/SingleJar_deploy.jar during build bazel on CentOS5
I installed gcc4.8.3 and jdk1.8 on CentOS5.5 and manage to pass the bootstrap process of compilation with slight modification. I also change the CROSSTOOL file to add gcc4.8 as compiler. Then when I try to build tools, it errors out like
____Loading... ____Loading complete. Analyzing... ____Found 1 target... ____Building... ____[2 / 30] Writing file src/java_tools/singlejar/libzip.jar-2.params ____[5 / 40] Writing file src/java_tools/singlejar/liblibSingleJar.jar-2.params ____[17 / 43] Creating source manifest for //src/java_tools/singlejar:SingleJar ____From Creating runfiles tree bazel-out/local_linux-fastbuild/bin/src/java_tools/singlejar/SingleJar.runfiles: /home/user/.cache/bazel/_bazel_ningyu/1cf9a622169d7e29af19957f4e094431/bazel.git/_bin/build-runfiles: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.14' not found (required by /home/user/.cache/bazel/_bazel_user/1cf9a622169d7e29af19957f4e094431/bazel.git/_bin/build-runfiles) ERROR: /home/user/build/bazel/bazel.git/src/java_tools/singlejar/BUILD:19:1: Creating runfiles tree bazel-out/local_linux-fastbuild/bin/src/java_tools/singlejar/SingleJar.runfiles failed: build-runfiles failed: error executing command /home/user/.cache/bazel/_bazel_ningyu/1cf9a622169d7e29af19957f4e094431/bazel.git/_bin/build-runfiles bazel-out/local_linux-fastbuild/bin/src/java_tools/singlejar/SingleJar.runfi les_manifest ... (remaining 1 argument(s) skipped): com.google.devtools.build.lib.shell.BadExitStatusExc eption: Process exited with status 1. Target //src/java_tools/singlejar:SingleJar_deploy.jar failed to build
Basically since bazel always clean the env, the intermediate binary build-runfiles require running with LD_LIBRARY_PATH set to the gcc4.8 library dir for compatiable libstdc++.so (system has gcc4.1 as default). How can I resolve this issue?
Thanks Ningyu
Worked it around by setting rpath in the BUILD file, but this is annoying especially during bootstrapping. Hopefully bazel can provide a way to retain user env (PATH, LD_LIBRARY_PATH) or support non-system-default compiler better.
Retaining the user environment will not be done -- we are actually moving towards stronger isolation of build steps using a namespace sandbox. What you can do, however, is to modify your CROSSTOOL file or point it to a shell script that invokes gcc with additional arguments or set environment variables there.
Would this work?
The problem is not the compilation stage which invokes gcc, that can be handled with CROSSTOOL. It's invoking some intermediate binary compiled by gcc, which need proper LD_LIBRARY_PATH to work because of the mismatch of system level gcc and the gcc used to compile the binary. The only way I see is to add rpath during compilation which looks like a hack.
The obvious thing to do is to link libstdc++ statically for the tools we build during bootstrap. I think for everything else you can set up the CROSSTOOL appropriately.
On Mon, Oct 26, 2015 at 3:08 PM, NingyuShi [email protected] wrote:
The problem is not the compilation stage which invokes gcc, that can be handled with CROSSTOOL. It's invoking some intermediate binary compiled by gcc, which need proper LD_LIBRARY_PATH to work because of the mismatch of system level gcc and the gcc used to compile the binary. The only way I see is to add rpath during compilation which looks like a hack.
— Reply to this email directly or view it on GitHub https://github.com/bazelbuild/bazel/issues/525#issuecomment-151144570.
I solved this problem by modifying CROSSTOOL to use rpath like this: linker_flag: "-Wl,-rpath,/somewhere"
However I noticed a couple issues.
The first and most annoying one is the CROSSTOOL used to build Bazel will be packaged into the final bazel binary. For my use case I have to build Bazel with gcc newer than system one, but things built with Bazel using the system toolchain. To solve this problem I have to build Bazel with a modified CROSSTOOL, revert CROSSTOOL, build Bazel again with the Bazel just built. It will be much better if the build step for Bazel can take a special CROSSTOOL. Doing BAZEL_ARGS="--crosstool_top=//some/toolchain" compile.sh doesn't seem to work.
The other issue is the scripts/bootstrap/compile.sh doesn't take LDFLAGS for linking the bootstrap executables like build-runfiles, process-wrapper and namespace-sandbox. I have this code review to address this: https://bazel-review.googlesource.com/#/c/2211/
2015-10-26 10:54 GMT-04:00 Ulf Adams [email protected]:
The obvious thing to do is to link libstdc++ statically for the tools we build during bootstrap. I think for everything else you can set up the CROSSTOOL appropriately.
On Mon, Oct 26, 2015 at 3:08 PM, NingyuShi [email protected] wrote:
The problem is not the compilation stage which invokes gcc, that can be handled with CROSSTOOL. It's invoking some intermediate binary compiled by gcc, which need proper LD_LIBRARY_PATH to work because of the mismatch of system level gcc and the gcc used to compile the binary. The only way I see is to add rpath during compilation which looks like a hack.
— Reply to this email directly or view it on GitHub https://github.com/bazelbuild/bazel/issues/525#issuecomment-151144570.
— Reply to this email directly or view it on GitHub https://github.com/bazelbuild/bazel/issues/525#issuecomment-151163890.
@NingyuShi : yes, yes, incidentally, this the problem I was struggling with interally so that Bazel can be compiled on a slightly weird Linux system. I ended up doing the following:
- Setting the
CXXandCCenvironment variables to a script that does the following to the gcc command line to makescripts/bootstrap/compile.shbe able to build a functional Bazel binary.- Causes zlib and libstdc++ to be linked statically into the Bazel,
build-runfiles,process-wrapperandnamespace-sandboxby adding their .a files to the command line - Removes
-lstdc++from the command line so that it is not linked in dynamically - Adds zlib to the include path by a well-aimed
-Ioption
- Causes zlib and libstdc++ to be linked statically into the Bazel,
- Changing the CROSSTOOL file of the system:
- Added a
-Icompiler_flagfor zlib and acxx_bulitin_include_directoryentry - Added the .a file of zlib to the linker command line using a
linker_flagoption - This particular system links libstdc++ statically by default, so no changes were needed there
- Added a
I actually went down the rpath route first, but then I realized that then the produced binary wouldn't be useful anywhere else. It is a viable approach to making bootstrap.sh compile Bazel, though. Statically linking everything makes the aforementioned intermediate binaries not require any dynamic libraries, which is nice.
@lberki It will be nice we can make this part of the official flow to support older version of linux. What do you think? I can help on this and submit patch probably based on some option in compile.sh.
Well... I'd be happy if my script could be simpler, but I'm not sure what the right approach here is: it would be nice if everything Just Worked, but that would require some measure of autodetection at least. Would this change help somewhat? It wouldn't Just Work, but maybe you can get away without editing compile.sh:
https://bazel-review.googlesource.com/#/c/2211
The change to compile.sh above allows me to do rpath.
For static linking we can just add an option to remove the -l args and allow people to put in .a files in LDFLAGS.
2015-10-26 11:52 GMT-04:00 lberki [email protected]:
Well... I'd be happy if my script could be simpler, but I'm not sure what the right approach here is: it would be nice if everything Just Worked, but that would require some measure of autodetection at least. Would this change help somewhat? It wouldn't Just Work, but maybe you can get away without editing compile.sh:
https://bazel-review.googlesource.com/#/c/2211
— Reply to this email directly or view it on GitHub https://github.com/bazelbuild/bazel/issues/525#issuecomment-151181275.
Adding ${LDFLAG} is very helpful for first round compilation. There are several other things I did to compile
- Add -fgnu89-inline to compile.sh and cc_binary(copts) to get over the behavior change of gcc4.8 on older linux system. Otherwise for system inline functions, gcc will compile multiple versions of them in different unit.
- Statically link libstdc++ on cc_binary() of bazel BUILD file too.
- Remove all the unsupported flags in src/main/tools/namespace-sandbox.c to get it compile. Actually it will be nice to provide a dummy mode for this binary since it will not be supported on older version of kernel anyway.
- In CROSSTOOL, use a wrapper to detect to use gcc or g++ as linker command, otherwise cpp program will refuse to link given only -lstdc++. There are no entry in CROSSTOOL to specify g++ command, only gcc command, but this doesn't work in the linking stage.
On Mon, Oct 26, 2015 at 5:39 PM, NingyuShi [email protected] wrote:
Adding ${LDFLAG} is very helpful for first round compilation. There are several other things I did to compile
- Add -fgnu89-inline to compile.sh and cc_binary(copts) to get over the behavior change of gcc4.8 on older linux system. Otherwise for system inline functions, gcc will compile multiple versions of them in different unit.
- Statically link libstdc++ on cc_binary() of bazel BUILD file too.
- Remove all the unsupported flags in src/main/tools/namespace-sandbox.c to get it compile. Actually it will be nice to provide a dummy mode for this binary since it will not be supported on older version of kernel anyway.
The namespace sandbox is automatically disabled on older kernels (with a warning).
- In CROSSTOOL, use a wrapper to detect to use gcc or g++ as linker command, otherwise cpp program will refuse to link given only -lstdc++. There are no entry in CROSSTOOL to specify g++ command, only gcc command, but this doesn't work in the linking stage.
— Reply to this email directly or view it on GitHub https://github.com/bazelbuild/bazel/issues/525#issuecomment-151202450.
@ulfjack Yes, it's disabled during runtime, but you will not be able to compile it on old kernel during compilation stage due to all the new kernel flags like CLONE_NEWIPC, CLONE_NEWUSER etc.
Right. We have a namespace-sandbox-dummy.c file, but we don't currently auto-detect during bootstrap (if it's linux, we assume it compiles).
On Mon, Oct 26, 2015 at 6:38 PM, NingyuShi [email protected] wrote:
@ulfjack https://github.com/ulfjack Yes, it's disabled during runtime, but you will not be able to compile it on old kernel during compilation stage due to all the new kernel flags like CLONE_NEWIPC, CLONE_NEWUSER etc.
— Reply to this email directly or view it on GitHub https://github.com/bazelbuild/bazel/issues/525#issuecomment-151220368.
Closing this, b/c the CentOS 5 is now quite old. (https://wiki.centos.org/Download)
...if we feel it's useful in general to add features to facilitate compiling to older kernels, please open an issue with the proposed solution.