Summary
The issue arises when compiling Yocto recipes, where the use of -Wl,-rpath=dir in a Makefile causes a “contains bad RPATH” error. This error occurs because the RPATH is set to a path that is not valid in the target system.
Root Cause
The root cause of this issue is the use of absolute paths in the RPATH directive. When the package is installed on the target system, these absolute paths are not valid, causing the error. The specific causes include:
- Using $(pwd) to set the RPATH, which is not a valid path on the target system
- Not using a relative path or a path that is valid on the target system
Why This Happens in Real Systems
This issue happens in real systems because the build environment and the target environment have different directory structures. The RPATH set during build time is not valid when the package is installed on the target system. This is a common issue in cross-compilation scenarios, where the build and target systems are different.
Real-World Impact
The real-world impact of this issue includes:
- Failed package installation: The package cannot be installed on the target system due to the invalid RPATH
- Linker errors: The linker is unable to find the required libraries, causing errors during execution
- System instability: The system may become unstable or crash due to the inability to find required libraries
Example or Code
# Incorrect RPATH usage
g++ -fPIC -shared -o libb.so lib.o -L../a -Wl,-rpath="$(pwd)/../a" -la
# Correct RPATH usage
g++ -fPIC -shared -o libb.so lib.o -L../a -Wl,-rpath='$ORIGIN/../a' -la
How Senior Engineers Fix It
Senior engineers fix this issue by:
- Using relative paths or $ORIGIN to set the RPATH
- Ensuring that the RPATH is valid on the target system
- Using Yocto’s built-in mechanisms, such as -Wl,-rpath=’$ORIGIN/..’, to set the RPATH
Why Juniors Miss It
Juniors may miss this issue because:
- Lack of understanding of cross-compilation and the differences between build and target environments
- Insufficient knowledge of Yocto’s build process and RPATH handling
- Not testing the package on the target system, only on the build system