History log of /haiku/src/system/runtime_loader/elf_load_image.cpp
Revision Date Author Comments
# 43d1a0dc 21-Mar-2024 Jérôme Duval <jerome.duval@gmail.com>

runtime_loader: Implement DT_RUNPATH

DT_RUNPATH is generated by the linker instead of DT_RPATH when using --enable-new-dtags
It seems to be the default when using ld.lld
Normally one difference is LD_LIBRARY_PATH is checked before DT_RUNPATH (and not with DT_RPATH),
but we don't check LD_LIBRARY_PATH at the moment. Checking LIBRARY_PATH isn't an option, because
runtime_loader dosesn't use default paths, test suites would define LIBRARY_PATH empty.
Tested with tcpdump build_matrix.sh script, with clang 17, local libpcap, which requires
--disable-new-dtags on r1beta4.

Change-Id: Iacccde8d20e25ad14c5c548dd8832ea32b67e228
Reviewed-on: https://review.haiku-os.org/c/haiku/+/7539
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>


# f83058d1 24-Sep-2023 X512 <danger_mail@list.ru>

elf: add PT_RISCV_ATTRIBUTES program header

Attribute is ignored for now.

It is supposed to check ABI compatiblity and reject loading incompatible images.
Haiku currently do not use multiple ABIs for RISC-V so it is safe to ignore attributes.

PT_RISCV_ATTRIBUTES program header is produced by default in GCC 13 and Clang 17.

Change-Id: I4659e9bacbf34a2a0bc16b34c2aaa37232d700fa
Reviewed-on: https://review.haiku-os.org/c/haiku/+/6948
Reviewed-by: David Karoly <karolyd577@gmail.com>
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
Reviewed-by: Alex von Gluck IV <kallisti5@unixzen.com>


# c5d3ca33 21-Mar-2022 David Karoly <karolyd577@gmail.com>

runtime_loader: ignore PT_ARM_UNWIND sections

Change-Id: I966e366c73d495c3b3396f0dd4b44bafaf5c77c5
Reviewed-on: https://review.haiku-os.org/c/haiku/+/5136
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
Reviewed-by: Adrien Destugues <pulkomandy@gmail.com>


# 6846668f 16-Oct-2021 Adrien Destugues <pulkomandy@pulkomandy.tk>

runime_loader: fix typo from hrev55497


# 13241731 09-Oct-2021 Adrien Destugues <pulkomandy@pulkomandy.tk>

runtime_loader: improve error message

When a library is not found, it is useful to know why it was linked in
by showing the previous link in the dependency chain. We had the
information available, but did not use it in the error message.


# 3d7fbc1a 08-Jan-2020 X512 <danger_mail@list.ru>

runtime_loader: allow loading executables without section table

Change-Id: I4bfee1d1aa40730586123a70fb480ee91787c15d
Reviewed-on: https://review.haiku-os.org/c/haiku/+/2089
Reviewed-by: Jérôme Duval <jerome.duval@gmail.com>


# be06cb25 11-Sep-2019 Jérôme Duval <jerome.duval@gmail.com>

libroot: make API version available.

Change-Id: I370d5c8e9b4f076e7f115ca6c87bc7f943d36c17
Reviewed-on: https://review.haiku-os.org/c/haiku/+/1850
Reviewed-by: Rene Gollent <rene@gollent.com>


# ef593f61 24-Nov-2018 Augustin Cavalier <waddlesplash@gmail.com>

ELF: Ignore PT_EH_FRAME and PT_STACK.

This allows Clang builds (linked with our cross binutils) to
at least start runtime_loader and then try to load launch_daemon.
That fails with an infinite loop somewhere...


# 0594302a 01-Aug-2018 Jérôme Duval <jerome.duval@gmail.com>

runtime_loader: <x86>runtime_loader can handle x86_gcc2 binaries.

* <x86_gcc2>runtime_loader can also handle x86 binaries.
* At the moment the x86_64 kernel will execute the x86 runtime_loader
when it sees x86 and x86_gcc2 binaries. The reason is checking the GCC
version of a binary in the kernel seems cumbersome, the kernel should
just fallback using the x86_gcc2 runtime_loader when the x86 one is missing.


# 2aaad308 02-May-2018 Jérôme Duval <jerome.duval@gmail.com>

runtime_loader: enable elf32 on x86_64, elf64 on x86.

use x86 as default sSearchPathSubDir in compatibility mode.
use the generic memset/memcpy when x86_64 is the primary arch.

Change-Id: Ib464c308ff97f7ae2482ef4c037de1b1bb2bf61b


# df9bc792 22-Nov-2017 Augustin Cavalier <waddlesplash@gmail.com>

runtime_loader: Set sSearchPathSubDir on first image, not on app image.

Under normal conditions this will behave identically. But when using LD_PRELOAD
or the like, some shared objects (and dependencies) are loaded before the
app image is, and on the secondary arch on hybrid builds, will fail to load
any of their dependencies due to sSearchPathSubDir not being set.

Fixes #12214, which had plagued users of libroot_debug for a long time now.


# e340f717 11-Oct-2016 Jérôme Duval <jerome.duval@gmail.com>

runtime_loader: add support for ELF init/term routine arrays.

* binutils 2.27 defaults to DT_INIT_ARRAY instead of DT_INIT.


# 8efb6db7 06-Aug-2016 Adrien Destugues <pulkomandy@gmail.com>

elf.h: rename ELF_MAGIC to ELFMAG

- This is how it is named in other versions of elf.h (Linux, glibc, possibly more)
- ELF_MAGIC is used by libelf for the same thing, and the defines conflicts,
breaking libelf build on Haiku.


# 6c009cde 28-Oct-2015 Jérôme Duval <jerome.duval@gmail.com>

kernel: avoid dprintf messages for known header types we don't use.

* fix a typo in runtime_loader/count_regions().


# 078b88b1 21-Oct-2015 Simon South <ssouth@simonsouth.com>

runtime_loader: Randomly position only relocatable code

The use of an unreliable test for relocatability effectively broke
runtime_loader's support for non-position-independent executables, as it
would insist on randomly positioning these files' segments in memory
anyway causing the program to quickly crash.

With this change runtime_loader uses the object type specified in the
file's header to determine whether its segments can be safely relocated,
restoring support for non-PI executables.

Fixes #12427.

Signed-off-by: Adrien Destugues <pulkomandy@pulkomandy.tk>


# 949cf6ac 19-Apr-2015 Murai Takashi <tmurai01@gmail.com>

Fix GCC 5 build.

* Add -fgnu89-inline flag for libroot/posix/glibc
* Change __GNUC__ == 4 to __GNUC__ >= 4

Signed-off-by: Adrien Destugues <pulkomandy@pulkomandy.tk>

Fixes #11990, most of the changes had already been done.


# 37f558d5 01-Aug-2014 Oliver Tappe <zooey@hirschkaefer.de>

Let runtime_loader ignore RT_RELRO program headers.

* The new libstdc++.so contains program headers of type PT_RELRO (for
making segments read-only after relocation). While the actual feature
has not been implemented, the runtime_loader should now silently
accept (and ignore) those program headers.


# 44c0c4d3 03-May-2014 Pawel Dziepak <pdziepak@quarnos.org>

runtime_loader: add support for ELF based TLS

This patch introduces support of ELF based TLS handling with lazy allocation
and initalization of TLS block for each DSO and thread. The implementation
generally follows the official ABI except that generation counter in dtv
is in fact a pointer to Generation object that contains both generation
counter and size of the dtv. That simplified the implementation a bit, but
could be changed later. The ABI requirements regariding in memory position
of TLS block is not honoured what results in static TLS model being
unsupported. However, that should not be a problem as long as
"executables" in Haiku are in fact shared objects and optimizations which
require specific TLS block in memory layout are not possible anyway.


# 8d23c440 26-Nov-2013 Ingo Weinhold <ingo_weinhold@gmx.de>

runtime loader: Add support for $ORIGIN in rpath

Like in Linux it resolves to the directory of the shared object whose
needed library is to be loaded.


# ded25be1 03-Oct-2013 Ingo Weinhold <ingo_weinhold@gmx.de>

runtime loader: 64-bit ktrace output fixes


# bddca418 05-Aug-2013 Ingo Weinhold <ingo_weinhold@gmx.de>

runtime loader: fix secondary arch search paths


# 5d0a1da8 14-May-2013 Pawel Dziepak <pdziepak@quarnos.org>

libroot: make all areas executable for old binaries

* If at least one image is either B_HAIKU_ABI_GCC_2_ANCIENT or
B_HAIKU_ABI_GCC_2_BEOS almost all areas are marked as executable.
* B_EXECUTE_AREA and B_STACK_AREA are made public. The former is enforced since
the introduction of DEP and apps need it to correctly set area protection.
The latter is currently needed only to recognize stack areas and fix their
protection in compatibility mode, but may also be useful if an app wants
to use sigaltstack from POSIX API.


# 26b24237 23-Apr-2013 Pawel Dziepak <pdziepak@quarnos.org>

runtime_loader: Always map program image at random position


# d2c8db26 04-Nov-2012 Axel Dörfler <axeld@pinc-software.de>

Just ignore unknown ELF program headers instead of failing.

* This fixes loading executables with a TLS section (which we do not support
so far, though). Still, no reason to let the runtime loader choke on it.


# e3ac2588 25-Jul-2012 Alex Smith <alex@alex-smith.me.uk>

Changed runtime_loader to use elf_* typedefs over Elf32_*.

This means that it will be using ELF64 types on x86_64 rather than
ELF32. The next step for supporting x86_64 is to implement relocations.


# 25dc253d 22-Nov-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

* Merged weak-symbols branch.
* Fixed trivial merge conflict in src/system/libroot/posix/locale/nl_langinfo.cpp
* Fixed gcc 2 compilation of src/system/glue/init_term_dyn.c.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39571 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 9704a425 27-Dec-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

When pre-loading stuff, we must not access gProgramImage unchecked.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34785 a95241bf-73f2-0310-859d-f6bbb57e9c96


# c533f813 27-May-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

Normalized the FATAL messages. The image path is always printed, now.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30878 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 94830eb2 20-May-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

* Moved most code of the heavy elf.cpp into several smaller source files.
* Some style cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30808 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 37f558d5a3e922f02d526c08bfc91594b79dcb10 01-Aug-2014 Oliver Tappe <zooey@hirschkaefer.de>

Let runtime_loader ignore RT_RELRO program headers.

* The new libstdc++.so contains program headers of type PT_RELRO (for
making segments read-only after relocation). While the actual feature
has not been implemented, the runtime_loader should now silently
accept (and ignore) those program headers.


# 44c0c4d3d0d68c3c3db23858b1089d3cf51bdf16 03-May-2014 Pawel Dziepak <pdziepak@quarnos.org>

runtime_loader: add support for ELF based TLS

This patch introduces support of ELF based TLS handling with lazy allocation
and initalization of TLS block for each DSO and thread. The implementation
generally follows the official ABI except that generation counter in dtv
is in fact a pointer to Generation object that contains both generation
counter and size of the dtv. That simplified the implementation a bit, but
could be changed later. The ABI requirements regariding in memory position
of TLS block is not honoured what results in static TLS model being
unsupported. However, that should not be a problem as long as
"executables" in Haiku are in fact shared objects and optimizations which
require specific TLS block in memory layout are not possible anyway.


# 8d23c440f7b0433f0daccf7e4018f99b8d3c3459 26-Nov-2013 Ingo Weinhold <ingo_weinhold@gmx.de>

runtime loader: Add support for $ORIGIN in rpath

Like in Linux it resolves to the directory of the shared object whose
needed library is to be loaded.


# ded25be1979db83060a21d11762502c178c77af9 03-Oct-2013 Ingo Weinhold <ingo_weinhold@gmx.de>

runtime loader: 64-bit ktrace output fixes


# bddca41824861df4c978b347099dd46ad4b14193 05-Aug-2013 Ingo Weinhold <ingo_weinhold@gmx.de>

runtime loader: fix secondary arch search paths


# 5d0a1da8bf914d4a26bba97ba40cbb36bf99ce52 14-May-2013 Pawel Dziepak <pdziepak@quarnos.org>

libroot: make all areas executable for old binaries

* If at least one image is either B_HAIKU_ABI_GCC_2_ANCIENT or
B_HAIKU_ABI_GCC_2_BEOS almost all areas are marked as executable.
* B_EXECUTE_AREA and B_STACK_AREA are made public. The former is enforced since
the introduction of DEP and apps need it to correctly set area protection.
The latter is currently needed only to recognize stack areas and fix their
protection in compatibility mode, but may also be useful if an app wants
to use sigaltstack from POSIX API.


# 26b2423794219b1fa70cc486a24787ed6a3a2921 23-Apr-2013 Pawel Dziepak <pdziepak@quarnos.org>

runtime_loader: Always map program image at random position


# d2c8db267dd912f719bb582acc14c8c521eac15c 04-Nov-2012 Axel Dörfler <axeld@pinc-software.de>

Just ignore unknown ELF program headers instead of failing.

* This fixes loading executables with a TLS section (which we do not support
so far, though). Still, no reason to let the runtime loader choke on it.


# e3ac2588e64059e0c140504e9acc8e73b3c36fdc 25-Jul-2012 Alex Smith <alex@alex-smith.me.uk>

Changed runtime_loader to use elf_* typedefs over Elf32_*.

This means that it will be using ELF64 types on x86_64 rather than
ELF32. The next step for supporting x86_64 is to implement relocations.


# 25dc253d6ab28ce204fa4de2d3e7a27d167fc817 22-Nov-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

* Merged weak-symbols branch.
* Fixed trivial merge conflict in src/system/libroot/posix/locale/nl_langinfo.cpp
* Fixed gcc 2 compilation of src/system/glue/init_term_dyn.c.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39571 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 9704a425ea92a2662b1c26eca9819c18b5044c0a 27-Dec-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

When pre-loading stuff, we must not access gProgramImage unchecked.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34785 a95241bf-73f2-0310-859d-f6bbb57e9c96


# c533f813a2c1392f51f8a0f803ab41775817d530 27-May-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

Normalized the FATAL messages. The image path is always printed, now.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30878 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 94830eb226ce51bd1fd0143bad2538f788883e85 20-May-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

* Moved most code of the heavy elf.cpp into several smaller source files.
* Some style cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30808 a95241bf-73f2-0310-859d-f6bbb57e9c96