There is a general rule on Linux systems where the items in /bin, /sbin and /lib should never referenced things location under the /usr mount. This is because /usr may be mounted much later in boot cycle, or perhaps won't be mounted at all in case of a system recovery action. A sanity check should be added that verify that scripts, and libraries from /bin, /sbin and /lib do not reference other libraries that exist in outside of the /bin, /sbin and /lib directories. This sanity check may be partially done during package generation, but may also have to be done at the end after the rootfs image has been constructed.
Design I'm starting with: Iterate through each file in /bin, /sbin, and /lib of the rootfs, and grep the output of the 'file' command to determine which type the file is. Based on my desktop system, the keywords I'd grep for are: ELF - binary or library Bourne - shell script "POSIX shell" - shell script Then based on this I would grep shell scripts for "usr", and grep the output of ldd of binaries/libraries for "usr". I'd then throw a QA warning. This would be a function I'd add to the default do_package step.
I think the general design is correct. But you'll likely want to break this up into a few steps as some are more useful (and time consuming) then others. The critical one for me is the library dependencies.. things installed in /bin or /sbin should not reference libraries in /usr/lib. Similarly libraries in /lib should also not references libraries in /usr/lib. These to me should be an error. For the scripts scanning for specific calls to /usr/... from the items in /bin and /sbin. This is likely the right approach. It's far from fool-proof, but it will help...
Design ACK'ed
In Poky master and oe-core as of: http://git.yoctoproject.org/cgit/cgit.cgi/poky/commit/?id=198f2ac06e60245750a2c6561b8c8e2eaa93f6be http://git.openembedded.org/openembedded-core/commit/?id=ed937940f54d1a376b518fc276da78811c4ac50b
I tested against latest master with commit cb89d43473a91ff4cb2447d642fcd9308d7366e3, the feature could work and improper link would be reported out by bitbake.