Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 826eff5

Browse files
committed
Ensure static libraries have correct mod time even if ranlib messes it up.
In at least Apple's version of ranlib, the output file is updated to have a mod time equal to the max of the timestamps of its components, and that data only has seconds precision. On a filesystem with sub-second file timestamp precision --- say, APFS --- this can result in the finished static library appearing older than its input files, which causes useless rebuilds and possible outright failures in parallel makes. We've only seen this reported in the field from people using Apple's ranlib with a non-Apple make, because Apple's make doesn't know about sub-second timestamps either so it doesn't decide rebuilds are needed. But Apple's ranlib presumably shares code with at least some BSDen, so it's not that unlikely that the same problem could arise elsewhere. To fix, just "touch" the output file after ranlib finishes. We seem to need this in only one place. There are other calls of ranlib in our makefiles, but they are working on intermediate files whose timestamps are not actually important, or else on an installed static library for which sub-second timestamp precision is unlikely to matter either. (Also, so far as I can tell, Apple's ranlib doesn't mess up the file timestamp in the latter usage anyhow.) In passing, change "ranlib" to "$(RANLIB)" in one place that was bypassing the make macro for no good reason. Per bug #15525 from Jack Kelly (via Alyssa Ross). Back-patch to all supported branches. Discussion: https://postgr.es/m/15525-a30da084f17a1faa@postgresql.org
1 parent 6812042 commit 826eff5

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/Makefile.shlib

+7-1
Original file line numberDiff line numberDiff line change
@@ -287,11 +287,17 @@ all-static-lib: $(stlib)
287287

288288
all-shared-lib: $(shlib)
289289

290+
# In this rule, "touch $@" works around a problem on some platforms wherein
291+
# ranlib updates the library file's mod time with a value calculated to
292+
# seconds precision. If the filesystem has sub-second timestamps, this can
293+
# cause the library file to appear older than its input files, triggering
294+
# parallel-make problems.
290295
ifndef haslibarule
291296
$(stlib): $(OBJS) | $(SHLIB_PREREQS)
292297
rm -f $@
293298
$(LINK.static) $@ $^
294299
$(RANLIB) $@
300+
touch $@
295301
endif #haslibarule
296302

297303

@@ -450,7 +456,7 @@ install-lib-static: $(stlib) installdirs-lib
450456
$(INSTALL_STLIB) $< '$(DESTDIR)$(libdir)/$(stlib)'
451457
ifeq ($(PORTNAME), darwin)
452458
cd '$(DESTDIR)$(libdir)' && \
453-
ranlib $(stlib)
459+
$(RANLIB) $(stlib)
454460
endif
455461

456462
install-lib-shared: $(shlib) installdirs-lib

0 commit comments

Comments
 (0)