Here's a revised version of my patch adding per-target syscall stubs
to the library. This is now tested on x86_64.
This patch adds a per-target module to the library, which can be used
to hold any arch or target dependent code. It uses this module to
provide a per-arch re-implementation of syscall(), which is used to
(finally) provide reliable error messages from elflink.c if they occur
while the program segments are unmapped.
Signed-off-by: David Gibson <[EMAIL PROTECTED]>
Index: libhugetlbfs/Makefile
===================================================================
--- libhugetlbfs.orig/Makefile 2007-03-07 13:04:37.000000000 +1100
+++ libhugetlbfs/Makefile 2007-03-07 13:05:03.000000000 +1100
@@ -1,7 +1,6 @@
PREFIX = /usr/local
-BASEOBJS = hugeutils.o version.o
-LIBOBJS = $(BASEOBJS) elflink.o morecore.o debug.o
+LIBOBJS = hugeutils.o version.o elflink.o morecore.o debug.o
INSTALL_OBJ_LIBS = libhugetlbfs.so libhugetlbfs.a
LDSCRIPT_TYPES = B BDT
LDSCRIPT_DIST_ELF = elf32ppclinux elf64ppc elf_i386 elf_x86_64
@@ -72,6 +71,10 @@
OBJDIRS += obj64
endif
+LIBOBJS32 = $(LIBOBJS:%=obj32/%) obj32/$(ELF32).o
+LIBOBJS64 = $(LIBOBJS:%=obj64/%) obj64/$(ELF64).o
+
+
LIBDIR32 = $(PREFIX)/$(LIB32)
LIBDIR64 = $(PREFIX)/$(LIB64)
LDSCRIPTDIR = $(PREFIX)/share/libhugetlbfs/ldscripts
@@ -159,15 +162,29 @@
@mkdir -p obj64
$(CC64) $(CPPFLAGS) $(CFLAGS) -o $@ -c $<
-%/libhugetlbfs.a: $(foreach OBJ,$(LIBOBJS),%/$(OBJ))
- @$(VECHO) AR $@
+obj32/%.o: %.S
+ @$(VECHO) AS32 $@
+ @mkdir -p obj32
+ $(CC32) $(CPPFLAGS) -o $@ -c $<
+
+obj64/%.o: %.S
+ @$(VECHO) AS64 $@
+ @mkdir -p obj64
+ $(CC64) $(CPPFLAGS) -o $@ -c $<
+
+obj32/libhugetlbfs.a: $(LIBOBJS32)
+ @$(VECHO) AR32 $@
+ $(AR) $(ARFLAGS) $@ $^
+
+obj64/libhugetlbfs.a: $(LIBOBJS64)
+ @$(VECHO) AR64 $@
$(AR) $(ARFLAGS) $@ $^
-obj32/libhugetlbfs.so: $(LIBOBJS:%=obj32/%)
+obj32/libhugetlbfs.so: $(LIBOBJS32)
@$(VECHO) LD32 "(shared)" $@
$(CC32) $(LDFLAGS) -shared -o $@ $^ $(LDLIBS)
-obj64/libhugetlbfs.so: $(LIBOBJS:%=obj64/%)
+obj64/libhugetlbfs.so: $(LIBOBJS64)
@$(VECHO) LD64 "(shared)" $@
$(CC64) $(LDFLAGS) -shared -o $@ $^ $(LDLIBS)
Index: libhugetlbfs/elf32ppclinux.S
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ libhugetlbfs/elf32ppclinux.S 2007-03-07 13:05:03.000000000 +1100
@@ -0,0 +1,34 @@
+/*
+ * libhugetlbfs - Easy use of Linux hugepages
+ * Copyright (C) 2007 David Gibson, IBM Corporation.
+ *
+ * Based on code from the GNU C Library, Copyright Free Software Foundation,
Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+ .text
+
+ .globl direct_syscall
+direct_syscall:
+ mr 0,3
+ mr 3,4
+ mr 4,5
+ mr 5,6
+ mr 6,7
+ mr 7,8
+ mr 8,9
+ sc
+ blr
Index: libhugetlbfs/elflink.c
===================================================================
--- libhugetlbfs.orig/elflink.c 2007-03-07 13:04:37.000000000 +1100
+++ libhugetlbfs/elflink.c 2007-03-07 13:05:03.000000000 +1100
@@ -55,31 +55,6 @@
#define ELF_ST_TYPE(x) ELF64_ST_TYPE(x)
#endif
-#ifdef __syscall_return
-#ifdef __i386__
-/* The normal i386 syscall macros don't work with -fPIC :( */
-#undef _syscall2
-#define _syscall2(type,name,type1,arg1,type2,arg2) \
-type name(type1 arg1,type2 arg2) \
-{ \
-long __res; \
-__asm__ volatile ("push %%ebx; movl %2,%%ebx; int $0x80; pop %%ebx" \
- : "=a" (__res) \
- : "0" (__NR_##name),"r" ((long)(arg1)),"c" ((long)(arg2))); \
-__syscall_return(type,__res); \
-}
-#undef _syscall3
-#define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \
-type name(type1 arg1,type2 arg2,type3 arg3) \
-{ \
-long __res; \
-__asm__ volatile ("push %%ebx; movl %2,%%ebx; int $0x80; pop %%ebx" \
- : "=a" (__res) \
- : "0" (__NR_##name),"r" ((long)(arg1)),"c" ((long)(arg2)), \
- "d" ((long)(arg3))); \
-__syscall_return(type,__res); \
-}
-#endif /* __i386__ */
/* This function prints an error message to stderr, then aborts. It
* is safe to call, even if the executable segments are presently
* unmapped.
@@ -90,21 +65,15 @@
* FIXME: This works in practice, but I suspect it
* is not guaranteed safe: the library functions we call could in
* theory call other functions via the PLT which will blow up. */
-#define __NR_sys_write __NR_write
-#define __NR_sys_getpid __NR_getpid
-#define __NR_sys_kill __NR_kill
-static _syscall3(ssize_t,sys_write,int,fd,const void *,buf,size_t,count);
-static _syscall0(pid_t,sys_getpid);
-static _syscall2(int,sys_kill,pid_t,pid,int,sig);
static void write_err(const char *start, int len)
{
- sys_write(2, start, len);
+ direct_syscall(__NR_write, 2 /*stderr*/, start, len);
}
static void sys_abort(void)
{
- pid_t pid = sys_getpid();
+ pid_t pid = direct_syscall(__NR_getpid);
- sys_kill(pid, SIGABRT);
+ direct_syscall(__NR_kill, pid, SIGABRT);
}
static void write_err_base(unsigned long val, int base)
{
@@ -173,13 +142,6 @@
sys_abort();
}
-#else /* __syscall_return */
-#warning __syscall_return macro not available. Some debugging will be \
- disabled during executable remapping
-static void unmapped_abort(const char *fmt, ...)
-{
-}
-#endif /* __syscall_return */
static char share_path[PATH_MAX+1];
Index: libhugetlbfs/libhugetlbfs_internal.h
===================================================================
--- libhugetlbfs.orig/libhugetlbfs_internal.h 2007-03-07 13:04:37.000000000
+1100
+++ libhugetlbfs/libhugetlbfs_internal.h 2007-03-07 13:05:03.000000000
+1100
@@ -69,4 +69,6 @@
#define __LP64__
#endif
+extern int direct_syscall(int sysnum, ...);
+
#endif /* _LIBHUGETLBFS_INTERNAL_H */
Index: libhugetlbfs/elf64ppc.S
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ libhugetlbfs/elf64ppc.S 2007-03-07 13:05:03.000000000 +1100
@@ -0,0 +1,43 @@
+/*
+ * libhugetlbfs - Easy use of Linux hugepages
+ * Copyright (C) 2007 David Gibson, IBM Corporation.
+ *
+ * Based on code from the GNU C Library, Copyright Free Software Foundation,
Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+ .text
+
+ .align 2
+ .globl direct_syscall
+ .globl .direct_syscall
+ .section ".opd","aw"
+direct_syscall:
+ .quad .direct_syscall
+ .quad [EMAIL PROTECTED]
+ .quad 0
+ .previous
+ .type .direct_syscall,@function
+.direct_syscall:
+ mr 0,3
+ mr 3,4
+ mr 4,5
+ mr 5,6
+ mr 6,7
+ mr 7,8
+ mr 8,9
+ sc
+ blr
Index: libhugetlbfs/elf_i386.S
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ libhugetlbfs/elf_i386.S 2007-03-07 13:05:03.000000000 +1100
@@ -0,0 +1,42 @@
+/*
+ * libhugetlbfs - Easy use of Linux hugepages
+ * Copyright (C) 2007 David Gibson, IBM Corporation.
+ *
+ * Based on code from the GNU C Library, Copyright Free Software Foundation,
Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+ .text
+
+ .globl direct_syscall
+direct_syscall:
+ push %ebp
+ push %edi
+ push %esi
+ push %ebx
+ mov 0x2c(%esp),%ebp
+ mov 0x28(%esp),%edi
+ mov 0x24(%esp),%esi
+ mov 0x20(%esp),%edx
+ mov 0x1c(%esp),%ecx
+ mov 0x18(%esp),%ebx
+ mov 0x14(%esp),%eax
+ int $0x80
+ pop %ebx
+ pop %esi
+ pop %edi
+ pop %ebp
+ ret
Index: libhugetlbfs/elf_x86_64.S
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ libhugetlbfs/elf_x86_64.S 2007-03-07 13:05:09.000000000 +1100
@@ -0,0 +1,34 @@
+/*
+ * libhugetlbfs - Easy use of Linux hugepages
+ * Copyright (C) 2007 David Gibson, IBM Corporation.
+ *
+ * Based on code from the GNU C Library, Copyright Free Software Foundation,
Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+ .text
+
+ .globl direct_syscall
+direct_syscall:
+ mov %rdi,%rax
+ mov %rsi,%rdi
+ mov %rdx,%rsi
+ mov %rcx,%rdx
+ mov %r8,%r10
+ mov %r9,%r8
+ mov 0x8(%rsp),%r9
+ syscall
+ retq
--
David Gibson | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Libhugetlbfs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/libhugetlbfs-devel