Backport of #9443 "Use linker capability detection to improve linker use" (#9797)