-
-
Notifications
You must be signed in to change notification settings - Fork 470
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow multiple
.eh_frame
sections in a single object file
A `.eh_frame` section contains data for exception handling. Usually, an object file contains only one `.eh_frame` section, which explains how to handle exceptions for all text sections in the same object file. However, it appears that, in rare cases, we need to handle object files containing multiple `.eh_frame` sections. An example of this is the `/usr/lib/clang/17/lib/x86_64-redhat-linux-gnu/clang_rt.crtbegin.o` file, which is provided by the `compiler-rt` package of Fedora 39. Specifically, I'm using the `quay.io/fedora/fedora:39` Docker image. The file contains two `.eh_frame` sections. One `.eh_frame` in the file is of type `STT_X86_64_UNWIND` and the other is of `STT_PROGBITS`. It's possible that the file was created with `ld -r`, and the linker failed to merge the two incoming `.eh_frame` sections into one output section due to the difference in section types. We did not expect such inputs and consequently produced corrupted output files. This commit improves our linker so that mold can handle multiple `.eh_frame` sections in a single object file. Fixes #1157
- Loading branch information
Showing
4 changed files
with
100 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#!/bin/bash | ||
. $(dirname $0)/common.inc | ||
|
||
[ $MACHINE = m68k ] && skip | ||
[ $MACHINE = sh4 ] && skip | ||
|
||
cat <<EOF | $CXX -o $t/a.o -c -xc++ - | ||
int foo() { | ||
try { | ||
throw 1; | ||
} catch (int x) { | ||
return x; | ||
} | ||
return 2; | ||
} | ||
EOF | ||
|
||
cat <<EOF | $CXX -o $t/b.o -c -xc++ - | ||
int bar() { | ||
try { | ||
throw 3; | ||
} catch (int x) { | ||
return x; | ||
} | ||
return 4; | ||
} | ||
EOF | ||
|
||
$OBJCOPY --rename-section .eh_frame=.eh_frame2 $t/a.o | ||
./mold -r -o $t/c.o $t/a.o $t/b.o | ||
$OBJCOPY --rename-section .eh_frame2=.eh_frame $t/c.o | ||
|
||
cat <<EOF | $CXX -o $t/d.o -c -xc++ - | ||
#include <stdio.h> | ||
int foo(); | ||
int bar(); | ||
int main() { | ||
printf("%d %d\n", foo(), bar()); | ||
} | ||
EOF | ||
|
||
$CXX -B. -o $t/exe1 $t/d.o $t/c.o | ||
$QEMU $t/exe1 | ||
$QEMU $t/exe1 | grep -q '^1 3$' |