diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index 38bdb7667c930a20c1598cc7aaeb90971982561c..b7735908de7a3666f60249a901b0413a81fb65ad 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -3145,6 +3145,11 @@ build/genmatch$(build_exeext): BUILD_LIBDEPS += $(LIBINTL_DEP) $(LIBICONV_DEP)
 build/genmatch$(build_exeext): BUILD_LIBS += $(LIBINTL) $(LIBICONV)
 endif
 
+# genmatch links in libcommon.a, which could have been compiled with
+# $(PICFLAG) set to -fno-PIE.  Make sure to link genmatch with -no-pie
+# in that case.
+build/genmatch$(build_exeext): LINKER_FOR_BUILD += $(findstring -no-pie,$(LD_PICFLAG))
+
 build/genmatch$(build_exeext) : $(BUILD_CPPLIB) \
   build/vec.o build/hash-table.o build/sort.o libcommon.a \
   $(LIBBACKTRACE)