Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F143148509
D15283.id42104.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
9 KB
Referenced Files
None
Subscribers
None
D15283.id42104.diff
View Options
Index: lib/libc/Makefile
===================================================================
--- lib/libc/Makefile
+++ lib/libc/Makefile
@@ -43,6 +43,7 @@
.endif
CLEANFILES+=tags
INSTALL_PIC_ARCHIVE=
+BUILD_NOSSP_PIC_ARCHIVE=
PRECIOUSLIB=
.ifndef NO_THREAD_STACK_UNWIND
@@ -198,10 +199,6 @@
# Disable warnings in contributed sources.
CWARNFLAGS:= ${.IMPSRC:Ngdtoa_*.c:C/^.+$/${CWARNFLAGS}/:C/^$/-w/}
-# XXX For now, we don't allow libc to be compiled with
-# -fstack-protector-all because it breaks rtld. We may want to make a librtld
-# in the future to circumvent this.
-SSP_CFLAGS:= ${SSP_CFLAGS:S/^-fstack-protector-all$/-fstack-protector/}
# Disable stack protection for SSP symbols.
SSP_CFLAGS:= ${.IMPSRC:N*/stack_protector.c:C/^.+$/${SSP_CFLAGS}/}
# Generate stack unwinding tables for cancellation points
Index: libexec/rtld-elf/Makefile
===================================================================
--- libexec/rtld-elf/Makefile
+++ libexec/rtld-elf/Makefile
@@ -51,7 +51,7 @@
CFLAGS.reloc.c+=-fno-jump-tables
.endif
LDFLAGS+= -shared -Wl,-Bsymbolic -Wl,-z,defs
-LIBADD= c_pic
+LIBADD= c_nossp_pic
.if ${MK_TOOLCHAIN} == "no"
LDFLAGS+= -L${LIBCDIR}
.endif
Index: libexec/rtld-elf/rtld.c
===================================================================
--- libexec/rtld-elf/rtld.c
+++ libexec/rtld-elf/rtld.c
@@ -238,8 +238,6 @@
int npagesizes, osreldate;
size_t *pagesizes;
-long __stack_chk_guard[8] = {0, 0, 0, 0, 0, 0, 0, 0};
-
static int stack_prot = PROT_READ | PROT_WRITE | RTLD_DEFAULT_STACK_EXEC;
static int max_stack_flags;
@@ -360,8 +358,7 @@
char **argv, *argv0, **env, **envp, *kexecpath, *library_path_rpath;
caddr_t imgentry;
char buf[MAXPATHLEN];
- int argc, fd, i, mib[2], phnum, rtld_argc;
- size_t len;
+ int argc, fd, i, phnum, rtld_argc;
bool dir_enable, explicit_fd, search_in_path;
/*
@@ -399,27 +396,6 @@
main_argc = argc;
main_argv = argv;
- if (aux_info[AT_CANARY] != NULL &&
- aux_info[AT_CANARY]->a_un.a_ptr != NULL) {
- i = aux_info[AT_CANARYLEN]->a_un.a_val;
- if (i > sizeof(__stack_chk_guard))
- i = sizeof(__stack_chk_guard);
- memcpy(__stack_chk_guard, aux_info[AT_CANARY]->a_un.a_ptr, i);
- } else {
- mib[0] = CTL_KERN;
- mib[1] = KERN_ARND;
-
- len = sizeof(__stack_chk_guard);
- if (sysctl(mib, 2, __stack_chk_guard, &len, NULL, 0) == -1 ||
- len != sizeof(__stack_chk_guard)) {
- /* If sysctl was unsuccessful, use the "terminator canary". */
- ((unsigned char *)(void *)__stack_chk_guard)[0] = 0;
- ((unsigned char *)(void *)__stack_chk_guard)[1] = 0;
- ((unsigned char *)(void *)__stack_chk_guard)[2] = '\n';
- ((unsigned char *)(void *)__stack_chk_guard)[3] = 255;
- }
- }
-
trust = !issetugid();
md_abi_variant_hook(aux_info);
@@ -5537,23 +5513,6 @@
{
}
-void
-__stack_chk_fail(void)
-{
-
- _rtld_error("stack overflow detected; terminated");
- rtld_die();
-}
-__weak_reference(__stack_chk_fail, __stack_chk_fail_local);
-
-void
-__chk_fail(void)
-{
-
- _rtld_error("buffer overflow detected; terminated");
- rtld_die();
-}
-
const char *
rtld_strerror(int errnum)
{
Index: share/mk/bsd.README
===================================================================
--- share/mk/bsd.README
+++ share/mk/bsd.README
@@ -115,6 +115,8 @@
The profiled libraries are no longer built in a different directory than
the regular libraries. A new suffix, ".po", is used to denote a profiled
object, and ".pico" denotes a position-independent relocatable object.
+".nossppico" denotes a position-independent relocatable object without
+stack smashing protection.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Index: share/mk/bsd.dep.mk
===================================================================
--- share/mk/bsd.dep.mk
+++ share/mk/bsd.dep.mk
@@ -160,13 +160,16 @@
@rm -f ${.TARGET}
${DTRACE} ${DTRACEFLAGS} -G -o ${.TARGET} -s ${.ALLSRC:N*.h}
.if defined(LIB)
-CLEANFILES+= ${_D}.pico ${_D}.po
+CLEANFILES+= ${_D}.pico ${_D}.po ${_D}.nossppico
${_D}.pico: ${_DSRC} ${SOBJS:S/^${_D}.pico$//}
@rm -f ${.TARGET}
${DTRACE} ${DTRACEFLAGS} -G -o ${.TARGET} -s ${.ALLSRC:N*.h}
${_D}.po: ${_DSRC} ${POBJS:S/^${_D}.po$//}
@rm -f ${.TARGET}
${DTRACE} ${DTRACEFLAGS} -G -o ${.TARGET} -s ${.ALLSRC:N*.h}
+${_D}.nossppico: ${_DSRC} ${SOBJS:S/^${_D}.nossppico$//}
+ @rm -f ${.TARGET}
+ ${DTRACE} ${DTRACEFLAGS} -G -o ${.TARGET} -s ${.ALLSRC:N*.h}
.endif
.endfor
.endfor
Index: share/mk/bsd.lib.mk
===================================================================
--- share/mk/bsd.lib.mk
+++ share/mk/bsd.lib.mk
@@ -21,9 +21,11 @@
# SHLIB_NAME will be defined only if we are to create a shared library.
# SHLIB_LINK will be defined only if we are to create a link to it.
# INSTALL_PIC_ARCHIVE will be defined only if we are to create a PIC archive.
+# BUILD_NOSSP_PIC_ARCHIVE will be defined only if we are to create a PIC archive.
.if defined(NO_PIC)
.undef SHLIB_NAME
.undef INSTALL_PIC_ARCHIVE
+.undef BUILD_NOSSP_PIC_ARCHIVE
.else
.if !defined(SHLIB) && defined(LIB)
SHLIB= ${LIB}
@@ -78,7 +80,8 @@
# prefer .s to a .c, add .po, remove stuff not used in the BSD libraries
# .pico used for PIC object files
-.SUFFIXES: .out .o .bc .ll .po .pico .S .asm .s .c .cc .cpp .cxx .C .f .y .l .ln
+# .nossppico used for NOSSP PIC object files
+.SUFFIXES: .out .o .bc .ll .po .pico .nossppico .S .asm .s .c .cc .cpp .cxx .C .f .y .l .ln
.if !defined(PICFLAG)
.if ${MACHINE_CPUARCH} == "sparc64"
@@ -98,12 +101,19 @@
${CC} ${PICFLAG} -DPIC ${SHARED_CFLAGS} ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
${CTFCONVERT_CMD}
+.c.nossppico:
+ ${CC} ${PICFLAG} -DPIC ${SHARED_CFLAGS:C/^-fstack-protector.*$//} ${CFLAGS:C/^-fstack-protector.*$//} -c ${.IMPSRC} -o ${.TARGET}
+ ${CTFCONVERT_CMD}
+
.cc.po .C.po .cpp.po .cxx.po:
${CXX} ${PO_FLAG} ${STATIC_CXXFLAGS} ${PO_CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET}
.cc.pico .C.pico .cpp.pico .cxx.pico:
${CXX} ${PICFLAG} -DPIC ${SHARED_CXXFLAGS} ${CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET}
+.cc.nossppico .C.nossppico .cpp.nossppico .cxx.nossppico:
+ ${CXX} ${PICFLAG} -DPIC ${SHARED_CXXFLAGS:C/^-fstack-protector.*$//} ${CXXFLAGS:C/^-fstack-protector.*$//} -c ${.IMPSRC} -o ${.TARGET}
+
.f.po:
${FC} -pg ${FFLAGS} -o ${.TARGET} -c ${.IMPSRC}
${CTFCONVERT_CMD}
@@ -112,7 +122,11 @@
${FC} ${PICFLAG} -DPIC ${FFLAGS} -o ${.TARGET} -c ${.IMPSRC}
${CTFCONVERT_CMD}
-.s.po .s.pico:
+.f.nossppico:
+ ${FC} ${PICFLAG} -DPIC ${FFLAGS:C/^-fstack-protector.*$//} -o ${.TARGET} -c ${.IMPSRC}
+ ${CTFCONVERT_CMD}
+
+.s.po .s.pico .s.nossppico:
${AS} ${AFLAGS} -o ${.TARGET} ${.IMPSRC}
${CTFCONVERT_CMD}
@@ -126,6 +140,11 @@
${CFLAGS} ${ACFLAGS} -c ${.IMPSRC} -o ${.TARGET}
${CTFCONVERT_CMD}
+.asm.nossppico:
+ ${CC:N${CCACHE_BIN}} -x assembler-with-cpp ${PICFLAG} -DPIC \
+ ${CFLAGS:C/^-fstack-protector.*$//} ${ACFLAGS} -c ${.IMPSRC} -o ${.TARGET}
+ ${CTFCONVERT_CMD}
+
.S.po:
${CC:N${CCACHE_BIN}} -DPROF ${PO_CFLAGS} ${ACFLAGS} -c ${.IMPSRC} \
-o ${.TARGET}
@@ -136,6 +155,11 @@
-c ${.IMPSRC} -o ${.TARGET}
${CTFCONVERT_CMD}
+.S.nossppico:
+ ${CC:N${CCACHE_BIN}} ${PICFLAG} -DPIC ${CFLAGS:C/^-fstack-protector.*$//} ${ACFLAGS} \
+ -c ${.IMPSRC} -o ${.TARGET}
+ ${CTFCONVERT_CMD}
+
_LIBDIR:=${LIBDIR}
_SHLIBDIR:=${SHLIBDIR}
@@ -285,6 +309,19 @@
${RANLIB} ${RANLIBFLAGS} ${.TARGET}
.endif
+.if defined(BUILD_NOSSP_PIC_ARCHIVE) && defined(LIB) && !empty(LIB) && ${MK_TOOLCHAIN} != "no"
+NOSSPSOBJS+= ${OBJS:.o=.nossppico}
+DEPENDOBJS+= ${NOSSPSOBJS}
+CLEANFILES+= ${NOSSPSOBJS}
+_LIBS+= lib${LIB_PRIVATE}${LIB}_nossp_pic.a
+
+lib${LIB_PRIVATE}${LIB}_nossp_pic.a: ${NOSSPSOBJS}
+ @${ECHO} building special nossp pic ${LIB} library
+ @rm -f ${.TARGET}
+ ${AR} ${ARFLAGS} ${.TARGET} ${NOSSPSOBJS} ${ARADD}
+ ${RANLIB} ${RANLIBFLAGS} ${.TARGET}
+.endif
+
.endif # !defined(INTERNALLIB)
.if defined(_SKIP_BUILD)
@@ -425,6 +462,11 @@
OBJS_DEPEND_GUESS.${_S:${OBJS_SRCS_FILTER:ts:}}.pico+= ${_S}
.endfor
.endif
+.if defined(BUILD_NOSSP_PIC_ARCHIVE) && defined(LIB) && !empty(LIB)
+.for _S in ${SRCS:N*.[hly]}
+OBJS_DEPEND_GUESS.${_S:${OBJS_SRCS_FILTER:ts:}}.nossppico+= ${_S}
+.endfor
+.endif
.if defined(HAS_TESTS)
MAKE+= MK_MAKE_CHECK_USE_SANDBOX=yes
Index: share/mk/meta.autodep.mk
===================================================================
--- share/mk/meta.autodep.mk
+++ share/mk/meta.autodep.mk
@@ -23,7 +23,7 @@
.if defined(SRCS)
# it would be nice to be able to query .SUFFIXES
-OBJ_EXTENSIONS+= .o .po .lo .pico
+OBJ_EXTENSIONS+= .o .po .lo .pico .nossppico
# explicit dependencies help short-circuit .SUFFIX searches
SRCS_DEP_FILTER+= N*.[hly]
@@ -179,7 +179,7 @@
@case "${.MAKE.META.FILES:T:M*.po.*}" in \
*.po.*) mv $@.${.MAKE.PID} $@;; \
*) { cat $@.${.MAKE.PID}; \
- sed 's,\.pico:,.o:,;s,\.o:,.po:,' $@.${.MAKE.PID}; } | sort -u > $@; \
+ sed 's,\.nossppico:,.o:,;s,\.pico:,.o:,;s,\.o:,.po:,' $@.${.MAKE.PID}; } | sort -u > $@; \
rm -f $@.${.MAKE.PID};; \
esac
.else
Index: share/mk/src.libnames.mk
===================================================================
--- share/mk/src.libnames.mk
+++ share/mk/src.libnames.mk
@@ -31,6 +31,7 @@
_INTERNALLIBS= \
amu \
bsnmptools \
+ c_nossp_pic \
cron \
elftc \
fifolog \
@@ -471,6 +472,9 @@
LIBPMCSTATDIR= ${OBJTOP}/lib/libpmcstat
LIBPMCSTAT?= ${LIBPMCSTATDIR}/libpmcstat.a
+LIBC_NOSSP_PICDIR= ${OBJTOP}/lib/libc
+LIBC_NOSSP_PIC?= ${LIBC_NOSSP_PICDIR}/libc_nossp_pic.a
+
# Define a directory for each library. This is useful for adding -L in when
# not using a --sysroot or for meta mode bootstrapping when there is no
# Makefile.depend. These are sorted by directory.
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Jan 27, 2:26 PM (13 h, 54 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
28057184
Default Alt Text
D15283.id42104.diff (9 KB)
Attached To
Mode
D15283: Created static pic libc with no SSP to be used by rtld
Attached
Detach File
Event Timeline
Log In to Comment