From 4c616abfbf6e52ae63c5ba4d8446104b1255218d Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Tue, 24 Jun 2014 18:39:09 +0100 Subject: [PATCH] app-tools: Provide rumpxen-app-* helpers Provide: * A GCC wrapper which allows a naive Makefile to compile and link an "executable" to generate a rump kernel image. This uses: * A GCC specs file. This provides the right "system" include directories - that is, the headers for the rump kernel application environment. It also uses: * A stunt wrapper for "ld". Building a minios-based Xen image needs two runs of ld. This ld wrapper parses and categorises its arguments and runs the two appropriate link steps. * A pair of simple wrapper scripts for configure and make, which set CC and pass the --host= option. With these changes, and a suitably modified xen.git, we can run configure and build a relevant subset of the Xen management libraries and tools. Signed-off-by: Ian Jackson --- .gitignore | 5 ++++ Makefile | 34 ++++++++++++++++++++++- app-tools/ld | 44 ++++++++++++++++++++++++++++++ app-tools/rumpxen-app-cc.in | 6 ++++ app-tools/rumpxen-app-configure.in | 5 ++++ app-tools/rumpxen-app-make.in | 5 ++++ app-tools/specs.in | 20 ++++++++++++++ 7 files changed, 118 insertions(+), 1 deletion(-) create mode 100755 app-tools/ld create mode 100755 app-tools/rumpxen-app-cc.in create mode 100755 app-tools/rumpxen-app-configure.in create mode 100755 app-tools/rumpxen-app-make.in create mode 100644 app-tools/specs.in diff --git a/.gitignore b/.gitignore index 27970b8..cf26239 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,8 @@ rumpobj rumptools include/mini-os/machine include/xen + +app-tools/rumpxen-app-cc +app-tools/specs +app-tools/rumpxen-app-configure +app-tools/rumpxen-app-make diff --git a/Makefile b/Makefile index d802004..3e4e12f 100644 --- a/Makefile +++ b/Makefile @@ -102,7 +102,7 @@ HTTPD_OBJS+= httpd/bozohttpd.o httpd/main.o httpd/ssl-bozo.o HTTPD_OBJS+= httpd/content-bozo.o httpd/dir-index-bozo.o .PHONY: default -default: objs $(TARGET) +default: objs app-tools $(TARGET) objs: mkdir -p $(OBJ_DIR)/lib $(OBJ_DIR)/xen/$(TARGET_ARCH_DIR) @@ -137,6 +137,38 @@ $(TARGET): links $(OBJS) $(HTTPD_OBJS) $(APP_O) arch_lib $(LD) $(LDFLAGS) $(LDFLAGS_FINAL) $@.o $(EXTRA_OBJS) -o $@ #gzip -f -9 -c $@ >$@.gz + +APP_TOOLS += rumpxen-app-cc specs +APP_TOOLS += rumpxen-app-configure rumpxen-app-make + +.PHONY: app-tools +app-tools: $(addprefix app-tools/, $(APP_TOOLS)) + +$(eval \ +APP_TOOLS_LDLIBS := $(patsubst -L%, -L$$(abspath %), $(LDARCHLIB) $(LDLIBS))) +# We need to expand this twice because the replacement argument to +# patsubst is normally expanded only once (beforehand), but we want to +# apply abspath to each individual argument. + +APP_TOOLS_OBJS := \ + $(abspath $(filter-out %/rumpkern_demo.o, $(OBJS))) \ + $(APP_TOOLS_LDLIBS) + +APP_TOOLS_ARCH := $(subst x86_32,i386, \ + $(subst x86_64,amd64, \ + $(XEN_TARGET_ARCH))) + +app-tools/%: app-tools/%.in Makefile Config.mk + sed <$< >$@.tmp \ + -e 's#!ARCH!#$(strip $(APP_TOOLS_ARCH))#;' \ + -e 's#!BASE!#$(abspath .)#;' \ + -e 's#!APPTOOLS!#$(abspath app-tools)#;' \ + -e 's#!OBJS!#$(APP_TOOLS_OBJS)#;' \ + -e 's#!HEAD_OBJ!#$(abspath $(HEAD_OBJ))#;' \ + -e 's#!LDSCRIPT!#$(abspath $(LDSCRIPT))#;' + if test -x $<; then chmod +x $@.tmp; fi + mv -f $@.tmp $@ + .PHONY: clean arch_clean arch_clean: diff --git a/app-tools/ld b/app-tools/ld new file mode 100755 index 0000000..322dd67 --- /dev/null +++ b/app-tools/ld @@ -0,0 +1,44 @@ +#!/bin/bash +set -e +outargs=() + +fail () { echo >&2 "stunt ld: $*"; exit 127; } + +noshift () { fail "no arg for $a"; } + +echo "stunt ld: $*" + +while [ $# != 0 ]; do + a=$1; shift + case "$a" in + [^-]*|-L*|-l*|--whole-archive|--no-whole-archive) + outargs+=("$a") + ;; + -m) + march="$1"; shift || noshift + outargs+=("$a" "$march") + ;; + -o) + outfile="$1"; shift || noshift + ;; + --as-needed|--no-as-needed) + ;; + --stunt-final-script) + finallds="$1"; shift || noshift + ;; + --stunt-intermediate) + inter1="$1"; shift || noshift + inter2="$1"; shift || noshift + ;; + *) + fail "unknown option $a" + ;; + esac +done + +if [ x"$outfile" = x ]; then outfile=a.out; fi + +set -x +ld -nostdlib -r "${outargs[@]}" -o "$inter1" +objcopy -w -G xenos_* -G _start "$inter1" "$inter2" +ld -m "$march" -T "$finallds" "$inter2" -o "$outfile" diff --git a/app-tools/rumpxen-app-cc.in b/app-tools/rumpxen-app-cc.in new file mode 100755 index 0000000..6a80a4a --- /dev/null +++ b/app-tools/rumpxen-app-cc.in @@ -0,0 +1,6 @@ +#!/bin/sh +set -e +case " $* " in +*" -v "*) set -x ;; +esac +exec gcc -D__RUMPUSER_XEN__ -D__NetBSD__ -specs=!APPTOOLS!/specs "$@" diff --git a/app-tools/rumpxen-app-configure.in b/app-tools/rumpxen-app-configure.in new file mode 100755 index 0000000..1cbaf73 --- /dev/null +++ b/app-tools/rumpxen-app-configure.in @@ -0,0 +1,5 @@ +#!/bin/sh +# invoke this (for example) as .../app-configure ./configure --prefix=... +set -e +prog=$1; shift +exec "$prog" --host=!ARCH!-rumpxen-netbsd CC=!APPTOOLS!/rumpxen-app-cc diff --git a/app-tools/rumpxen-app-make.in b/app-tools/rumpxen-app-make.in new file mode 100755 index 0000000..ea9b1e9 --- /dev/null +++ b/app-tools/rumpxen-app-make.in @@ -0,0 +1,5 @@ +#!/bin/sh +# invoke this (for example) as .../app-build make target +set -e +prog=$1; shift +exec "$prog" CC=!APPTOOLS!/rumpxen-app-cc "$@" diff --git a/app-tools/specs.in b/app-tools/specs.in new file mode 100644 index 0000000..99309e8 --- /dev/null +++ b/app-tools/specs.in @@ -0,0 +1,20 @@ +%rename cpp_options old_cpp_options + +*cpp_options: +-nostdinc -isystem !BASE!/rump/include %(old_cpp_options) + +*linker: +!APPTOOLS!/ld --stunt-intermediate %g.link1 %g.link2 --stunt-final-script !LDSCRIPT! + +*link: +%{m64:-m elf_x86_64} %{m64|mx32:;:-m elf_i386} %{mx32:-m elf32_x86_64} + +*endfile: +!OBJS! + +*startfile: +!HEAD_OBJ! + +%rename link_libgcc old_link_libgcc + +%rename libgcc old_libgcc -- 2.39.5