Second attempt at eliminating .text relocations in shared libraries
compiled with stack protector. Use libssp_nonshared library to pull __stack_chk_fail_local symbol into each library that needs it instead of pulling it from libc. GCC generates local calls to this function which result in absolute relocations put into position-independent code segment, making dynamic loader do extra work every time given shared library is being relocated and making affected text pages non-shareable. Reviewed by: kib Approved by: re (kib)
This commit is contained in:
parent
0fe0ed8bf8
commit
2286fe7635
@ -1069,7 +1069,7 @@ libraries:
|
|||||||
#
|
#
|
||||||
# static libgcc.a prerequisite for shared libc
|
# static libgcc.a prerequisite for shared libc
|
||||||
#
|
#
|
||||||
_prereq_libs= gnu/lib/libgcc
|
_prereq_libs= gnu/lib/libssp/libssp_nonshared gnu/lib/libgcc
|
||||||
|
|
||||||
# These dependencies are not automatically generated:
|
# These dependencies are not automatically generated:
|
||||||
#
|
#
|
||||||
|
@ -168,6 +168,7 @@ is built with the --enable-threads configure-time option.} \
|
|||||||
%{pg: %{pthread:-lpthread_p} -lc_p}} \
|
%{pg: %{pthread:-lpthread_p} -lc_p}} \
|
||||||
%{shared: \
|
%{shared: \
|
||||||
%{pthread:-lpthread} -lc} \
|
%{pthread:-lpthread} -lc} \
|
||||||
|
%{fstack-protector|fstack-protector-all:-lssp_nonshared} \
|
||||||
"
|
"
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
@ -7,6 +7,12 @@ SHLIB_NAME= libgcc_s.so.1
|
|||||||
SHLIBDIR?= /lib
|
SHLIBDIR?= /lib
|
||||||
|
|
||||||
.include <bsd.own.mk>
|
.include <bsd.own.mk>
|
||||||
|
#
|
||||||
|
# libgcc is linked in last and thus cannot depend on ssp symbols coming
|
||||||
|
# from earlier libraries. Disable stack protection for this library.
|
||||||
|
#
|
||||||
|
MK_SSP= no
|
||||||
|
|
||||||
.include "${.CURDIR}/../../usr.bin/cc/Makefile.tgt"
|
.include "${.CURDIR}/../../usr.bin/cc/Makefile.tgt"
|
||||||
|
|
||||||
.PATH: ${GCCDIR}/config/${GCC_CPU} ${GCCDIR}/config ${GCCDIR}
|
.PATH: ${GCCDIR}/config/${GCC_CPU} ${GCCDIR}/config ${GCCDIR}
|
||||||
|
@ -13,6 +13,6 @@ SRCS= ssp-local.c
|
|||||||
|
|
||||||
CFLAGS+= -DHAVE_CONFIG_H
|
CFLAGS+= -DHAVE_CONFIG_H
|
||||||
CFLAGS+= -I${.CURDIR}/.. -I${GCCLIB}/libssp -I${GCCLIB}/include
|
CFLAGS+= -I${.CURDIR}/.. -I${GCCLIB}/libssp -I${GCCLIB}/include
|
||||||
CFLAGS+= -fPIC -DPIC
|
CFLAGS+= -fPIC -DPIC -fvisibility=hidden
|
||||||
|
|
||||||
.include <bsd.lib.mk>
|
.include <bsd.lib.mk>
|
||||||
|
@ -26,7 +26,7 @@ PRECIOUSLIB=
|
|||||||
#
|
#
|
||||||
DPADD+= ${LIBGCC}
|
DPADD+= ${LIBGCC}
|
||||||
LDFLAGS+= -nodefaultlibs
|
LDFLAGS+= -nodefaultlibs
|
||||||
LDADD+= -lgcc
|
LDADD+= -lgcc -lssp_nonshared
|
||||||
|
|
||||||
# Define (empty) variables so that make doesn't give substitution
|
# Define (empty) variables so that make doesn't give substitution
|
||||||
# errors if the included makefiles don't change these:
|
# errors if the included makefiles don't change these:
|
||||||
|
@ -282,7 +282,6 @@ FBSD_1.0 {
|
|||||||
socket;
|
socket;
|
||||||
socketpair;
|
socketpair;
|
||||||
__stack_chk_fail;
|
__stack_chk_fail;
|
||||||
__stack_chk_fail_local;
|
|
||||||
__stack_chk_guard;
|
__stack_chk_guard;
|
||||||
stat;
|
stat;
|
||||||
statfs;
|
statfs;
|
||||||
|
@ -47,7 +47,6 @@ static void __guard_setup(void) __attribute__((__constructor__, __used__));
|
|||||||
static void __fail(const char *);
|
static void __fail(const char *);
|
||||||
void __stack_chk_fail(void);
|
void __stack_chk_fail(void);
|
||||||
void __chk_fail(void);
|
void __chk_fail(void);
|
||||||
void __stack_chk_fail_local(void);
|
|
||||||
|
|
||||||
/*LINTED used*/
|
/*LINTED used*/
|
||||||
static void
|
static void
|
||||||
@ -109,8 +108,4 @@ __chk_fail(void)
|
|||||||
__fail("buffer overflow detected; terminated");
|
__fail("buffer overflow detected; terminated");
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
__sym_compat(__stack_chk_fail_local, __stack_chk_fail, FBSD_1.0);
|
||||||
__stack_chk_fail_local(void)
|
|
||||||
{
|
|
||||||
__stack_chk_fail();
|
|
||||||
}
|
|
||||||
|
@ -22,7 +22,7 @@ MLINKS= rtld.1 ld-elf.so.1.1 \
|
|||||||
CFLAGS+= -fpic -DPIC
|
CFLAGS+= -fpic -DPIC
|
||||||
LDFLAGS+= -shared -Wl,-Bsymbolic
|
LDFLAGS+= -shared -Wl,-Bsymbolic
|
||||||
DPADD= ${LIBC_PIC}
|
DPADD= ${LIBC_PIC}
|
||||||
LDADD= -lc_pic
|
LDADD= -lc_pic -lssp_nonshared
|
||||||
|
|
||||||
.if ${MACHINE_ARCH} != "ia64"
|
.if ${MACHINE_ARCH} != "ia64"
|
||||||
.if ${MK_SYMVER} == "yes"
|
.if ${MK_SYMVER} == "yes"
|
||||||
|
@ -200,11 +200,11 @@ ${SHLIB_NAME}: ${SOBJS}
|
|||||||
@ln -fs ${.TARGET} ${SHLIB_LINK}
|
@ln -fs ${.TARGET} ${SHLIB_LINK}
|
||||||
.endif
|
.endif
|
||||||
.if !defined(NM)
|
.if !defined(NM)
|
||||||
@${CC} ${LDFLAGS} -shared -Wl,-x \
|
@${CC} ${LDFLAGS} ${SSP_CFLAGS} -shared -Wl,-x \
|
||||||
-o ${.TARGET} -Wl,-soname,${SONAME} \
|
-o ${.TARGET} -Wl,-soname,${SONAME} \
|
||||||
`lorder ${SOBJS} | tsort -q` ${LDADD}
|
`lorder ${SOBJS} | tsort -q` ${LDADD}
|
||||||
.else
|
.else
|
||||||
@${CC} ${LDFLAGS} -shared -Wl,-x \
|
@${CC} ${LDFLAGS} ${SSP_CFLAGS} -shared -Wl,-x \
|
||||||
-o ${.TARGET} -Wl,-soname,${SONAME} \
|
-o ${.TARGET} -Wl,-soname,${SONAME} \
|
||||||
`NM='${NM}' lorder ${SOBJS} | tsort -q` ${LDADD}
|
`NM='${NM}' lorder ${SOBJS} | tsort -q` ${LDADD}
|
||||||
.endif
|
.endif
|
||||||
|
Loading…
Reference in New Issue
Block a user