Skip to content

Commit

Permalink
Always create a .eh_frame section even if it's empty
Browse files Browse the repository at this point in the history
glibc's `__register_frame_info_bases` expect that it can read a terminator
if a .eh_frame is empty. Removing the section completely caused a crash bug
on Alpine Linux with musl as libc.

Specifically, mold-generated binaries crash if all the following
condition were met:

 1. musl is used as a libc
 2. .eh_frame is empty
 3. libgcc_s.so is linked

Prior to 06b5926, condition (3) was not
usually satisfied, so we didn't notice this issue. Now, the shared library
is linked against almost all output files because the file is referenced by
`__deregister_frame_info`.

https://github.com/bminor/glibc/blob/910aae6e5a2196938fc30fa54dd1e96f16774ce7/sysdeps/generic/unwind-dw2-fde.c#L105-L107

Fixes #1309
  • Loading branch information
rui314 committed Jul 19, 2024
1 parent 14d525c commit 14a4b05
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 26 deletions.
8 changes: 0 additions & 8 deletions elf/output-chunks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2208,14 +2208,6 @@ template <typename E>
void EhFrameSection<E>::construct(Context<E> &ctx) {
Timer t(ctx, "eh_frame");

// If .eh_frame is missing in all input files, we don't want to
// create an output .eh_frame section.
if (std::all_of(ctx.objs.begin(), ctx.objs.end(),
[](ObjectFile<E> *file) { return file->cies.empty(); })) {
this->shdr.sh_size = 0;
return;
}

// Remove dead FDEs and assign them offsets within their corresponding
// CIE group.
tbb::parallel_for_each(ctx.objs, [&](ObjectFile<E> *file) {
Expand Down
18 changes: 0 additions & 18 deletions test/elf/relocatable-no-ehframe.sh

This file was deleted.

0 comments on commit 14a4b05

Please sign in to comment.