mailing list of musl libc
 help / color / mirror / code / Atom feed
From: 'Rich Felker' <dalias@aerifal.cx>
To: Weiming Zhao <weimingz@codeaurora.org>
Cc: musl@lists.openwall.com
Subject: Re: static PIE
Date: Wed, 30 Jul 2014 16:27:10 -0400	[thread overview]
Message-ID: <20140730202710.GN1674@brightrain.aerifal.cx> (raw)
In-Reply-To: <000001cfac2b$2030bd30$60923790$@codeaurora.org>

On Wed, Jul 30, 2014 at 12:19:03PM -0700, Weiming Zhao wrote:
> I just find a very interesting article written by you:
> 
> http://www.openwall.com/lists/musl/2012/05/24/1

This method is somewhat outdated. In particular, requiring a custom
linker script is a pain.

The new method is to use -shared instead of -pie to trick gcc that
it's generating a shared library (this will cause it to use a linker
mode that does not add a PT_INTERP header, and to omit crt1) and
manually add the needed Zcrt[12].o (no need to use -nostartfiles to
suppress others). The command line should look like:

gcc -shared -static-libgcc -Wl,-static -Wl,-Bsymbolic \
    Zcrt1.o Zcrt2.o [your object files...]

> I want to do the similar thing on ARM linux. I see _static_pie_reloc does
> the relocation, which would be done by loader in dynamic PIE.

Nice! Are you interested in trying to get this 'upstream' in gcc?
Technically it's not needed, but it would be nice if "-pie -static"
just did the right thing without the command line hackery.

> But with "-static", those reloc entries has already been fixed by ld.
> Without that, my code can still run but at fixed address space.

I don't think that should happen. Static linking objects (as long as
they're PIC/PIE) into a ET_DYN ELF file (.so or PIE executable) should
not result in fixed addresses but "relative" type relocations for the
dynamic linker.

> To get the benefit of PIE, there should be address randomization (at least
> for data sections), which should be done in startup code. Is my
> understanding right?

No, the kernel does the address randomization (the random base address
it loads the program at). The userspace side is just applying this
base address to the relative relocations in the rel/rela tables.

Rich


  reply	other threads:[~2014-07-30 20:27 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-30 19:19 Weiming Zhao
2014-07-30 20:27 ` 'Rich Felker' [this message]
2014-07-30 23:27   ` Weiming Zhao
2014-07-31  0:22     ` Weiming Zhao
     [not found]     ` <003501cfac55$8242fea0$86c8fbe0$@codeaurora.org>
2014-08-01  5:39       ` weimingz

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=20140730202710.GN1674@brightrain.aerifal.cx \
    --to=dalias@aerifal.cx \
    --cc=musl@lists.openwall.com \
    --cc=weimingz@codeaurora.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.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

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 NNTP newsgroup(s).