This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
question about using gcc and ld
- From: Min-Hua Chen <orca dot chen at gmail dot com>
- To: binutils at sourceware dot org
- Date: Mon, 23 Feb 2009 16:52:11 +0800
- Subject: question about using gcc and ld
hi:
I tried to generate a binary executable by gcc and ld, but I had some problems.
1) I wrote a simple program, say test.c.
int main() { return 0;}
2) I compiled it by gcc:
%gcc -o a.out test.c
and I got a executable file a.out,
but when I tried to do the same thing by ld, there are some problems
%gcc -c a.c -o a.o
%ld -e main a.o -o b.out
I got b.out, a binary executable file, but when I executed b.out, I always got
segmentation fault.
I checked a.out and b.out with ldd
%ldd a.out
linux-gate.so.1 => (0xffffe000)
libc.so.6 => /lib/libc.so.6 (0xb7e31000)
/lib/ld-linux.so.2 (0xb7f81000)
%ldd b.out
noting
I don't understand why this happened. gcc calls ld to link object
file, but why can't I
generate the same result by using gcc and ld separately?
(the default linker script should work, does it?)
thx for reading
Min-Hua