CMUCL commit: src (lisp/elf.c lisp/mach-o.c tools/linker-x86.sh)
Raymond Toy
rtoy at common-lisp.net
Sat Jul 31 04:45:45 CEST 2010
Date: Friday, July 30, 2010 @ 22:45:45
Author: rtoy
Path: /project/cmucl/cvsroot/src
Modified: lisp/elf.c lisp/mach-o.c tools/linker-x86.sh
For Linux and Darwin, we don't actually need to set the starting
address of the core sections. In map_core_sections, we can map them
to the correct addresses, just like we do on Solaris.
lisp/elf.c:
o Mmap the Lisp core sections with the correct address, not using the
one in the executable itself, just like on Solaris.
lisp/mach-o.c:
o Add the array of addresses of the dynamic, static, and read-only
spaces.
o Mmap the Lisp core sections with the correct address, not using the
one in the executable itself, just like on Solaris.
o Small update to print out the names of the spaces, just like for elf
files.
tools/linker-x86.sh:
o Don't need to tell the linker the starting addresses of the sections
anymore for Linux and Darwin. map_core_sections handles that.
---------------------+
lisp/elf.c | 7 +++----
lisp/mach-o.c | 31 ++++++++++++++++++++++++++++---
tools/linker-x86.sh | 14 +++++++-------
3 files changed, 38 insertions(+), 14 deletions(-)
Index: src/lisp/elf.c
diff -u src/lisp/elf.c:1.24 src/lisp/elf.c:1.25
--- src/lisp/elf.c:1.24 Fri Jul 30 21:07:15 2010
+++ src/lisp/elf.c Fri Jul 30 22:45:45 2010
@@ -8,7 +8,7 @@
Above changes put into main CVS branch. 05-Jul-2007.
- $Id: elf.c,v 1.24 2010-07-31 01:07:15 rtoy Exp $
+ $Id: elf.c,v 1.25 2010-07-31 02:45:45 rtoy Exp $
*/
#include <stdio.h>
@@ -37,7 +37,7 @@
static char *section_names[] = {"CORDYN", "CORSTA", "CORRO"};
-#ifdef SOLARIS
+#if defined(SOLARIS) || defined(__linux__)
/*
* Starting address of the three ELF sections/spaces. These must be
* in the same order as section_names above!
@@ -482,7 +482,7 @@
if (!strncmp(nambuf, section_names[j], 6)) {
os_vm_address_t addr;
-#ifdef SOLARIS
+#if defined(SOLARIS) || defined(__linux__)
/*
* On Solaris, the section header sets the addr
* field to 0 because the linker script says the
@@ -532,4 +532,3 @@
exit(-1);
}
}
-
Index: src/lisp/mach-o.c
diff -u src/lisp/mach-o.c:1.3 src/lisp/mach-o.c:1.4
--- src/lisp/mach-o.c:1.3 Fri Jul 30 20:18:40 2010
+++ src/lisp/mach-o.c Fri Jul 30 22:45:45 2010
@@ -19,11 +19,24 @@
/* Uncomment to enable debugging prints */
/* #define DEBUG_MACH_O */
-/* Names of the Lisp image ELF sections. These names must be the same as
- the corresponding names found in the linker script. */
+/*
+ * Names of the Lisp image sections. These names must be the same as
+ * the corresponding names found in the linker script.
+ */
static char *section_names[] = {"CORDYN", "CORSTA", "CORRO"};
+/*
+ * Starting addresses of the various spaces. Must be in the same
+ * order as section_names
+ */
+static os_vm_address_t section_addr[] =
+{
+ (os_vm_address_t) DYNAMIC_0_SPACE_START,
+ (os_vm_address_t) STATIC_SPACE_START,
+ (os_vm_address_t) READ_ONLY_SPACE_START
+};
+
/* Note: write errors are not fatal. */
static int
ewrite(int fd, const void *buf, size_t nbytes, const char *func)
@@ -165,6 +178,7 @@
/* 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" };
if(id < 1 || id > 3) {
fprintf(stderr, "Invalid space id in %s: %d\n", __func__, id);
@@ -175,6 +189,9 @@
/* Make id be 0-based to match array. */
id--;
+ printf("\t %s: %d bytes...\n", names[id], (end - start));
+ fflush(stdout);
+
if ((write_mach_o_header(out) == -1)
|| (write_load_command(out, section_names[id], length, start) == -1)
|| (write_section(out, length, start, section_names[id]) == -1)
@@ -343,6 +360,8 @@
/* See if the segment name matches any of our section names */
for (j = 0; j < 3; ++j) {
if (strncmp(sc.segname, section_names[j], sizeof(sc.segname)) == 0) {
+ os_vm_address_t addr;
+
/* Found a core segment. Map it! */
#ifdef DEBUG_MACH_O
fprintf(stderr, "Matched!\n");
@@ -350,9 +369,15 @@
fprintf(stderr, " vmaddr = 0x%x\n", sc.vmaddr);
fprintf(stderr, " vmsize = 0x%x\n", sc.vmsize);
#endif
+ /*
+ * We don't care what address the segment has. We
+ * will map it where want it to go.
+ */
+
+ addr = section_addr[j];
if ((os_vm_address_t) os_map(exec_fd, sc.fileoff,
- (os_vm_address_t) sc.vmaddr,
+ (os_vm_address_t) addr,
sc.vmsize)
== (os_vm_address_t) -1) {
fprintf(stderr, "%s: Can't map section %s\n", __func__, section_names[j]);
Index: src/tools/linker-x86.sh
diff -u src/tools/linker-x86.sh:1.4 src/tools/linker-x86.sh:1.5
--- src/tools/linker-x86.sh:1.4 Fri Jul 30 21:07:15 2010
+++ src/tools/linker-x86.sh Fri Jul 30 22:45:45 2010
@@ -1,6 +1,6 @@
#!/bin/sh
-# $Id: linker-x86.sh,v 1.4 2010-07-31 01:07:15 rtoy Exp $
+# $Id: linker-x86.sh,v 1.5 2010-07-31 02:45:45 rtoy Exp $
# This file written by Raymond Toy as part of CMU Common Lisp and is
# placed in the public domain.
@@ -33,9 +33,9 @@
case `uname` in
Linux*)
# How to specify the starting address for each of the sections
- RO_ADDR="-Wl,--section-start=CORRO=$4"
- STATIC_ADDR="-Wl,--section-start=CORSTA=$5"
- DYN_ADDR="-Wl,--section-start=CORDYN=$6"
+ #RO_ADDR="-Wl,--section-start=CORRO=$4"
+ #STATIC_ADDR="-Wl,--section-start=CORSTA=$5"
+ #DYN_ADDR="-Wl,--section-start=CORDYN=$6"
#OPT_IFADDR="-Wl,--defsym -Wl,initial_function_addr=$IFADDR"
@@ -50,9 +50,9 @@
;;
Darwin*)
# How to specify the starting address for each of the sections
- RO_ADDR="-segaddr CORRO $4"
- STATIC_ADDR="-segaddr CORSTA $5"
- DYN_ADDR="-segaddr CORDYN $6"
+ #RO_ADDR="-segaddr CORRO $4"
+ #STATIC_ADDR="-segaddr CORSTA $5"
+ #DYN_ADDR="-segaddr CORDYN $6"
# Specify how to link the entire lisp.a library
OPT_ARCHIVE="-all_load $CMUCLLIB/lisp.a"
More information about the cmucl-commit
mailing list