summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorItamar <itamar8910@gmail.com>2021-04-26 21:11:34 +0300
committerAndreas Kling <kling@serenityos.org>2021-04-30 18:47:39 +0200
commit2c9541315de9322951a7476ecda75d44746c6c9d (patch)
treedda67dd18f2d986bc971e40a543d53730b67aed3 /Userland
parent6a12420d9dbc266f5cd1e8e18e0c2bcead423156 (diff)
downloadserenity-2c9541315de9322951a7476ecda75d44746c6c9d.zip
LibELF: Fix TLS offset calculation for libraries
This fixes a regression that was introduced in f40ee1b and caused the tls_offset of all objects other than the main program to be 0. After this fix map_library's is_program argument is no longer used, so it was removed.
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibELF/DynamicLinker.cpp21
1 files changed, 10 insertions, 11 deletions
diff --git a/Userland/Libraries/LibELF/DynamicLinker.cpp b/Userland/Libraries/LibELF/DynamicLinker.cpp
index 777444966d..520c3f4cf2 100644
--- a/Userland/Libraries/LibELF/DynamicLinker.cpp
+++ b/Userland/Libraries/LibELF/DynamicLinker.cpp
@@ -12,6 +12,7 @@
#include <AK/LexicalPath.h>
#include <AK/NonnullRefPtrVector.h>
#include <AK/ScopeGuard.h>
+#include <AK/Vector.h>
#include <LibC/bits/pthread_integration.h>
#include <LibC/link.h>
#include <LibC/mman.h>
@@ -75,7 +76,7 @@ static String get_library_name(String path)
return LexicalPath(move(path)).basename();
}
-static Result<NonnullRefPtr<DynamicLoader>, DlErrorMessage> map_library(const String& filename, int fd, bool is_program)
+static Result<NonnullRefPtr<DynamicLoader>, DlErrorMessage> map_library(const String& filename, int fd)
{
auto result = ELF::DynamicLoader::try_create(fd, filename);
if (result.is_error()) {
@@ -86,21 +87,19 @@ static Result<NonnullRefPtr<DynamicLoader>, DlErrorMessage> map_library(const St
s_loaders.set(get_library_name(filename), *loader);
- if (is_program) {
- loader->set_tls_offset(s_current_tls_offset);
- s_current_tls_offset += loader->tls_size();
- }
+ loader->set_tls_offset(s_current_tls_offset);
+ s_current_tls_offset += loader->tls_size();
return loader;
}
-static Result<NonnullRefPtr<DynamicLoader>, DlErrorMessage> map_library(const String& name, bool is_program)
+static Result<NonnullRefPtr<DynamicLoader>, DlErrorMessage> map_library(const String& name)
{
if (name.contains("/")) {
int fd = open(name.characters(), O_RDONLY);
if (fd < 0)
return DlErrorMessage { String::formatted("Could not open shared library: {}", name) };
- return map_library(name, fd, is_program);
+ return map_library(name, fd);
}
// TODO: Do we want to also look for libs in other paths too?
@@ -110,7 +109,7 @@ static Result<NonnullRefPtr<DynamicLoader>, DlErrorMessage> map_library(const St
int fd = open(path.characters(), O_RDONLY);
if (fd < 0)
continue;
- return map_library(name, fd, is_program);
+ return map_library(name, fd);
}
return DlErrorMessage { String::formatted("Could not find required shared library: {}", name) };
@@ -139,7 +138,7 @@ static Result<void, DlErrorMessage> map_dependencies(const String& name)
String library_name = get_library_name(needed_name);
if (!s_loaders.contains(library_name) && !s_global_objects.contains(library_name)) {
- auto result1 = map_library(needed_name, false);
+ auto result1 = map_library(needed_name);
if (result1.is_error()) {
return result1.error();
}
@@ -339,7 +338,7 @@ static Result<void*, DlErrorMessage> __dlopen(const char* filename, int flags)
VERIFY(!library_name.is_empty());
- auto result1 = map_library(filename, false);
+ auto result1 = map_library(filename);
if (result1.is_error()) {
return result1.error();
}
@@ -404,7 +403,7 @@ void ELF::DynamicLinker::linker_main(String&& main_program_name, int main_progra
// NOTE: We always map the main library first, since it may require
// placement at a specific address.
- auto result1 = map_library(main_program_name, main_program_fd, true);
+ auto result1 = map_library(main_program_name, main_program_fd);
if (result1.is_error()) {
warnln("{}", result1.error().text);
fflush(stderr);