introducing-cmake/rpath-build-install-tree.tex

136 lines
3.9 KiB
TeX

\begin{frame}
\frametitle{Relocatable binaries and resources}
\begin{center}
\huge Making packages relocatable
\end{center}
\end{frame}
% --------------------------------------------------------------------
\begin{frame}[containsverbatim]
\frametitle{rpath}
Runtime search path - embedded in the binaries
\vspace{1em}
\includegraphics[width=.95\textwidth,keepaspectratio]{images/so_rpath.png}
\vspace{1em}
\includegraphics[width=.95\textwidth,keepaspectratio]{images/dylib_rpath.png}
\end{frame}
% --------------------------------------------------------------------
\begin{frame}[containsverbatim]
\frametitle{rpath}
Used by the Dynamic Linker (DL) on UNIX systems
\begin{itemize}
\item rpath - almost the first place to look for the libraries,
\newline nowadays {\code{DT\_RUNPATH}} is more common than
{\code{DT\_RPATH}} as a tag
\item Search path sequence for DL -
{\code{RPATH, LD\_LIBRARY\_PATH, RUNPATH, /etc/ld.so.conf, /lib/,
/usr/lib}, …}
\end{itemize}
\end{frame}
% --------------------------------------------------------------------
\begin{frame}[containsverbatim]
\frametitle{rpath}
\begin{itemize}
\item Can be overwritten - {\code {chrpath, patchelf}}
\item Can be extracted - {\code {objdump, readelf, otool, etc.}}
\end{itemize}
\begin{codebox}{Shell}{}
$ objdump -x <path-to-library> | grep RPATH
$ readelf -d <path-to-library> | grep RPATH
$ otool -L <path-to-library>
\end{codebox}
\end{frame}
% --------------------------------------------------------------------
\begin{frame}
\frametitle{rpath}
\begin{tabular}{ | p{5cm} | p{5cm} |}
\hline
{\textbf {In Build Tree}} & {\textbf {In Install Tree}} \\
\hline
{Points to directories in the build folder
{\begin{itemize}
\item Usually full paths
\item Updated while installing
\end{itemize}}} &
{Points to directories specified during build for installation
{\begin{itemize}
\item Can be full path
\item Can be relative path
\item Can be empty
\end{itemize}}} \\
\hline
\end{tabular}
\end{frame}
% --------------------------------------------------------------------
\begin{frame}
\frametitle {Relocatable packages}
Relative or empty rpaths when installed
\begin{itemize}
\item {\code \$ORIGIN} - *nix OSs
\item {\code @rpath} (+ {\code @loader\_path}, {\code @executable\_path}) - Mac OSX \& IOS
\item Always Empty - Android\\
{\info {Usually libraries are packed with {\code APK} and loaded using {\code
dlopen} interface\\}}
\item Always Empty - for Windows\\
{\info {Only user account and system env paths are
searched for libraries, plus the current folder\\}}
\end{itemize}
\end{frame}
% --------------------------------------------------------------------
\begin{frame}
\frametitle{Making loading resources relocatable}
Resources used by package should be easily locatable\\
\textbf{Bad:} when resource paths are hardcoded in the source code\\
\textbf{Good:} when resource paths are dynamically determined at runtime\\
\end{frame}
\begin{frame}
\frametitle{Making loading resources relocatable}
You need to write a function able to determine the relative path from its
containing binary to the installation root at runtime.\\
\begin{itemize}
\item No need to hardcode resouce location in the sources
\item Path to resources should be located based on their types, such as:\\
{\code LIBRARY}, {\code BINARY}, {\code DATA}, {\code CONFIG},
etc.
\item Aware of the install tree directory structure
\item Just make sure that install tree structure is not violated
\end{itemize}
\end{frame}
% --------------------------------------------------------------------