From: Waldemar Kozaczuk <jwkozac...@gmail.com>
Committer: Nadav Har'El <n...@scylladb.com>
Branch: master
elf: handle new DT_RUNPATH
This patch enhances dynamic linker to resolve dependent
objects that rely on DT_RUNPATH entry to specify directories to search for.
Some ELFs have both DT_RUNPATH and DT_RPATH in which case our
linker disregards the latter per specification.
For details read slide "Finding shared libraries at run time" under
http://man7.org/training/download/shlib_dynlinker_slides.pdf.
Fixes #1039
Signed-off-by: Waldemar Kozaczuk <jwkozac...@gmail.com>
Message-Id: <20190517220153.22066-1-jwkozac...@gmail.com>
---
diff --git a/core/elf.cc b/core/elf.cc
--- a/core/elf.cc
+++ b/core/elf.cc
@@ -932,8 +932,17 @@ static std::string dirname(std::string path)
void object::load_needed(std::vector<std::shared_ptr<object>>&
loaded_objects)
{
std::vector<std::string> rpath;
- if (dynamic_exists(DT_RPATH)) {
- std::string rpath_str = dynamic_str(DT_RPATH);
+
+ std::string rpath_str;
+ // Prefer newer DT_RUNPATH
+ if (dynamic_exists(DT_RUNPATH)) {
+ rpath_str = dynamic_str(DT_RUNPATH);
+ // Otherwise fall back to older DT_RPATH
+ } else if (dynamic_exists(DT_RPATH)) {
+ rpath_str = dynamic_str(DT_RPATH);
+ }
+
+ if (!rpath_str.empty()) {
boost::replace_all(rpath_str, "$ORIGIN", dirname(_pathname));
boost::split(rpath, rpath_str, boost::is_any_of(":"));
}
diff --git a/include/osv/elf.hh b/include/osv/elf.hh
--- a/include/osv/elf.hh
+++ b/include/osv/elf.hh
@@ -167,7 +167,7 @@ enum {
DT_INIT = 12, // d_ptr Address of the initialization function.
DT_FINI = 13, // d_ptr Address of the termination function.
DT_SONAME = 14, // d_val The string table offset of the name of this
shared object.
- DT_RPATH = 15, // d_val The string table offset of a shared library
search path string.
+ DT_RPATH = 15, // d_val The string table offset of a shared library
search path string (deprecated)
DT_SYMBOLIC = 16, // ignored The presence of this dynamic table entry
modifies the
// symbol resolution algorithm for references within the
// library. Symbols defined within the library are used to
@@ -191,6 +191,7 @@ enum {
DT_FINI_ARRAY = 26, // d_ptr Pointer to an array of pointers to
termination functions.
DT_INIT_ARRAYSZ = 27, // d_val Size, in bytes, of the array of
initialization functions.
DT_FINI_ARRAYSZ = 28, // d_val Size, in bytes, of the array of
termination functions.
+ DT_RUNPATH = 29, // d_val The string table offset of a shared library
search path string.
DT_FLAGS = 30, // value is various flags, bits from DF_*.
DT_FLAGS_1 = 0x6ffffffb, // value is various flags, bits from DF_1_*.
DT_LOOS = 0x60000000, // Defines a range of dynamic table tags that
are reserved for
--
You received this message because you are subscribed to the Google Groups "OSv
Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to osv-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/osv-dev/00000000000045a29e05893a8140%40google.com.
For more options, visit https://groups.google.com/d/optout.