diff --git a/lib/csu/tests/dso/Makefile b/lib/csu/tests/dso/Makefile index cdfea2031c99..3363132c71bb 100644 --- a/lib/csu/tests/dso/Makefile +++ b/lib/csu/tests/dso/Makefile @@ -5,6 +5,8 @@ SHLIB= h_csu SHLIB_NAME= libh_csu.so SHLIB_MAJOR= 1 +ALLOW_MIPS_SHARED_TEXTREL= + WITHOUT_STATIC= WITHOUT_PROFILE= WITHOUT_PIC= diff --git a/lib/libc++/Makefile b/lib/libc++/Makefile index f8c8da4f2035..ed16e3837e37 100644 --- a/lib/libc++/Makefile +++ b/lib/libc++/Makefile @@ -11,6 +11,8 @@ CXXINCLUDEDIR= ${INCLUDEDIR}/c++/v${SHLIB_MAJOR} STATIC_CXXFLAGS+= -mlong-calls .endif +ALLOW_MIPS_SHARED_TEXTREL= + .PATH: ${SRCDIR} LIB= c++ diff --git a/lib/libcxxrt/Makefile b/lib/libcxxrt/Makefile index 8480cad42674..902d01b42404 100644 --- a/lib/libcxxrt/Makefile +++ b/lib/libcxxrt/Makefile @@ -5,6 +5,7 @@ SRCDIR= ${SRCTOP}/contrib/libcxxrt SHLIB_MAJOR= 1 SHLIBDIR?= /lib +ALLOW_MIPS_SHARED_TEXTREL= .PATH: ${SRCDIR} diff --git a/lib/libgcc_eh/Makefile.inc b/lib/libgcc_eh/Makefile.inc index 232f5d8d46fa..a556ff20d882 100644 --- a/lib/libgcc_eh/Makefile.inc +++ b/lib/libgcc_eh/Makefile.inc @@ -6,6 +6,8 @@ UNWINDSRCDIR= ${SRCTOP}/contrib/libunwind/src STATIC_CFLAGS+=${PICFLAG} -fvisibility=hidden -DVISIBILITY_HIDDEN +ALLOW_MIPS_SHARED_TEXTREL= + .PATH: ${COMPILERRTDIR}/lib/builtins .PATH: ${UNWINDSRCDIR} SRCS_EXC+= gcc_personality_v0.c diff --git a/lib/libpmc/Makefile b/lib/libpmc/Makefile index 35af606a7225..d3d3a4cb21e7 100644 --- a/lib/libpmc/Makefile +++ b/lib/libpmc/Makefile @@ -5,6 +5,8 @@ LIB= pmc 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" diff --git a/share/mk/bsd.lib.mk b/share/mk/bsd.lib.mk index 499eeeee9a0e..67788697229c 100644 --- a/share/mk/bsd.lib.mk +++ b/share/mk/bsd.lib.mk @@ -287,6 +287,10 @@ CLEANFILES+= ${SOBJS} .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 @@ -295,6 +299,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} ${SHLIB_NAME_FULL}: beforelinking