Consider the hello world C program:
hello.c:
#include "stdio.h"
int main()
{
printf("Hello, World!\n");
}
If I call:
$ gcc -c hello.c -o hello.o
It will produce an ELF Relocatable File hello.o
If I then call:
$ gcc hello.o -o hello [1]
It will link hello.o with ld and produce an ELF Executable File hello
However if I call ld directly [2]
instead of [1]
:
$ ld hello.o -o hello [2]
I get these errors:
/usr/bin/ld.bfd.real: warning: cannot find entry symbol _start
test.c:(.text+0xa): undefined reference to `puts'
gcc must be passing other options to ld (to link the C library for example).
Is there anyway to determine exactly what the command-line gcc is passing through to ld in command [1]
?
collect2
is not a simple alias forld
.collect2
is an executable- whereasld
is a sym link told.bfd
which is a symlink tohardened-ld
which is a perl script. No idea what is going on there. – Amr