1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 01:47:35 +00:00

LibELF: Take TLS segment alignment into account in DynamicLoader

Previously we would just tightly pack the different libraries' TLS
segments together, but that is incorrect, as they might require some
kind of minimum alignment for their TLS base address.

We now plumb the required TLS segment alignment down to the TLS block
linear allocator and align the base address down to the appropriate
alignment.
This commit is contained in:
Idan Horowitz 2022-07-05 01:18:40 +03:00 committed by Andreas Kling
parent 33214c29d3
commit 753844ec96
3 changed files with 19 additions and 12 deletions

View file

@ -67,6 +67,7 @@ public:
void set_tls_offset(size_t offset) { m_tls_offset = offset; };
size_t tls_size_of_current_object() const { return m_tls_size_of_current_object; }
size_t tls_alignment_of_current_object() const { return m_tls_alignment_of_current_object; }
size_t tls_offset() const { return m_tls_offset; }
const ELF::Image& image() const { return *m_elf_image; }
@ -134,7 +135,7 @@ private:
};
RelocationResult do_relocation(DynamicObject::Relocation const&, ShouldInitializeWeak should_initialize_weak);
void do_relr_relocations();
size_t calculate_tls_size() const;
void find_tls_size_and_alignment();
ssize_t negative_offset_from_tls_block_end(ssize_t tls_offset, size_t value_of_symbol) const;
String m_filename;
@ -157,6 +158,7 @@ private:
ssize_t m_tls_offset { 0 };
size_t m_tls_size_of_current_object { 0 };
size_t m_tls_alignment_of_current_object { 0 };
Vector<DynamicObject::Relocation> m_unresolved_relocations;