Message ID | 75ca9a71-aaf5-dd21-f71f-4bcfc2880faa@grandegger.com |
---|---|
State | Not Applicable |
Headers | show |
On 20-07-17 11:03, Wolfgang Grandegger wrote: > case "${tree}" in > host) > ... > # we always want $ORIGIN-based rpaths to make it relocatable. Perfect. Just please start the sentence with a capital (it ends with a .) > sanitize_extra_args+=( "--relative-to-file" ) > ;; > > staging) > ... > # should be like for the target tree below s/like/the same as/ > sanitize_extra_args+=( "--no-standard-lib-dirs" ) > ;; > > target) > ... > # we don't want $ORIGIN-based rpaths but absolute paths without rootdir. > # we also want to remove rpaths pointing to /lib or /usr/lib. Capitalization, otherwise perfect. [snip] > As I said, the execution time comes form scanning for ELF files. The rest doesn't > matter a lot. Instead of the patch you attached, it might actually make more sense to create a tiny C file that does this, and execute that as part of the find command. Or you could just create support/scripts/elfmagic with those 4 bytes and use "cmp -n 4 {} ${0%/*}/elfmagic". By the way, I believe filtering with -exec is much faster than doing it with while/if. Unfortunately you can't use that with patchelf --print-rpath because the output of patchelf would be mixed up with the find output. Regards, Arnout > The attached patch speeds up ELF file checking. As said, readelf > is still faster even with that patch. [snip]
Hello Arnout, Am 20.07.2017 um 15:45 schrieb Arnout Vandecappelle: > > > On 20-07-17 11:03, Wolfgang Grandegger wrote: >> case "${tree}" in >> host) >> ... >> # we always want $ORIGIN-based rpaths to make it relocatable. > > Perfect. Just please start the sentence with a capital (it ends with a .) Well, I followed the style of the original script... just to be consistent... otherwise we will have an ugly mix. > >> sanitize_extra_args+=( "--relative-to-file" ) >> ;; >> >> staging) >> ... >> # should be like for the target tree below > > s/like/the same as/ > >> sanitize_extra_args+=( "--no-standard-lib-dirs" ) >> ;; >> >> target) >> ... >> # we don't want $ORIGIN-based rpaths but absolute paths without rootdir. >> # we also want to remove rpaths pointing to /lib or /usr/lib. > > Capitalization, otherwise perfect. > > [snip] >> As I said, the execution time comes form scanning for ELF files. The rest doesn't >> matter a lot. > > Instead of the patch you attached, it might actually make more sense to create > a tiny C file that does this, and execute that as part of the find command. Or > you could just create support/scripts/elfmagic with those 4 bytes and use "cmp > -n 4 {} ${0%/*}/elfmagic". Yes, I had that idea as well and I have already hacked something. The problem is that it does not check if it does have an rpath. "cmp" is not faster, I already tried! > By the way, I believe filtering with -exec is much faster than doing it with > while/if. Unfortunately you can't use that with patchelf --print-rpath because > the output of patchelf would be mixed up with the find output. I already tried various other solutions. Just preparing v8... Wolfgang.
On 20-07-17 16:08, Wolfgang Grandegger wrote: > Hello Arnout, > > Am 20.07.2017 um 15:45 schrieb Arnout Vandecappelle: >> >> >> On 20-07-17 11:03, Wolfgang Grandegger wrote: >>> case "${tree}" in >>> host) >>> ... >>> # we always want $ORIGIN-based rpaths to make it relocatable. >> >> Perfect. Just please start the sentence with a capital (it ends with a .) > > Well, I followed the style of the original script... just to be consistent... > otherwise we will have an ugly mix. There is no original script, only an original author :-) So indeed, fix it script-wide please. [snip] >>> As I said, the execution time comes form scanning for ELF files. The rest >>> doesn't >>> matter a lot. >> >> Instead of the patch you attached, it might actually make more sense to create >> a tiny C file that does this, and execute that as part of the find command. Or >> you could just create support/scripts/elfmagic with those 4 bytes and use "cmp >> -n 4 {} ${0%/*}/elfmagic". > > Yes, I had that idea as well and I have already hacked something. The problem is > that it does not check if it does have an rpath. Well, you could do that particular check in the find -exec and keep the --print-rpath check in the while loop. > "cmp" is not faster, I already > tried! OK good. Might be a good idea to keep track of the things you already tried in the cover letter. Regards, Arnout > >> By the way, I believe filtering with -exec is much faster than doing it with >> while/if. Unfortunately you can't use that with patchelf --print-rpath because >> the output of patchelf would be mixed up with the find output. > > I already tried various other solutions. > > Just preparing v8... > > Wolfgang. >
Am 20.07.2017 um 16:19 schrieb Arnout Vandecappelle: > > > On 20-07-17 16:08, Wolfgang Grandegger wrote: >> Hello Arnout, >> >> Am 20.07.2017 um 15:45 schrieb Arnout Vandecappelle: >>> >>> >>> On 20-07-17 11:03, Wolfgang Grandegger wrote: >>>> case "${tree}" in >>>> host) >>>> ... >>>> # we always want $ORIGIN-based rpaths to make it relocatable. >>> >>> Perfect. Just please start the sentence with a capital (it ends with a .) >> >> Well, I followed the style of the original script... just to be consistent... >> otherwise we will have an ugly mix. > > There is no original script, only an original author :-) I have no problem to adapt the style of the original author(s) ;). It should just be consistent. > So indeed, fix it script-wide please. > > [snip] >>>> As I said, the execution time comes form scanning for ELF files. The rest >>>> doesn't >>>> matter a lot. >>> >>> Instead of the patch you attached, it might actually make more sense to create >>> a tiny C file that does this, and execute that as part of the find command. Or >>> you could just create support/scripts/elfmagic with those 4 bytes and use "cmp >>> -n 4 {} ${0%/*}/elfmagic". >> >> Yes, I had that idea as well and I have already hacked something. The problem is >> that it does not check if it does have an rpath. > > Well, you could do that particular check in the find -exec and keep the > --print-rpath check in the while loop. > > >> "cmp" is not faster, I already >> tried! > > OK good. Might be a good idea to keep track of the things you already tried in > the cover letter. Well, it's already a few month ago that I tried finding a good and fast solution. I tried a lot of things, be can't remember the details. My time working on this topic is limited! When I have more free time I will take care. Wolfgang.
On 20-07-17 18:50, Wolfgang Grandegger wrote: > > > Am 20.07.2017 um 16:19 schrieb Arnout Vandecappelle: [snip] >> OK good. Might be a good idea to keep track of the things you already tried in >> the cover letter. > > Well, it's already a few month ago that I tried finding a good and fast > solution. I tried a lot of things, be can't remember the details. That's exactly why I ask to keep track of it in the cover letter. :-) Since you already posted the series, no need to do it now. But when you post patches that speed things up, please try to write down what you tested (at least the things that you are sure of). Regards, Arnout > My time > working on this topic is limited! When I have more free time I will take care. > > Wolfgang.
Index: patchelf-0.9/src/patchelf.cc =================================================================== --- patchelf-0.9.orig/src/patchelf.cc 2017-07-04 19:38:55.744223853 +0200 +++ patchelf-0.9/src/patchelf.cc 2017-07-05 09:43:42.417493549 +0200 @@ -317,20 +317,30 @@ } -static void readFile(string fileName) +static void readElfFile(string fileName) { struct stat st; + unsigned char elfmag[SELFMAG]; + + int fd = open(fileName.c_str(), O_RDONLY); + if (fd == -1) error("open"); + + if (read(fd, elfmag, SELFMAG) != SELFMAG) error("read"); + + if (memcmp(elfmag, ELFMAG, SELFMAG) != 0) + error("not an ELF executable"); + if (stat(fileName.c_str(), &st) != 0) error("stat"); + fileSize = st.st_size; maxSize = fileSize + 32 * 1024 * 1024; - contents = (unsigned char *) malloc(fileSize + maxSize); if (!contents) abort(); + memcpy(contents, elfmag, SELFMAG); - int fd = open(fileName.c_str(), O_RDONLY); - if (fd == -1) error("open"); - - if (read(fd, contents, fileSize) != fileSize) error("read"); + /* Read the rest of the file */ + if (read(fd, contents + SELFMAG, fileSize - SELFMAG) + != fileSize - SELFMAG) error("read"); close(fd); } @@ -1609,15 +1619,11 @@ debug("Kernel page size is %u bytes\n", getPageSize()); - readFile(fileName); - + readElfFile(fileName); /* Check the ELF header for basic validity. */ if (fileSize < (off_t) sizeof(Elf32_Ehdr)) error("missing ELF header"); - if (memcmp(contents, ELFMAG, SELFMAG) != 0) - error("not an ELF executable"); - if (contents[EI_CLASS] == ELFCLASS32 && contents[EI_VERSION] == EV_CURRENT) {