Linkers and loaders , Where are they stored? - operating-system

Where are linker , loaders and compilers located in a processor ?
Like linker are present in gcc but I cannot find for Loaders or Compilers .

The linker is just a program. It can be anywhere and there can be more than one linker on a system.
The same goes for compilers. They are just programs. There are often many compilers on a system. They can be wherever programs are stored.
The loader is usually a system service routine linked to the kernel.

Related

On solaris, when compiled with g++, socket() and bind() are not getting intercepted using dlsym()

I have written a simple server program using socket functions.
When compiled with g++, it gives undefined symbol error for send, __xnet_socket, listen, accept, __xnet_bind.
Why the symbols for socket and bind are different than others.
Also, when the program is compiled using gcc, this 'xnet' difference does not happen.
This linking error goes when linked with libsocket.so.
Actually, I am writing a shared library which overloads these socket API's and intercept them using dlsym().
On Solaris, when this library is compiled with gcc, these calls goes through the library, but when compiled with g++, socket() and bind() calls does not gets intercepted, but all other apis goes through the library.
Has libxnet.so to do something with this?
Can dtrace be of some help?
You need to link with libsocket (via -lsocket) in order for the linker to pick up those functions. libxnet is a filter library in 11.3; the functions were moved from libxnet to libsocket, libnsl and libc.
I've found in the past when building OSS on Solaris that appending -lsocket -lnsl to LDLIBS generally gets me through configure and build stages with ease. The linker is smart enough to remove unnecessary references from the output.

If programs depend on system calls to perform important tasks how can they run on different oss?

If i understood correctly programs depend on system calls to perform tasks like creating files, create new process, and stuff like that.
How can programs run on different os?
Are system calls standarised?
It's a linking process that actually resolve missing symbols after compilation. When you cross compile something or compile any software for other platform. Than you have to provide that symbol table.
That symbol table consist of many library components and system call table. So, they are specific (and different) for each OS. System calls are indirectly called by library functions.
Try to compile any C program with this command (It should call some type of system call, like call malloc function).
gcc -c -nostdlib main.c -o main.o
This will create object file with no OS (target) specific library and without linking (-c flag).
After that look at the symbols of output ELF.
readelf --symbols main.o | grep "UND"
You will see unresolved symbols.

Is it possible to produce .o files with a compiler and then link them using another compiler?

For being more specific, I'm wondering if it's possible to compile a .c and a .pl with the gnu prolog compiler but link them with Apple LLVM compiler along with the rest of an iOS project for being able to use prolog in an iOS app.
When you link files, you do that using a linker, not a compiler. Some times the compilers call the linker for you so you don't have to do that, that is why you think that the compilers are doing the linking.
This is how you link some object files together:
ld -o myprogram program.o program1.o ...
For more information on ld look here.
EDIT: If you are going to use your prolog .o files in an iOS project, you must be sure that you compile your prolog code for the same plattform as the iOS is running on, let's say ARM.

cross compilation from Solaris sparc to Solaris x86

May I know if I can cross compile the Solaris x86 library from Solaris sparc server?
The source code is mainly in C++ (some C). I need to use the Solaris C++ compiler CC to compile. I understand that some compile or link flags are different between sparc and x86. I have done a check to make sure that the flags I used are common.
Is it possible to simply copy the library compiled in sparc to x86? Or I need to apply specific flag during compiling and linking?
Thanks,
The Sun/Oracle Studio C++ compilers do not support cross-compilation. You would need to use another compiler that does, like a specially built gcc.
Simply copying the library can't work - SPARC and x86 are very different instruction sets, with no binary compatibility between the two.
Even if you could cross compile the Solaris libraries on SPARC for x86, it would seem a lot simpler to just install the x86 compilers and libraries. The interdependencies of these libraries is probably so complex that such a project would probably not work.
What's preventing you from just downloading and installing the Studio software on x86 Solaris?
Oracle Sun Studio C++ compiler (CC) has --xarch option with big variety of architectures. There are: sparc, amd64, pentium_pro and various extensions/modifications. This flag should be provided for both compiler and linker if you compile and link in separate steps.
You can verify target architecture with file command; e.g:
bash-3.2$ file /usr/bin/CC
/usr/bin/CC: ELF 32-bit LSB executable 80386 Version 1 [FPU], dynamically linked, stripped
Please, refer to CC manual for details:
Sun Studio 11 C++ Man Page

Recompile Arduino Target for Simulink for Windows 64 bit

I want to use Arduino Target for Simulink. It is made only for 32bit versions of Windows, but I read that you can recompile it and use it in 64-bit Windows.
I have tried, but I have not succeeded. I think that the files you need to create are the ones ending on .mexw32. What do you use to recompile these?
From http://www.mathworks.com/matlabcentral/fileexchange/24675-arduino-target:
To compile the C files for win64 (or
another platform), first make sure you
have a supported compiler:
http://www.mathworks.com/support/compilers/R2010b/win64.html
Once you have a compiler installed,
you can run "mex -setup" to point to
the appropriate compiler.
Finally, you can run "mex filename.c"
to compile all the functions in the
blocks directory.