Mirror of the gdb mailing list
 help / color / mirror / Atom feed
* GDB confused by -shared object executable
@ 2007-09-28 16:05 Alex Bennee
  2007-09-28 16:29 ` Daniel Jacobowitz
  0 siblings, 1 reply; 5+ messages in thread
From: Alex Bennee @ 2007-09-28 16:05 UTC (permalink / raw)
  To: gdb; +Cc: binutils

Hi,

For reasons of necessity we wanted out executable to run at the top of
64 bit memory space. This is because we want to stay out of the 32bit
memory space. We achieved this by building with:

CFLAGS =  -fpic -shared 
LDFLAGS =  -Wl,-e,_start

All this works fine (with a little hackage to initialise like a
library). However it confuses the hell out of GDB should we ever want to
do any debugging:

$ gdb ourprog
This GDB was configured as "x86_64-linux-gnu"...
Using host libthread_db library "/lib/libthread_db.so.1".
(gdb) start
Breakpoint 1 at 0x32e753: file ourprog/main.cc, line 67.
Starting program: ourprog
Warning:
Cannot insert breakpoint 1.
Error accessing memory address 0x32e753: Input/output error.

This is to be expected of course as our executable live way up high:

$ cat /proc/123456/map
<snip>
2b8268e6a000-2b8268fb1000 r-xp 00000000 08:01 1733565                    /lib/libc-2.5.so
2b8268fb1000-2b82691b1000 ---p 00147000 08:01 1733565                    /lib/libc-2.5.so
2b82691b1000-2b82691b4000 r-xp 00147000 08:01 1733565                    /lib/libc-2.5.so
2b82691b4000-2b82691b6000 rwxp 0014a000 08:01 1733565                    /lib/libc-2.5.so
2b82691b6000-2b82691bd000 rwxp 2b82691b6000 00:00 0 
2b82691bd000-2b82691be000 ---p 2b82691bd000 00:00 0 
2b82691be000-2b82692fe000 rwxp 2b82691be000 00:00 0 
2b82692fe000-2b82692ff000 r-xp 00000000 00:12 29833155                   /tmp/dynaEcmyWf (deleted)
2b82692ff000-2b82695c3000 rwxp 2b82692ff000 00:00 0 
555555554000-555555a32000 r-xp 00000000 08:04 12649433                   ourprog
555555b32000-555555b79000 rwxp 004de000 08:04 12649433                   ourprog
555555b79000-555555c77000 rwxp 555555b79000 00:00 0                      [heap]
7fff42c04000-7fff42c1a000 rwxp 7fff42c04000 00:00 0                      [stack]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0                  [vdso]

Running the binary with "r" works fine although you can't set any breakpoints in the code.
I suspect this is because the symbols in our shared object are relative.
It looks like the add-symbol-file should be able to handle this but I'm
not seeing it work.

(gdb) add-symbol-file ourprog 0x555555554000
add symbol table from file "ourprog" at
        .text_addr = 0x555555554000
(y or n) y
Reading symbols from ourprog...done
(gdb) x/5i main
0x32e740 <main>:        push   %rbp
0x32e741 <main+1>:      mov    %rsp,%rbp

Which doesn't seem to work. So questions:

1. Am I using the correct instantiation to load symbols at a particular
address?
2. Should GDB check the ELF when it loads it to see if it is an
executable shared object?

-- 
Alex, homepage: http://www.bennee.com/~alex/
"By golly, I'm beginning to think Linux really *is* the best thing since
sliced bread." (By Vance Petree, Virginia Power)


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: GDB confused by -shared object executable
  2007-09-28 16:05 GDB confused by -shared object executable Alex Bennee
@ 2007-09-28 16:29 ` Daniel Jacobowitz
  2007-09-28 16:31   ` Alex Bennee
  0 siblings, 1 reply; 5+ messages in thread
From: Daniel Jacobowitz @ 2007-09-28 16:29 UTC (permalink / raw)
  To: Alex Bennee; +Cc: gdb, binutils

On Fri, Sep 28, 2007 at 05:02:37PM +0100, Alex Bennee wrote:
> Which doesn't seem to work. So questions:
> 
> 1. Am I using the correct instantiation to load symbols at a particular
> address?
> 2. Should GDB check the ELF when it loads it to see if it is an
> executable shared object?

Red Hat (Elena, I think) long ago implemented support for PIE in GDB.
What you're doing is basically the same thing.  So far, no one has
gotten around to merging that support to the FSF releases.

I think it's in both the Red Hat and Ubuntu packages nowadays.

-- 
Daniel Jacobowitz
CodeSourcery


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: GDB confused by -shared object executable
  2007-09-28 16:29 ` Daniel Jacobowitz
@ 2007-09-28 16:31   ` Alex Bennee
  2007-09-28 17:56     ` Daniel Jacobowitz
  0 siblings, 1 reply; 5+ messages in thread
From: Alex Bennee @ 2007-09-28 16:31 UTC (permalink / raw)
  To: Daniel Jacobowitz; +Cc: gdb, binutils

On Fri, 2007-09-28 at 12:05 -0400, Daniel Jacobowitz wrote:
> On Fri, Sep 28, 2007 at 05:02:37PM +0100, Alex Bennee wrote:
> > Which doesn't seem to work. So questions:
> > 
> > 1. Am I using the correct instantiation to load symbols at a particular
> > address?
> > 2. Should GDB check the ELF when it loads it to see if it is an
> > executable shared object?
> 
> Red Hat (Elena, I think) long ago implemented support for PIE in GDB.
> What you're doing is basically the same thing.  So far, no one has
> gotten around to merging that support to the FSF releases.
> 
> I think it's in both the Red Hat and Ubuntu packages nowadays.

I can't speak for RedHat but it doesn't seem to be in my Ubuntu setup:

17:24 alexjb@murta/x86_64 [testcases] >gdb --version
GNU gdb 6.6-debian

I'll see if I can track down a patch from the RedHat srpms...

-- 
Alex, homepage: http://www.bennee.com/~alex/
The Force is what holds everything together. It has its dark side, and
it has its light side. It's sort of like cosmic duct tape.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: GDB confused by -shared object executable
  2007-09-28 16:31   ` Alex Bennee
@ 2007-09-28 17:56     ` Daniel Jacobowitz
  2007-10-01 10:22       ` Alex Bennee
  0 siblings, 1 reply; 5+ messages in thread
From: Daniel Jacobowitz @ 2007-09-28 17:56 UTC (permalink / raw)
  To: Alex Bennee; +Cc: gdb, binutils

On Fri, Sep 28, 2007 at 05:30:28PM +0100, Alex Bennee wrote:
> I can't speak for RedHat but it doesn't seem to be in my Ubuntu setup:

I think Matthias added it very recently.  Or, perhaps it's not quite
enough to work in your case :-(

-- 
Daniel Jacobowitz
CodeSourcery


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: GDB confused by -shared object executable
  2007-09-28 17:56     ` Daniel Jacobowitz
@ 2007-10-01 10:22       ` Alex Bennee
  0 siblings, 0 replies; 5+ messages in thread
From: Alex Bennee @ 2007-10-01 10:22 UTC (permalink / raw)
  To: Daniel Jacobowitz; +Cc: gdb, binutils

On Fri, 2007-09-28 at 12:31 -0400, Daniel Jacobowitz wrote:
> On Fri, Sep 28, 2007 at 05:30:28PM +0100, Alex Bennee wrote:
> > I can't speak for RedHat but it doesn't seem to be in my Ubuntu setup:
> 
> I think Matthias added it very recently.  Or, perhaps it's not quite
> enough to work in your case :-(

I tried the 6.6.dfsg-1ubuntu7 package which contains the patch
patches/pie-support.patch but unfortunately it still doesn't work. I
haven't got time to poke around the internals of GDB at the moment so
I'll have to try another work around.

I've added a comment to problem report 2069 which documents the issue.

-- 
Alex, homepage: http://www.bennee.com/~alex/
"Engineering without management is art." -- Jeff Johnson


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2007-10-01 10:22 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-09-28 16:05 GDB confused by -shared object executable Alex Bennee
2007-09-28 16:29 ` Daniel Jacobowitz
2007-09-28 16:31   ` Alex Bennee
2007-09-28 17:56     ` Daniel Jacobowitz
2007-10-01 10:22       ` Alex Bennee

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox