Index: head/lib/csu/tests/dso/Makefile =================================================================== --- head/lib/csu/tests/dso/Makefile +++ head/lib/csu/tests/dso/Makefile @@ -5,6 +5,8 @@ SHLIB_NAME= libh_csu.so SHLIB_MAJOR= 1 +ALLOW_MIPS_SHARED_TEXTREL= + WITHOUT_STATIC= WITHOUT_PROFILE= WITHOUT_PIC= Index: head/lib/libc++/Makefile =================================================================== --- head/lib/libc++/Makefile +++ head/lib/libc++/Makefile @@ -11,6 +11,8 @@ STATIC_CXXFLAGS+= -mlong-calls .endif +ALLOW_MIPS_SHARED_TEXTREL= + .PATH: ${SRCDIR} LIB= c++ Index: head/lib/libcxxrt/Makefile =================================================================== --- head/lib/libcxxrt/Makefile +++ head/lib/libcxxrt/Makefile @@ -5,6 +5,7 @@ SHLIB_MAJOR= 1 SHLIBDIR?= /lib +ALLOW_MIPS_SHARED_TEXTREL= .PATH: ${SRCDIR} Index: head/lib/libgcc_eh/Makefile.inc =================================================================== --- head/lib/libgcc_eh/Makefile.inc +++ head/lib/libgcc_eh/Makefile.inc @@ -6,6 +6,8 @@ STATIC_CFLAGS+=${PICFLAG} -fvisibility=hidden -DVISIBILITY_HIDDEN +ALLOW_MIPS_SHARED_TEXTREL= + .PATH: ${COMPILERRTDIR}/lib/builtins .PATH: ${UNWINDSRCDIR} SRCS_EXC+= gcc_personality_v0.c Index: head/lib/libpmc/Makefile =================================================================== --- head/lib/libpmc/Makefile +++ head/lib/libpmc/Makefile @@ -5,6 +5,8 @@ SRCS= libpmc.c pmclog.c libpmc_pmu_util.c libpmc_json.cc INCS= pmc.h pmclog.h pmcformat.h +ALLOW_MIPS_SHARED_TEXTREL= + .if ${MACHINE_ARCH} == "amd64" || ${MACHINE_ARCH} == "i386" .if ${MACHINE_ARCH} == "aarch64" Index: head/share/mk/bsd.lib.mk =================================================================== --- head/share/mk/bsd.lib.mk +++ head/share/mk/bsd.lib.mk @@ -287,6 +287,10 @@ .if defined(SHLIB_NAME) _LIBS+= ${SHLIB_NAME} +.if ${CFLAGS:M-fexceptions} || defined(SHLIB_CXX) || defined(LIB_CXX) +ALLOW_MIPS_SHARED_TEXTREL= +.endif + SOLINKOPTS+= -shared -Wl,-x .if defined(LD_FATAL_WARNINGS) && ${LD_FATAL_WARNINGS} == "no" SOLINKOPTS+= -Wl,--no-fatal-warnings @@ -294,6 +298,15 @@ SOLINKOPTS+= -Wl,--fatal-warnings .endif SOLINKOPTS+= -Wl,--warn-shared-textrel + +.if defined(ALLOW_MIPS_SHARED_TEXTREL) && ${MACHINE_CPUARCH:Mmips} +# Check if we should be defining ALLOW_SHARED_TEXTREL... basically, C++ +# or -fexceptions in CFLAGS on MIPS. This works around clang/lld attempting +# to generate text relocations in read-only .eh_frame. A future version of +# clang/lld should instead transform them into relative references at link +# time, and then we can stop doing this. +SOLINKOPTS+= -Wl,-z,notext +.endif .if target(beforelinking) beforelinking: ${SOBJS}