build libgcc for mips with micromips - gcc

I am trying to build cross compiler gcc for mips architecture. Build and host are x86_64 and target is mips. I also want -micromips built version of libgcc.
I am able to build and install binutils and bootstrap gcc as below:
TARGET=mips-sde-elf
cd binutils-2.31-build
../binutils-2.31/configure --prefix=$PREFIX --target=$TARGET --disable-nls
make -j24
make install
cd gcc-6.5.0-build
../gcc-6.5.0/configure --prefix=$PREFIX --target=$TARGET \
--enable-languages=c,c++ --disable-nls \
--with-newlib --disable-threads --disable-shared --disable-libssp \
--disable-libstdcxx-pch --disable-libgomp --with-system-zlib
make -j24 all-gcc
However, when trying to build libgcc I get below error.
make -j24 all-target-libgcc
/projects/k2072/users/nima/tools/sources/gcc/gcc-6.5.0/gcc-6.5.0-build-mips/./gcc/xgcc -B/projects/k2072/users/nima/tools/sources/gcc/gcc-6.5.0/gcc-6.5.0-build-mips/./gcc/ -B/projects/k2072/users/nima/jadarite/toolchain/gcc-6.5.0-mips/mips-sde-elf/bin/ -B/projects/k2072/users/nima/jadarite/toolchain/gcc-6.5.0-mips/mips-sde-elf/lib/ -isystem /projects/k2072/users/nima/jadarite/toolchain/gcc-6.5.0-mips/mips-sde-elf/include -isystem /projects/k2072/users/nima/jadarite/toolchain/gcc-6.5.0-mips/mips-sde-elf/sys-include -g -O2 -Os -mcode-readable=pcrel -mno-gpopt -mmicromips -O2 -g -O2 -Os -minterlink-mips16 -mcode-readable=pcrel -mno-gpopt -DIN_GCC -DCROSS_DIRECTORY_STRUCTURE -W -Wall -Wno-narrowing -Wwrite-strings -Wcast-qual -Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition -isystem ./include -g -DIN_LIBGCC2 -fbuilding-libgcc -fno-stack-protector -Dinhibit_libc -I. -I. -I../../.././gcc -I../../../../gcc-6.5.0/libgcc -I../../../../gcc-6.5.0/libgcc/. -I../../../../gcc-6.5.0/libgcc/../gcc -I../../../../gcc-6.5.0/libgcc/../include -DHAVE_CC_TLS -o fixsfsi.o -MT fixsfsi.o -MD -MP -MF fixsfsi.dep -DFUNC=__fixsfsi -DOP_fixsi -DTYPE=sf -c ../../../../gcc-6.5.0/libgcc/config/hardfp.c -fvisibility=hidden -DHIDE_EXPORTS -Wno-missing-prototypes
/tmp/cc8vFnc3.s: Assembler messages:
/tmp/cc8vFnc3.s:29: Error: invalid operands `trunc.w.s $f0,$f12,$2'
If I remove -mmicromips from above compile command, compilation passes. I also can build libgcc with other compile options like -EL -msoft-float, etc. but not micromips.
find -name "libgcc.a"
./libgcc/libgcc.a
./el/libgcc/libgcc.a
./mips32/libgcc/libgcc.a
./mips32r2/libgcc/libgcc.a
./mips64/libgcc/libgcc.a
./mips64r2/libgcc/libgcc.a
./mips16/libgcc/libgcc.a
Greatly appreciate any help.

Related

F2py errors with a MAC M2

I'm trying to use f2py on a MAC M2. My programs all run successfully on an Intel MAC. The first part of the process to produce C code from my Fortran source which seems to work but I get the following error when the C compilation attempts and fails
clang-14clang-14: : error: error: the clang compiler does not support '-march=core2'the clang compiler does not support '-march=core2'
Followed by this long string
error: Command "x86_64-apple-darwin13.4.0-clang -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -fwrapv -O2 -Wall -fPIC -O2 -isystem /opt/homebrew/Caskroom/miniforge/base/envs/condaTest/include -arch arm64 -fPIC -O2 -isystem /opt/homebrew/Caskroom/miniforge/base/envs/condaTest/include -arch arm64 -march=core2 -mtune=haswell -mssse3 -ftree-vectorize -fPIC -fPIE -fstack-protector-strong -O2 -pipe -isystem /opt/homebrew/Caskroom/miniforge/base/include -D_FORTIFY_SOURCE=2 -isystem /opt/homebrew/Caskroom/miniforge/base/include -ftrapping-math -DNPY_DISABLE_OPTIMIZATION=1 -I/var/folders/np/393cjs953159dbj23mgqmlqr0000gn/T/tmpf0_vcv2d/src.macosx-11.0-arm64-3.9 -I/opt/homebrew/Caskroom/miniforge/base/envs/condaTest/lib/python3.9/site-packages/numpy/core/include -I/opt/homebrew/Caskroom/miniforge/base/envs/condaTest/include/python3.9 -c /var/folders/np/393cjs953159dbj23mgqmlqr0000gn/T/tmpf0_vcv2d/src.macosx-11.0-arm64-3.9/fib3module.c -o /var/folders/np/393cjs953159dbj23mgqmlqr0000gn/T/tmpf0_vcv2d/var/folders/np/393cjs953159dbj23mgqmlqr0000gn/T/tmpf0_vcv2d/src.macosx-11.0-arm64-3.9/fib3module.o -MMD -MF /var/folders/np/393cjs953159dbj23mgqmlqr0000gn/T/tmpf0_vcv2d/var/folders/np/393cjs953159dbj23mgqmlqr0000gn/T/tmpf0_vcv2d/src.macosx-11.0-arm64-3.9/fib3module.o.d" failed with exit status 1
I would be very grateful for any help with this.

How to setup CLion IDE with custom libc++ and clang?

CLion website says they support "libc++" but there is no information on how to set up CLlion to use libc++. I'm using Ubuntu 16 and downloaded libc++ source and built it. So I want to use this specific version.
Here's what I've tried so far:
So I have now libc++ binaries. Then I created simple hello world project and changed its CMakeLists.txt to use my custom libc++. However when I try to run the project, I get error:
/home/shitals/CLionProjects/JsonTest/cmake-build-debug/JsonTest: error while loading shared libraries: libc++.so.1: cannot open shared object file: No such file or directory
Here's my project cmake to force using my custom libc++.
cmake_minimum_required(VERSION 3.8)
project(JsonTest)
set(CMAKE_CXX_STANDARD 14)
#libcxx which we will use with specific version of clang
SET(LIBCXX_INC_PATH /home/shitals/mylibc++/include/c++/v1)
SET(LIBCXX_LIB_PATH /home/shitals/mylibc++/lib)
set(CMAKE_C_COMPILER clang-3.9)
set(CMAKE_CXX_COMPILER clang++-3.9)
set(CMAKE_CXX_FLAGS "\
-std=c++14 -ggdb -Wall -Wextra -Wstrict-aliasing -Wunreachable-code -Wcast-qual -Wctor-dtor-privacy \
-Wdisabled-optimization -Wformat=2 -Winit-self -Wmissing-include-dirs -Wswitch-default \
-Wold-style-cast -Woverloaded-virtual -Wredundant-decls -Wshadow -Wstrict-overflow=5 -Wswitch-default -Wundef \
-Wno-variadic-macros -Wno-parentheses -Wno-unused-function -Wno-unused -Wno-documentation -fdiagnostics-show-option -ferror-limit=10 \
-pthread ${CMAKE_CXX_FLAGS}")
set(CMAKE_CXX_FLAGS "\
-nostdinc++ -isystem ${LIBCXX_INC_PATH} \
-D__CLANG__ ${CMAKE_CXX_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "\
${CMAKE_EXE_LINKER_FLAGS} -stdlib=libc++ -lc++ -lc++abi -lm -lc -lgcc_s -lgcc -ldl \
-L ${LIBCXX_LIB_PATH}")
set(SOURCE_FILES main.cpp)
add_executable(JsonTest ${SOURCE_FILES})
My compiled libc++ binaries does have libc++.so.1 file.
Ok... so below CMakeLists.txt in project root does seem to work:
cmake_minimum_required(VERSION 3.8)
project(JsonTest)
set(CMAKE_CXX_STANDARD 14)
#libcxx which we will use with specific version of clang
SET(LIBCXX_INC_PATH /home/shitals/GitHubSrc/AirSim/llvm-build/output/include/c++/v1)
SET(LIBCXX_LIB_PATH /home/shitals/GitHubSrc/AirSim/llvm-build/output/lib)
set(CMAKE_C_COMPILER clang-3.9)
set(CMAKE_CXX_COMPILER clang++-3.9)
set(CMAKE_CXX_FLAGS "\
-std=c++14 -ggdb -Wall -Wextra -Wstrict-aliasing -Wunreachable-code -Wcast-qual -Wctor-dtor-privacy \
-Wdisabled-optimization -Wformat=2 -Winit-self -Wmissing-include-dirs -Wswitch-default \
-Wold-style-cast -Woverloaded-virtual -Wredundant-decls -Wshadow -Wstrict-overflow=5 -Wswitch-default -Wundef \
-Wno-variadic-macros -Wno-parentheses -Wno-unused-function -Wno-unused -Wno-documentation -fdiagnostics-show-option -ferror-limit=10 \
-pthread ${CMAKE_CXX_FLAGS}")
set(CMAKE_CXX_FLAGS "\
-nostdinc++ -isystem ${LIBCXX_INC_PATH} \
-D__CLANG__ ${CMAKE_CXX_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "\
${CMAKE_EXE_LINKER_FLAGS} -v -nodefaultlibs -lc++ -lc++abi -lm -lc -lgcc_s -lgcc -ldl \
-L ${LIBCXX_LIB_PATH}")
LINK_DIRECTORIES(${LIBCXX_LIB_PATH})
set(SOURCE_FILES main.cpp)
add_executable(JsonTest ${SOURCE_FILES})
TARGET_LINK_LIBRARIES(JsonTest c++ c++abi)

linux kernel 4.4 build error: garbage following instruction

I am trying to build a custom linux kernel 4.4 running for AT91 with mostly default configuration that I set up from menuconfig. The build fails with the following error. The gcc version is 4.6.3 and the binutils version is 2.22. There is nothing obvious in main.c which is where the compilation is at the time of failure. Dont understand what to look for as I have run out of ideas.
arm-none-linux-gnueabi-gcc -Wp,-MD,init/.main.o.d -nostdinc -isystem /opt/arm-2009q1/bin/../lib/gcc/arm-none-linux-gnueabi/4.3.3/include -I./arch/arm/include -Iarch/arm/include/generated/uapi -Iarch/arm/include/generated -Iinclude -I./arch/arm/include/uapi -Iarch/arm/include/generated/uapi -I./include/uapi -Iinclude/generated/uapi -include ./include/linux/kconfig.h -D__KERNEL__ -mlittle-endian -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -Werror-implicit-function-declaration -Wno-format-security -std=gnu89 -fno-omit-frame-pointer -mapcs -mno-sched-prolog -mabi=apcs-gnu -mno-thumb-interwork -marm -D__LINUX_ARM_ARCH__=7 -march=armv7-a -msoft-float -Uarm -fno-delete-null-pointer-checks -O2 -fno-stack-protector -fno-omit-frame-pointer -fno-optimize-sibling-calls -gdwarf-2 -pg -Wdeclaration-after-statement -Wno-pointer-sign -fno-strict-overflow -Werror=implicit-int -Werror=strict-prototypes -D"KBUILD_STR(s)=#s" -D"KBUILD_BASENAME=KBUILD_STR(main)" -D"KBUILD_MODNAME=KBUILD_STR(main)" -c -o init/.tmp_main.o init/main.c
/tmp/ccbj4Zgm.s: Assembler messages:
/tmp/ccbj4Zgm.s:852: Error: garbage following instruction -- `dmb ishst'
/tmp/ccbj4Zgm.s:874: Error: garbage following instruction -- `dmb ishst'
/tmp/ccbj4Zgm.s:909: Error: garbage following instruction -- `dmb ish'
/tmp/ccbj4Zgm.s:921: Error: garbage following instruction -- `dsb ishst'
make[2]: *** [init/main.o] Error 1
make[1]: *** [init] Error 2

Conflicting declaration while compiling 6.3.0 gcc

Ubuntu Xenial, x86_64
Compiling 6.3.0 gcc
nativ gcc version is 5.4.0
Error Source:
g++ -c -g -O2 -DIN_GCC -DCROSS_DIRECTORY_STRUCTURE -fno-exceptions -fno-rtti -fasynchronous-unwind-tables -W -Wall -Wno-narrowing -Wwrite-strings -Wcast-qual -Wmissing-format-attribute -Woverloaded-virtual -pedantic -Wno-long-long -Wno-variadic-macros -Wno-overlength-strings -DHAVE_CONFIG_H -DGENERATOR_FILE -fno-PIE -I. -Ibuild -I../../gcc-6.3.0/gcc -I../../gcc-6.3.0/gcc/build -I../../gcc-6.3.0/gcc/../include -I../../gcc-6.3.0/gcc/../libcpp/include \
-o build/genmddeps.o ../../gcc-6.3.0/gcc/genmddeps.c
Error:
In file included from ./bconfig.h:3:0,
from ../../gcc-6.3.0/gcc/genmddeps.c:18:
./auto-host.h:2321:16: error: declaration does not declare anything [-fpermissive]
#define rlim_t long
^
In file included from ../../gcc-6.3.0/gcc/genmddeps.c:19:0:
../../gcc-6.3.0/gcc/system.h:488:23: error: conflicting declaration of C function ‘void* sbrk(int)’
extern void *sbrk (int);
^
I am trying to compile gcc from scratch. My config options are
../gcc-6.3.0/configure --target=arm-eabi --prefix=/local/development/arm-project/tools/ --enable-languages=c --with-newlib --without-headers
Can anyone please help with debugging?
Try (and edit accordingly):
tar xzf gcc-6.3.0.tar.gz
cd gcc-6.3.0
./contrib/download_prerequisites
cd ..
mkdir objdir
cd objdir
$PWD/../gcc-6.3.0/configure --prefix=$HOME/GCC-6.3.0 --enable-languages=c,c++
make
make install
Source: Installing GCC
I could resolve this issue, by installing gmp-devel, mpfr-devel and libmpc-devel. See GCC docs for details.
There are some additional requirements for GCC 9.1.0 such as DejaGnu 1.6.2 and GDB 8.3 (solved my libiberty make target error).
If you have more than one compiler installed, use the GCC compiler:
export CC=gcc
export CXX=g++

"internal compiler error" from yajl-ruby build on OpenSUSE 12.1

As a requirement for chef-client, I am trying to install yajl-ruby on OpenSUSE 12.1. So far, it is returning the following message:
linux:~ # gem install yajl-ruby
Building native extensions. This could take a while...
ERROR: Error installing yajl-ruby:
ERROR: Failed to build gem native extension.
/usr/bin/ruby extconf.rb
creating Makefile
make
gcc -I. -I/usr/lib64/ruby/1.8/x86_64-linux -I/usr/lib64/ruby/1.8/x86_64-linux -I. -fPIC -fmessage-length=0 -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector -funwind-tables -fasynchronous-unwind-tables -g -g -fno-strict-aliasing -fPIC -Wall -funroll-loops -c yajl.c
gcc -I. -I/usr/lib64/ruby/1.8/x86_64-linux -I/usr/lib64/ruby/1.8/x86_64-linux -I. -fPIC -fmessage-length=0 -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector -funwind-tables -fasynchronous-unwind-tables -g -g -fno-strict-aliasing -fPIC -Wall -funroll-loops -c yajl_alloc.c
gcc -I. -I/usr/lib64/ruby/1.8/x86_64-linux -I/usr/lib64/ruby/1.8/x86_64-linux -I. -fPIC -fmessage-length=0 -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector -funwind-tables -fasynchronous-unwind-tables -g -g -fno-strict-aliasing -fPIC -Wall -funroll-loops -c yajl_buf.c
gcc -I. -I/usr/lib64/ruby/1.8/x86_64-linux -I/usr/lib64/ruby/1.8/x86_64-linux -I. -fPIC -fmessage-length=0 -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector -funwind-tables -fasynchronous-unwind-tables -g -g -fno-strict-aliasing -fPIC -Wall -funroll-loops -c yajl_encode.c
yajl_encode.c: In function ‘hexToDigit’:
yajl_encode.c:201:1: internal compiler error: Aborted
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://bugs.opensuse.org/> for instructions.
make: *** [yajl_encode.o] Error 1
Gem files will remain installed in /usr/lib64/ruby/gems/1.8/gems/yajl-ruby-1.1.0 for inspection.
Results logged to /usr/lib64/ruby/gems/1.8/gems/yajl-ruby-1.1.0/ext/yajl/gem_make.out
The appropriate packages are installed:
zypper install ruby ruby-devel ruby-ri ruby-rdoc ruby-shadow gcc gcc-c++ automake autoconf make curl dmidecode
It may be an issue with the compiler or there may be an issue specific on OpenSUSE. So far, I am not sure which path to take.
gcc clearly recommends you to send bug report to OpenSuse with full preprocessed source (-E option instead of "-c" and add a redirect to file). This may be because opensuse gcc might have some modifications. You should check instructions on bugs.opensuse.org and send a bug report to OpenSuse. If the bug is in basic gcc too, opensuse bugzilla people will forward it upstream or will ask you to do this
To avoid an "internal compiler error" without sending bugs you can try to change build options. Usually "internal compiler error" means that something goes wrong in complex process of optimizations, so you can just change this process (order of optimization stages and which are enabled). Easiest is to change level of optimization (e.g. replace -O2 with -O1 or -O0) or add something like -Osize.

Resources