0

I've compiled cpuid2.s to cpuid2.o by as cpuid2.s -o cpuid2.o -gstabs

Firstly I linked it by ld -o cpuid2 cpuid2.o -lc but a message says ./cpuid2:no such file or directory when I executed it (which is due to having not use dynamic linker, says the book)

So I linked it by ld -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o cpuid2 cpuid2.o -lc then executed it, however a SegmentationFault occurs: when gdb it step by step, gdb says printf.c:no such file or directory at the line call printf

is it because I haven't install C's library(however I can run simple C programs with function in stdio.h)?

#cpuid2.s View the CPUID Vendor ID string using C library calls
.code32
.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
8
  • 1
    is it because I haven't install C's library Close. It is because you don't have the source code of the C library. Normally you don't need it. You can also assume that the C library implementation for printf is very likely correct. Commented Feb 21, 2022 at 9:08
  • Please do not post pictures of code. Code is text and should be included directly into the question. Just copy&paste it into the question and put a line containint 3 byckticks above and below it as I did with my edit Commented Feb 21, 2022 at 9:17
  • @Gerhardh Many thanks, I can't simply step into C library, haha. And I've post the code the way you said and it looks much better. However there's still a SegmentationFalult in the line second to last("pushl $0"), and I can't understand why Commented Feb 21, 2022 at 10:09
  • I think you are using the wrong dynamic loader for your 32-bit code. Commented Feb 21, 2022 at 11:02
  • 2
    The 12-character cpuid string is not null-terminated, so you will need to either make the buffer longer (it is in BSS so the extra characters will be initialized to 0), or use %.12s to print no more than 12 characters. Commented Feb 21, 2022 at 11:08

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.