diff options
author | Tim Schumacher <timschumi@gmx.de> | 2022-04-22 13:34:43 +0200 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-05-07 20:02:00 +0200 |
commit | 89da0f2da526d027d8daf2f155f748683a85ef07 (patch) | |
tree | 655f83debc73350d4877ea2fcda5da88848c402e | |
parent | 2b7b7f281697dac93fac921c128ccccee9a1dd96 (diff) | |
download | serenity-89da0f2da526d027d8daf2f155f748683a85ef07.zip |
LibELF: Name library maps with the full file path
-rw-r--r-- | Userland/Libraries/LibELF/DynamicLinker.cpp | 10 | ||||
-rw-r--r-- | Userland/Libraries/LibELF/DynamicLoader.cpp | 15 | ||||
-rw-r--r-- | Userland/Libraries/LibELF/DynamicLoader.h | 5 | ||||
-rw-r--r-- | Userland/Utilities/readelf.cpp | 2 |
4 files changed, 17 insertions, 15 deletions
diff --git a/Userland/Libraries/LibELF/DynamicLinker.cpp b/Userland/Libraries/LibELF/DynamicLinker.cpp index 79f7fc5aff..0c2ff31fa1 100644 --- a/Userland/Libraries/LibELF/DynamicLinker.cpp +++ b/Userland/Libraries/LibELF/DynamicLinker.cpp @@ -84,9 +84,9 @@ static String get_library_name(String path) return LexicalPath::basename(move(path)); } -static Result<NonnullRefPtr<DynamicLoader>, DlErrorMessage> map_library(String const& filename, int fd) +static Result<NonnullRefPtr<DynamicLoader>, DlErrorMessage> map_library(String const& filename, int fd, String const& filepath) { - auto result = ELF::DynamicLoader::try_create(fd, filename); + auto result = ELF::DynamicLoader::try_create(fd, filename, filepath); if (result.is_error()) { return result; } @@ -136,7 +136,7 @@ static Result<NonnullRefPtr<DynamicLoader>, DlErrorMessage> map_library(String c 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); + return map_library(name, fd, name); } auto resolved_library_name = resolve_library(name, parent_object); @@ -147,7 +147,7 @@ static Result<NonnullRefPtr<DynamicLoader>, DlErrorMessage> map_library(String c if (fd < 0) return DlErrorMessage { String::formatted("Could not open resolved shared library '{}': {}", resolved_library_name.value(), strerror(errno)) }; - return map_library(name, fd); + return map_library(name, fd, resolved_library_name.value()); } static Vector<String> get_dependencies(String const& name) @@ -559,7 +559,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); + auto result1 = map_library(main_program_name, main_program_fd, main_program_name); if (result1.is_error()) { warnln("{}", result1.error().text); fflush(stderr); diff --git a/Userland/Libraries/LibELF/DynamicLoader.cpp b/Userland/Libraries/LibELF/DynamicLoader.cpp index 120d52f6ab..ca9f442aa8 100644 --- a/Userland/Libraries/LibELF/DynamicLoader.cpp +++ b/Userland/Libraries/LibELF/DynamicLoader.cpp @@ -37,7 +37,7 @@ static void* mmap_with_name(void* addr, size_t length, int prot, int flags, int namespace ELF { -Result<NonnullRefPtr<DynamicLoader>, DlErrorMessage> DynamicLoader::try_create(int fd, String filename) +Result<NonnullRefPtr<DynamicLoader>, DlErrorMessage> DynamicLoader::try_create(int fd, String filename, String filepath) { struct stat stat; if (fstat(fd, &stat) < 0) { @@ -49,20 +49,21 @@ Result<NonnullRefPtr<DynamicLoader>, DlErrorMessage> DynamicLoader::try_create(i if (size < sizeof(ElfW(Ehdr))) return DlErrorMessage { String::formatted("File {} has invalid ELF header", filename) }; - String file_mmap_name = String::formatted("ELF_DYN: {}", filename); + String file_mmap_name = String::formatted("ELF_DYN: {}", filepath); auto* data = mmap_with_name(nullptr, size, PROT_READ, MAP_SHARED, fd, 0, file_mmap_name.characters()); if (data == MAP_FAILED) { return DlErrorMessage { "DynamicLoader::try_create mmap" }; } - auto loader = adopt_ref(*new DynamicLoader(fd, move(filename), data, size)); + auto loader = adopt_ref(*new DynamicLoader(fd, move(filename), data, size, filepath)); if (!loader->is_valid()) return DlErrorMessage { "ELF image validation failed" }; return loader; } -DynamicLoader::DynamicLoader(int fd, String filename, void* data, size_t size) +DynamicLoader::DynamicLoader(int fd, String filename, void* data, size_t size, String filepath) : m_filename(move(filename)) + , m_filepath(move(filepath)) , m_file_size(size) , m_image_fd(fd) , m_file_data(data) @@ -236,7 +237,7 @@ Result<NonnullRefPtr<DynamicObject>, DlErrorMessage> DynamicLoader::load_stage_3 } #ifdef __serenity__ - if (set_mmap_name(m_relro_segment_address.as_ptr(), m_relro_segment_size, String::formatted("{}: .relro", m_filename).characters()) < 0) { + if (set_mmap_name(m_relro_segment_address.as_ptr(), m_relro_segment_size, String::formatted("{}: .relro", m_filepath).characters()) < 0) { return DlErrorMessage { String::formatted("set_mmap_name .relro: {}", strerror(errno)) }; } #endif @@ -344,7 +345,7 @@ void DynamicLoader::load_program_headers() FlatPtr ph_end = ph_base + round_up_to_power_of_two(region.size_in_memory() + region.desired_load_address().get() - ph_base, PAGE_SIZE); StringBuilder builder; - builder.append(m_filename); + builder.append(m_filepath); if (region.is_executable()) builder.append(": .text"); else @@ -396,7 +397,7 @@ void DynamicLoader::load_program_headers() MAP_ANONYMOUS | MAP_PRIVATE | MAP_FIXED, 0, 0, - String::formatted("{}: .data", m_filename).characters()); + String::formatted("{}: .data", m_filepath).characters()); if (MAP_FAILED == data_segment) { perror("mmap writable"); diff --git a/Userland/Libraries/LibELF/DynamicLoader.h b/Userland/Libraries/LibELF/DynamicLoader.h index db3ab6cfba..bc306481f6 100644 --- a/Userland/Libraries/LibELF/DynamicLoader.h +++ b/Userland/Libraries/LibELF/DynamicLoader.h @@ -42,7 +42,7 @@ enum class ShouldInitializeWeak { class DynamicLoader : public RefCounted<DynamicLoader> { public: - static Result<NonnullRefPtr<DynamicLoader>, DlErrorMessage> try_create(int fd, String filename); + static Result<NonnullRefPtr<DynamicLoader>, DlErrorMessage> try_create(int fd, String filename, String filepath); ~DynamicLoader(); String const& filename() const { return m_filename; } @@ -83,7 +83,7 @@ public: DynamicObject const& dynamic_object() const; private: - DynamicLoader(int fd, String filename, void* file_data, size_t file_size); + DynamicLoader(int fd, String filename, void* file_data, size_t file_size, String filepath); class ProgramHeaderRegion { public: @@ -135,6 +135,7 @@ private: ssize_t negative_offset_from_tls_block_end(ssize_t tls_offset, size_t value_of_symbol) const; String m_filename; + String m_filepath; size_t m_file_size { 0 }; int m_image_fd { -1 }; void* m_file_data { nullptr }; diff --git a/Userland/Utilities/readelf.cpp b/Userland/Utilities/readelf.cpp index 8403213c75..519c179647 100644 --- a/Userland/Utilities/readelf.cpp +++ b/Userland/Utilities/readelf.cpp @@ -336,7 +336,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) } int fd = TRY(Core::System::open(path, O_RDONLY)); - auto result = ELF::DynamicLoader::try_create(fd, path); + auto result = ELF::DynamicLoader::try_create(fd, path, path); if (result.is_error()) { outln("{}", result.error().text); return 1; |