mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Michael Forney <mforney@mforney.org>
To: Rich Felker <dalias@libc.org>
Cc: musl@lists.openwall.com
Subject: Re: [musl] ld-musl-* and empty .eh_frame
Date: Fri, 5 Mar 2021 14:53:41 -0800	[thread overview]
Message-ID: <CAGw6cButdXa+Y49-FHtqRJR+Sv73iFvpnNPC39LMRnDfOTf8YQ@mail.gmail.com> (raw)
In-Reply-To: <20210305161256.GO32655@brightrain.aerifal.cx>

On 2021-03-05, Rich Felker <dalias@libc.org> wrote:
>> The section itself isn't the problem; rather the linker making a
>> dedicated PROT_READ segment with no non-zero-length sections in it is.
>> It really should have collapsed that out. (Also it would not happen
>> without the separate-text option, which mcm disables because it makes
>> lots of problems.)

Ah, that makes more sense. It explains why my attempt to strip
.eh_frame from the executable did not have an effect; only stripping
it from the objects before linking fixed the issue.

>> With that said, there's no good reason we should error out on this;
>> it's syntactically and semantically valid just pointless for the
>> linker to emit. I think adding if (!n) return p; at the top of
>> mmap_fixed in dynlink.c fixes it.
>
> In practice this probably does, but there's also something of a
> question what to do if the zero-size segment is not page aligned. This
> is not actually a mmap error since it will be automatically expanded
> out to page boundaries in both directions, but if ld is capable of
> emitting such segments they may be semantically wrong (mapping over
> top of something else they're not intended to). Can you confirm that
> ld isn't doing anything awful here?

I'm not too familiar with the binutils codebase, but I can try. As far
as I can tell, the alignment is set to at least the maximum page size:
https://sourceware.org/git/?p=binutils-gdb.git;a=blob;f=bfd/elf.c;h=84a5d942817a9a54b1170fbbb594787c5839aa54;hb=f35674005e609660f5f45005a9e095541ca4c5fe#l5601

The offset to make p_vaddr page-aligned is computed here:
https://sourceware.org/git/?p=binutils-gdb.git;a=blob;f=bfd/elf.c;h=84a5d942817a9a54b1170fbbb594787c5839aa54;hb=f35674005e609660f5f45005a9e095541ca4c5fe#l5622

and p_vaddr is adjusted here:
https://sourceware.org/git/?p=binutils-gdb.git;a=blob;f=bfd/elf.c;h=84a5d942817a9a54b1170fbbb594787c5839aa54;hb=f35674005e609660f5f45005a9e095541ca4c5fe#l5688

So it seems to me that these segments will be page-aligned, but it
could very well be the case that I am not following the code correctly
(or I am just looking at the wrong part of this 13k line file).
Someone more familiar with binutils should probably confirm.

  reply	other threads:[~2021-03-05 22:53 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-05  3:18 Michael Forney
2021-03-05 15:07 ` Rich Felker
2021-03-05 16:12   ` Rich Felker
2021-03-05 22:53     ` Michael Forney [this message]
2021-03-06  1:14       ` Fangrui Song
2021-03-06  1:28         ` Rich Felker
2021-03-06  1:30         ` Michael Forney
2021-03-06  1:39           ` Fangrui Song
2021-03-06  2:04             ` Michael Forney
2021-03-06  2:09               ` Fangrui Song

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=CAGw6cButdXa+Y49-FHtqRJR+Sv73iFvpnNPC39LMRnDfOTf8YQ@mail.gmail.com \
    --to=mforney@mforney.org \
    --cc=dalias@libc.org \
    --cc=musl@lists.openwall.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.
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).