Skip to content
Snippets Groups Projects
Commit 17a01e38 authored by rtoy's avatar rtoy
Browse files

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.
parent bbb63fe2
No related branches found
No related tags found
No related merge requests found
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
Above changes put into main CVS branch. 05-Jul-2007. 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> #include <stdio.h>
...@@ -37,7 +37,7 @@ static Elf_Shdr sh; ...@@ -37,7 +37,7 @@ static Elf_Shdr sh;
static char *section_names[] = {"CORDYN", "CORSTA", "CORRO"}; 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 * Starting address of the three ELF sections/spaces. These must be
* in the same order as section_names above! * in the same order as section_names above!
...@@ -482,7 +482,7 @@ map_core_sections(const char *exec_name) ...@@ -482,7 +482,7 @@ map_core_sections(const char *exec_name)
if (!strncmp(nambuf, section_names[j], 6)) { if (!strncmp(nambuf, section_names[j], 6)) {
os_vm_address_t addr; os_vm_address_t addr;
#ifdef SOLARIS #if defined(SOLARIS) || defined(__linux__)
/* /*
* On Solaris, the section header sets the addr * On Solaris, the section header sets the addr
* field to 0 because the linker script says the * field to 0 because the linker script says the
...@@ -532,4 +532,3 @@ map_core_sections(const char *exec_name) ...@@ -532,4 +532,3 @@ map_core_sections(const char *exec_name)
exit(-1); exit(-1);
} }
} }
...@@ -19,11 +19,24 @@ typedef struct mach_header MachO_hdr; ...@@ -19,11 +19,24 @@ typedef struct mach_header MachO_hdr;
/* Uncomment to enable debugging prints */ /* Uncomment to enable debugging prints */
/* #define DEBUG_MACH_O */ /* #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"}; 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. */ /* Note: write errors are not fatal. */
static int static int
ewrite(int fd, const void *buf, size_t nbytes, const char *func) ewrite(int fd, const void *buf, size_t nbytes, const char *func)
...@@ -165,6 +178,7 @@ write_space_object(const char *dir, int id, os_vm_address_t start, os_vm_address ...@@ -165,6 +178,7 @@ write_space_object(const char *dir, int id, os_vm_address_t start, os_vm_address
/* The length should be a multiple of the page size. */ /* The length should be a multiple of the page size. */
size_t length = end - start + (os_vm_page_size - size_t length = end - start + (os_vm_page_size -
((end - start) % os_vm_page_size)); ((end - start) % os_vm_page_size));
static char *names[] = { "Dynamic", "Static", "Read-Only" };
if(id < 1 || id > 3) { if(id < 1 || id > 3) {
fprintf(stderr, "Invalid space id in %s: %d\n", __func__, id); fprintf(stderr, "Invalid space id in %s: %d\n", __func__, id);
...@@ -175,6 +189,9 @@ write_space_object(const char *dir, int id, os_vm_address_t start, os_vm_address ...@@ -175,6 +189,9 @@ write_space_object(const char *dir, int id, os_vm_address_t start, os_vm_address
/* Make id be 0-based to match array. */ /* Make id be 0-based to match array. */
id--; id--;
printf("\t %s: %d bytes...\n", names[id], (end - start));
fflush(stdout);
if ((write_mach_o_header(out) == -1) if ((write_mach_o_header(out) == -1)
|| (write_load_command(out, section_names[id], length, start) == -1) || (write_load_command(out, section_names[id], length, start) == -1)
|| (write_section(out, length, start, section_names[id]) == -1) || (write_section(out, length, start, section_names[id]) == -1)
...@@ -343,6 +360,8 @@ map_core_sections(const char *exec_name) ...@@ -343,6 +360,8 @@ map_core_sections(const char *exec_name)
/* See if the segment name matches any of our section names */ /* See if the segment name matches any of our section names */
for (j = 0; j < 3; ++j) { for (j = 0; j < 3; ++j) {
if (strncmp(sc.segname, section_names[j], sizeof(sc.segname)) == 0) { if (strncmp(sc.segname, section_names[j], sizeof(sc.segname)) == 0) {
os_vm_address_t addr;
/* Found a core segment. Map it! */ /* Found a core segment. Map it! */
#ifdef DEBUG_MACH_O #ifdef DEBUG_MACH_O
fprintf(stderr, "Matched!\n"); fprintf(stderr, "Matched!\n");
...@@ -350,9 +369,15 @@ map_core_sections(const char *exec_name) ...@@ -350,9 +369,15 @@ map_core_sections(const char *exec_name)
fprintf(stderr, " vmaddr = 0x%x\n", sc.vmaddr); fprintf(stderr, " vmaddr = 0x%x\n", sc.vmaddr);
fprintf(stderr, " vmsize = 0x%x\n", sc.vmsize); fprintf(stderr, " vmsize = 0x%x\n", sc.vmsize);
#endif #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, if ((os_vm_address_t) os_map(exec_fd, sc.fileoff,
(os_vm_address_t) sc.vmaddr, (os_vm_address_t) addr,
sc.vmsize) sc.vmsize)
== (os_vm_address_t) -1) { == (os_vm_address_t) -1) {
fprintf(stderr, "%s: Can't map section %s\n", __func__, section_names[j]); fprintf(stderr, "%s: Can't map section %s\n", __func__, section_names[j]);
......
#!/bin/sh #!/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 # This file written by Raymond Toy as part of CMU Common Lisp and is
# placed in the public domain. # placed in the public domain.
...@@ -33,9 +33,9 @@ OPT_CORE="CORRO.o CORSTA.o CORDYN.o" ...@@ -33,9 +33,9 @@ OPT_CORE="CORRO.o CORSTA.o CORDYN.o"
case `uname` in case `uname` in
Linux*) Linux*)
# How to specify the starting address for each of the sections # How to specify the starting address for each of the sections
RO_ADDR="-Wl,--section-start=CORRO=$4" #RO_ADDR="-Wl,--section-start=CORRO=$4"
STATIC_ADDR="-Wl,--section-start=CORSTA=$5" #STATIC_ADDR="-Wl,--section-start=CORSTA=$5"
DYN_ADDR="-Wl,--section-start=CORDYN=$6" #DYN_ADDR="-Wl,--section-start=CORDYN=$6"
#OPT_IFADDR="-Wl,--defsym -Wl,initial_function_addr=$IFADDR" #OPT_IFADDR="-Wl,--defsym -Wl,initial_function_addr=$IFADDR"
...@@ -50,9 +50,9 @@ case `uname` in ...@@ -50,9 +50,9 @@ case `uname` in
;; ;;
Darwin*) Darwin*)
# How to specify the starting address for each of the sections # How to specify the starting address for each of the sections
RO_ADDR="-segaddr CORRO $4" #RO_ADDR="-segaddr CORRO $4"
STATIC_ADDR="-segaddr CORSTA $5" #STATIC_ADDR="-segaddr CORSTA $5"
DYN_ADDR="-segaddr CORDYN $6" #DYN_ADDR="-segaddr CORDYN $6"
# Specify how to link the entire lisp.a library # Specify how to link the entire lisp.a library
OPT_ARCHIVE="-all_load $CMUCLLIB/lisp.a" OPT_ARCHIVE="-all_load $CMUCLLIB/lisp.a"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment