Here is the code of cpuid2.s
:
#cpuid2.s view the cpuid vendor id string using c library calls
.section .data
output:
.asciz "The processor Vendor ID is '%s'\n"
.section .bss
.lcomm buffer, 12
.section .text
.global _start
_start:
movl $0, %eax
cpuid
movl $buffer, %edi
movl %ebx, (%edi)
movl %edx, 4(%edi)
movl %ecx, 8(%edi)
push $buffer
push $output
call printf
addl $8, %esp
push $0
call exit
I assemble, link, and run it as so:
as -o cpuid2.o cpuid2.s
ld -dynamic-linker /lib/ld-linux.so.2 -o cpuid2 -lc cpuid2.o
./cpuid2
bash: ./cpuid2: Accessing a corrupted shared library
I've searched StackOverflow for this error. I found this question which is similar to mine. And I tried the method given by @rasion. Like this:
as -32 -o cpuid2.o cpuid2.s
ld -melf_i386 -L/lib -lc -o cpuid2 cpuid2.o
ld: cannot find -lc
His answer doesn't solve my problem. I hope someone can help me.
I'm using AT&T syntax with GNU assembler.
My computer has 64 bit Ubuntu 14.04.