link with -rpath to ease finding libLTO

This commit is contained in:
Thomas Pöchtrager 2014-08-31 10:31:32 +02:00
parent f7a5930c3f
commit f88e9d4096
2 changed files with 5 additions and 75 deletions

View File

@ -26,79 +26,6 @@ static uint32_t (*lto_get_num_symbols)(void *mod) = NULL;
static lto_symbol_attributes (*lto_get_sym_attr)(void *mod, uint32_t n) = NULL; static lto_symbol_attributes (*lto_get_sym_attr)(void *mod, uint32_t n) = NULL;
static char * (*lto_get_sym_name)(void *mod, uint32_t n) = NULL; static char * (*lto_get_sym_name)(void *mod, uint32_t n) = NULL;
#ifndef __APPLE__
static char *liblto_dirs[] = {
"/usr/lib/llvm/lib",
"/usr/lib/llvm-3.5/lib",
"/usr/lib/llvm-3.4/lib",
"/usr/lib/llvm-3.3/lib",
"/usr/lib/llvm-3.2/lib",
"/usr/lib/llvm-3.1/lib",
NULL
};
static void *load_liblto()
{
/*
* Try to load it normally first,
* maybe libLTO.so is even in a known place.
*/
void *h = dlopen("libLTO.so", RTLD_NOW);
char *p, *path;
int i;
if(h)
return h;
/*
* Now try the hardcoded paths from above.
*/
for(i = 0; liblto_dirs[i] != NULL; i++){
char liblto[MAXPATHLEN];
snprintf(liblto, sizeof(liblto), "%s/libLTO.so", liblto_dirs);
if((h = dlopen(liblto, RTLD_NOW)))
return h;
}
/*
* Locate the path of the clang binary and try to load
* <clangpath>/../lib/libLTO.so.
*/
path = getenv("PATH");
if(!path) return NULL;
path = strdup(path);
if(!path) return NULL;
p = strtok(path, ":");
while(p != NULL){
char clangbin[MAXPATHLEN];
struct stat st;
snprintf(clangbin, sizeof(clangbin), "%s/clang", p);
if(stat(clangbin, &st) == 0 && access(clangbin, F_OK|X_OK) == 0){
char liblto[MAXPATHLEN];
snprintf(liblto, sizeof(liblto), "%s/../lib/libLTO.so", p);
if((h = dlopen(liblto, RTLD_NOW))){
free(path);
return h;
}
}
p = strtok(NULL, ":");
}
free(path);
return NULL;
}
#endif /* ! __APPLE__ */
/* /*
* is_llvm_bitcode() is passed an ofile struct pointer and a pointer and size * is_llvm_bitcode() is passed an ofile struct pointer and a pointer and size
* of some part of the ofile. If it is an llvm bit code it returns 1 and * of some part of the ofile. If it is an llvm bit code it returns 1 and
@ -198,7 +125,7 @@ void **pmod) /* maybe NULL */
return(0); return(0);
#else #else
lto_path = NULL; lto_path = NULL;
lto_handle = load_liblto(); lto_handle = dlopen("libLTO.so", RTLD_NOW);
if(lto_handle == NULL) if(lto_handle == NULL)
{ {
fprintf(stderr, "cannot find or load libLTO.so\n"); fprintf(stderr, "cannot find or load libLTO.so\n");

View File

@ -11,9 +11,10 @@ function try()
set -e set -e
LLVM_INC_DIR=`$LLVM_CONFIG --includedir` LLVM_INC_DIR=`$LLVM_CONFIG --includedir`
LLVM_LIB_DIR=`$LLVM_CONFIG --libdir` LLVM_LIB_DIR=`$LLVM_CONFIG --libdir`
# Adding the include directory with -I causes the build to fail.
ln -sf "$LLVM_INC_DIR/llvm-c/lto.h" "include/llvm-c/lto.h" ln -sf "$LLVM_INC_DIR/llvm-c/lto.h" "include/llvm-c/lto.h"
mkdir -p tmp mkdir -p tmp
echo -n "-L$LLVM_LIB_DIR -lLTO " > tmp/ldflags echo -n "-Wl,-rpath,$LLVM_LIB_DIR,--enable-new-dtags -L$LLVM_LIB_DIR -lLTO " > tmp/ldflags
echo -n "-DLTO_SUPPORT=1 " > tmp/cflags echo -n "-DLTO_SUPPORT=1 " > tmp/cflags
echo -n "-DLTO_SUPPORT=1 " > tmp/cxxflags echo -n "-DLTO_SUPPORT=1 " > tmp/cxxflags
echo -n "$LLVM_LIB_DIR" > tmp/ldpath echo -n "$LLVM_LIB_DIR" > tmp/ldpath
@ -26,11 +27,13 @@ try "-3.2"
try "-3.3" try "-3.3"
try "-3.4" try "-3.4"
try "-3.5" try "-3.5"
try "-3.6"
try "-devel" try "-devel"
try "32" try "32"
try "33" try "33"
try "34" try "34"
try "35" try "35"
try "36"
exit 1 exit 1