diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/config_global.c | 2 | ||||
-rw-r--r-- | lib/internal_cmd.c | 7 | ||||
-rw-r--r-- | lib/relocation.c | 2 | ||||
-rw-r--r-- | lib/rpath.c | 49 |
4 files changed, 46 insertions, 14 deletions
diff --git a/lib/config_global.c b/lib/config_global.c index 95302c3..0d244fc 100644 --- a/lib/config_global.c +++ b/lib/config_global.c @@ -138,7 +138,7 @@ void check_runtime_environment(void) { #endif "objdump", "rsync", - "tar", + "bsdtar", "bash", "reloc", NULL, diff --git a/lib/internal_cmd.c b/lib/internal_cmd.c index a859b5b..6489986 100644 --- a/lib/internal_cmd.c +++ b/lib/internal_cmd.c @@ -323,7 +323,7 @@ int rpath_set_interface(int argc, char **argv) { * */ void rpath_autoset_interface_usage(void) { - printf("usage: rpath_autoset {file} {topdir}\n"); + printf("usage: rpath_autoset {file} {topdir} {destroot}\n"); } /** @@ -333,12 +333,13 @@ void rpath_autoset_interface_usage(void) { * @return return value of `rpath_autoset` */ int rpath_autoset_interface(int argc, char **argv) { - if (argc < 3) { + if (argc < 4) { rpath_autoset_interface_usage(); return -1; } char *filename = argv[1]; const char *topdir = argv[2]; + const char *destroot = argv[3]; if (exists(filename) != 0) { perror(filename); @@ -351,7 +352,7 @@ int rpath_autoset_interface(int argc, char **argv) { } FSTree *libs = rpath_libraries_available(topdir); - int result = rpath_autoset(filename, libs); + int result = rpath_autoset(filename, libs, destroot); if (result < 0) { fprintf(SYSERROR); diff --git a/lib/relocation.c b/lib/relocation.c index a0ba6a6..870d7cf 100644 --- a/lib/relocation.c +++ b/lib/relocation.c @@ -423,7 +423,7 @@ void relocate_root(const char *destroot, const char *baseroot) { if (SPM_GLOBAL.verbose) { printf("Relocate RPATH: %s\n", b_record[i]->path); } - rpath_autoset(b_record[i]->path, libs); + rpath_autoset(b_record[i]->path, libs, destroot); } if (SPM_GLOBAL.verbose) { printf("Relocate DATA : %s\n", b_record[i]->path); diff --git a/lib/rpath.c b/lib/rpath.c index 0044db8..f15de86 100644 --- a/lib/rpath.c +++ b/lib/rpath.c @@ -105,13 +105,13 @@ char *rpath_get(const char *_filename) { * @param _filename * @return */ -char *rpath_generate(const char *_filename, FSTree *tree) { +char *rpath_generate(const char *_filename, FSTree *tree, const char *destroot) { char *filename = realpath(_filename, NULL); if (!filename) { return NULL; } - char *result = rpath_autodetect(filename, tree); + char *result = rpath_autodetect(filename, tree, destroot); if (!result) { free(filename); return NULL; @@ -134,7 +134,7 @@ int rpath_set(const char *filename, const char *rpath) { memset(args, '\0', PATH_MAX); #if OS_LINUX - sprintf(args, "--set-rpath '%s'", rpath); + sprintf(args, "--force-rpath --set-rpath '%s'", rpath); pe = patchelf(filename, args); #elif OS_DARWIN sprintf(args, "-add-rpath '%s'", rpath); @@ -156,10 +156,10 @@ int rpath_set(const char *filename, const char *rpath) { * @param _rpath * @return */ -int rpath_autoset(const char *filename, FSTree *tree) { +int rpath_autoset(const char *filename, FSTree *tree, const char *destroot) { int returncode = 0; - char *rpath_new = rpath_generate(filename, tree); + char *rpath_new = rpath_generate(filename, tree, destroot); if (!rpath_new) { return -1; } @@ -192,7 +192,7 @@ FSTree *rpath_libraries_available(const char *root) { * @param filename path to file (or a directory) * @return success=relative path from `filename` to nearest lib directory, failure=NULL */ -char *rpath_autodetect(const char *filename, FSTree *tree) { +char *rpath_autodetect(const char *filename, FSTree *tree, const char *destroot) { const char *origin; char *rootdir = dirname(filename); char *start = realpath(rootdir, NULL); @@ -216,6 +216,7 @@ char *rpath_autodetect(const char *filename, FSTree *tree) { // This function returns `$ORIGIN/../../../CORE` which is not what we want to see. // TODO: We WANT to see this: `$ORIGIN/../lib/perl5/xx.xx.xx/<arch>/CORE` not just the basename() + /* // Change directory to the requested root chdir(start); @@ -233,6 +234,7 @@ char *rpath_autodetect(const char *filename, FSTree *tree) { // return to calling directory chdir(cwd); + */ StrList *libs = strlist_init(); if (libs == NULL) { @@ -249,6 +251,30 @@ char *rpath_autodetect(const char *filename, FSTree *tree) { } for (size_t i = 0; i < strlist_count(libs_wanted); i++) { + char *shared_library = strlist_item(libs_wanted, i); + char *match = NULL; + char *repl = NULL; + + match = dirname(fstree_search(tree, shared_library)); + + if (match != NULL) { + char *libpath = match; + if (startswith(match, "./")) { + libpath = &match[2]; + } + repl = join((char *[]){destroot, libpath, NULL}, DIRSEPS); + } else { + repl = join((char *[]){destroot, "lib", NULL}, DIRSEPS); + } + + if (strstr_array(libs->data, repl) == NULL) { + strlist_append(libs, repl); + } + free(repl); + } + + /* + for (size_t i = 0; i < strlist_count(libs_wanted); i++) { // zero out relative path string memset(_relative, '\0', sizeof(_relative)); // Get the shared library name we are going to look for in the tree @@ -258,8 +284,8 @@ char *rpath_autodetect(const char *filename, FSTree *tree) { char *match = NULL; if ((match = dirname(fstree_search(tree, shared_library))) != NULL) { // Begin generating the relative path string - strcat(relative, origin); - strcat(relative, DIRSEPS); + //strcat(relative, origin); + //strcat(relative, DIRSEPS); // Append the number of relative levels to the relative path string if (depth_to_root) { @@ -276,18 +302,23 @@ char *rpath_autodetect(const char *filename, FSTree *tree) { // Append relative path to array of libraries (if it isn't already in there) if (strstr_array(libs->data, relative) == NULL) { - strlist_append(libs, relative); + char *final = realpath(relative, NULL); + strlist_append(libs, final); + free(final); } } } + */ #if OS_LINUX // Some programs do not require local libraries provided by SPM (i.e. libc) // Inject "likely" defaults here + /* if (strlist_count(libs) == 0) { strlist_append(libs, "$ORIGIN/../lib"); strlist_append(libs, "$ORIGIN/../lib64"); } + */ #endif // Populate result string |