gcc generates 32bit code on sparc - gcc

I have a Solaris sparc machine and when i build my programs, it generates 32bit code which should be 64bit. How to check the cause?
$uname -a
SunOS sol 5.10 Generic_118833-33 sun4u sparc SUNW,Sun-Fire-V240
$/usr/sfw/bin/gcc --version
gcc (GCC) 3.4.3 (csl-sol210-3_4-branch+sol_rpath)
Copyright (C) 2004 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$/usr/sfw/bin/gcc test.c
$file a.out
a.out: ELF 32-bit MSB executable SPARC Version 1, dynamically linked, not stripped, no debugging information available
$

OSNews - SPARC Optimizations With GCC
The creation of 64-bit code requires using the -m64 flag (-m32 for 32-bit code is implied by default).
(Yes, this is different than GCC for x86_64, which defaults to -m64 unless overridden with -m32.)

You should be able to force a 64-bit build using the -m64 option.
If that fails, you can download and install a prebuilt GCC package with 64-bit SPARC support for Solaris 10 from SunFreeware.com (download, gunzip, install with pkgadd -d gcc-...-sparc-local) which will run from /usr/local/bin/gcc.

Related

nano.specs not found in arm-none-eabi-gcc

I am using Ubuntu 20.04.3 LTS and I need to use arm-none-eabi-gcc version 4.8.2 ( I know it is old, but i have to use this version)
So I successfully install this library with below files:
binutils-arm-none-eabi_2.24-2ubuntu2+4_amd64.deb
gcc-arm-none-eabi_4.8.2-14ubuntu1+6_amd64.deb
libcloog-isl4_0.18.2-1_amd64.deb
libisl10_0.12.2-1_amd64.deb
libnewlib-arm-none-eabi_2.1.0-3_all.deb
libnewlib-dev_2.1.0-3_all.deb
multiarch-support_2.27-3ubuntu1_amd64.deb
libmpfr4_3.1.6-1_amd64.deb
Than I checked my gcc-arm-none-eabi version like this :
arm-none-eabi-gcc --version
arm-none-eabi-gcc (4.8.2-14ubuntu1+6) 4.8.2
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Than I am trying to compile the source code for stm32f4 with makefile.
If I use the -specs=nano.specs in makefile I get below error:
arm-none-eabi-gcc: error: nano.specs: No such file or directory
But if I dont use -specs=nano.specs command in makefile I can compile successfuly, but I need to use -specs=nano.specs command how can I solve this problem ?

ld unrecognized emulation mode /tmp/ccK2pwtc.o on ubuntu

I'm using the following machine:
Linux version 5.4.0-42-generic (buildd#lgw01-amd64-038) (gcc version 9.3.0 (Ubuntu 9.3.0-10ubuntu2)) #46-Ubuntu SMP Fri Jul 10 00:24:02 UTC 2020
The program
int main() {
return 0;
}
when compiled
gcc -Wl,-m main.c
returns
/usr/bin/ld: unrecognised emulation mode: /tmp/ccJI1LRo.o
Supported emulations: elf_x86_64 elf32_x86_64 elf_i386 elf_iamcu elf_l1om elf_k1om i386pep i386pe
collect2: error: ld returned 1 exit status
I am not sure where to start as to knowing why.
Also, gcc and ld versions:
> gcc --version
gcc (Ubuntu 9.3.0-10ubuntu2) 9.3.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
> ld --version
GNU ld (GNU Binutils for Ubuntu) 2.34
Copyright (C) 2020 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or (at your option) a later version.
This program has absolutely no warranty.
The -Wl,-m argument specifies that gcc should pass the -m argument to the linker.
When the linker is called, the -m option is used, and it's followed by a intermediate object file that's been compiled (/tmp/ccJI1LRo.o), as opposed to a supported emulation, which leads to the error message you've encountered.
The linker's -m option requires an argument for specifying an emulation. The output in your question lists supported emulations.

GDB Compilation Issue

I have run in an issue with compiling gdb from source. I am downloading version 8.2.1 but when I try to compile it, I get the following error:
configure: error: *** A compiler with support for C++11 language features is required.
make[1]: *** [configure-gdb] Error 1
My operating system is Red Hat 7.6 (Maipo) but i have a compiled from source gcc(that i set as the default one with an alias in bashrc)
gcc --version
gcc (GCC) 8.2.0
Copyright (C) 2018 Free Software Foundation, Inc.
which gcc
alias gcc='/usr/local/gcc8.2/bin/gcc'
/usr/local/gcc8.2/bin/gcc
which g++
alias g++='/usr/local/gcc8.2/bin/g++'
/usr/local/gcc8.2/bin/g++
What i have tried/read so far
Read the gdb manual regarding the configure and instalation part, also various stackoverflow links but nobody seems to have this problem
Read the README file in the gdb folder/subfolders
Tried setting the following env options CXX_FOR_TARGET=/usr/local/gcc8.2/bin/g++ GCC_FOR_TARGET=/usr/local/gcc8.2/bin/gcc (not sure if i should replace target with my actual target architecture)
Looked in the gdb-8.2.1 folder at the file config.log and found these: ac_cv_env_GCC_FOR_TARGET_value=/usr/local/gcc8.2/bin/gcc
ac_cv_prog_CXX_FOR_TARGET=/usr/local/gcc8.2/bin/g++
ac_cv_prog_GCC_FOR_TARGET=/usr/local/gcc8.2/bin/gcc
However in the C compiler section of the same config log I have found the following:
configure:4284: checking for C compiler version
configure:4293: gcc --version >&5
gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-36)
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
I am not sure ifi can use the devtoolset-8 gdb from RedHat because i have compiled gcc with GLIBCXX_USE_CXX11_ABI=1 and on RedHat due to a bug this is disabled by default and i am not sure if gdb will be able to manage the different binary interface.
Short version: What am I doing wrong that is making the GDB configure script not find the correct compiler and how can i fix/workaround this?
Thank you very much for your help!
A C++11-capable compiler for Red Hat Enterprise Linux 7 is provided as part of Red Hat Developer Toolset. It happens to include not just GCC 8, but GDB 8.2 as well, so you may not even have to compile it yourself. The DTS C++ compiler has been built in a special way so that it interoperates with the system C++ runtime. Unless you have replicated those modifications in your GCC build, it will not be compatible with the rest of the system (and you will have to replace the system libstdc++ library).
The system compiler in Red Hat Enterprise Linux 7 is based on GCC 4.8. In that version, C++11 support was still experimental and not enabled by default. You can try to configure GDB with
./configure CXX="g++ -std=gnu+11"
but this is not recommended (only the C++98 mode is supported).
The configure script does not use shell aliases because those are not inherited by shell scripts invoked from a shell. You will have to specify the full path to the C++ compiler explicitly (in the CXX= argument to configure), or adjust the PATH environment variable manually, or use scl enable to do so in a more polished fashion (for software collections such as Developer Toolset).

Exec format error 32-bit executable Windows Subsystem for Linux?

When I try to execute a 32-bit file compiled with gcc -m32 main.c -o main on Windows Subsystem for Linux, I get the following error: bash: ./main: cannot execute binary file: Exec format error.
If I compile it without -m32 it runs.
Any solution for running 32-bit executable on WSL?
QEMU and binfmt support light the way :)
https://github.com/microsoft/wsl/issues/2468#issuecomment-374904520
After reading that the WSLInterop between WSL and Windows processes used binfmt, I was tinkering with QEMU to try some ARM development, and incidentally discovered how to get 32-bit support working.
Edit: requires "Fall Creators Update", 1709, build 16299 or newer
Install qemu and binfmt config:
sudo apt install qemu-user-static
sudo update-binfmts --install i386 /usr/bin/qemu-i386-static --magic '\x7fELF\x01\x01\x01\x03\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\x03\x00\x01\x00\x00\x00' --mask '\xff\xff\xff\xff\xff\xff\xff\xfc\xff\xff\xff\xff\xff\xff\xff\xff\xf8\xff\xff\xff\xff\xff\xff\xff'
You'll need to reactivate binfmt support every time you start WSL:
sudo service binfmt-support start
Enable i386 architecture packages:
sudo dpkg --add-architecture i386
sudo apt update
sudo apt install gcc:i386
Try it out:
$ file /usr/bin/gcc-5
/usr/bin/gcc-5: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=2637bb7cb85f8f12b40f03cd015d404930c3c790, stripped
$ /usr/bin/gcc-5 --version
gcc-5 (Ubuntu 5.4.0-6ubuntu1~16.04.9) 5.4.0 20160609
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ gcc helloworld.c -o helloworld
$ ./helloworld
Hello, world!
$ file helloworld
helloworld: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=3a0c7be5c6a8d45613e4ef2b7b3474df6224a5da, not stripped
And to prove it really was working, disable i386 support and try again:
$ sudo service binfmt-support stop
* Disabling additional executable binary formats binfmt-support [ OK ]
$ ./helloworld
-bash: ./helloworld: cannot execute binary file: Exec format error
32-bit ELF support isn't provided by WSL (yet). There doesn't seem to be any progress since the UserVoice was raised - you are out luck.
See UserVoice: Please add 32 bit ELF support to the kernel and Support for 32-bit i386 ELF binaries.
If possible, switch to a real Linux ;-)
Since this was originally posted, the support has been available on WSL2 which does support real Linux kernel! So that should be the preferred way.
As noted in the linked github issue, there's also qemu-user which can be used if WSL1 is still used.
WSL2 runs in a real virtual machine using a real Linux kernel, therefore it's actually possible to do anything a Linux VM can do, including running 32-bit code. Just install 32-bit libs by running
sudo dpkg --add-architecture i386
sudo apt-get update
For more information read
Announcing WSL 2
WSL 2 FAQ

Trouble installing PETSc on Mac OS X

I'm trying to install the PETSc scientific computation library on Mac OS X 10.6.8.
When configuring the project, I am running into the following error message:
cls ~/Downloads/petsc-3.2-p6 $ ./configure
===============================================================================
Configuring PETSc to compile on your system
===============================================================================
TESTING: checkFortranNameMangling from config.compilers(config/BuildSystem/config/compilers.py:589) *******************************************************************************
UNABLE to CONFIGURE with GIVEN OPTIONS (see configure.log for details):
-------------------------------------------------------------------------------
Unknown Fortran name mangling: Are you sure the C and Fortran compilers are compatible?
Perhaps one is 64 bit and one is 32 bit?
See http://www.mcs.anl.gov/petsc/petsc-as/documentation/faq.html#gfortran
*******************************************************************************
I have the following versions gcc
cls ~/Downloads/petsc-3.2-p6 $ gcc --version
i686-apple-darwin10-llvm-gcc-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.1.00)
Copyright (C) 2007 Free Software Foundation, Inc.
and gfortran
cls ~/Downloads/petsc-3.2-p6 $ gfortran --version
GNU Fortran (GCC) 4.2.3
Copyright (C) 2007 Free Software Foundation, Inc.
Why are those not compatible?
It seems that the two compilers come from two different packages. Maybe you should show us where do their binary reside, for example by using which gcc and which gfortran. Try to find accompanying build of gfortran to your build of gcc, which comes from LLVM. Your gfortran is probably not provided by LLVM, but it is normal gcc build. The installer suggests that they may even be 32 and 64 bit.

Resources