mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@libc.org>
To: Michael Forney <mforney@mforney.org>
Cc: musl@lists.openwall.com
Subject: Re: [musl] ld-musl-* and empty .eh_frame
Date: Fri, 5 Mar 2021 10:07:32 -0500	[thread overview]
Message-ID: <20210305150730.GN32655@brightrain.aerifal.cx> (raw)
In-Reply-To: <2XR4N9WTZJRRB.388AF1JAC0M8E@mforney.org>

On Thu, Mar 04, 2021 at 07:18:11PM -0800, Michael Forney wrote:
> Hi,
> 
> Érico noticed that cproc (my C compiler) produced executables that
> musl's dynamic linker fails to load when passed as an argument:
> 
>   /lib/ld-musl-x86_64.so.1: ./t: Not a valid dynamic program
> 
> However, running ./t directly works fine. It turns out that this
> is because the executables have an empty .eh_frame section, which
> causes musl to attempt an mmap with length 0 which fails with EINVAL.

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.)

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.

> This leaves me with a few questions:
> 
> 1. Is it invalid for an ELF executable to have an empty .eh_frame
>    section? The only documentation I could find about it is [0],
>    which says that it must contain one or more CFI records, so 0
>    would be invalid.
> 2. Is it the compiler's responsibility to link with an object
>    containing a CIE terminator (like gcc's crtend.o) to prevent an
>    empty .eh_frame section?

Sections are irrelevant to an executable file so it doesn't matter
whatsoever. They're involved only in pre-link contracts and debugging.

> 3. Is it a bug that GNU ld creates an empty .eh_frame by default,
>    even when none of the objects it is linking have one? It looks
>    like lld does not create an .eh_frame in this case.

I don't think so. I think the bug is in the segment logic.

> 4. Should musl's ld.so be able to handle such executables? The
>    kernel does not seem to have a problem with it, as well glibc's
>    ld.so with an executable I crafted with a 0-length .eh_frame
>    section.

Yes.

Rich

  reply	other threads:[~2021-03-05 15:07 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 [this message]
2021-03-05 16:12   ` Rich Felker
2021-03-05 22:53     ` Michael Forney
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=20210305150730.GN32655@brightrain.aerifal.cx \
    --to=dalias@libc.org \
    --cc=mforney@mforney.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).