Error building go compiler from source - linux

I am trying to build the latest version (tip of the master branch) of Go from source.
The official Go documentation (https://golang.org/doc/install/source) states that you should download Go 1.4 binaries to build a more recent version. However it should be possible to build all from source.
To do this, I set variables in .bashrc :
PATH="$HOME/go/bin:$PATH"
export GOPATH=$HOME
then to build go 1.4 from source :
source ~/.bashrc
git clone https://go.googlesource.com/go
mkdir ~/go1.4
cd ~/go
git archive --format=tar go1.4.3 |tar -xv -C ~/go1.4
cd ~/go1.4/src
./make.bash
and finally build the latest version :
cd ~/go/src/
GOROOT_BOOTSTRAP=$HOME/go1.4 ./make.bash
I remember doing this months ago without problems, but today I get these errors building go 1.4 make.bash:
# cmd/pprof
.../go1.4/pkg/linux_amd64/runtime/cgo.a(_all.o): unknown relocation type 42; compiled without -fpic?
.../go1.4/pkg/linux_amd64/runtime/cgo.a(_all.o): unknown relocation type 42; compiled without -fpic?
runtime/cgo(.text): unexpected relocation type 298
runtime/cgo(.text): unexpected relocation type 298
...
Is there something wrong in my method ?

The error messages point to CGO, and environment variables that control make.bash are explained at the beginning of the file :
CGO_ENABLED: Controls cgo usage during the build. Set it to 1
to include all cgo related files, .c and .go file with "cgo"
build directive, in the build. Set it to 0 to ignore them.
so if you disable CGO while building GO 1.4 :
cd ~/go1.4/src
CGO_ENABLED=0 ./make.bash
everything works and pass the tests.

Related

How do I remove the dependency on libunwind when cross-compiling Rust programs with the panic_abort option?

I'm specifying the -Cpanic=abort and -Zbuild-std=panic_abort when compiling. Why does the linker still say it needs libunwind to compile a program?
I'm experimenting with various ways to cross-compile Rust programs as small as possible (using the min-sized-rust repo as a reference). Right now I'm trying to compile the powerpc64-unknown-linux-musl target and I'm stuck on trying to remove a dependency on libunwind.
Here's my setup:
# 1. Install the Rust std source code
rustup component add rust-src --toolchain nightly
# 2. Setup a simple rust repo
cargo init testing
cd testing
# 3. Download a musl toolchain
wget https://musl.cc/powerpc64-linux-musl-cross.tgz
tar xzf powerpc64-linux-musl-cross.tgz
# 4. Try to compile the project (options on the command line instead of in files for
# maximum obviousness).
# RUSTFLAGS:
# -Cpanic=abort - abort immediately on panic
# -Clink-self-contained=no - don't use rustc's builtin libraries and objects (this
# is needed because powerpc64-unknown-linux-musl is a tier 3 target)
# -Clink-arg=--sysroot and -Clink-arg=/path/to/sysroot - pass the option to the linker
# to specify the sysroot of cross-compilation toolchain
# Cargo options:
# --config target.<triple>.linker - specify the linker to use
# -Zbuild-std=std,panic_abort - build the standard library from source. Specify
# panic_abort to make the abort on panic work
RUSTFLAGS="-Cpanic=abort -Clink-self-contained=no -Clink-arg=--sysroot -Clink-arg=powerpc64-linux-musl-cross/powerpc64-linux-musl/" \
cargo +nightly build \
--config "target.powerpc64-unknown-linux-musl.linker=\"powerpc64-linux-musl-cross/bin/powerpc64-linux-musl-gcc\"" \
--target powerpc64-unknown-linux-musl -Zbuild-std=panic_abort,std --release
This fails with the following error:
error: linking with `/home/user/Projects/testing/powerpc64-linux-musl-cross/bin/powerpc64-linux-musl-gcc` failed: exit status: 1
<output snipped>
= note: /home/user/Projects/testing/powerpc64-linux-musl-cross/bin/../lib/gcc/powerpc64-linux-musl/11.2.1/../../../../powerpc64-linux-musl/bin/ld: cannot find -lunwind
From min-size-rust repository:
"Even if panic = "abort" is specified in Cargo.toml, rustc will still include panic strings and formatting code in final binary by default. An unstable panic_immediate_abort feature has been merged into the nightly rustc compiler to address this.
To use this, repeat the instructions above to use build-std, but also pass the following -Z build-std-features=panic_immediate_abort option."
Still, you will get "cannot find -lunwind", because the linker still uses libunwind, even though it's truly unneeded,why! I do not know, maybe it's a bug.(Maybe someone with fair knowledge about linkers can easily solve that.I tried a naive solution which is "cargo .... --verbose", copy , remove "libunwind" then relinking which failed)
I verified that is indeed the missing piece by build from source(--target=x86_64-unknown-linux-musl) AND using an old simple trick which is "touch libunwind.a" in the "self-contained" directory inside a target lib folder.(because the linker would still use it even though it's now truly unneeded, then I gave him a dummy libunwind.a)
In your case, I really tried to build it to your target until I got a headache, but couldn't and stopped, but here is possible solutions:
Giving that you're using "-Z build-std-features=panic_immediate_abort"
-If you can custom the linking process, then solve it (until what seems to be a bug is solved)
-Create a dummy(empty) libunwind.a where it should be in your toolchain

"gnu/stubs-o32_hard.h: No such file or directory" golang cgo mipsel embedded chip system fatal error:

1. bg: i got a project to develop the embedded camera system, the system is using mips 32bit, i got the toolchain in ubuntu. go version: 1.17.7
2. my question:
2.1) pure golang cross compile into mipsle platform is good and working.the command it use is :
GOOS=linux GOARCH=mipsle CGO_ENABLED=0 go build main.go
2.2) but i got some third-party lib which they offer as xxx.so and xxx.h to me. when i finish coding it into my go project using cgo. i want to cross complie into mips system which i found fail.
3. what i had try:
3.1) i know go is not support cross complie cgo, so i try the normal way which is like this:
GOOS=linux GOARCH=mipsle CGO_ENABLED=1 CC=/opt/mips-gcc720-glibc226/bin/mips-linux-gnu-gcc go build main.go
result:
# runtime/cgo
In file included from /opt/mips-gcc720-glibc226/mips-linux-gnu/libc/usr/include/features.h:447:0,
from /opt/mips-gcc720-glibc226/mips-linux-gnu/libc/usr/include/bits/libc-header-start.h:33,
from /opt/mips-gcc720-glibc226/mips-linux-gnu/libc/usr/include/stdlib.h:25,
from _cgo_export.c:3:
/opt/mips-gcc720-glibc226/mips-linux-gnu/libc/usr/include/gnu/stubs.h:11:11: fatal error: gnu/stubs-o32_hard.h: No such file or directory
# include <gnu/stubs-o32_hard.h>
^~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
3.2) i also try gccgo, in ubuntu, i try:
go build -compiler=mipsel-linux-gnu-gccgo main.go
result:
invalid value "mipsel-linux-gnu-gccgo" for flag -compiler: unknown compiler "mipsel-linux-gnu-gccgo"
usage: go build [-o output] [build flags] [packages]
Run 'go help build' for details.
3.3) i had try xgo project to compile, which is can output a result, but when i move to the mipsle system it still can not working.
so , can any body help? if need the toolchain to test, i can send you
cantact me: justforjobonly#126.com
thanks!

Run ./configure from bash script fails due "error: cannot compute suffix of object files"

I'm trying to automate some stage of compile/build on Linux RHEL7 host using a bash script, but when i try to use ./configure it fails due to :
configure:3793: error: in `/app/compiling/BUILD_AREA/TEST/SRC/zabbix-4.2.6':
configure:3795: error: cannot compute suffix of object files: cannot compile
using :
CC="gcc"
PATH="/app/app_lib/mysql/bin:/app/app_lib/bin:/app/app_lib/build-1:/app/app_lib:$PATH"
LD_LIBRARY_PATH="/app/app_lib:/app/app_lib/include:/app/app_lib/lib:/app/apache/modules:/app/app_lib/ssl:/app/app_lib/lib/iconv:/app/oracle/product/12.1.0/lib:/app/ap_lib/mysql/lib:$LD_LIBRARY_PATH"
export CC
export PATH
export LD_LIBRARY_PATH
ARG_ZABBIX="--prefix=/app/zabbix --datarootdir=/app/zabbix/share --docdir=/app/zabbix/share/doc/$PKGAPPDIR --enable-agent --enable-ipv6 --enable-java --enable-server --includedir=/app/zabbix/include --libdir=/app/zabbix/lib --mandir=/app/zabbix/share/man/$PKGAPPDIR --with-libcurl=/app/app_lib/bin/curl-config --with-libxml2=/app/app_lib/bin/xml2-config --with-mysql=/app/mysql/bin/mysql_config --with-net-snmp=/app/app_lib/bin/net-snmp-config --with-openipmi=/app/app_lib --with-ssh2=/app/app_lib"
CONFIGURE="configure"
cd /app/compiling/BUILD_AREA/TEST/SRC/zabbix-4.2.6
"./${CONFIGURE}" "${ARG_ZABBIX}" 2>&1
Any help would be really appreciated!
Any help would be really appreciated!
Find the respective config.log (like the one in $(builddir)/gcc) and have a look. Some configure tests might fail as configure is querying availability of host features; the relevant fail is usually recorded at the end of the relevant config.log.
A common cause for this error is that the target Binutils (as, the assembler) cannot be found as configure is trying to find out what suffix to use for object files. Or host as is used where actually the target as (as of --target=) should be used, and the host as throws a syntax error because it is fed with target assembly.
./configure
GCC does not support configuring in the source directory or any of its sub-folders:
"First, we highly recommend that GCC be built into a separate directory from the sources which does not reside within the source tree."

eBPF (bcc) on centos

It's possible deploy bcc --> https://iovisor.github.io/bcc/
... on centos /redhat SO?
someone knows what's the problem to compile bcc tools from centos? (all dependencies are installed), but when I execute the last step:
cmake .. -DCMAKE_INSTALL_PREFIX=/usr
Returns:
[root#ebpf build]# cmake -DCMAKE_INSTALL_PREFIX=/usr ..
-- Latest recognized Git tag is v0.3.0
-- Git HEAD is 007d28c534e1a98e6017ac9f4c8cb1c0f5244388
-- Revision is 0.3.0-007d28c5 CMake Error at CMakeLists.txt:22 (find_package): Could not find a package configuration file provided
by "LLVM" with any of the following names:
LLVMConfig.cmake
llvm-config.cmake
Add the installation prefix of "LLVM" to CMAKE_PREFIX_PATH or set
"LLVM_DIR" to a directory containing one of the above files. If
"LLVM" provides a separate development package or SDK, be sure it
has been installed.
-- Configuring incomplete, errors occurred! See also "/root/bcc/build/CMakeFiles/CMakeOutput.log".
for llvm issue. just run below CLI:
cp /usr/share/llvm/cmake/LLVM-Config.cmake /usr/share/llvm/cmake/llvm-config.cmake

Creating binary with CMake removes runtime path

I am using CMake to build a program on linux. The program compiles successfully and runs from the project build directory. The program is linked with a custom library in the directory ${HOME}/build/lib
I have an install stage with:
install(TARGETS ProgName RUNTIME DESTINATION bin)
When I run make install the program gets put in the correct place, but the cmake installer removes the runtime path from the binary.
-- Install configuration: "Debug"
-- Installing: *binary name*
-- Removed runtime path from "*binary name*"
I have read articles on the internet discussing the misuse of the LD_LIBRARY_PATH variable so I like to keep mine limited to system library locations if possible. I am not sysadmin so I cannot add the location to the default linker search path either.
Does anyone know how I can keep the development-time linking paths when installing or at least customising which paths are added to the runtime?
Cheers
Note: if you don't want to modify the cmake scripts themselves, setting property around, you can launch you cmake with a directive asking to not remove the runtime path:
See "Variables that Control the Build", with variable: "CMAKE_SKIP_RPATH"
If true, do not add run time path information.
If this is set to TRUE, then the rpath information is not added to compiled executables.
The default is to add rpath information if the platform supports it. This allows for easy running from the build tree.
To omit RPATH in the install step, but not the build step, use CMAKE_SKIP_INSTALL_RPATH instead.
If the deliveries already contained the right runtime path, that directive will avoid cmake to do any modification to the current runtime path included in said deliveries.
cmake -DCMAKE_SKIP_RPATH=ON xxx.cmake
You should look at set_target_properties command and the property BUILD_WITH_INSTALL_RPATH
http://www.cmake.org/cmake/help/cmake-2-8-docs.html#command:set_target_properties
This works for CMake 2.8
set_target_properties(foo PROPERTIES INSTALL_RPATH_USE_LINK_PATH TRUE)
where foo is the target you defined earlier:
project(foo)
add_executable(foo ...)
...
install(TARGETS foo DESTINATION bin)
...
Before
% sudo make install
Install the project...
-- Install configuration: ""
-- Installing: /opt/mystuff/bin/foo
-- Removed runtime path from "/opt/mystuff/bin/foo"
After
% sudo make install
Install the project...
-- Install configuration: ""
-- Installing: /opt/mystuff/bin/foo
-- Set runtime path of "/opt/mystuff/bin/foo" to "/opt/zzyzx/lib:/opt/bar/lib/x86_64"

Resources