Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Fri, 5 Mar 2021 17:14:05 -0800
From: Fangrui Song <>
Cc: Rich Felker <>
Subject: Re: ld-musl-* and empty .eh_frame

On 2021-03-05, Michael Forney wrote:
>On 2021-03-05, Rich Felker <> 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?

Can you clarify how GNU ld creates an empty .eh_frame?
The program header PT_GNU_EH_FRAME is created from .eh_frame_hdr, which
is created by ld --eh-frame-hdr.
If .eh_frame is empty, from my observation GNU ld does not create .eh_frame_hdr

>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:

max-page-size is for layouting PT_LOAD.
It is unrelated to PT_GNU_EH_FRAME.

>The offset to make p_vaddr page-aligned is computed here:
>and p_vaddr is adjusted here:
>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.

The requirement is
"p_vaddr should equal p_offset, modulo p_align."

p_vaddr % p_align != 0 is valid.

p_memsz can be zero.

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.