Index: lib/csu/tests/dso/Makefile =================================================================== --- lib/csu/tests/dso/Makefile +++ 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: lib/libc++/Makefile =================================================================== --- lib/libc++/Makefile +++ lib/libc++/Makefile @@ -11,6 +11,8 @@ STATIC_CXXFLAGS+= -mlong-calls .endif +ALLOW_MIPS_SHARED_TEXTREL= + .PATH: ${SRCDIR} LIB= c++ Index: lib/libcxxrt/Makefile =================================================================== --- lib/libcxxrt/Makefile +++ lib/libcxxrt/Makefile @@ -5,6 +5,7 @@ SHLIB_MAJOR= 1 SHLIBDIR?= /lib +ALLOW_MIPS_SHARED_TEXTREL= .PATH: ${SRCDIR} Index: lib/libgcc_eh/Makefile.inc =================================================================== --- lib/libgcc_eh/Makefile.inc +++ 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: lib/libpmc/Makefile =================================================================== --- lib/libpmc/Makefile +++ 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: share/mk/bsd.lib.mk =================================================================== --- share/mk/bsd.lib.mk +++ share/mk/bsd.lib.mk @@ -281,6 +281,10 @@ .if defined(SHLIB_NAME) _LIBS+= ${SHLIB_NAME} +.if ${CFLAGS:M-fexceptions} || defined(SHLIB_CXX) || defined(LIB_CXX) +ALLOW_MIPS_SHARED_TEXTREL= yes +.endif + SOLINKOPTS+= -shared -Wl,-x .if defined(LD_FATAL_WARNINGS) && ${LD_FATAL_WARNINGS} == "no" SOLINKOPTS+= -Wl,--no-fatal-warnings @@ -289,6 +293,13 @@ .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 +SOLINKOPTS+= -Wl,-z,notext +.endif + .if target(beforelinking) beforelinking: ${SOBJS} ${SHLIB_NAME_FULL}: beforelinking