Command to check the 'linker' used(by clang++) for executable creation on Mac OS - clang++

I have an executable created using 'clang++' compiler(using mac os 10.9 sdk) on mac os.
$ clang++ -v
Apple LLVM version 6.0 (clang-600.0.57) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin13.4.0
Thread model: posix
$ ld -v
#(#)PROGRAM:ld PROJECT:ld64-241.9
configured to support archs: armv6 armv7 armv7s arm64 i386 x86_64 x86_64h armv6m armv7m armv7em
LTO support using: LLVM version 3.5svn
$ sw_vers
ProductName: Mac OS X
ProductVersion: 10.9.5
BuildVersion: 13F1911
My query is how to confirm(command to check) if my executable is created using ld.lld linker or ld.gold/some other linker? What is the default linker 'clang++' uses(command to cross-check) on mac os?
Regards,
Vinay

Pass -v to see the subcommands clang runs. Pass -### to only see the subcommands and make clang not actually run them.

Related

-bash: ./ex1: cannot execute binary file: Exec format error [duplicate]

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

MinGW on windows gcc compiler to create 64 Bit DLL for a nodejs (ffi-napi)

I am using a sample program from https://www.npmjs.com/package/ffi-napi A Node.js Foreign Function Interface for N-API factorial.c is there a way to compile a sample C(factorial_lib.c) program as a windows 64Bit .DLL I am using gcc under windows( MinGW installed, not cygwin) ,
no luck: gives error, it seems the following is compiling it into 32BIT need to know how to change the gcc default compilation into 64bit windows DLL
gcc -c -DBUILD_DLL factorial_lib.c
gcc -shared -o factorial.dll factorial_lib.o
PLEASE HELP , I have tried MS VSC compile and ran into issues
MinGW does not support 64-bit Windows. MinGW-w64 does support both 32-bit and 64-bit Windows. You can download a standalone version from http://winlibs.com/.

Finding gcc location

I am on a cluster and do not have root permission, I am new to linux. I wish to run a tool with a gcc 5 version or less. My default gcc version is 6.3.0. But there is another version of gcc (gcc 4:6.3.0-4) on the system. I am trying to find its location so that I can set CC and CXX variable value to that location (e.g. export CC="/usr/bin/gcc"). I tried which gcc (it is pointing to my default gcc location) and whereis gcc. I am not able to find the location of other gcc. It would be really helpful if someone can share the way to do it.
dpkg --list | grep compiler
Name Version Architecture Description
gcc 4:6.3.0-4 amd64 GNU C compiler
gcc-6 6.3.0-18+deb9u1 amd64 GNU C compiler
My system description is as follows:
Linux b03 4.9.0-6-amd64 #1 SMP Debian 4.9.82-1+deb9u3 (2018-03-02) x86_64 GNU/Linux
Running dpkg -L gcc 4:6.3.0-4 will give you a list of all files installed by that package. You should be able to find the executable path in there.

How to change gcc version linux

I have gcc-4.6 & gcc-4.7 both installed on my machine and I made gcc the default compiler. But still I could see 4.6 under "cat /proc/version" but I want 4.7 in place of 4.6.
cat /proc/version
Linux version 3.2.0-4-rt-686-pae (debian-kernel#lists.debian.org) (gcc version 4.6.3 (Debian 4.6.3-14) ) #1 SMP PREEMPT RT Debian 3.2.65-1+deb7u2
How can I change gcc version here from 4.6 to 4.7 ?
Any help would be really helpfull for me.
Many Thanks.
As the same problem is mentioned here https://askubuntu.com/questions/193539/having-2-versions-of-gcc
I suggest you to check the solution.
This is because you have both versions installed,and 4.6 being treated as the default.
The easiest way make gcc-4.7 the default gcc is to move the symlink of /usr/bin/gcc:
sudo rm /usr/bin/gcc
sudo ln -s /usr/bin/gcc-4.7 /usr/bin/gcc
Reference link here
Is there any way to use a module in 3.2 which is compiled with kernel
3.10 ?
You can try the option -f of modprobe.

How to install/update gcc-4.6 on openSUSE 11.2 (x86_64)?

I met an err when I installed JikesRVM, that is,
skipping incompatible /usr/lib64/gcc/x86_64-suse-linux/4.4/libstdc++.so when searching for -lstdc++
So I am trying to install/update it to a later version. Now, the machine already has
gcc (SUSE Linux) 4.4.1 [gcc-4_4-branch revision 150839]
I am new to openSUSE, could you help?
Thanks!
You need to install 32 bit support for the GNU C/C++ compiler since JikesRVM on x86_64 currently supports only the 32 bit architecture.
To install this support in OpenSuSE 11.2 type
sudo zypper install gcc44-32bit gcc-32bit libstdc++44-devel-32bit
The first two provide runtime support for the C language and the 32-bit version of libgcc, the GCC low level runtime library. The third provides the 32-bit version of libstdc++, both the static import library and the dynamic library. It is the static libstdc++.a that was missing for JikesRVM.
To verify that the 32bit C++ build system is installed correctly you can test it with the following
echo "int main(){}" | g++ -x c++ -m32 -
Note Official support for OpenSuSE 11.2 has ended. Evergreen support will be available through 2013. Yet it is reasonable to update to 11.3 or a later version soon.

Resources