From 697e56459c4d74cd4987e1273f18e47a912b4933 Mon Sep 17 00:00:00 2001 From: zrj Date: Wed, 12 Oct 2016 17:04:52 +0300 Subject: [PATCH] LTO: Prevent -flto being used in main system libraries. There are subtle ways it can get broken specially in libc and libm. (-plugin-opt=-pass-through=-lc) Both libpthread.a and rtld-elf could have use of LTO but it is safer for now not to expose internals. (affects only static libs) --- lib/libc/Makefile.inc | 6 ++++++ lib/libm/Makefile | 6 ++++++ lib/libthread_xu/Makefile | 7 +++++++ libexec/rtld-elf/Makefile | 6 ++++++ 4 files changed, 25 insertions(+) diff --git a/lib/libc/Makefile.inc b/lib/libc/Makefile.inc index 1f0be47152..5c2c9fe1e8 100644 --- a/lib/libc/Makefile.inc +++ b/lib/libc/Makefile.inc @@ -12,6 +12,12 @@ NOASM= WARNS=2 +# for now do not let the use of -flto (check -plugin-opt=-pass-through=-lc !) +.if ${CFLAGS:M-flto} +CFLAGS+= -fno-lto +LDFLAGS+= -flto +.endif + .include "${.CURDIR}/../libc/${MACHINE_ARCH}/Makefile.inc" .include "${.CURDIR}/../libc/citrus/Makefile.inc" diff --git a/lib/libm/Makefile b/lib/libm/Makefile index 616543ae15..d4dde120d0 100644 --- a/lib/libm/Makefile +++ b/lib/libm/Makefile @@ -114,6 +114,12 @@ PAST_SRCS = imprecise.c frexp.c isfinite.c isnanf.c isnormal.c signbit.c SRCS= ${COMMON_SRCS} ${PURE_SRCS} SRCS+= ${PAST_SRCS} +# for now do not let the use of -flto +.if ${CFLAGS:M-flto} +CFLAGS+= -fno-lto +LDFLAGS+= -flto +.endif + .if (${MACHINE_ARCH} == "x86_64") .PATH: ${OPENSRC}/src/ld80 .PATH: ${.CURDIR}/src/amd64 diff --git a/lib/libthread_xu/Makefile b/lib/libthread_xu/Makefile index ee4aa1563a..da4020aca0 100644 --- a/lib/libthread_xu/Makefile +++ b/lib/libthread_xu/Makefile @@ -2,6 +2,13 @@ LIB=thread_xu SHLIB_MAJOR= 2 + +# for now do not let the use of -flto +.if ${CFLAGS:M-flto} +CFLAGS+= -fno-lto +LDFLAGS+= -flto +.endif + CFLAGS+=-DPTHREAD_KERNEL -D_THREAD_SAFE CFLAGS+=-I${.CURDIR}/../libc/include -I${.CURDIR}/thread \ -I${.CURDIR}/../../include diff --git a/libexec/rtld-elf/Makefile b/libexec/rtld-elf/Makefile index b06b039476..6a68dae827 100644 --- a/libexec/rtld-elf/Makefile +++ b/libexec/rtld-elf/Makefile @@ -13,6 +13,12 @@ WARNS?= 2 # To activate LD_DEBUG functionality, define ENABLE_DEBUG # e.g. make -DENABLE_DEBUG +# for now do not let the use of -flto +.if ${CFLAGS:M-flto} +CFLAGS+= -fno-lto +LDFLAGS+= -flto +.endif + CFLAGS+= -DIN_RTLD CFLAGS+= -I${.CURDIR}/${MACHINE_ARCH} -I${.CURDIR} -D__thread= CFLAGS+= -I${.CURDIR}/../../lib/csu/common -- 2.41.0