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_SHARED_TEXTREL= yes + 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_SHARED_TEXTREL= yes + .PATH: ${SRCDIR} LIB= c++ Index: lib/libcxxrt/Makefile =================================================================== --- lib/libcxxrt/Makefile +++ lib/libcxxrt/Makefile @@ -5,6 +5,7 @@ SHLIB_MAJOR= 1 SHLIBDIR?= /lib +ALLOW_SHARED_TEXTREL= yes .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_SHARED_TEXTREL=yes + .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_SHARED_TEXTREL= yes + .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,13 +281,29 @@ .if defined(SHLIB_NAME) _LIBS+= ${SHLIB_NAME} +.if ${MACHINE_CPUARCH:Mmips} == "" +# Sabotage non-MIPS usage; these shouldn't crop up. +.undef ALLOW_SHARED_TEXTREL +.elif ${MACHINE_CPUARCH:Mmips} && !defined(ALLOW_SHARED_TEXTREL) +# 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 +.if ${CFLAGS:M-fexceptions} || defined(SHLIB_CXX) || defined(LIB_CXX) +ALLOW_SHARED_TEXTREL= yes +.endif +.endif + SOLINKOPTS+= -shared -Wl,-x +.if !defined(ALLOW_SHARED_TEXTREL) .if defined(LD_FATAL_WARNINGS) && ${LD_FATAL_WARNINGS} == "no" SOLINKOPTS+= -Wl,--no-fatal-warnings .else SOLINKOPTS+= -Wl,--fatal-warnings .endif SOLINKOPTS+= -Wl,--warn-shared-textrel +.elif ${ALLOW_SHARED_TEXTREL} != "no" +SOLINKOPTS+= -Wl,-z,notext +.endif .if target(beforelinking) beforelinking: ${SOBJS}