public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@polymtl.ca>
To: rodney.m.bates@acm.org, gdb@sourceware.org
Subject: Re: Change in relocation of debug info
Date: Mon, 31 May 2021 11:08:42 -0400	[thread overview]
Message-ID: <83239e44-c732-7dad-56b6-b12c98dc6795@polymtl.ca> (raw)
In-Reply-To: <f183a233-a401-17c4-32e4-74c479860510@lcwb.coop>

> When I link using gcc 5.4:
> 
>   $gcc --version:
>   gcc (Ubuntu 5.4.0-6ubuntu1~16.04.12) 5.4.0 20160609,
> 
> giving executable named prog I see:
> 
>   $objdump -g prog
>   ...
>   /* file ../src/SetElem.m3 line 11 addr 0x4008ee */
>   ...

> But when linking with gcc 9.3:
> 
>   $gcc --version:
>   gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0
> 
> I see:
> 
>   $objdump -g prog
>   ...
>   /* file ../src/SetElem.m3 line 11 addr 0x9b1 */

It just sounds like your gcc 9.3.0 is producing position-indenpendent
executables by default, whereas your gcc 5.4.0 did not.  In the recent
years, this has become the norm.

The executable produced by your gcc 5.4.0 is made to always be loaded at
the same address, so the code at virtual address 0x4008ee in the
executable will always end up at address 0x4008ee in the virtual address
space of the process.

With the executable produced by your gcc 9.3.0, the OS / dynamic linker
will choose a different random base address for the executable
every time it's loaded (except when address randomization is disabled,
which GDB tries to do by default, then it will always be the same random
address).  So the virtual address 0x9b1 in the executable will end up at
<load address> + 0x9b1 in the virtual address space of the process.  GDB
has to account for that: detect the load address of the executable,
adjust the addresses of the symbols.

This works for DWARF but doesn't seem to work for stabs for some reason
(based on what you have shown, I didn't try it myself).  I don't know
how difficult it would be to make it work for stabs, but it's unlikely
that anybody working on GDB will do it, given that stabs is pretty much
a dead format.  You can try if you want though.

An alternative is to instruct your gcc 9.3.0 to produce good old
position-dependent executables, as your gcc 5.4.0 does.  This is done
using -fno-pie at link time, IIRC.

Simon

  reply	other threads:[~2021-05-31 15:08 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-30 17:51 Rodney M. Bates
2021-05-31 15:08 ` Simon Marchi [this message]
2021-06-03 18:54   ` Rodney M. Bates
2021-06-03 19:02     ` Simon Marchi
2021-06-03 19:41       ` Rodney M. Bates

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=83239e44-c732-7dad-56b6-b12c98dc6795@polymtl.ca \
    --to=simon.marchi@polymtl.ca \
    --cc=gdb@sourceware.org \
    --cc=rodney.m.bates@acm.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).