scons: Add a convenience method to set RPATH for local libraries.

When linking in a dynamic library which is in the gem5 build directory,
it's useful to set RPATH so that you don't have to set LD_LIBRARY_PATH
when you run gem5 so that the dynamic linker can find it.

Since it's tricky and not entirely obvious how to set up those paths
correctly, this change adds a small convenience function which does
that for you. It also handles situations where the same dynamic
library may be linked into different binaries in different directories
which each need a different relative RPATH. It does that by letting the
environment for each binary set a construction variable which says
how to get from that particular binary back to the build directory.
This helper method then sets RPATH to start at $ORIGIN (the binary),
to follow that relative path to the variant build directory, and then
the per-library but not per-binary path to the library's directory.

This change also adds the -z origin linker flag which makes the linker
handle $ORIGIN properly.

Change-Id: I45f4d72cd14396a73e0b963cea6a39d9bfb7f984
Reviewed-by: Andreas Sandberg <>
Maintainer: Gabe Black <>
2 files changed