scripts: recordmcount: break hardlinks
authorRussell King <rmk+kernel@arm.linux.org.uk>
Fri, 11 Dec 2015 12:09:03 +0000 (12:09 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 3 Mar 2016 23:06:22 +0000 (15:06 -0800)
commit dd39a26538e37f6c6131e829a4a510787e43c783 upstream.

recordmcount edits the file in-place, which can cause problems when
using ccache in hardlink mode.  Arrange for recordmcount to break a
hardlinked object.

Link: http://lkml.kernel.org/r/E1a7MVT-0000et-62@rmk-PC.arm.linux.org.uk
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
scripts/recordmcount.c

index 9c22317778eb7e3f995c73845cfcceba15062739..ee625e3a56ba894ffa5e0f0ba1352b624a637b34 100644 (file)
@@ -189,6 +189,20 @@ static void *mmap_file(char const *fname)
                addr = umalloc(sb.st_size);
                uread(fd_map, addr, sb.st_size);
        }
+       if (sb.st_nlink != 1) {
+               /* file is hard-linked, break the hard link */
+               close(fd_map);
+               if (unlink(fname) < 0) {
+                       perror(fname);
+                       fail_file();
+               }
+               fd_map = open(fname, O_RDWR | O_CREAT, sb.st_mode);
+               if (fd_map < 0) {
+                       perror(fname);
+                       fail_file();
+               }
+               uwrite(fd_map, addr, sb.st_size);
+       }
        return addr;
 }