Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix crash when linking with libdl on arm with NEON
With -mfpu=neon, libdl got a badly aligned .init_array section which caused the dynamic linker to segfault when initializing any program that links to libdl. Added eglibc-2.15-fix-neon-libdl.patch to fix it. Signed-off-by: Richard Braakman <richard.braakman@jollamobile.com>
- Loading branch information
Showing
3 changed files
with
48 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
When compiled for arm with -mfpu=neon, the .init_array section declared | ||
here becomes 64-bit aligned. Since the dynamic linker expects an array of | ||
32-bit function pointers with no gaps, this causes an immediate SIGSEGV | ||
for any application linked with libdl. | ||
|
||
I suspect the default array alignment becomes 64 bits because the neon | ||
has 64-bit registers, but I'm not sure. The explicit aligned attribute | ||
does not help because it can only increase the alignment. | ||
|
||
Fortunately, the whole declaration can be replaced with a constructor | ||
attribute on the init function, which also adds it to the init_array | ||
table and does the right thing with alignment. | ||
|
||
(Why wasn't it this way already? I don't know, but maybe the constructor | ||
attribute wasn't available yet when this code was written.) | ||
|
||
Richard Braakman | ||
richard.braakman@jollamobile.com | ||
|
||
--- eglibc-2.15/dlfcn/dlfcn.c 2006-08-17 04:18:26.000000000 +0300 | ||
+++ glibc-fixed/dlfcn/dlfcn.c 2013-06-10 13:20:34.846885906 +0300 | ||
@@ -24,16 +24,9 @@ | ||
char **__dlfcn_argv attribute_hidden; | ||
|
||
|
||
-static void | ||
+static void __attribute ((constructor)) | ||
init (int argc, char *argv[]) | ||
{ | ||
__dlfcn_argc = argc; | ||
__dlfcn_argv = argv; | ||
} | ||
- | ||
-static void (*const init_array []) (int argc, char *argv[]) | ||
- __attribute__ ((section (".init_array"), aligned (sizeof (void *)))) | ||
- __attribute_used__ = | ||
-{ | ||
- init | ||
-}; |
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