LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 02-02-2017, 03:31 AM   #1
shakaiba
LQ Newbie
 
Registered: Mar 2016
Posts: 3

Rep: Reputation: Disabled
Error while loading shared library inside GDB


I am trying to debug a program with GDB. The program runs correctly when run freely. It uses the shared library libc.so.6 which is loaded at address 0x7efff08. But when i run the program in GDB, the loader loads the shared library libc.so.6 for the program at some other address. My program tries to read the library from the original address (0x07efff08), there it cannot find the ELF header, therefore gives error and terminates. (Invalid ELF header: could not load shared libc.so.6)

Note that I have disabled ASLR.

Is that something to do with shared library relocation? Both GDB and myprogram (being debugged) are using the same shared library. How can I make sure that the library is loaded at the same address space for my process when run inside GDB?
 
Old 02-02-2017, 12:05 PM   #2
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: Fedora 33
Posts: 3,602

Rep: Reputation: 1029Reputation: 1029Reputation: 1029Reputation: 1029Reputation: 1029Reputation: 1029Reputation: 1029Reputation: 1029
You could rebuild gdb with personality(ADDR_NO_RANDOMIZE) and load libc the same way you are doing it in your program.
 
Old 02-02-2017, 08:07 PM   #3
shakaiba
LQ Newbie
 
Registered: Mar 2016
Posts: 3

Original Poster
Rep: Reputation: Disabled
Apparently the macro ADDR_NO_RANDOMIZE defined in personality.h can be controlled by the gdb command "set disable-randomization on/off". I tried it.
Please see https://outflux.net/blog/archives/20...urns-off-aslr/
Moreover, while building GDB on my system the flag ADDR_NO_RANDOMIZE in /usr/include/linux/personality.h is already set.
 
  


Reply

Tags
gdb, library, relocation, shared object


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Error while loading shared library that is already there jesse_m Linux - Software 5 04-28-2016 06:59 AM
Error while loading shared library : libpng12.so.0 dhanilshah Linux - Software 5 08-18-2011 07:38 AM
Shared library libfrint.so loading error Jhvdb Linux - Software 8 09-13-2008 10:32 AM
error while loading shared library lucky6969b Programming 2 02-08-2006 12:41 AM
error while loading shared library bonniehandi Linux - Newbie 2 11-18-2005 11:43 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 09:04 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration