Function tango_bench::linux::patch_pie_binary_if_needed
source · pub fn patch_pie_binary_if_needed(
path: impl AsRef<Path>,
) -> Result<Option<PathBuf>, Error>
Expand description
Patches executable file for new version of glibc dynamic loader
After glibc 2.29 on linux dlopen
is explicitly denying loading
PIE executables as a shared library. The following error might appear:
dlopen error: cannot dynamically load position-independent executable
From 2.29 dynamic loader throws an error if DF_1_PIE
flag is set in
DT_FLAG_1
tag on the PT_DYNAMIC
section. Although the loading of executable
files as a shared library was never an intended use case, through the years
some applications adopted this technique and it is very convenient in the context
of paired benchmarking.
Following method check if this flag is set and patch binary at runtime
(writing patched version in a different file). As far as I am aware
this is safe modification because DF_1_PIE
is purely informational and doesn’t
changle the dynamic linking process in any way. Theoretically in the future this modification
could prevent ASLR ramndomization on the OS level which is irrelevant for benchmark
executables.