-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
elf: Second ld.so relocation only if libc.so has been loaded
Commit 8f8dd90 (“elf: rtld_multiple_ref is always true”) removed some code that happened to enable compatibility with programs that do not link against libc.so. Such programs cannot call dlopen or any dynamic linker functions (except __tls_get_addr), so this is not really useful. Still ld.so should not crash with a null-pointer dereference or undefined symbol reference in these cases. In the main relocation loop, call _dl_relocate_object unconditionally because it already checks if the object has been relocated. If libc.so was loaded, self-relocate ld.so against it and call __rtld_mutex_init and __rtld_malloc_init_real to activate the full implementations. Those are available only if libc.so is there, so skip these initialization steps if libc.so is absent. Without libc.so, the global scope can be completely empty. This can cause ld.so self-relocation to fail because if it uses symbol-based relocations, which is why the second ld.so self-relocation is not performed if libc.so is missing. The previous concern regarding GOT updates through self-relocation no longer applies because function pointers are updated explicitly through __rtld_mutex_init and __rtld_malloc_init_real, and not through relocation. However, the second ld.so self-relocation is still delayed, in case there are other symbols being used. Fixes commit 8f8dd90 (“elf: rtld_multiple_ref is always true”). Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
- Loading branch information
1 parent
a257f20
commit 7062098
Showing
5 changed files
with
81 additions
and
34 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
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,25 @@ | ||
/* Test program not linked against libc.so and not using any glibc functions. | ||
Copyright (C) 2024 Free Software Foundation, Inc. | ||
This file is part of the GNU C Library. | ||
The GNU C Library is free software; you can redistribute it and/or | ||
modify it under the terms of the GNU Lesser General Public | ||
License as published by the Free Software Foundation; either | ||
version 2.1 of the License, or (at your option) any later version. | ||
The GNU C Library is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
Lesser General Public License for more details. | ||
You should have received a copy of the GNU Lesser General Public | ||
License along with the GNU C Library; if not, see | ||
<https://www.gnu.org/licenses/>. */ | ||
|
||
#include <sysdep.h> | ||
|
||
void | ||
_start (void) | ||
{ | ||
INTERNAL_SYSCALL_CALL (exit_group, 0); | ||
} |