05-21-06 12:15 PM
I am trying to assemble and link an assembly program which uses C
library functions. When I assemble and link the program using gas and ld
everything goes fine and the program is build properly. However when
using GCC it wont. I'm wondering why this is happening. Below are the
errors I get when using GCC followed by the program code
-- Using gas and ld --
roeland@rootland:$ as cpuid2.s -o cpuid2.o roeland@rootland:$ ld
-dynamic-linker /lib/ld-linux.so.2 -o cpuid2 -lc cpuid2.o
roeland@rootland:$ ./cpuid2
The processor Vendor ID is 'AuthenticAMD'
-- GCC errors --
roeland@rootland:$ gcc -o cpuid2 cpuid2.s
/tmp/ccHXqNul.o(.text+0x0): In function `_start':
: multiple definition of `_start'
/usr/lib/gcc-lib/i486-linux/3.3.5/../../../crt1.o(.text+0x0):../sysdeps/i386
/elf/start.S:47:
first defined here
/usr/lib/gcc-lib/i486-linux/3.3.5/../../../crt1.o(.text+0x18): In
function `_start':
../sysdeps/i386/elf/start.S:98: undefined reference to `main'
collect2: ld returned 1 exit status
roeland@rootland:$
-- Program Code --
# CPUID program 2, view the Vendor ID string using system calls
.section .data
output:
.asciz "The processor Vendor ID is '%s'\n"
.section .bss
.lcomm buffer, 12
.section .text
.globl _start
_start:
movl $0, %eax
cpuid
movl $buffer, %edi
movl %ebx, (%edi)
movl %edx, 4(%edi)
movl %ecx, 8(%edi)
pushl $buffer
pushl $output
call printf
addl $8, %esp
pushl $0
call exit
Can someone explain why gcc comes up with these errors? (I also tried "
gcc -dynamic-linker /lib/ld-linux.so.2 -o cpuid2 -lc cpuid2.s" with the
same problems)
[ Post a follow-up to this message ]
|