When a library file name is encountered multiple times, reuse the result from the first time. This more closely matches the behavior of the dynamic loader on Linux. Fixes: #24621