[LibOS] asm offset constants generation

Auto generate offset constants for assembly. replace magic number with
symbolic constants in LibOS/shim/src/syscallas.S.

This patch also introduces Makefile.rules to accommodate common make rules
so that V=1 (like Linux style make) is accepted.

Signed-off-by: Isaku Yamahata <isaku.yamahata@gmail.com>
This commit is contained in:
Isaku Yamahata
2019-03-25 14:54:51 +01:00
committed by Don Porter
parent fb48d0e388
commit 4b190baef7
6 changed files with 81 additions and 15 deletions
-6
View File
@@ -8,12 +8,6 @@
#define SHIM_TLS_CANARY $xdeadbeef
#if defined(__x86_64__)
# define SHIM_TCB_OFFSET 80
#else
# define SHIM_TCB_OFFSET 44
#endif
#else /* !__ASSEMBLER__ */
#define SHIM_TLS_CANARY 0xdeadbeef
+2
View File
@@ -1 +1,3 @@
libsysdb.so.cached
asm-offsets.h
asm-offsets.s
+5 -1
View File
@@ -129,5 +129,9 @@ elf/shim_rtld.o: $(wildcard elf/*.h)
@echo [ $@ ]
@$(AS) $(ASFLAGS) $(defs) -E $< -o $@
syscallas.S: asm-offsets.h
include ../../../Makefile.rules
clean:
rm -rf $(addsuffix .o,$(objs)) $(shim_target) $(files_to_build) .lib
rm -rf $(addsuffix .o,$(objs)) $(shim_target) $(files_to_build) .lib $(CLEAN_FILES)
+18
View File
@@ -0,0 +1,18 @@
#include <stddef.h>
#include <shim_internal.h>
#include <shim_tls.h>
#define OFFSET_T(name, str_t, member) \
asm volatile(".ascii \" #define " #name " %0 \"\n":: \
"i"(offsetof(str_t, member)))
void dummy(void)
{
OFFSET_T(SHIM_TCB_OFFSET, __libc_tcb_t, shim_tcb);
OFFSET_T(TCB_SYSCALL_NR, shim_tcb_t, context.syscall_nr);
OFFSET_T(TCB_SP, shim_tcb_t, context.sp);
OFFSET_T(TCB_RET_IP, shim_tcb_t, context.ret_ip);
OFFSET_T(TCB_REGS, shim_tcb_t, context.regs);
}
+10 -8
View File
@@ -23,6 +23,8 @@
#include <shim_tls.h>
#include <shim_unistd_defs.h>
#include "asm-offsets.h"
.global syscalldb
.type syscalldb, @function
.extern shim_table, debug_unsupp
@@ -62,22 +64,22 @@ isdef:
pushq %r14
pushq %r15
movq %rax, %fs:(SHIM_TCB_OFFSET + 24)
movq %rax, %fs:(SHIM_TCB_OFFSET + TCB_SYSCALL_NR)
leaq 16(%rbp), %rax
movq %rax, %fs:(SHIM_TCB_OFFSET + 32)
movq %rax, %fs:(SHIM_TCB_OFFSET + TCB_SP)
movq 8(%rbp), %rax
movq %rax, %fs:(SHIM_TCB_OFFSET + 40)
movq %rsp, %fs:(SHIM_TCB_OFFSET + 48)
movq %rax, %fs:(SHIM_TCB_OFFSET + TCB_RET_IP)
movq %rsp, %fs:(SHIM_TCB_OFFSET + TCB_REGS)
/* Translating x86_64 kernel calling convention to user-space
* calling convention */
movq %r10, %rcx
call *%rbx
movq $0, %fs:(SHIM_TCB_OFFSET + 24)
movq $0, %fs:(SHIM_TCB_OFFSET + 32)
movq $0, %fs:(SHIM_TCB_OFFSET + 40)
movq $0, %fs:(SHIM_TCB_OFFSET + 48)
movq $0, %fs:(SHIM_TCB_OFFSET + TCB_SYSCALL_NR)
movq $0, %fs:(SHIM_TCB_OFFSET + TCB_SP)
movq $0, %fs:(SHIM_TCB_OFFSET + TCB_RET_IP)
movq $0, %fs:(SHIM_TCB_OFFSET + TCB_REGS)
popq %r15
popq %r14
+46
View File
@@ -0,0 +1,46 @@
ifeq ("$(origin V)", "command line")
BUILD_VERBOSE = $(V)
endif
ifndef BUILD_VERBOSE
BUILD_VERBOSE = 0
endif
ifeq ($(BUILD_VERBOSE),1)
quiet =
Q =
else
quiet = quiet_
Q = @
endif
export Q quiet BUILD_VERBOSE
squote := '
escsq = $(subst $(squote),'\$(squote)',$1)
echo-cmd = $(if $($(quiet)cmd_$(1)), echo ' $(call escsq,$($(quiet)cmd_$(1)))';)
cmd = @$(echo-cmd) $(cmd_$(1))
quiet_cmd_asm_offsets_s = [ $@ ]
cmd_asm_offsets_s = $(CC) $(CFLAGS) $(defs) -S $< -o $@
asm-offsets.s: asm-offsets.c $(headers)
$(call cmd,asm_offsets_s)
CLEAN_FILES += asm-offsets.s
quiet_cmd_asm_offsets_h = [ $@ ]
cmd_asm_offsets_h = \
(set -e; \
echo "/* DO NOT MODIFY. THIS FILE WAS AUTO-GENERATED. */"; \
echo "\#ifndef _ASM_OFFSETS_H_"; \
echo "\#define _ASM_OFFSETS_H_"; \
echo ""; \
awk '/\.ascii \" \#define/{val=$$5; gsub("\\$$", "", val); print $$3" "$$4" "val}' $^; \
echo ""; \
echo "\#endif") > $@
asm-offsets.h: asm-offsets.s
$(call cmd,asm_offsets_h)
CLEAN_FILES += asm-offests.h