summaryrefslogtreecommitdiffstats
path: root/src/patchelf.cc
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2016-09-19 16:12:19 (GMT)
committerEelco Dolstra <eelco.dolstra@logicblox.com>2016-09-19 16:12:19 (GMT)
commita4d21661d510ccf7ff72bb0e4ccd3f087e9086ad (patch)
tree103eb33cf173a2c6177899821989755428fff524 /src/patchelf.cc
parent5f37ae6b41e8ffdb3e80988922732893f84928ed (diff)
downloadpatchelf-a4d21661d510ccf7ff72bb0e4ccd3f087e9086ad.zip
patchelf-a4d21661d510ccf7ff72bb0e4ccd3f087e9086ad.tar.gz
patchelf-a4d21661d510ccf7ff72bb0e4ccd3f087e9086ad.tar.bz2
--shrink-rpath: Ignore libraries for different architectures
Fixes #93.
Diffstat (limited to 'src/patchelf.cc')
-rw-r--r--src/patchelf.cc22
1 files changed, 16 insertions, 6 deletions
diff --git a/src/patchelf.cc b/src/patchelf.cc
index 4cf715e..3dacbc3 100644
--- a/src/patchelf.cc
+++ b/src/patchelf.cc
@@ -272,19 +272,25 @@ static void growFile(FileContents contents, size_t newSize)
}
-static FileContents readFile(std::string fileName)
+static FileContents readFile(std::string fileName,
+ size_t cutOff = std::numeric_limits<size_t>::max())
{
struct stat st;
if (stat(fileName.c_str(), &st) != 0) error("stat");
+ if ((uint64_t) st.st_size > (uint64_t) std::numeric_limits<size_t>::max())
+ error("cannot read file of size " + std::to_string(st.st_size) + " into memory");
+
+ size_t size = std::min(cutOff, (size_t) st.st_size);
+
FileContents contents = std::make_shared<std::vector<unsigned char>>();
- contents->reserve(st.st_size + 32 * 1024 * 1024);
- contents->resize(st.st_size, 0);
+ contents->reserve(size + 32 * 1024 * 1024);
+ contents->resize(size, 0);
int fd = open(fileName.c_str(), O_RDONLY);
if (fd == -1) error("open");
- if (read(fd, contents->data(), st.st_size) != st.st_size) error("read");
+ if ((size_t) read(fd, contents->data(), size) != size) error("read");
close(fd);
@@ -317,6 +323,7 @@ ElfType getElfType(const FileContents & fileContents)
bool is32Bit = contents[EI_CLASS] == ELFCLASS32;
+ // FIXME: endianness
return ElfType{is32Bit, is32Bit ? ((Elf32_Ehdr *) contents)->e_machine : ((Elf64_Ehdr *) contents)->e_machine};
}
@@ -1162,8 +1169,11 @@ void ElfFile<ElfFileParamNames>::modifyRPath(RPathOp op,
std::string libName = dirName + "/" + neededLibs[j];
struct stat st;
if (stat(libName.c_str(), &st) == 0) {
- neededLibFound[j] = true;
- libFound = true;
+ if (getElfType(readFile(libName, sizeof(Elf32_Ehdr))).machine == rdi(hdr->e_machine)) {
+ neededLibFound[j] = true;
+ libFound = true;
+ } else
+ debug("ignoring library '%s' because its machine type differs\n", libName.c_str());
}
}