public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Siddhesh Poyarekar <siddhesh@gotplt.org>
To: Topi Miettinen <toiwoton@gmail.com>, libc-alpha@sourceware.org
Subject: Re: Randomize offset between program segments?
Date: Wed, 21 Oct 2020 15:24:04 +0530	[thread overview]
Message-ID: <c2e87d0b-3a0f-dc2c-0771-cadcf15dda5e@gotplt.org> (raw)
In-Reply-To: <d4414858-1656-96b3-bc7a-05b8487a6224@gmail.com>

On 10/21/20 3:04 PM, Topi Miettinen wrote:
> Why can't the dynamic linker calculate the offset?
> 

It can calculate, but to be able to patch the pc-relative load
instructions it will need the executable section to also be writable and
is a really bad idea.

The alternative (which is what PIC does for global variables) is to have
a GOT-like indirection, where instead of the single pc-relative load,
the compiler emits a load from that table and a subsequent load from the
address in GOT.  Here, patching by the dynamic linker is safe since the
offset table is rw, but you will have doubled the number of instructions
needed to access your data.

Hence the question: how much benefit does this provide on top of what is
achieved by randomizing the base address and does it justify doubling
the number of instructions to access static variables?

To be clear, that question is not rhetorical, I am genuinely curious and
would be interested in an answer to that if you explore this further.

Siddhesh

  reply	other threads:[~2020-10-21  9:54 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-19 15:31 Topi Miettinen
2020-10-21  2:21 ` Siddhesh Poyarekar
2020-10-21  7:40   ` Topi Miettinen
2020-10-21  9:14     ` Siddhesh Poyarekar
2020-10-21  9:34       ` Topi Miettinen
2020-10-21  9:54         ` Siddhesh Poyarekar [this message]
2020-10-21 10:44           ` Topi Miettinen
2020-10-29  8:04             ` Siddhesh Poyarekar
2020-10-30 15:37               ` Topi Miettinen
2020-10-21  5:33 ` Florian Weimer
2020-10-21  8:02   ` Topi Miettinen
2020-10-21  8:06     ` Florian Weimer
2020-10-21  9:28       ` Topi Miettinen

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=c2e87d0b-3a0f-dc2c-0771-cadcf15dda5e@gotplt.org \
    --to=siddhesh@gotplt.org \
    --cc=libc-alpha@sourceware.org \
    --cc=toiwoton@gmail.com \
    /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).