Does a 32-bit Linux program's entire runtime lib tree need to be 32-bit? - linux

On my 64-bit RHEL machine, I'm compiling and running a C & Fortran program that is 32-bit only. It invokes the non-static version of a lot of standard Linux libs (X11, OpenGL/Mesa, Motif, etc...), which of course invoke other libs (libjpeg, libc, etc). Do I have to install the 32-bit versions of that entire devl lib tree in order to build this program validly? And do I have to install the 32-bit versions of that entire run-time lib tree in order to run it without it segfaulting or whatever?

As far as i know you can't use 64 bit versions of your libs to run 32 bit software. So yes you need the 32 bit versions.

Related

compiling application with gcc -m32 on 64-bit system

I try to understand the requirements for developing Linux application running on 64-bit OS (with 64-bit architecture).
If the code was written for 32-bits architecture, does it mean that on regular compilation (gcc -m32) it will run on the 64-bit system OS, without any problems ?
Thank you,
Ran
Yes, it will. The only caveats to this are that you need 32 bit libraries to run the program, and 32 bit development packages to compile it. Most distros provide these and make it simple to install them as well.

Run 32-bit executable directly on 64-bit linux system

After migrating a Debian 7.6 system from i368 to amd64 I encountered the problem to use some older ELF 32-bit LSB executables. Of course, there is the possibility to setup a secondary 32-bit system (in fact I could use my old one) and to apply chroot(8) or schroot(1). But I do not like the additional admin effort, the performance loss by a wrapper program and a different command sequence.
I am wondering whether there is really no way to run a 32-bit application directly on the x86_64 architecture (as possible, e.g., for HP-UX 11.0)? Both
$ /home/alf/prog32
and
$ /usr/bin/linux32 /home/alf/prog32
just lead to the failure message /home/alf/prog32: file or directory not found. This behavior is observed for all ELF 32-bit LSB executables (Debian i386, downloaded, self-written and compiled C-programs).

How do I compile and link a 32-bit Windows executable using mingw-w64

I am using Ubuntu 13.04 and installed mingw-w64 using apt-get install mingw-w64. I can compile and link a working 64-bit version of my program with the following command:
x86_64-w64-mingw32-g++ code.cpp -o app.exe
Which generates a 64-bit app.exe file.
What binary or command line flags do I use to generate a 32-bit version of app.exe?
That depends on which variant of toolchain you're currently using. Both DWARF and SEH variants (which come starting from GCC 4.8.0) are only single-target. You can see it yourself by inspecting the directory structure of their distributions, i.e. they contain only the libraries with either 64- or 32-bit addressing, but not both. On the other hand, plain old SJLJ distributions are indeed dual-target, and in order to build 32-bit target, just supply -m32 flag. If that doesn't work, then just build with i686-w64-mingw32-g++.
BONUS
By the way, the three corresponding dynamic-link libraries (DLLs) implementing each GCC exception model are
libgcc_s_dw2-1.dll (DWARF);
libgcc_s_seh-1.dll (SEH);
libgcc_s_sjlj-1.dll (SJLJ).
Hence, to find out what exception model does your current MinGW-w64 distribution exactly provide, you can either
inspect directory and file structure of MinGW-w64 installation in hope to locate one of those DLLs (typically in bin); or
build some real or test C++ code involving exception handling to force linkage with one of those DLLs and then see on which one of those DLLs does the built target depend (for example, can be seen with Dependency Walker on Windows); or
take brute force approach and compile some test code to assembly (instead of machine code) and look for presence of references like ___gxx_personality_v* (DWARF), ___gxx_personality_seh* (SEH), ___gxx_personality_sj* (SJLJ); see Obtaining current GCC exception model.

Use of ia32-libs

I'm trying to use the asmlibrary which I've obtained from here
I'm running in 64-bit, but the pre-compiled static library is build for 32-bit.
I don't really want to recompile the library, because I do not have OpenCV 1.0 installed, and don't really want to install such an old version of this piece of software.
My employer has told me that you may use ia32-libs which would allow me to use the library on a 64-bit machine. I have installed these libs using apt.
In netbeans, my IDE of choice, I'm now attempting to use the library. I keep getting the messages:
/usr/bin/ld: i386 architecture of input file
`../asmlib/libasmlibrary.a(asm_shape.o)' is incompatible with
i386:x86-64 output
Etc..
I have two questions:
1) Will ia32-libs allow me to use this library?
2) How must I "enable" it's use, either generally or preferably specific to netbeans (if applicable)
Thank you
An executable (including the libraries it depends on) has to be entirely 32 bits or 64 bits. You cannot mix and match object files of different types.
So to use a 32 bits library, you must compile your program as a 32 bits executable and link with a 32 bits version of libc and other core libraries. On debian you'll need packages like libc6-dev-i386 and ia32-libs-dev.
To compile foo.c as a 32 bits executable, use
gcc -m32 -o foo foo.c
How to do this with netbeans is left as an exercise.
I don't think that you are able to use ia32-libs to compile a 64-bit program, using 32-bit libraries. That isn't what ia32-libs is designed for...it's designed to run entirely 32-bit programs on 64-bit systems.
I think your best bet would be to compile as 32-bit software. If you were using the command line, you can just add the -m32 flag to gcc. With netbeans, in Project Properties > Build > C Compiler (or C++ compiler if that's what you are using), there is a dropdown to select architecture. If 32-bit is not available in that dropdown, you can add -m32 to the Additional Options box.

Compiling with DMD on 64bit Linux or Linking with 32bit object files

What is the best way to compile programs with DMD on a 64bit machine? It doesn't need to compile to 64Bit code. I know about GDC, but want to work with D2 also. There is also chroot, but am hoping for a simpler way.
The actual problem isn't with compiling, but linking. DMD calls on GCC to perform linking with system libraries. Could I get DMD to have GCC link against 32bit library? Or how would I do it manually?
I already have the ia32 libraries installed which is why I can run DMD.
Ask GCC to perform 32-bit link by passing it '-m32' flag.
It appears that DMD doesn't invoke gcc to perform the link, but rather invokes ld directly. The equivalent ld switch is '-melf_i386', and apparently the way to make DMD pass that option to the linker is with '-L-melf_i386' flag.
Note that many systems separate runtime and development libraries. 32-bit runtime packages are almost always installed by default, but 32-bit development packages may not be.
You need development 32-bit packages to build 32-bit programs. The fact that 32-bit DMD can run does not in itself prove that you have all the 32-bit libraries you need in order to build 32-bit programs.

Resources