0

I am trying to emulate a 'C' program by using qemu instruction level simulator.The 'C' program is compiled by issuing the following command

arm-none-linux-gnueabi-gcc -g ex_qsort.c -o ex_qsort_lin_work

I then start qemu with the following command

"qemu-arm -g 1234 -L /path/to/codesourcery/arm-none-linux-gnueabi/libc ./ex_qsort_lin_work"

Then I connect to the program using gdb. I am trying to access program memory location and change the assembly code. But when i try to access the memory I get the following error

   (gdb) x 0x00008510
   0x8510 <main+76>:    0xe3530004
   (gdb) set *(0x8510) = 0xe3530002
   Cannot access memory at address 0x8510 

I am not sure why this error occurs . Gdb does not give any other warning . When i start gdb I have the sysroot pointed to the arm library. However when i check for the shared libarary I get the following message

   (gdb) info sharedlibrary 
   From        To          Syms Read   Shared Object Library
   0xf67d67d0  0xf67f0f58  Yes (*)     /path/to/codesourcery/arm-none-linux-gnueabi/libc/lib/ld-linux.so.3
   (*): Shared library is missing debugging information.

Not sure if this causes the problem. Statically linking the libraries also does not help My aim is to change the instruction at a given address

1 Answer 1

1

The issue is that the memory you are trying to modify is read-only. It looks like you're trying to modify code in the text segment of the executable, which is normally mapped read-only, so that is not unexpected. If you want to be able to modify it, it needs to be mapped as writable.

You can build an executable with a writable text segment (so it will load as writable by default) by linking with the -N flag -- use either -Xlinker -N or -Wl,-N on your gcc command line.

Sign up to request clarification or add additional context in comments.

3 Comments

I tried both the options you mentioned separately. I still get the same "Cannot access memory at address" error. Now there are no shared libraries in the code since it is statically linked
@user2955638: check the binary to make sure it's properly writable with objdump -p or -x. You can also modify an existing binary to make the text writeable with objcopy --writable-text, which should allow you to create a writeable text dynamically linked executable.
Thanks for the quick replies but it still does not work. The qemu-arm accepts ELF executable & Binary Flat file as input but not a writable one. The gdb 's input file is always a writable one. Still I am not able to write to a location. I am inclined to think it is more a problem with qemu-arm. Are there any other ways ?

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.