Skip to content
Snippets Groups Projects
Commit 3a882467 authored by rtoy's avatar rtoy
Browse files

Change how we build executables for Linux. We no longer need the

hairy and fragile linker script.  Instead, we can use regular old gcc
to do what we need.

(Should also work for FreeBSD, but not yet implemented.)

lisp/elf.c:
o Include validate.h so we can get the starting addresses of the
  read-only, static, and dynamic spaces.
o Add special case for linux to run the linker script correctly.

lisp/elf.h:
o There's a separate linker script for Linux.

lisp/save.c:
o Temporarily don't run elf_cleanup so we can have easier
  testing/debugging.

tools/linker.sh:
o Don't need BIFLAG anymore.

tools/make-main-dist.sh:
o Install linker-x86.sh.
parent 8760ca06
Branches
Tags
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.20 2010/07/27 02:35:25 rtoy Exp $ $Id: elf.c,v 1.21 2010/07/29 04:34:10 rtoy Exp $
*/ */
#include <stdio.h> #include <stdio.h>
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "internals.h" #include "internals.h"
#include "globals.h" #include "globals.h"
#include "elf.h" #include "elf.h"
#include "validate.h"
static char elf_magic_string[] = {ELFMAG0, ELFMAG1, ELFMAG2, ELFMAG3}; static char elf_magic_string[] = {ELFMAG0, ELFMAG1, ELFMAG2, ELFMAG3};
...@@ -37,7 +38,6 @@ static Elf_Shdr sh; ...@@ -37,7 +38,6 @@ static Elf_Shdr sh;
static char *section_names[] = {"CORDYN", "CORSTA", "CORRO"}; static char *section_names[] = {"CORDYN", "CORSTA", "CORRO"};
#ifdef SOLARIS #ifdef SOLARIS
#include "sparc-validate.h"
/* /*
* 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!
...@@ -331,7 +331,6 @@ elf_cleanup(const char *dirname) ...@@ -331,7 +331,6 @@ elf_cleanup(const char *dirname)
int int
elf_run_linker(long init_func_address, char *file) elf_run_linker(long init_func_address, char *file)
{ {
lispobj libstring = SymbolValue(CMUCL_LIB); /* Get library: */ lispobj libstring = SymbolValue(CMUCL_LIB); /* Get library: */
struct vector *vec = (struct vector *)PTR(libstring); struct vector *vec = (struct vector *)PTR(libstring);
char *paths; char *paths;
...@@ -373,14 +372,22 @@ elf_run_linker(long init_func_address, char *file) ...@@ -373,14 +372,22 @@ elf_run_linker(long init_func_address, char *file)
printf(" %s\n", command); printf(" %s\n", command);
} }
if(stat(command, &st) == 0) { if (stat(command, &st) == 0) {
extern int main(); extern int main();
free(paths); free(paths);
printf("\t[%s: linking %s... \n", command, file); printf("\t[%s: linking %s... \n", command, file);
fflush(stdout); fflush(stdout);
#ifdef __linux__
sprintf(command_line, "%s %s 0x%lx '%s' 0x%lx 0x%lx 0x%lx", command,
C_COMPILER, init_func_address, file,
(unsigned long) READ_ONLY_SPACE_START,
(unsigned long) STATIC_SPACE_START,
(unsigned long) DYNAMIC_0_SPACE_START);
#else
sprintf(command_line, "%s %s 0x%lx 0x%lx %s", command, C_COMPILER, sprintf(command_line, "%s %s 0x%lx 0x%lx %s", command, C_COMPILER,
init_func_address, (unsigned long) &main, file); init_func_address, (unsigned long) &main, file);
#endif
ret = system(command_line); ret = system(command_line);
if(ret == -1) { if(ret == -1) {
perror("Can't run link script"); perror("Can't run link script");
......
/* $Id: elf.h,v 1.10 2009/01/20 03:58:11 agoncharov Rel $ */ /* $Id: elf.h,v 1.11 2010/07/29 04:34:10 rtoy Exp $ */
/* This code was written by Fred Gilham and has been placed in the public domain. It is /* This code was written by Fred Gilham and has been placed in the public domain. It is
provided "AS-IS" and without warranty of any kind. provided "AS-IS" and without warranty of any kind.
...@@ -8,7 +8,11 @@ ...@@ -8,7 +8,11 @@
#define _ELF_H_INCLUDED_ #define _ELF_H_INCLUDED_
#if defined(__linux__)
#define LINKER_SCRIPT "linker-x86.sh"
#else
#define LINKER_SCRIPT "linker.sh" #define LINKER_SCRIPT "linker.sh"
#endif
#if defined(SOLARIS) #if defined(SOLARIS)
#include <sys/elf.h> #include <sys/elf.h>
......
/* /*
$Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/save.c,v 1.23 2009/12/18 04:03:24 agoncharov Exp $ $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/save.c,v 1.24 2010/07/29 04:34:10 rtoy Exp $
This code was written as part of the CMU Common Lisp project at This code was written as part of the CMU Common Lisp project at
Carnegie Mellon University, and has been placed in the public domain. Carnegie Mellon University, and has been placed in the public domain.
...@@ -362,8 +362,9 @@ save_executable(char *filename, lispobj init_function) ...@@ -362,8 +362,9 @@ save_executable(char *filename, lispobj init_function)
printf("Linking executable...\n"); printf("Linking executable...\n");
fflush(stdout); fflush(stdout);
elf_run_linker(init_function, filename); elf_run_linker(init_function, filename);
#if 0
elf_cleanup(dir_name); elf_cleanup(dir_name);
#endif
printf("done.\n"); printf("done.\n");
exit(0); exit(0);
} }
......
#!/bin/sh -x #!/bin/sh -x
# $Id: linker.sh,v 1.13 2010/07/29 01:51:12 rtoy Exp $ # $Id: linker.sh,v 1.14 2010/07/29 04:34:10 rtoy Exp $
# This file was written by Fred Gilham and is placed in the public domain. # This file was written by Fred Gilham and is placed in the public domain.
# It comes without warranty of any kind. # It comes without warranty of any kind.
...@@ -72,7 +72,7 @@ SCRIPT="-T $CMUCLLIB/$OPSYS$VER-cmucl-linker-script" ...@@ -72,7 +72,7 @@ SCRIPT="-T $CMUCLLIB/$OPSYS$VER-cmucl-linker-script"
# XXXX The process image start address can change depending on the OS # XXXX The process image start address can change depending on the OS
# (at least). # (at least).
BIFLAG="--defsym builtin_image_flag=$2" #BIFLAG="--defsym builtin_image_flag=$2"
# IFADDR is the initial function address, needed to start lisp processing. # IFADDR is the initial function address, needed to start lisp processing.
IFADDR="--defsym initial_function_addr=$1" IFADDR="--defsym initial_function_addr=$1"
......
...@@ -92,6 +92,7 @@ if [ "$EXECUTABLE" = "true" ] ...@@ -92,6 +92,7 @@ if [ "$EXECUTABLE" = "true" ]
then then
install ${GROUP} ${OWNER} -m 0755 $TARGET/lisp/lisp.a $DESTDIR/lib/cmucl/lib/ install ${GROUP} ${OWNER} -m 0755 $TARGET/lisp/lisp.a $DESTDIR/lib/cmucl/lib/
install ${GROUP} ${OWNER} -m 0755 src/tools/linker.sh $DESTDIR/lib/cmucl/lib/ install ${GROUP} ${OWNER} -m 0755 src/tools/linker.sh $DESTDIR/lib/cmucl/lib/
install ${GROUP} ${OWNER} -m 0755 src/tools/linker-x86.sh $DESTDIR/lib/cmucl/lib/
install ${GROUP} ${OWNER} -m 0755 src/tools/$SCRIPT-cmucl-linker-script $DESTDIR/lib/cmucl/lib/ install ${GROUP} ${OWNER} -m 0755 src/tools/$SCRIPT-cmucl-linker-script $DESTDIR/lib/cmucl/lib/
fi fi
for corefile in $TARGET/lisp/$CORE for corefile in $TARGET/lisp/$CORE
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment