Changeset View
Standalone View
libexec/rtld-elf/rtld-libc/Makefile.inc
- This file was added.
# $FreeBSD$ | |||||
# Add the necessary libc dependencies for RTLD without pulling in all of the | |||||
# complex libc bits such as locales, etc. | |||||
# TODO: avoid linking libc_pic | |||||
LIBADD= c_nossp_pic | |||||
CFLAGS+= -I${SRCTOP}/libexec/rtld-elf/rtld-libc | |||||
# Build all the files that use __libc_interposing here with -DIN_RTLD. With that | |||||
# define they avoid the use of __libc_interposing and call the syscall directly. | |||||
.PATH: ${SRCTOP}/lib/libc/gen | |||||
SRCS+= opendir.c closedir.c readdir.c telldir.c | |||||
# Avoid further dependencies by providing simple implementations of libc | |||||
# functions such as __error(), etc. | |||||
.PATH: ${SRCTOP}/libexec/rtld-elf/rtld-libc | |||||
kib: Is this needed ? | |||||
Done Inline ActionsThis is needed for CHERI where we convert the variadic system call to always pass the optional argument (since the variadic calling convention is different and passes all arguments on the stack. I forgot to remove that part of the diff and will only add it to CheriBSD. arichardson: This is needed for CHERI where we convert the variadic system call to always pass the optional… | |||||
SRCS+= rtld_libc.c | |||||
Done Inline ActionsIs that happens due to -DIN_RTLD or because of rtld-hacked namespace.h ? kib: Is that happens due to -DIN_RTLD or because of rtld-hacked namespace.h ? | |||||
Done Inline ActionsI'm afraid I don't understand the question. Are you asking why we need those files for CHERI? For all non-CHERI arichardson: I'm afraid I don't understand the question. Are you asking why we need those files for CHERI? | |||||
Done Inline ActionsNo, I am asking, what magic gets rid of the interposing calls. Your comment claims that this is because of -DIN_RTLD defined while *dir.c files are compiled, but IMO it happens because you provide different namespace.h which directs interposed calls to non-interposed functions. kib: No, I am asking, what magic gets rid of the interposing calls. Your comment claims that this… | |||||
Done Inline ActionsYes, it is a combination of the two. For opendir.o it's both the ifdefs and the macros that redirect to __sys_foo arichardson: Yes, it is a combination of the two. For opendir.o it's both the ifdefs and the macros that… | |||||
Not Done Inline ActionsWhich specific #ifdef do you mean there ? kib: Which specific #ifdef do you mean there ? | |||||
Done Inline Actions-DIN_RTLD arichardson: -DIN_RTLD | |||||
Not Done Inline ActionsI should be extremely explicit. Please give me the line number in opendir.c which contains that #ifdef. kib: I should be extremely explicit. Please give me the line number in opendir.c which contains… | |||||
Done Inline ActionsSorry I got confused here. -DIN_RTLD only affects the CheriBSD-specific compiles of fctnl.c and open.c. In this patch it doesn't actually change anything in opendir. The changes in opendir are due to the defines at the start of rtld_libc.h to avoid calling pthreads functions. arichardson: Sorry I got confused here. -DIN_RTLD only affects the CheriBSD-specific compiles of fctnl.c and… | |||||
Not Done Inline ActionsSo the comment is misleading, which is why I am so attached to this point. It is not -DIN_RTLD which avoids interposing for FreeBSD. kib: So the comment is misleading, which is why I am so attached to this point. It is not -DIN_RTLD… | |||||
# The following logic was used to avoid dependencies. If you would like to | |||||
# verify that we haven't started including more files from libc due to more | |||||
# recent changes, you can compile with -DRTLD_VERIFY_LIBC_DEPENDENCIES and | |||||
# check that rtld still compiles. | |||||
.ifdef RTLD_VERIFY_LIBC_DEPENDENCIES | |||||
# __libc_interposing adds lots of unncessary dependencies | |||||
Not Done Inline ActionsIs this a stray comment ? kib: Is this a stray comment ? | |||||
Done Inline ActionsI could keep this in under .ifdef DEBUG_RTLD_LIBC_DEPENDENCIES so that we can check that other architectures don't accidentally pull in more files (I only tested MIPS and x86). arichardson: I could keep this in under `.ifdef DEBUG_RTLD_LIBC_DEPENDENCIES` so that we can check that… | |||||
_blacklisted_symbols=__libc_interposing | |||||
# So does _elf_aux_info (it pulls in pthreads) | |||||
_blacklisted_symbols+= _elf_aux_info | |||||
# Avoid pthreads depedency | |||||
_blacklisted_symbols+=_pthread_mutex_lock pthread_mutex_lock | |||||
# And fprintf (pulls in all the locale code) | |||||
_blacklisted_symbols+=fprintf | |||||
# Now list all symbols inside the __libc_interposing table: | |||||
_blacklisted_symbols+=accept accept4 aio_suspend close connect fcntl fsync \ | |||||
fork msync nanosleep openat poll pselect recvfrom recvmsg select sendmsg \ | |||||
sendto setcontext sigaction sigsuspend sigwait sigtimedwait sigwaitinfo \ | |||||
swapcontext system tcdrain read readv wait4 write writev \ | |||||
_pthread_mutex_init_calloc_cb spinlock spinunlock kevent wait6 ppoll \ | |||||
map_stacks_exec fdatasync clock_nanosleep distribute_static_tls | |||||
# Some more symbols that were previously defined in rtld (but are not needed) | |||||
_blacklisted_symbols+=__pthread_cxa_finalize | |||||
_blacklisted_symbols+=exit | |||||
# Note: this library is a hack to verify that we didn't link those symbols. It | |||||
# would be nice if LD supported a flag that caused an error when linking against | |||||
# a given symbol. | |||||
LDADD+=${.OBJDIR}/rtld_verify_linked_symbols.a | |||||
${sym}.c: ensure_not_linked.h | |||||
_blacklisted_objs= | |||||
LDFLAGS+= -Wl,--trace | |||||
.for sym in ${_blacklisted_symbols} | |||||
${sym}.c: ensure_not_linked.h | |||||
printf "#include \"ensure_not_linked.h\"\nLINK_ERROR_ON_REFERENCE(${sym})\n" > ${sym}.c | |||||
${sym}.o: ${sym}.c | |||||
${CC} ${CFLAGS} ${sym}.c -c -o ${sym}.o | |||||
_blacklisted_objs+= ${sym}.o | |||||
CLEANFILES+=${sym}.o | |||||
LDFLAGS+= -Wl,--trace-symbol=${sym} | |||||
.endfor | |||||
rtld_verify_linked_symbols.a: ensure_not_linked.h ${_blacklisted_objs} | |||||
${AR} cr ${.OBJDIR}/${.TARGET} ${_blacklisted_objs} | |||||
CLEANFILES+=rtld_verify_linked_symbols.a | |||||
${PROG}: rtld_verify_linked_symbols.a | |||||
.endif RTLD_VERIFY_LIBC_DEPENDENCIES | |||||
Done Inline ActionsFIXME ? kib: FIXME ? |
Is this needed ?