From ce6597fb9d53fe884782001bbe33d3a248de0963 Mon Sep 17 00:00:00 2001 From: TheAssassin Date: Tue, 29 Jan 2019 01:00:36 +0100 Subject: [PATCH] Better handle debug-symbols-only ELF files --- src/core/appdir.cpp | 38 +++++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/src/core/appdir.cpp b/src/core/appdir.cpp index c386f14..3a9439b 100644 --- a/src/core/appdir.cpp +++ b/src/core/appdir.cpp @@ -221,10 +221,16 @@ namespace linuxdeploy { const auto& filePath = currentEntry.first; const auto& rpath = currentEntry.second; - ldLog() << "Setting rpath in ELF file" << filePath << "to" << rpath << std::endl; - if (!elf::ElfFile(filePath).setRPath(rpath)) { - ldLog() << LD_ERROR << "Failed to set rpath in ELF file:" << filePath << std::endl; - success = false; + // no need to set rpath in debug symbols files + // also, patchelf crashes on such symbols + if (isInDebugSymbolsLocation(filePath)) { + ldLog() << LD_WARNING << "Not setting rpath in debug symbols file:" << filePath << std::endl; + } else { + ldLog() << "Setting rpath in ELF file" << filePath << "to" << rpath << std::endl; + if (!elf::ElfFile(filePath).setRPath(rpath)) { + ldLog() << LD_ERROR << "Failed to set rpath in ELF file:" << filePath << std::endl; + success = false; + } } setElfRPathOperations.erase(setElfRPathOperations.begin()); @@ -238,8 +244,6 @@ namespace linuxdeploy { if (disableCopyrightFilesDeployment) return true; - ldLog() << logPrefix << LD_NO_SPACE << "Deploying copyright files for file" << from << std::endl; - if (copyrightFilesManager == nullptr) return false; @@ -248,6 +252,8 @@ namespace linuxdeploy { if (copyrightFiles.empty()) return false; + ldLog() << logPrefix << LD_NO_SPACE << "Deploying copyright files for file" << from << std::endl; + for (const auto& file : copyrightFiles) { std::string targetDir = file.string(); targetDir.erase(0, 1); @@ -391,8 +397,12 @@ namespace linuxdeploy { rpath = "$ORIGIN/" + relPath.string() + ":$ORIGIN"; } + // no need to set rpath in debug symbols files + // also, patchelf crashes on such symbols + if (!isInDebugSymbolsLocation(destinationPath)) { + setElfRPathOperations[destinationPath] = rpath; + } - setElfRPathOperations[destinationPath] = rpath; stripOperations.insert(destinationPath); if (!deployElfDependencies(path, recursionLevel)) @@ -529,6 +539,16 @@ namespace linuxdeploy { return true; } + + bool isInDebugSymbolsLocation(const bf::path& path) { + // TODO: check if there's more potential locations for debug symbol files + for (const std::string& dbgSymbolsPrefix : {".debug/"}) { + if (path.string().substr(0, dbgSymbolsPrefix.size()) == dbgSymbolsPrefix) + return true; + } + + return false; + } }; AppDir::AppDir(const bf::path& path) { @@ -799,6 +819,10 @@ namespace linuxdeploy { std::vector sharedLibraries; for (const auto& file : listFilesInDirectory(path() / "usr" / "lib", true)) { + // exclude debug symbols + if (d->isInDebugSymbolsLocation(file)) + continue; + // make sure it's an ELF file try { elf::ElfFile elfFile(file);