rubygems/rubygems — pull request #1038 by pushrax (2014-10-07 16:43:31+00:00)
Title: Remove shared libraries before copying them into place

Fixes issue #1037

When building an extension that's still loaded into memory, cp_r replaces the file contents of the same inode. Since Linux mmaps shared libs, they will get reloaded but not relocated, leading to corruption of the GOT/PLT.

The fix is to unlink the destination before copying, which creates a new inode and prevents the file from being reloaded.

A test for this would be fairly complicated, but if necessary I can add one.

@dylanahsmith @camilo @csfrancis