+
+# Bootstrap test support. We use ld-new to build ld1, then use ld1 to
+# build ld2. ld1 and ld2 should be identical. ld-new need not be
+# identical to ld1, since it was linked with the host linker.
+
+if GCC
+if NATIVE_LINKER
+
+gcctestdir1/ld: ld-new
+ test -d gcctestdir1 || mkdir -p gcctestdir1
+ rm -f gcctestdir1/ld
+ (cd gcctestdir1 && $(LN_S) ../ld-new ld)
+
+ld1_SOURCES = $(sources_var)
+ld1_DEPENDENCIES = $(deps_var) gcctestdir1/ld
+ld1_LDADD = $(ldadd_var)
+ld1_LDFLAGS = -Bgcctestdir1/
+
+gcctestdir2/ld: ld1
+ test -d gcctestdir2 || mkdir -p gcctestdir2
+ rm -f gcctestdir2/ld
+ (cd gcctestdir2 && $(LN_S) ../ld1 ld)
+
+ld2_SOURCES = $(sources_var)
+ld2_DEPENDENCIES = $(deps_var) gcctestdir2/ld
+ld2_LDADD = $(ldadd_var)
+ld2_LDFLAGS = -Bgcctestdir2/
+
+bootstrap-test: ld2
+ rm -f $@
+ echo "#!/bin/sh" > $@
+ echo "cmp ld1 ld2" >> $@
+ chmod +x $@
+
+libgold-1-r.o: gcctestdir1/ld libgold.a
+ gcctestdir1/ld -o $@ -r --whole-archive libgold.a
+
+ld1_r_SOURCES = $(sources_var)
+ld1_r_DEPENDENCIES = libgold-1-r.o $(deps_var) gcctestdir1/ld
+ld1_r_LDADD = libgold-1-r.o $(ldadd_var)
+ld1_r_LDFLAGS = -Bgcctestdir1/
+
+gcctestdir2-r/ld: ld1-r
+ test -d gcctestdir2-r || mkdir -p gcctestdir2-r
+ rm -f gcctestdir2-r/ld
+ (cd gcctestdir2-r && $(LN_S) ../ld1-r ld)
+
+libgold-2-r.o: gcctestdir2-r/ld libgold.a
+ gcctestdir2-r/ld -o $@ -r --whole-archive libgold.a
+
+ld2_r_SOURCES = $(sources_var)
+ld2_r_DEPENDENCIES = libgold-2-r.o $(deps_var) gcctestdir2-r/ld
+ld2_r_LDADD = libgold-2-r.o $(ldadd_var)
+ld2_r_LDFLAGS = -Bgcctestdir2-r/
+
+bootstrap-test-r: ld2-r
+ rm -f $@
+ echo "#!/bin/sh" > $@
+ echo "cmp ld1-r ld2-r" >> $@
+ chmod +x $@
+
+check_PROGRAMS = ld1 ld2 ld1-r ld2-r
+TESTS = bootstrap-test bootstrap-test-r
+
+# Verify that changing the number of threads doesn't change the
+# treehash computation, by building ld1 and ld3 the same way except
+# for the number of threads. However, the build ID should change if
+# we change the chunk size for --build-id=tree, so ld4 should be
+# different. We run the latter test even if multithreading is unavailable,
+# because the treehash can still operate in that mode.
+check_PROGRAMS += ld4
+TESTS += bootstrap-test-treehash-chunksize
+
+gcctestdir3/ld: ld-new
+ test -d gcctestdir3 || mkdir -p gcctestdir3
+ rm -f gcctestdir3/ld
+ (cd gcctestdir3 && $(LN_S) ../ld-new ld)
+
+ld3_SOURCES = $(sources_var)
+ld3_DEPENDENCIES = $(deps_var) gcctestdir3/ld
+ld3_LDADD = $(ldadd_var)
+ld3_LDFLAGS = -Bgcctestdir3/
+
+gcctestdir4/ld: ld-new
+ test -d gcctestdir4 || mkdir -p gcctestdir4
+ rm -f gcctestdir4/ld
+ (cd gcctestdir4 && $(LN_S) ../ld-new ld)
+
+ld4_SOURCES = $(sources_var)
+ld4_DEPENDENCIES = $(deps_var) gcctestdir4/ld
+ld4_LDADD = $(ldadd_var)
+ld4_LDFLAGS = -Bgcctestdir4/
+
+ld1_LDFLAGS += -Wl,--build-id=tree -Wl,--build-id-chunk-size-for-treehash=12345 -Wl,--build-id-min-file-size-for-treehash=0
+ld2_LDFLAGS += -Wl,--build-id=tree -Wl,--build-id-chunk-size-for-treehash=12345 -Wl,--build-id-min-file-size-for-treehash=0
+ld3_LDFLAGS += -Wl,--build-id=tree -Wl,--build-id-chunk-size-for-treehash=12345 -Wl,--build-id-min-file-size-for-treehash=0
+ld4_LDFLAGS += -Wl,--build-id=tree -Wl,--build-id-chunk-size-for-treehash=12346 -Wl,--build-id-min-file-size-for-treehash=0
+
+if THREADS
+
+ld1_LDFLAGS += -Wl,--thread-count=3
+ld2_LDFLAGS += -Wl,--thread-count=3
+ld3_LDFLAGS += -Wl,--thread-count=13
+ld4_LDFLAGS += -Wl,--thread-count=3
+check_PROGRAMS += ld3
+TESTS += bootstrap-test-treehash-chunksize
+
+bootstrap-test-treehash: ld1 ld3
+ rm -f $@
+ echo "#!/bin/sh" > $@
+ echo "cmp ld1 ld3" >> $@
+ chmod +x $@
+
+endif
+
+bootstrap-test-treehash-chunksize: ld1 ld4
+ rm -f $@
+ echo "#!/bin/sh" > $@
+ echo "cmp ld1 ld4 | grep ." >> $@
+ chmod +x $@
+
+endif
+endif