Commit be986326 authored by Charles Jacobsen's avatar Charles Jacobsen Committed by Vikram Narayanan

deker-setup: Original llvm example builds, but Smack crashes.

We developed an example to test a clang/llvm/smack build before;
that example is now incorporated with the rest of the examples.

To experiment with weak symbols, I moved a few of the redefines
into libdeker (lcd_enter, lcd_exit, lcd_printk). These override
the liblcd versions. I also left the lcd_sync_call and
lcd_sync_reply redefines in environment.c.

There were a couple more clang fixes - one in the trampoline
assembly. The gnu assembler accepts "movq mem, mem" as a pseudo
instruction, but clang does not.

Fixed the "make clean" target. Made some extra scripts so it's easier
to build larger components (e.g. the entire microkernel, or all of
libdeker - including the special liblcd build).

The "main" required for Smack is in a "runtime" object file (sort of
like the C runtime). This is in libdeker/deker_rt.c.

Finally, I tweaked the LCD test module configuration so that you can
build a subset of the test modules (and choose how to build them).
This means you don't have to build everything (e.g., before, if a
module wanted to be built as non-isolated, you'd have to have the
microkernel built; but to get a successful microkernel build, you'd
probably need a full kernel build).
parent 8e07d9e7
......@@ -117,12 +117,13 @@ libasync/configure: libasync/configure.ac
# (clean is set in included makefiles above)
distclean:
distclean: clean
rm -rf $(LCD_BUILD_DIR)
# ------------------------------------------------------------
# phonies
.PHONY += \
.PHONY: \
clean \
distclean
......@@ -46,7 +46,7 @@ struct lcd_trampoline_handle {
* trampoline you write.
*/
#define LCD_TRAMPOLINE_PROLOGUE(hidden_args, fname) { \
void **__ip; \
void **__ip; \
asm( \
"jmp 1f \n\t" \
\
......@@ -59,10 +59,11 @@ struct lcd_trampoline_handle {
/* This next bit may not be portable. It assumes that */ \
/* the following instruction is 7 bytes. RIP-relative */ \
/* addressing is relative to the *next* instruction. */ \
"movq -0xf(%%rip), %0 \n\t" \
"movq -0xf(%%rip), %%rax \n\t" \
"movq %%rax, %0 \n\t" \
\
: "=g"(__ip) \
::); \
:: "rax"); \
hidden_args = *(__ip - 1); \
}
......
/*
* main.c
* deker_rt.c
*
* This contains the main function, as required by Smack.
*/
......@@ -10,7 +10,8 @@
#include <lcd_config/post_hook.h>
int main(void)
int
main(void)
{
return init_module();
}
/*
* console.c
*
* printk redefines
*/
#include <lcd_config/pre_hook.h>
#include <liblcd/console.h>
#include <lcd_config/post_hook.h>
void
LIBDEKER_FUNC_ATTR
lcd_printk(const char *fmt, ...)
{
return; /* no op */
}
/*
* enter_exit.c
*
* LCD boot redefines
*/
#include <lcd_config/pre_hook.h>
#include <liblcd/enter_exit.h>
#include <lcd_config/post_hook.h>
int
LIBDEKER_FUNC_ATTR
lcd_enter(void)
{
/* No-op */
return 0;
}
void
LIBDEKER_FUNC_ATTR
__noreturn lcd_exit(int ret)
{
/* No-op */
for (;;)
;
}
......@@ -14,5 +14,12 @@ int
LIBDEKER_FUNC_ATTR
lcd_sync_send(cptr_t c)
{
return 12345;
return 0;
}
int
LIBDEKER_FUNC_ATTR
lcd_sync_reply(void)
{
return 0;
}
......@@ -13,7 +13,9 @@
#include <lcd_config/post_hook.h>
struct lcd_boot_info * lcd_get_boot_info(void)
struct lcd_boot_info *
LIBLCD_FUNC_ATTR
lcd_get_boot_info(void)
{
return (struct lcd_boot_info *)gva_val(LCD_BOOTSTRAP_PAGES_GV_ADDR);
}
......@@ -32,7 +32,9 @@ void _lcd_printk(const char *fmt, va_list args)
lcd_syscall_putchar(0);
}
void lcd_printk(const char *fmt, ...)
void
LIBLCD_FUNC_ATTR
lcd_printk(const char *fmt, ...)
{
va_list args;
/*
......
......@@ -18,7 +18,9 @@
static int thc_initialized;
int lcd_enter(void)
int
LIBLCD_FUNC_ATTR
lcd_enter(void)
{
int ret;
/*
......@@ -101,7 +103,9 @@ fail:
return ret;
}
void __noreturn lcd_exit(int retval)
void
LIBLCD_FUNC_ATTR
__noreturn lcd_exit(int retval)
{
lcd_printk("=================");
lcd_printk("LCD SHUTTING DOWN");
......
......@@ -13,17 +13,22 @@
#include <lcd_config/post_hook.h>
struct lcd_utcb *
LIBLCD_FUNC_ATTR
lcd_get_utcb(void)
{
return (struct lcd_utcb *)gva_val(LCD_UTCB_GV_ADDR);
}
int _lcd_create_sync_endpoint(cptr_t slot)
int
LIBLCD_FUNC_ATTR
_lcd_create_sync_endpoint(cptr_t slot)
{
return lcd_syscall_create_sync_ep(slot);
}
int lcd_create_sync_endpoint(cptr_t *slot_out)
int
LIBLCD_FUNC_ATTR
lcd_create_sync_endpoint(cptr_t *slot_out)
{
int ret;
/*
......@@ -51,22 +56,30 @@ fail1:
return ret;
}
int lcd_sync_send(cptr_t endpoint)
int
LIBLCD_FUNC_ATTR
lcd_sync_send(cptr_t endpoint)
{
return lcd_syscall_sync_send(endpoint);
}
int lcd_sync_recv(cptr_t endpoint)
int
LIBLCD_FUNC_ATTR
lcd_sync_recv(cptr_t endpoint)
{
return lcd_syscall_sync_recv(endpoint);
}
int lcd_sync_call(cptr_t endpoint)
int
LIBLCD_FUNC_ATTR
lcd_sync_call(cptr_t endpoint)
{
return lcd_syscall_sync_call(endpoint);
}
int lcd_sync_reply(void)
int
LIBLCD_FUNC_ATTR
lcd_sync_reply(void)
{
return lcd_syscall_sync_reply();
}
......@@ -8,3 +8,4 @@ export CC=$(WLLVM_PATH)
# Remove cflags that clang throws a fit about
KBUILD_CFLAGS := $(filter-out $(LIBDEKER_BAD_CFLAGS), $(KBUILD_CFLAGS))
KBUILD_AFLAGS := $(filter-out $(LIBDEKER_BAD_CFLAGS), $(KBUILD_AFLAGS))
\ No newline at end of file
......@@ -13,16 +13,22 @@ src = $(LCD_DOMAINS_TOP_SRC_DIR)
# ------------------------------------------------------------
lib-y += $(addprefix libdeker/, \
main.o \
smack.o \
)
lib-y += $(addprefix libdeker/lcd-domains/, \
sync_ipc.o \
enter_exit.o \
console.o \
)
lib-y += $(addprefix $(LIBDEKER_BUILD_DIR)/libdeker, \
smack.o \
)
# Don't include this in the static lib.a. Modules built for deker
# always need to include this, and the functions in deker_rt.o won't
# get sucked in if we put them in a lib.a (if nothing in the module
# calls the functions, like "main").
extra-y += $(addprefix libdeker/, \
deker_rt.o \
)
ccflags-y += $(LIBDEKER_CFLAGS)
......
......@@ -23,3 +23,4 @@ obj-m += string_example/
obj-m += pmfs/
obj-m += bug/
obj-m += async_rpc/
obj-m += llvm_example/
\ No newline at end of file
......@@ -35,6 +35,12 @@ LIBDEKER_WEAK_ATTR='__attribute__((weak))'
# gcc doesn't. There's enough of them that it's easier for now just to turn
# off this warning.
# Turn off -Wtautological-compare. clang warns of comparisons that are
# always true/false.
# Turn off -Wundef. Smack uses some undefined macros in the wrong way and
# clang complains.
LIBDEKER_BASE_CFLAGS=\
$(LCD_DOMAINS_CFLAGS) \
-I$(LCD_DOMAINS_TOP_SRC_DIR)/include \
......@@ -50,19 +56,22 @@ LIBDEKER_BASE_CFLAGS=\
-Wno-pointer-sign \
-Wno-gnu-variable-sized-type-not-at-end \
-Wno-unused-function \
-Wno-tautological-compare \
-Wno-undef \
-DHAVE_INLINE \
-DHAVE_BUILTIN_EXPECT \
-DHAVE_BUILTIN_MEMCPY \
-DHAVE_BUILTIN_VA_START \
-DHAVE_BUILTIN_OBJECT_SIZE
-DHAVE_BUILTIN_OBJECT_SIZE \
-DLIBDEKER_FUNC_ATTR=$(LIBDEKER_WEAK_ATTR) \
-DLIBLCD_FUNC_ATTR=$(LIBDEKER_WEAK_ATTR)
LIBDEKER_CFLAGS= \
$(LIBDEKER_BASE_CFLAGS) \
-I$(LIBDEKER_BUILD_DIR)/libcap.install/include \
-I$(LIBDEKER_BUILD_DIR)/libfipc.install/include \
-I$(LIBDEKER_BUILD_DIR)/libasync.install/include \
-DLIBDEKER_FUNC_ATTR=$(LIBDEKER_WEAK_ATTR) \
-DLIBLCD_FUNC_ATTR=$(LIBDEKER_WEAK_ATTR)
-I$(LIBDEKER_BUILD_DIR)/libasync.install/include
LIBDEKER_BAD_CFLAGS= \
-fno-delete-null-pointer-checks \
......@@ -104,15 +113,8 @@ LIBDEKER_LIB_CFLAGS= $(LIBDEKER_BASE_CFLAGS)
# I mash this in one line for now.
LIBLCD_FOR_DEKER_AR_SCRIPT="CREATE $(LIBDEKER_BUILD_DIR)/liblcd_build/liblcd.a\nADDLIB $(LIBDEKER_BUILD_DIR)/liblcd_build/lib.a\nADDLIB $(LIBDEKER_BUILD_DIR)/libcap.install/lib/libcap.a\nADDLIB $(LIBDEKER_BUILD_DIR)/libfipc.install/lib/libfipc.a\nADDLIB $(LIBDEKER_BUILD_DIR)/libasync.install/lib/libasync.a\nSAVE\nEND\n"
$(LIBDEKER_BUILD_DIR)/libdeker.bca: libdeker
$(WLLVM_EXTRACT_BC_PATH) $(LIBDEKER_BUILD_DIR)/libdeker.a
libdeker: $(LIBDEKER_BUILD_DIR)/lib.a
@echo " AR $@"
@echo $(LIBDEKER_AR_SCRIPT) | ar -M
$(LIBDEKER_BUILD_DIR)/liblcd_build/liblcd.bca: liblcd_for_deker
$(WLLVM_EXTRACT_BC_PATH) $(LIBLCD_BUILD_DIR)/liblcd_build/liblcd.a
cp $< $(LIBDEKER_BUILD_DIR)/libdeker.a
liblcd_for_deker: $(LIBDEKER_BUILD_DIR)/liblcd_build/lib.a | \
$(LIBDEKER_LIBCAP) $(LIBDEKER_LIBFIPC) $(LIBDEKER_LIBASYNC)
......@@ -129,18 +131,16 @@ $(LIBDEKER_BUILD_DIR)/liblcd_build/Kbuild: scripts/Kbuild.liblcd | \
$(LIBDEKER_BUILD_DIRS)
@echo " KBUILD $@"
@printf "# This part is auto prepended by Makefile.libdeker:\n\n" > $@ && \
printf "export CC=$(WLLVM_PATH)\n" >> $@ && \
printf 'KBUILD_CFLAGS := $$(filter-out $$(LIBDEKER_BAD_CFLAGS), $$(KBUILD_CFLAGS))\n' >> $@ && \
printf 'KBUILD_AFLAGS := $$(filter-out $$(LIBDEKER_BAD_CFLAGS), $$(KBUILD_AFLAGS))\n' >> $@ && \
printf 'include $$(DEKER_KBUILD_CONFIG)' >> $@ && \
printf "\n# End of auto prepended part\n\n" >> $@ && \
cat $< >> $@
$(LIBDEKER_BUILD_DIR)/lib.a: $(LIBDEKER_BUILD_DIR)/Kbuild | \
$(LIBDEKER_BUILD_DIR)/lib.a: $(LIBDEKER_BUILD_DIR)/Kbuild \
libdeker/smack.c | \
$(LIBDEKER_BUILD_DIRS)
$(MAKE) -C .. M=$(LIBDEKER_BUILD_DIR) $(MAKEFLAGS)
$(LIBDEKER_BUILD_DIR)/libdeker/smack.c: $(SMACK_LIB_PATH)/smack.c | \
$(LIBDEKER_BUILD_DIRS)
libdeker/smack.c: $(SMACK_LIB_PATH)/smack.c
ln -s $< $@
libcap.libdeker: $(LIBDEKER_BUILD_DIR)/libcap.build/Makefile
......@@ -217,6 +217,7 @@ clean-libdeker: clean-libdeker-libcap clean-libdeker-libfipc \
rm -f $(LIBDEKER_BUILD_DIR)/libdeker.a.bc
rm -f $(LIBDEKER_BUILD_DIR)/liblcd_build/liblcd.a
rm -f $(LIBDEKER_BUILD_DIR)/liblcd_build/liblcd.a.bc
rm -f libdeker/smack.c
clean-libdeker-lib%:
if test -d $(LIBDEKER_BUILD_DIR)/$(subst clean-libdeker-,,$@).build; then \
......@@ -224,9 +225,9 @@ clean-libdeker-lib%:
fi
rm -rf $(LIBDEKER_BUILD_DIR)/$(subst clean-libdeker-,,$@).install
clean += clean-libdeker
clean: clean-libdeker
.PHONY += \
.PHONY: \
libdeker \
$(LIBDEKER_BUILD_DIR)/lib.a \
liblcd_for_deker \
......
......@@ -8,6 +8,8 @@
LIBLCD_BUILD_DIR=$(LCD_BUILD_DIR)/liblcd_build
export LIBLCD_BUILD_DIR
LIBLCD_WEAK_ATTR=
LIBLCD_BASE_CFLAGS=\
$(LCD_DOMAINS_CFLAGS) \
-I$(LCD_DOMAINS_TOP_SRC_DIR)/include \
......@@ -16,7 +18,8 @@ LIBLCD_BASE_CFLAGS=\
-DCONFIG_LAZY_THC \
-DMODULE \
-DLCD_ISOLATE \
-DCPTR_CACHE_LOCK_PADDING_SIZE=8
-DCPTR_CACHE_LOCK_PADDING_SIZE=8 \
-DLIBLCD_FUNC_ATTR=$(LIBLCD_WEAK_ATTR)
LIBLCD_CFLAGS= \
$(LIBLCD_BASE_CFLAGS) \
......@@ -44,8 +47,6 @@ LIBLCD_LIBCAP=$(LIBLCD_BUILD_DIR)/libcap.install/lib/libcap.a
LIBLCD_LIBFIPC=$(LIBLCD_BUILD_DIR)/libfipc.install/lib/libfipc.a
LIBLCD_LIBFIPC=$(LIBLCD_BUILD_DIR)/libasync.install/lib/libasync.a
LIBLCD_WEAK_ATTR=
LIBLCD_LIB_CFLAGS= $(LIBLCD_BASE_CFLAGS)
# There isn't a nice easy way to multiline this, and I want access to the
......@@ -125,9 +126,9 @@ clean-liblcd-lib%:
fi
rm -rf $(LIBLCD_BUILD_DIR)/$(subst clean-liblcd-,,$@).install
clean += clean-liblcd
clean: clean-liblcd
.PHONY += \
.PHONY: \
liblcd \
$(LIBLCD_BUILD_DIR)/lib.a \
libcap.liblcd \
......
......@@ -109,9 +109,9 @@ clean-mk-lib%:
fi
rm -rf $(MICROKERNEL_BUILD_DIR)/$(subst clean-mk-,,$@).install
clean += clean-microkernel
clean: clean-microkernel
.PHONY += \
.PHONY: \
microkernel \
libcap.microkernel \
libfipc.microkernel \
......
......@@ -34,7 +34,7 @@ export DEKER_CFLAGS=$(LIBDEKER_CFLAGS)
# ------------------------------------------------------------
# LIBLCD
LIBLCD_PATH_CMD=$(shell scripts/relpath.py $(LIBDLCD_BUILD_DIR)/liblcd.a $(shell dirname $(shell readlink -f $@)))
LIBLCD_PATH_CMD=$(shell scripts/relpath.py $(LIBLCD_BUILD_DIR)/liblcd.a $(shell dirname $(shell readlink -f $@)))
# ------------------------------------------------------------
# LIBDEKER
......@@ -47,7 +47,9 @@ ifneq ($(DEKER),)
LIBDEKER_PATH_CMD=$(shell scripts/relpath.py $(LIBDEKER_BUILD_DIR)/libdeker.a $(shell dirname $(shell readlink -f $@))) $(shell scripts/relpath.py $(LIBDEKER_BUILD_DIR)/liblcd_build/liblcd.a $(shell dirname $(shell readlink -f $@)))
MAYBE_LIBDEKER=$(LIBDEKER_BUILD_PATH)/libdeker/libdeker.a
LIBDEKER_RUNTIME_PATH_CMD=$(shell scripts/relpath.py $(LIBDEKER_BUILD_DIR)/libdeker/deker_rt.o $(shell dirname $(shell readlink -f $@)))
MAYBE_LIBDEKER=$(LIBDEKER_BUILD_DIR)/libdeker.a
endif
......@@ -57,16 +59,20 @@ endif
ifneq ($(DEKER),)
test_mods_deker: test_mods
scripts/deker_mod_post.sh test_mods/config \
@echo " DEKER MODPOST"
@scripts/deker_mod_post.sh test_mods/config \
$(WLLVM_EXTRACT_BC_PATH)
else:
test_mods_deker: test_mods
endif
test_mods: $(LCD_TEST_MODULES_BUILD_DIR)/Kbuild \
$(LCD_TEST_MODULES_BUILD_DIR)/Kbuild.config \
$(TEST_MODULES_BUILD_KBUILDS) | \
$(LIBLCD_BUILD_DIR)/liblcd.a $(TEST_MODULES_BUILD_DIRS) \
$(MAYBE_LIBDEKER)
$(TEST_MODULES_BUILD_DIRS)
$(MAKE) -C .. M=$(LCD_TEST_MODULES_BUILD_DIR) \
KBUILD_EXTRA_SYMBOLS=$(KLIBLCD_SYMBOLS) $(MAKEFLAGS)
......@@ -76,6 +82,7 @@ $(LCD_TEST_MODULES_BUILD_DIR)/%/Kbuild: $(LCD_TEST_MODULES_DIR)/%/Kbuild | \
@printf "#\n# BEGIN: Auto-generated part.\n#\n" > $@ && \
printf "\n" >> $@ && \
printf "LIBDEKER=$(LIBDEKER_PATH_CMD)\n" >> $@ && \
printf "LIBDEKER_RUNTIME=$(LIBDEKER_RUNTIME_PATH_CMD)\n" >> $@ && \
printf "LIBLCD=$(LIBLCD_PATH_CMD)\n" >> $@ && \
printf "src=$(shell dirname `readlink -f $<`)\n" >> $@ && \
printf "\n" >> $@ && \
......@@ -101,8 +108,8 @@ clean-test_mods:
$(MAKE) -C .. M=$(LCD_TEST_MODULES_BUILD_DIR) clean; \
fi
clean += clean-test_mods
clean: clean-test_mods
.PHONY += \
.PHONY: \
test_mods \
clean-test_mods
......@@ -16,4 +16,4 @@ make libasync.libdeker $@
make liblcd_for_deker $@
make libdeker
make test_mods $@
make test_mods_deker $@
#! /bin/bash -e
make libcap.libdeker DEKER=1 $@
make libfipc.libdeker DEKER=1 $@
make libasync.libdeker DEKER=1 $@
make liblcd_for_deker DEKER=1 $@
make libdeker DEKER=1
#! /bin/bash -e
make libcap.liblcd $@
make libfipc.liblcd $@
make libasync.liblcd $@
make liblcd $@
#! /bin/bash -e
make libcap.microkernel $@
make libfipc.microkernel $@
make libasync.microkernel $@
make microkernel $@
......@@ -19,6 +19,7 @@ NF == 0 { next }
# Print out build config define for all others
{
gsub(/\//, "_", $1)
print "export LCD_CONFIG_BUILD_" toupper($1) "=m";
print "export LCD_CONFIG_" toupper($1) "_" toupper($2) "=y";
}
#
# Lists the modules in config file that are built for deker.
#
# Invocation example:
#
# cat config | awk -f deker.awk
#
# where conf is the module build configuration file (test_mods/config).
#
# Skip comment lines
/#.*/ { next }
# Skip empty lines
NF == 0 { next }
# Print out build config define for all others
$2 == "deker" {
print $1
}
......@@ -4,9 +4,10 @@ config=$1
wllvm_extract_bc=$2
# Parse config to get those modules that were built and linked for deker
mods=`cat ${config} | awk -f scripts/conf.awk | awk '$2 == "deker" { print $1 }'`
mods=`cat ${config} | awk -f scripts/deker.awk`
# For each deker module, run extract-bc
for mod in $mods; do
${wllvm_extract_bc} ${mod}/*.ko
echo " EXTRACT-BC $mod"
${wllvm_extract_bc} ${LCD_TEST_MODULES_BUILD_DIR}/${mod}/*.ko
done
obj-m += boot/
obj-m += lcd/
\ No newline at end of file
obj-$(LCD_CONFIG_BUILD_ASYNC_BOOT) += boot/
obj-$(LCD_CONFIG_BUILD_ASYNC_LCD) += lcd/
\ No newline at end of file
obj-m += boot/
obj-m += caller_lcd/
obj-m += callee_lcd/
\ No newline at end of file
obj-$(LCD_CONFIG_BUILD_ASYNC_RPC_BOOT) += boot/
obj-$(LCD_CONFIG_BUILD_ASYNC_RPC_CALLER_LCD) += caller_lcd/
obj-$(LCD_CONFIG_BUILD_ASYNC_RPC_CALLEE_LCD) += callee_lcd/
\ No newline at end of file
obj-$(LCD_CONFIG_BUILD_BUG_BOOT) += boot/
obj-$(LCD_CONFIG_BUILD_BUG_LCD) += lcd/
......@@ -7,39 +7,42 @@
# This file determines how a module is built and linked.
#
async/boot nonisolated
async/lcd isolated
# async/boot nonisolated
# async/lcd isolated
async_rpc/boot nonisolated
async_rpc/caller isolated
async_rpc/callee isolated
# async_rpc/boot nonisolated
# async_rpc/caller isolated
# async_rpc/callee isolated
bug/boot nonisolated
bug/lcd isolated
# bug/boot nonisolated
# bug/lcd isolated
create_klcd/boot nonisolated
create_klcd/klcd nonisolated
# create_klcd/boot nonisolated
# create_klcd/klcd nonisolated
glue_example/boot nonisolated
glue_example/minix deker
glue_example/vfs deker
# glue_example/boot nonisolated
# glue_example/minix isolated
# glue_example/vfs isolated
ipc1/boot nonisolated
ipc1/lcd isolated
# ipc1/boot nonisolated
# ipc1/lcd isolated
ipc2/boot nonisolated
ipc2/lcd1 isolated
ipc2/lcd2 isolated