Skip to content

Commit e0af707

Browse files
authored
Improve build reproducibility of stub archives (WebAssembly#682)
Currently, the `default` target produces byte-identical binary artifacts on Linux and macOS, except for the stub archives (e.g. `libcrypt.a`). This is because `llvm-ar` defaults to `--format=darwin` on macOS, which generates an empty symbol index for an empty archive. We can make this build completely reproducible across macOS and Linux by specifying `--format=gnu`, which is the default used on Linux.
1 parent ac020b8 commit e0af707

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

Makefile

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ NM ?= $(patsubst %clang,%llvm-nm,$(filter-out ccache sccache,$(CC)))
88
ifeq ($(origin AR), default)
99
AR = $(patsubst %clang,%llvm-ar,$(filter-out ccache sccache,$(CC)))
1010
endif
11+
ifeq ($(origin ARFLAGS), default)
12+
# Use `--format=gnu` to generate identical archives regardless of the host.
13+
ARFLAGS = --format=gnu crs
14+
endif
1115
ifeq ($(DEBUG), true)
1216
EXTRA_CFLAGS ?= -O0 -g
1317
else
@@ -705,13 +709,13 @@ $(SYSROOT_LIB)/libsetjmp.a: $(LIBSETJMP_OBJS)
705709
%.a:
706710
@mkdir -p "$(@D)"
707711
# On Windows, the commandline for the ar invocation got too long, so it needs to be split up.
708-
$(AR) crs $@ $(wordlist 1, 199, $(sort $^))
709-
$(AR) crs $@ $(wordlist 200, 399, $(sort $^))
710-
$(AR) crs $@ $(wordlist 400, 599, $(sort $^))
711-
$(AR) crs $@ $(wordlist 600, 799, $(sort $^))
712+
$(AR) $(ARFLAGS) $@ $(wordlist 1, 199, $(sort $^))
713+
$(AR) $(ARFLAGS) $@ $(wordlist 200, 399, $(sort $^))
714+
$(AR) $(ARFLAGS) $@ $(wordlist 400, 599, $(sort $^))
715+
$(AR) $(ARFLAGS) $@ $(wordlist 600, 799, $(sort $^))
712716
# This might eventually overflow again, but at least it'll do so in a loud way instead of
713717
# silently dropping the tail.
714-
$(AR) crs $@ $(wordlist 800, 100000, $(sort $^))
718+
$(AR) $(ARFLAGS) $@ $(wordlist 800, 100000, $(sort $^))
715719

716720
$(PIC_OBJS): CFLAGS += -fPIC -fvisibility=default
717721

@@ -875,7 +879,7 @@ $(DUMMY_LIBS):
875879
#
876880
mkdir -p "$(SYSROOT_LIB)"
877881
for lib in $@; do \
878-
$(AR) crs "$$lib"; \
882+
$(AR) $(ARFLAGS) "$$lib"; \
879883
done
880884

881885
no-check-symbols: $(STARTUP_FILES) libc $(DUMMY_LIBS)

0 commit comments

Comments
 (0)