summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llee/ExecveHandler.c
diff options
context:
space:
mode:
authorMisha Brukman <brukman+llvm@gmail.com>2003-09-29 22:37:00 +0000
committerMisha Brukman <brukman+llvm@gmail.com>2003-09-29 22:37:00 +0000
commit64adfee89351e264e63202294ebe2571583fa9c7 (patch)
treee0fd273032b0885f847abe9a5474bc09fab7f8ab /llvm/tools/llee/ExecveHandler.c
parentb3541d4264a79c22941354abacbfdd251a50fc22 (diff)
downloadbcm5719-llvm-64adfee89351e264e63202294ebe2571583fa9c7.tar.gz
bcm5719-llvm-64adfee89351e264e63202294ebe2571583fa9c7.zip
* Added an interface for how LLEE would communicate with the OS
* Implemented the interface in StorageProxy.c * Removed the script `llee' as it is now created by the Makefile * Makefile now compiles a shared object version of the library, but only if using gcc-3.3, linking fails under gcc-3.2 llvm-svn: 8751
Diffstat (limited to 'llvm/tools/llee/ExecveHandler.c')
-rw-r--r--llvm/tools/llee/ExecveHandler.c79
1 files changed, 37 insertions, 42 deletions
diff --git a/llvm/tools/llee/ExecveHandler.c b/llvm/tools/llee/ExecveHandler.c
index dba419cfa31..4b740147adf 100644
--- a/llvm/tools/llee/ExecveHandler.c
+++ b/llvm/tools/llee/ExecveHandler.c
@@ -5,8 +5,8 @@
//
//===----------------------------------------------------------------------===//
+#include "OSInterface.h"
#include "SysUtils.h"
-#include "Config/dlfcn.h"
#include "Config/errno.h"
#include "Config/stdlib.h"
#include "Config/unistd.h"
@@ -21,32 +21,6 @@
static const char llvmHeader[] = "llvm";
/*
- * The type of the execve() function is long and boring, but required.
- */
-typedef int(*execveTy)(const char*, char *const[], char *const[]);
-
-/*
- * This method finds the real `execve' call in the C library and executes the
- * given program.
- */
-int executeProgram(const char *filename, char *const argv[], char *const envp[])
-{
- /*
- * Find a pointer to the *real* execve() function starting the search in the
- * next library and forward, to avoid finding the one defined in this file.
- */
- char *error;
- execveTy execvePtr = (execveTy) dlsym(RTLD_NEXT, "execve");
- if ((error = dlerror()) != NULL) {
- fprintf(stderr, "%s\n", error);
- return -1;
- }
-
- /* Really execute the program */
- return execvePtr(filename, argv, envp);
-}
-
-/*
* This replacement execve() function first checks the file to be executed
* to see if it is a valid LLVM bytecode file, and then either invokes our
* execution environment or passes it on to the system execve() call.
@@ -56,8 +30,21 @@ int execve(const char *filename, char *const argv[], char *const envp[])
/* Open the file, test to see if first four characters are "llvm" */
size_t headerSize = strlen(llvmHeader);
char header[headerSize];
+ char* realFilename = 0;
+ /*
+ * If the program is specified with a relative or absolute path,
+ * then just use the path and filename as is, otherwise search for it.
+ */
+ if (filename[0] != '.' && filename[0] != '/')
+ realFilename = FindExecutable(filename);
+ else
+ realFilename = (char*) filename;
+ if (!realFilename) {
+ fprintf(stderr, "Cannot find path to `%s', exiting.\n", filename);
+ return -1;
+ }
errno = 0;
- int file = open(filename, O_RDONLY);
+ int file = open(realFilename, O_RDONLY);
/* Check validity of `file' */
if (errno) return EIO;
/* Read the header from the file */
@@ -65,6 +52,27 @@ int execve(const char *filename, char *const argv[], char *const envp[])
close(file);
if (bytesRead != (ssize_t)headerSize) return EIO;
if (!memcmp(llvmHeader, header, headerSize)) {
+ /*
+ * Check if we have a cached translation on disk
+ */
+ struct stat buf;
+ llvmStat(realFilename, &buf);
+ if (isExecutable(&buf)) {
+ size_t size;
+ void *fileAddr = llvmReadFile(realFilename, &size);
+ fprintf(stderr, "Found in cache: '%s'\n", realFilename);
+ if (fileAddr) {
+ free(fileAddr);
+ }
+ llvmExecve(realFilename, argv, envp);
+ } else {
+ /*
+ * Not in cache: save translation
+ */
+ //llvmSaveFile(realFilename, addr, len);
+ //fprintf(stderr, "Cached: '%s'\n", realFilename);
+ }
+
/*
* This is a bytecode file, so execute the JIT with the program and
* parameters.
@@ -73,26 +81,13 @@ int execve(const char *filename, char *const argv[], char *const envp[])
for (argvSize = 0, idx = 0; argv[idx] && argv[idx][0]; ++idx)
++argvSize;
char **LLIargs = (char**) malloc(sizeof(char*) * (argvSize+2));
- char *BCpath;
- /*
- * If the program is specified with a relative or absolute path,
- * then just use the path and filename as is, otherwise search for it.
- */
- if (filename[0] != '.' && filename[0] != '/')
- BCpath = FindExecutable(filename);
- else
- BCpath = (char*) filename;
- if (!BCpath) {
- fprintf(stderr, "Cannot find path to `%s', exiting.\n", filename);
- return -1;
- }
char *LLIpath = FindExecutable("lli");
if (!LLIpath) {
fprintf(stderr, "Cannot find path to `lli', exiting.\n");
return -1;
}
LLIargs[0] = LLIpath;
- LLIargs[1] = BCpath;
+ LLIargs[1] = realFilename;
for (idx = 1; idx != argvSize; ++idx)
LLIargs[idx+1] = argv[idx];
LLIargs[argvSize + 1] = '\0';
OpenPOWER on IntegriCloud