diff options
author | Kyle Evans <kevans@FreeBSD.org> | 2019-10-02 17:18:18 +0000 |
---|---|---|
committer | Kyle Evans <kevans@FreeBSD.org> | 2019-10-02 17:18:18 +0000 |
commit | 982f1fc2d8ae42cec10044918d1ddf04271f8950 (patch) | |
tree | 48bcdeba72f22b16db54696c6cc4b4c35d175561 | |
parent | 4f68b172e160e4cecb62be805c6cdc04d61eec8d (diff) | |
download | src-982f1fc2d8ae42cec10044918d1ddf04271f8950.tar.gz src-982f1fc2d8ae42cec10044918d1ddf04271f8950.zip |
Override the TLS model when building mips64 binaries and static libraries
GCC uses "dynamic" TLS models when -fpic or -fPIC is explicitly
specified on the command line (which is only true for shared libraries).
It uses "static" (or "exec") TLS models otherwise. In particular, GCC
does _not_ use dynamic TLS models when PIC is implicitly enabled (which
it is on MIPS), only if a PIC flag is explicitly provided.
llvm uses "dynamic" TLS models if PIC is enabled either via a PIC flag
or if it is implicily enabled (as on MIPS64). This means that llvm on
MIPS64 always uses "dynamic" TLS models. However, dynamic TLS models
do not work for static binaries and libraries as the __tls_get_addr
function they invoke is only defined in rtld.
Written by: jhb
Reviewed by: arichardson
Differential Revision: https://reviews.freebsd.org/D21699
Notes
Notes:
svn path=/head/; revision=353019
-rw-r--r-- | share/mk/bsd.lib.mk | 6 | ||||
-rw-r--r-- | share/mk/bsd.prog.mk | 5 |
2 files changed, 11 insertions, 0 deletions
diff --git a/share/mk/bsd.lib.mk b/share/mk/bsd.lib.mk index 70ba98bb361b..499eeeee9a0e 100644 --- a/share/mk/bsd.lib.mk +++ b/share/mk/bsd.lib.mk @@ -92,6 +92,12 @@ CXXFLAGS+= ${DEBUG_FILES_CFLAGS} CTFFLAGS+= -g .endif +# clang currently defaults to dynamic TLS for mips64 object files without -fPIC +.if ${MACHINE_ARCH:Mmips64*} && ${COMPILER_TYPE} == "clang" +STATIC_CFLAGS+= -ftls-model=initial-exec +STATIC_CXXFLAGS+= -ftls-model=initial-exec +.endif + .include <bsd.libnames.mk> # prefer .s to a .c, add .po, remove stuff not used in the BSD libraries diff --git a/share/mk/bsd.prog.mk b/share/mk/bsd.prog.mk index d2631452bedc..f0368ec5d2b8 100644 --- a/share/mk/bsd.prog.mk +++ b/share/mk/bsd.prog.mk @@ -82,6 +82,11 @@ TAG_ARGS= -T ${TAGS:[*]:S/ /,/g} LDFLAGS+= -static .endif +# clang currently defaults to dynamic TLS for mips64 binaries +.if ${MACHINE_ARCH:Mmips64*} && ${COMPILER_TYPE} == "clang" +CFLAGS+= -ftls-model=initial-exec +.endif + .if ${MK_DEBUG_FILES} != "no" PROG_FULL=${PROG}.full # Use ${DEBUGDIR} for base system debug files, else .debug subdirectory |