CMUCL commit: src (4 files)
Raymond Toy
rtoy at common-lisp.net
Fri Jul 30 22:26:12 CEST 2010
Date: Friday, July 30, 2010 @ 16:26:12
Author: rtoy
Path: /project/cmucl/cvsroot/src
Modified: lisp/elf.c lisp/lisp.c lisp/save.c tools/linker-x86.sh
Some cleanup for Linux executables. The value of the
initial_function_addr is saved to a file and compiled in when linking
the executable. This makes building the executable more portable.
All that's need is a way for gcc to link all of lisp.a and to set the
starting address of some segments.
lisp/lisp.c:
o For Linux, use the value of initial_function_addr instead of the
address.
tools/linker-x86.sh:
o Disable -x option, unless CMU_DEBUG_LINKER is not empty.
o Instead of using --defsym feature of GNU ld, save the initial
function address in a file to be compiled when making the
executable.
lisp/elf.c:
o Remove printing of the sizeof elf headers
o Print some info about the object being written and print somewhat
neatly.
lisp/save.c:
o Rework printing info of the core objects. Let write_elf_object do
it.
---------------------+
lisp/elf.c | 9 +++++----
lisp/lisp.c | 12 +++++++++---
lisp/save.c | 12 +++---------
tools/linker-x86.sh | 16 +++++++++++++---
4 files changed, 30 insertions(+), 19 deletions(-)
Index: src/lisp/elf.c
diff -u src/lisp/elf.c:1.21 src/lisp/elf.c:1.22
--- src/lisp/elf.c:1.21 Thu Jul 29 00:34:10 2010
+++ src/lisp/elf.c Fri Jul 30 16:26:11 2010
@@ -8,7 +8,7 @@
Above changes put into main CVS branch. 05-Jul-2007.
- $Id: elf.c,v 1.21 2010-07-29 04:34:10 rtoy Exp $
+ $Id: elf.c,v 1.22 2010-07-30 20:26:11 rtoy Exp $
*/
#include <stdio.h>
@@ -285,10 +285,8 @@
/* The length should be a multiple of the page size. */
size_t length = end - start + (os_vm_page_size -
((end - start) % os_vm_page_size));
+ static char *names[] = { "Dynamic", "Static", "Read-Only" };
- fprintf(stderr, "sizeof Elf_Ehdr = %d\n", sizeof(Elf_Ehdr));
- fprintf(stderr, "sizeof Elf32_Phdr = %d\n", sizeof(Elf32_Phdr));
-
if(id < 1 || id > 3) {
fprintf(stderr, "Invalid space id in %s: %d\n", __func__, id);
fprintf(stderr, "Executable not built.\n");
@@ -300,6 +298,9 @@
object_name = section_names[id];
+ printf("\t %s: %d bytes...\n", names[id], (end - start));
+ fflush(stdout);
+
if ((write_elf_header(out) == -1) ||
(write_zero_section_header(out) == -1) ||
(write_object_section_header(out, length, start) == -1) ||
Index: src/lisp/lisp.c
diff -u src/lisp/lisp.c:1.71 src/lisp/lisp.c:1.72
--- src/lisp/lisp.c:1.71 Mon Jul 26 11:58:47 2010
+++ src/lisp/lisp.c Fri Jul 30 16:26:11 2010
@@ -1,7 +1,7 @@
/*
* main() entry point for a stand alone lisp image.
*
- * $Header: /project/cmucl/cvsroot/src/lisp/lisp.c,v 1.71 2010-07-26 15:58:47 rtoy Exp $
+ * $Header: /project/cmucl/cvsroot/src/lisp/lisp.c,v 1.72 2010-07-30 20:26:11 rtoy Exp $
*
*/
@@ -436,8 +436,14 @@
boolean monitor;
lispobj initial_function = 0;
- if (builtin_image_flag != 0)
- initial_function = (lispobj) & initial_function_addr;
+ if (builtin_image_flag != 0) {
+#if defined(i386) && defined(__linux__)
+ initial_function = initial_function_addr;
+#else
+ initial_function = (lispobj) & initial_function_addr;
+#endif
+ }
+
#if defined(SVR4)
tzset();
Index: src/lisp/save.c
diff -u src/lisp/save.c:1.24 src/lisp/save.c:1.25
--- src/lisp/save.c:1.24 Thu Jul 29 00:34:10 2010
+++ src/lisp/save.c Fri Jul 30 16:26:11 2010
@@ -1,6 +1,6 @@
/*
- $Header: /project/cmucl/cvsroot/src/lisp/save.c,v 1.24 2010-07-29 04:34:10 rtoy Exp $
+ $Header: /project/cmucl/cvsroot/src/lisp/save.c,v 1.25 2010-07-30 20:26:11 rtoy Exp $
This code was written as part of the CMU Common Lisp project at
Carnegie Mellon University, and has been placed in the public domain.
@@ -285,14 +285,10 @@
#endif
printf("[Saving current lisp image as executable into \"%s\":\n", filename);
- printf("\t[Writing core objects... ");
- fflush(stdout);
- printf("read-only... ");
+ printf("\t[Writing core objects\n");
fflush(stdout);
write_elf_object(dir_name, READ_ONLY_SPACE_ID, (os_vm_address_t)read_only_space,
(os_vm_address_t)SymbolValue(READ_ONLY_SPACE_FREE_POINTER));
- printf("static... ");
- fflush(stdout);
write_elf_object(dir_name, STATIC_SPACE_ID, (os_vm_address_t)static_space,
(os_vm_address_t)SymbolValue(STATIC_SPACE_FREE_POINTER));
#ifdef GENCGC
@@ -346,8 +342,6 @@
#endif
#endif
- printf("dynamic... ");
- fflush(stdout);
#ifdef reg_ALLOC
write_elf_object(dir_name, DYNAMIC_SPACE_ID, (os_vm_address_t)current_dynamic_space,
(os_vm_address_t)current_dynamic_space_free_pointer);
@@ -356,7 +350,7 @@
(os_vm_address_t)SymbolValue(ALLOCATION_POINTER));
#endif
- printf("done]\n");
+ printf("\tdone]\n");
fflush(stdout);
printf("Linking executable...\n");
Index: src/tools/linker-x86.sh
diff -u src/tools/linker-x86.sh:1.1 src/tools/linker-x86.sh:1.2
--- src/tools/linker-x86.sh:1.1 Thu Jul 29 00:36:28 2010
+++ src/tools/linker-x86.sh Fri Jul 30 16:26:12 2010
@@ -1,10 +1,16 @@
-#!/bin/sh -x
+#!/bin/sh
-# $Id: linker-x86.sh,v 1.1 2010-07-29 04:36:28 rtoy Exp $
+# $Id: linker-x86.sh,v 1.2 2010-07-30 20:26:12 rtoy Exp $
# This file written by Raymond Toy as part of CMU Common Lisp and is
# placed in the public domain.
+OPSYS=`uname`
+
+if [ "X$CMU_DEBUG_LINKER" != "X" ]; then
+ set -x
+fi
+
if [ $# -ne 6 ]; then
echo "Usage: `basename $0` <c-compiler> <initial-func-addr> <executable> <ro-addr> <static-addr> <dyn-addr>"
exit 1
@@ -22,10 +28,14 @@
CMUCLLIB=`dirname $0`
-OPT_IFADDR="-Wl,--defsym -Wl,initial_function_addr=$IFADDR"
+#OPT_IFADDR="-Wl,--defsym -Wl,initial_function_addr=$IFADDR"
+OPT_IFADDR="ifaddr.c"
OPT_ARCHIVE="-Wl,--whole-archive -Wl,$CMUCLLIB/lisp.a -Wl,--no-whole-archive"
OPT_CORE="CORRO.o CORSTA.o CORDYN.o"
+trap 'rm -f $OUTDIR/$OPT_IFADDR' 0
+
(cd $OUTDIR
+echo "long initial_function_addr = $IFADDR;" > $OPT_IFADDR
$CCOMPILER -m32 -o $OUTNAME -rdynamic $OPT_IFADDR $OPT_ARCHIVE $OPT_CORE $RO_ADDR $STATIC_ADDR $DYN_ADDR -ldl -lm)
More information about the cmucl-commit
mailing list