<div dir="ltr"><div>Hi Mark,</div><div><br></div><div>Thank you for your reply and no problem -- I chose to benchmark ssh-add with it. It contains no `.plt`.</div><div><br></div><div>The results are as follows:<br><br></div><div>Without prelink (ran prelink -auv):<br><br>   26019:<br>   26019:   runtime linker statistics:<br>   26019:    total startup time in dynamic loader: 1321674 cycles<br>   26019:         time needed for relocation: 797948 cycles (60.3%)<br>   26019:            number of relocations: 624<br>   26019:      number of relocations from cache: 3<br>   26019:       number of relative relocations: 9691<br>   26019:         time needed to load objects: 389972 cycles (29.5%)<br>Could not open a connection to your authentication agent.<br>   26019:<br>   26019:   runtime linker statistics:<br>   26019:         final number of relocations: 630<br>   26019:   final number of relocations from cache: 3</div><div><br></div><div>With prelink (ran prelink -av):</div><div><br></div><div>   1930:<br>   1930:   runtime linker statistics:<br>   1930:    total startup time in dynamic loader: 462288 cycles<br>   1930:         time needed for relocation: 48730 cycles (10.5%)<br>   1930:            number of relocations: 7<br>   1930:      number of relocations from cache: 134<br>   1930:       number of relative relocations: 0<br>   1930:         time needed to load objects: 286076 cycles (61.8%)<br>Could not open a connection to your authentication agent.<br>   1930:<br>   1930:   runtime linker statistics:<br>   1930:         final number of relocations: 9<br>   1930:   final number of relocations from cache: 134<br></div><div><br></div><div>I also tested against execstack, which for sure had the assertion fire on.<br></div><div>Without prelink:<br><br>   27736:<br>   27736:   runtime linker statistics:<br>   27736:    total startup time in dynamic loader: 1955954 cycles<br>   27736:         time needed for relocation: 755440 cycles (38.6%)<br>   27736:            number of relocations: 247<br>   27736:      number of relocations from cache: 3<br>   27736:       number of relative relocations: 1353<br>   27736:         time needed to load objects: 710384 cycles (36.3%)<br>/usr/bin/execstack: no files given<br>   27736:<br>   27736:   runtime linker statistics:<br>   27736:         final number of relocations: 251<br>   27736:   final number of relocations from cache: 3</div><div><br></div><div>With prelink:<br><br>   3268:<br>   3268:   runtime linker statistics:<br>   3268:    total startup time in dynamic loader: 1421206 cycles<br>   3268:         time needed for relocation: 199396 cycles (14.0%)<br>   3268:            number of relocations: 3<br>   3268:      number of relocations from cache: 88<br>   3268:       number of relative relocations: 0<br>   3268:         time needed to load objects: 696886 cycles (49.0%)<br>/usr/bin/execstack: no files given<br>   3268:<br>   3268:   runtime linker statistics:<br>   3268:         final number of relocations: 5<br>   3268:   final number of relocations from cache: 88</div><div><br></div><div>So, it looks like prelink is working on these :)<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, May 28, 2019 at 2:57 PM Mark Hatle <<a href="mailto:mark.hatle@windriver.com">mark.hatle@windriver.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Sorry for my delayed reply. I was out on a business trip.<br>
<br>
Did you try this with the ld.so statistics to see if the relocations were indeed<br>
reduced at runtime?<br>
<br>
One of my worries with these changes (since I am not an ELF expert either) is<br>
that we make a change that doesn't actually do anything -- but people expect it to.<br>
<br>
$ LD_DEBUG=help /lib/ld-linux.so.2<br>
Valid options for the LD_DEBUG environment variable are:<br>
<br>
 libs    display library search paths<br>
 reloc    display relocation processing<br>
 files    display progress for input file<br>
 symbols   display symbol table processing<br>
 bindings  display information about symbol binding<br>
 versions  display version dependencies<br>
 scopes   display scope information<br>
 all     all previous options combined<br>
 statistics display relocation statistics<br>
 unused   determined unused DSOs<br>
 help    display this help message and exit<br>
<br>
To direct the debugging output into a file instead of standard output<br>
a filename can be specified using the LD_DEBUG_OUTPUT environment variable.<br>
<br>
I believe that it's the 'statistics' option.<br>
<br>
LD_DEBUG=statistics <executable that's been prelinked><br>
<br>
Should result in something like:<br>
<br>
  128820:   runtime linker statistics:<br>
  128820:    total startup time in dynamic loader: 1974661 cycles<br>
  128820:         time needed for relocation: 354639 cycles (17.9%)<br>
  128820:           number of relocations: 90<br>
  128820:      number of relocations from cache: 3<br>
  128820:       number of relative relocations: 1201<br>
  128820:        time needed to load objects: 1303654 cycles (66.0%)<br>
  128820:<br>
  128820:   runtime linker statistics:<br>
  128820:        final number of relocations: 94<br>
  128820:   final number of relocations from cache: 3<br>
<br>
If prelink is working, the number of relocations (relative or otherwise) will be<br>
significantly reduced from the original non-relocated version.<br>
<br>
If you can run this test, it would give me the assurance that the patch is safe,<br>
and I'll get it incorporated into the prelink-cross sources.<br>
<br>
--Mark<br>
<br>
On 5/25/19 2:53 PM, Shane Peelar wrote:<br>
> Patch is attached. Thank you!<br>
> <br>
> On Sat, May 25, 2019 at 2:30 AM Khem Raj <<a href="mailto:raj.khem@gmail.com" target="_blank">raj.khem@gmail.com</a><br>
> <mailto:<a href="mailto:raj.khem@gmail.com" target="_blank">raj.khem@gmail.com</a>>> wrote:<br>
> <br>
>Â Â Â On Fri, May 24, 2019 at 6:58 PM Shane Peelar <<a href="mailto:lookatyouhacker@gmail.com" target="_blank">lookatyouhacker@gmail.com</a><br>
>Â Â Â <mailto:<a href="mailto:lookatyouhacker@gmail.com" target="_blank">lookatyouhacker@gmail.com</a>>> wrote:<br>
>Â Â Â ><br>
>   > Great! Would you be willing to accept a patch that makes arch-x86_64.c<br>
>Â Â Â handle that condition like the other arches?<br>
>Â Â Â ><br>
> <br>
>Â Â Â yes certainly.<br>
> <br>
>Â Â Â > -Shane<br>
>Â Â Â ><br>
>Â Â Â > On Fri, May 24, 2019 at 12:27 PM Khem Raj <<a href="mailto:raj.khem@gmail.com" target="_blank">raj.khem@gmail.com</a><br>
>Â Â Â <mailto:<a href="mailto:raj.khem@gmail.com" target="_blank">raj.khem@gmail.com</a>>> wrote:<br>
>Â Â Â >><br>
>Â Â Â >><br>
>Â Â Â >><br>
>Â Â Â >> On 5/24/19 8:10 AM, Shane Peelar wrote:<br>
>   >> > I did some reading into the sources in other architectures. The closest<br>
>Â Â Â >> > match, arch_i386.c, makes the write conditional as you say.<br>
>Â Â Â >> > So do other arches, including |arch_arm.c, |arch_sh.c, |arch-mips.c,<br>
>Â Â Â >> > |arch-s390.c, |arch-s390x.c, and |arch-ia64.c.||||||<br>
>Â Â Â >> > ||||||<br>
>Â Â Â >> > ||||||<br>
>Â Â Â >> > Notably, |||||||arch-cris.c||||||| has the same assert as<br>
>Â Â Â >> > |||||||arch-x86_64.c||||||| instead of the conditional.<br>
>Â Â Â >> ><br>
>Â Â Â >> > The code roughly looks like follows:||||||||||||||<br>
>Â Â Â >> > ||||||||||||||<br>
>Â Â Â >> > |||||||<br>
>Â Â Â >> > |||||||<br>
>   >> > 1. Check for dso->info[DT_PLTGOT]. If it does not exist, return 0<br>
>Â Â Â >> > 2. Call addr_to_sec on dso->info[DT_PLTGOT], return 1 if error<br>
>Â Â Â >> > 3. Look for the section named ".plt" in the ELF.<br>
>Â Â Â >> > 4. If the section cannot be found, return 0<br>
>Â Â Â >> > 5. Otherwise, write the address of .plt + constant (dependent on arch)<br>
>Â Â Â >> > to got[1]||||||||||||||<br>
>Â Â Â >> > ||||||||||||||<br>
>Â Â Â >> > |||||||<br>
>Â Â Â >> > |||||||<br>
>Â Â Â >> > In |||||||arch-x86_64.c and arch-cris.c|||||||, step (4) above is an<br>
>Â Â Â >> > assert:|||||||<br>
>Â Â Â >> ><br>
>   >> > |||||||1. Check for dso->info[DT_PLTGOT]. If it does not exist, return 0<br>
>Â Â Â >> > 2. Call addr_to_sec on dso->info[DT_PLTGOT], return 1 if error<br>
>Â Â Â >> > 3. Look for the section named ".plt" in the ELF.<br>
>Â Â Â >> > 4. Assert that the section was found<br>
>Â Â Â >> > 5. Write the address of .plt + constant (dependent on arch) to got[1]<br>
>Â Â Â >> ><br>
>Â Â Â >> > I tested out making the assert conditional and nothing seemed to break<br>
>Â Â Â >> > at least.<br>
>Â Â Â >> > |||||||<br>
>Â Â Â >> > |||||||<br>
>Â Â Â >><br>
>Â Â Â >> It seems ok to me.<br>
>Â Â Â >><br>
>Â Â Â >> ><br>
>Â Â Â >> > On Fri, May 24, 2019 at 12:08 AM Khem Raj <<a href="mailto:raj.khem@gmail.com" target="_blank">raj.khem@gmail.com</a><br>
>Â Â Â <mailto:<a href="mailto:raj.khem@gmail.com" target="_blank">raj.khem@gmail.com</a>><br>
>Â Â Â >> > <mailto:<a href="mailto:raj.khem@gmail.com" target="_blank">raj.khem@gmail.com</a> <mailto:<a href="mailto:raj.khem@gmail.com" target="_blank">raj.khem@gmail.com</a>>>> wrote:<br>
>Â Â Â >> ><br>
>Â Â Â >> ><br>
>Â Â Â >> ><br>
>Â Â Â >> >Â Â Â On 5/23/19 7:53 PM, Shane Peelar wrote:<br>
>Â Â Â >> >Â Â Â > Any of them on the system pretty much, and yes they are also<br>
>Â Â Â >> >Â Â Â built with<br>
>Â Â Â >> >Â Â Â > -fno-plt.<br>
>Â Â Â >> ><br>
>Â Â Â >> >Â Â Â OK, I think its better to them conditionally check for .plt section,<br>
>Â Â Â >> >Â Â Â can you describe more of whats going on when sections are checked.<br>
>Â Â Â >> ><br>
>Â Â Â >> >Â Â Â ><br>
>Â Â Â >> >Â Â Â > On Thu, May 23, 2019 at 9:59 PM Khem Raj <<a href="mailto:raj.khem@gmail.com" target="_blank">raj.khem@gmail.com</a><br>
>Â Â Â <mailto:<a href="mailto:raj.khem@gmail.com" target="_blank">raj.khem@gmail.com</a>><br>
>Â Â Â >> >Â Â Â <mailto:<a href="mailto:raj.khem@gmail.com" target="_blank">raj.khem@gmail.com</a> <mailto:<a href="mailto:raj.khem@gmail.com" target="_blank">raj.khem@gmail.com</a>>><br>
>Â Â Â >> >Â Â Â > <mailto:<a href="mailto:raj.khem@gmail.com" target="_blank">raj.khem@gmail.com</a> <mailto:<a href="mailto:raj.khem@gmail.com" target="_blank">raj.khem@gmail.com</a>><br>
>Â Â Â <mailto:<a href="mailto:raj.khem@gmail.com" target="_blank">raj.khem@gmail.com</a> <mailto:<a href="mailto:raj.khem@gmail.com" target="_blank">raj.khem@gmail.com</a>>>>> wrote:<br>
>Â Â Â >> >Â Â Â ><br>
>Â Â Â >> >Â Â Â ><br>
>Â Â Â >> >Â Â Â ><br>
>Â Â Â >> >Â Â Â >Â Â Â On 5/23/19 8:05 AM, Shane Peelar wrote:<br>
>Â Â Â >> >Â Â Â >Â Â Â > Hi Everyone @ the Yocto project,<br>
>Â Â Â >> >Â Â Â >Â Â Â ><br>
>Â Â Â >> >Â Â Â >Â Â Â > I'm Shane Peelar, a PhD Candidate at the University of<br>
>Â Â Â >> >Â Â Â Windsor.<br>
>Â Â Â >> >Â Â Â >Â Â Â > I'm writing to you about prelink-cross, as part of the<br>
>Â Â Â >> >Â Â Â Yocto project.<br>
>Â Â Â >> >Â Â Â >Â Â Â > Specifically, I'm looking at using it with executables<br>
>Â Â Â >> >Â Â Â built using<br>
>Â Â Â >> >Â Â Â >Â Â Â > `-fno-plt` under GCC.<br>
>Â Â Â >> >Â Â Â >Â Â Â > I wasn't quite sure where to send this email to, so I<br>
>Â Â Â >> >Â Â Â figured I'd<br>
>Â Â Â >> >Â Â Â >Â Â Â try<br>
>   >> >   >   > here. If there's a better place to send this, please let<br>
>Â Â Â >> >Â Â Â me know.<br>
>Â Â Â >> >Â Â Â >Â Â Â ><br>
>Â Â Â >> >Â Â Â >Â Â Â > Right now, prelink-cross seems to fail an assertion in<br>
>Â Â Â >> >Â Â Â >Â Â Â arch-x86_64.c,<br>
>Â Â Â >> >Â Â Â >Â Â Â > line 421, when<br>
>Â Â Â >> >Â Â Â >Â Â Â > using it with an executable built with `-fno-plt`:<br>
>Â Â Â >> >Â Â Â >Â Â Â ><br>
>Â Â Â >> >Â Â Â >Â Â Â > ...<br>
>Â Â Â >> >Â Â Â >Â Â Â > assert (i < dso->ehdr.e_shnum)<br>
>Â Â Â >> >Â Â Â >Â Â Â > ...<br>
>Â Â Â >> >Â Â Â >Â Â Â ><br>
>Â Â Â >> >Â Â Â >Â Â Â > This snippet seems to be looking for the ".plt" section and,<br>
>Â Â Â >> >Â Â Â >Â Â Â since it<br>
>   >> >   >   > can't find it, the assertion fires. This makes sense<br>
>Â Â Â >> >Â Â Â because in<br>
>Â Â Â >> >Â Â Â >Â Â Â > `-fno-plt` executables, the `.plt` section is missing<br>
>Â Â Â >> >Â Â Â entirely.<br>
>Â Â Â >> >Â Â Â >Â Â Â > I'm not an expert on ELF stuff, although I am learning<br>
>   >> >   quickly. It<br>
>Â Â Â >> >Â Â Â >Â Â Â > looks like<br>
>Â Â Â >> >Â Â Â >Â Â Â > this code wants to write into GOT[1] the address of ".plt"<br>
>Â Â Â >> >Â Â Â + 0x16 --<br>
>Â Â Â >> >Â Â Â >Â Â Â > since ".plt" doesn't<br>
>Â Â Â >> >Â Â Â >Â Â Â > exist, does it make sense to just change this assert to an if<br>
>Â Â Â >> >Â Â Â >Â Â Â statement<br>
>Â Â Â >> >Â Â Â >Â Â Â > like so:<br>
>Â Â Â >> >Â Â Â >Â Â Â ><br>
>Â Â Â >> >Â Â Â >Â Â Â > ...<br>
>Â Â Â >> >Â Â Â >Â Â Â >Â Â Â Â if (i < dso->ehdr.e_shnum)<br>
>Â Â Â >> >Â Â Â >Â Â Â >Â Â Â Â { ... }<br>
>Â Â Â >> >Â Â Â >Â Â Â > ...<br>
>Â Â Â >> >Â Â Â >Â Â Â ><br>
>   >> >   >   > and skip over that part? Or is this a real error<br>
>Â Â Â >> >Â Â Â condition for<br>
>   >> >   >   > prelink-cross and it really should not continue? The<br>
>Â Â Â >> >Â Â Â executable in<br>
>Â Â Â >> >Â Â Â >Â Â Â > question is also non-PIE, if that makes a difference.<br>
>Â Â Â >> >Â Â Â >Â Â Â ><br>
>Â Â Â >> >Â Â Â ><br>
>Â Â Â >> >Â Â Â >Â Â Â what shared libs is this linking to ? are they also built with<br>
>Â Â Â >> >Â Â Â >Â Â Â -fno-plt ?<br>
>Â Â Â >> >Â Â Â ><br>
>Â Â Â >> >Â Â Â >Â Â Â > Thanks for your time,<br>
>Â Â Â >> >Â Â Â >Â Â Â > Shane<br>
>Â Â Â >> >Â Â Â >Â Â Â ><br>
>Â Â Â >> >Â Â Â ><br>
>Â Â Â >> ><br>
> <br>
> <br>
<br>
</blockquote></div>