ranlib truncates archive modification time

Number:rdar://50408760 Date Originated:
Status: Resolved:
Product:Developer Tools Product Version:
Classification: Reproducible:always
Recent ninja-build versions support sub-second timestamps. With CMake I noticed that static libraries are always out-of-date after the first build due to the archive file older than newest object file.

See also https://gitlab.kitware.com/cmake/cmake/issues/19222

Steps to Reproduce:
touch bar.c
clang -c bar.c
ar -qc bar.a bar.o
./timestamp bar.a # outputs: 1556814480 10926633 bar.a
ranlib bar.a
./timestamp bar.a # outputs: 1556814492 0 bar.a

Expected Results:
The file touched by ranlib does not always have 0 for the fractional seconds field.

Actual Results:
tv_nsec is 0

Xcode 10.2
macOS 10.14
APFS file system



#include <stdio.h>
#include <string.h>
#include <sys/stat.h>

int main(int argc, char* argv[]) {

	for (int i = 1; i < argc; ++i) {
	    struct stat attr;
	    memset(&attr, '\0', sizeof(attr));
	    int ret = stat(argv[i], &attr);
	    if (ret) {
	    	return 1;
	    printf("%ld %ld %s\n", attr.st_mtimespec.tv_sec, attr.st_mtimespec.tv_nsec, argv[i]);
    return 0;


Marked as duplicate

Duplicate of rdar://49604334

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!