I'm unsure about library support, but gcc and clang support function multi-versioning (FMV), which resolves the function based on CPUID the first time the function is called.
This LWN article has some additional information: https://lwn.net/Articles/691932/