Linking problem under linux

Reply

Join Date: Jul 2009
Posts: 1
Reputation: m_a_xim is an unknown quantity at this point 
Solved Threads: 0
m_a_xim m_a_xim is offline Offline
Newbie Poster

Linking problem under linux

 
0
  #1
Jul 9th, 2009
Hello,
I'm actually learning assembly and I have a problem even though I am copying word for word what my book tells me. Here's the code:
  1. 1 .section .data
  2. 2 helloworld:
  3. 3 .ascii "hello world\n\0"
  4. 4 .section .text
  5. 5 .globl _start
  6. 6 _start:
  7. 7 pushq $helloworld
  8. 8 call printf
  9. 9 pushq $0
  10. 10 call exit
(there used to be 'pushl's but as I am using an AMD64 I had to replace them with 'pushq's)
It is then written that I must compile and link in this way:
  1. as helloworld-lib.s -o helloworld-lib.o
  2. ld -dynamic-linker /lib/ld-linux.so.2 \
  3. -o helloworld-lib helloworld-lib.o -lc
It works without printing out an error but during execution of the newly generated executable, it crashes immediately and I get this:
"bash: ./helloworld-lib: Accessing a corrupted shared library"

I also tried replacing "-dynamic-linker /lib/ld-linux.so.2" by "-dynamic-linker /lib/ld-linux-x86-64.so.2" but I get this error now when I execute "Illegal instruction".
After checking with gdb, I conclude that the SIGILL is sent during the fprintf function call.


Any idea how I could solve this problem?
Thanks.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC