<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugzilla.yoctoproject.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.6"
          urlbase="https://bugzilla.yoctoproject.org/"
          
          maintainer="it-coreprojects-helpdesk@linuxfoundation.org"
>

    <bug>
          <bug_id>2383</bug_id>
          
          <creation_ts>2012-05-01 21:14:52 +0000</creation_ts>
          <short_desc>Relocatable SDK</short_desc>
          <delta_ts>2012-08-30 08:40:01 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>7</classification_id>
          <classification>Build System, Metadata &amp; Runtime</classification>
          <product>Meta-yocto</product>
          <component>meta-yocto</component>
          <version>1.3</version>
          <rep_platform>All</rep_platform>
          <op_sys>Multiple</op_sys>
          <bug_status>VERIFIED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard>(P2)(Scheduled)</status_whiteboard>
          <keywords></keywords>
          <priority>Low</priority>
          <bug_severity>enhancement</bug_severity>
          <target_milestone>1.3 M3</target_milestone>
          
          <blocked>2838</blocked>
          <everconfirmed>1</everconfirmed>
          <reporter name="Khem Raj">raj.khem</reporter>
          <assigned_to name="Laurentiu Palcu">laurentiu.palcu</assigned_to>
          <cc>alexandru.c.georgescu</cc>
    
    <cc>bogdan.a.marinescu</cc>
    
    <cc>jason.wessel</cc>
    
    <cc>jessica.zhang</cc>
    
    <cc>poky.bs.watcher</cc>
    
    <cc>poky.watcher</cc>
    
    <cc>richard.purdie</cc>
    
    <cc>song.liu</cc>
          
          
          <cf_os>---</cf_os>
          <cf_regression_type>---</cf_regression_type>
          
          <cf_docchange>---</cf_docchange>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>20967</commentid>
    <comment_count>0</comment_count>
    <who name="Khem Raj">raj.khem</who>
    <bug_when>2012-05-01 21:14:52 +0000</bug_when>
    <thetext>currently SDKs are not relocatable. It would be a nice feature to dump the SDK anywhere and use it (as long as the tree structure underneath is mantained same)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>20970</commentid>
    <comment_count>1</comment_count>
    <who name="Richard Purdie">richard.purdie</who>
    <bug_when>2012-05-01 22:10:55 +0000</bug_when>
    <thetext>Biggest problem is we hardcode in the path to our dynamic loader. You can&apos;t use $ORIGIN in the dynamic loader path. Our only option is probably to write and require some kind of &quot;bounce&quot; binary which would get installed to a known location and allow us to bounce to something $ORIGIN like to locate the dynamic loader.

Using the host systems dynamic loader proves problematic since it essentially implies you need the host libc and then you have to link against the lowest common denomninator of the platforms you want to support rather than being independent like we currently are.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>21060</commentid>
    <comment_count>2</comment_count>
    <who name="Jason Wessel">jason.wessel</who>
    <bug_when>2012-05-03 14:14:59 +0000</bug_when>
    <thetext>(In reply to comment #1)
&gt; Biggest problem is we hardcode in the path to our dynamic loader. You can&apos;t
&gt; use $ORIGIN in the dynamic loader path. Our only option is probably to write
&gt; and require some kind of &quot;bounce&quot; binary which would get installed to a
&gt; known location and allow us to bounce to something $ORIGIN like to locate
&gt; the dynamic loader.
&gt; 

Using a &quot;bounce&quot; binary is an interesting idea, but what about the possibility of changing the linker to NULL pad the absolute path to the dynamic loader lookup?  With this concept you would not be depending on anything that is external.  You would either design in an SDK sanity check to make sure the path the SDK is currently at is the same as the binaries else  &quot;update&quot; the binaries as needed.  Or leave behind a &quot;setup_sdk.sh&quot; script with the intended purpose that you run it to generate your initial environment script and do the check and update at that point.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>21062</commentid>
    <comment_count>3</comment_count>
    <who name="Richard Purdie">richard.purdie</who>
    <bug_when>2012-05-03 14:51:07 +0000</bug_when>
    <thetext>(In reply to comment #2)
&gt; (In reply to comment #1)
&gt; &gt; Biggest problem is we hardcode in the path to our dynamic loader. You can&apos;t
&gt; &gt; use $ORIGIN in the dynamic loader path. Our only option is probably to write
&gt; &gt; and require some kind of &quot;bounce&quot; binary which would get installed to a
&gt; &gt; known location and allow us to bounce to something $ORIGIN like to locate
&gt; &gt; the dynamic loader.
&gt; &gt; 
&gt; 
&gt; Using a &quot;bounce&quot; binary is an interesting idea, but what about the
&gt; possibility of changing the linker to NULL pad the absolute path to the
&gt; dynamic loader lookup?  With this concept you would not be depending on
&gt; anything that is external.  You would either design in an SDK sanity check
&gt; to make sure the path the SDK is currently at is the same as the binaries
&gt; else  &quot;update&quot; the binaries as needed.  Or leave behind a &quot;setup_sdk.sh&quot;
&gt; script with the intended purpose that you run it to generate your initial
&gt; environment script and do the check and update at that point.

I agree, this is the other option. We could inject a long linker path, update it to a shorter standard one matching the current baviour as post processing, then have a &quot;relocate&quot; script allowing it to be updated to a new location...</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>22662</commentid>
    <comment_count>4</comment_count>
    <who name="Laurentiu Palcu">laurentiu.palcu</who>
    <bug_when>2012-06-28 11:14:13 +0000</bug_when>
    <thetext>I&apos;ve been doing a little bit of reaserch on both solutions and I might have found a 3rd one which, in my opinion, is the simplest. Unless I got the entire problem completely wrong: 
- I&apos;ll start with Jason&apos;s solution. Null padding the dynamic loader path wouldn&apos;t be possible unless the linker itself is changed to do that by default. An alternative to this would be to pass a very long pattern (as Richard suggested) that would later be changed to our path. This is doable but we would need some special tools at install time in order to change the pattern in the path we want: readelf would be necessary to get .interp offset in the ELF file(unless we want to write everything from scratch) and a sed-like tool (bbe might be able to do that) to search/replace stuff in binary files (an alternative would be to use a combination of head/tail and temporary files). Aditional tools mean that the user has to install them all in order to complete SDK installation... Not very nice. Another option to this would be to use the patchelf tool, compile it statically and use it at install time to change the dynamic loader path;
- Richard&apos;s solution: First off, having a binary installed at a known location means that we would need to put in a directory like /lib, /bin, etc. These are known locations that are very unlikely not to exist on a host. But for installing a binary in these locations the user would need root permissions... Are we OK to assume the user has root permissions on the dev machine? Also, depending on the type of bouncing binary, we might need to handle virtual addresses conflicts between first executable and our interpreter.
- 3rd solution: based, partially, on Richard&apos;s solution. However, instead of a bouncing binary, we have a soft link to the loader itself that gets set at install time: /lib/ld-linux-poky -&gt; &lt;path_to_our_sdk&gt;/lib/ld-linux-x86-64.so.2. So .interp section will be hardcoded to: /lib/ld-linux-poky.  It needs, however, root permissions too but it looks like it&apos;s the simplest of all.

What do you guys say?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>22664</commentid>
    <comment_count>5</comment_count>
    <who name="Richard Purdie">richard.purdie</who>
    <bug_when>2012-06-28 12:02:39 +0000</bug_when>
    <thetext>(In reply to comment #4)
&gt; I&apos;ve been doing a little bit of reaserch on both solutions and I might have
&gt; found a 3rd one which, in my opinion, is the simplest. Unless I got the
&gt; entire problem completely wrong: 
&gt; - I&apos;ll start with Jason&apos;s solution. Null padding the dynamic loader path
&gt; wouldn&apos;t be possible unless the linker itself is changed to do that by
&gt; default. An alternative to this would be to pass a very long pattern (as
&gt; Richard suggested) that would later be changed to our path. This is doable
&gt; but we would need some special tools at install time in order to change the
&gt; pattern in the path we want: readelf would be necessary to get .interp
&gt; offset in the ELF file(unless we want to write everything from scratch) and
&gt; a sed-like tool (bbe might be able to do that) to search/replace stuff in
&gt; binary files (an alternative would be to use a combination of head/tail and
&gt; temporary files).

Another option here is some kind of script, say in python or perl which simply loads the file as a binary blob, looks for the magic interpreter string within the first say 500 bytes of the file and then rewrites it. In some ways this is pretty nasty but it would also be pretty effective.

&gt; Aditional tools mean that the user has to install them all
&gt; in order to complete SDK installation... Not very nice. Another option to
&gt; this would be to use the patchelf tool, compile it statically and use it at
&gt; install time to change the dynamic loader path;
&gt; - Richard&apos;s solution: First off, having a binary installed at a known
&gt; location means that we would need to put in a directory like /lib, /bin,
&gt; etc. These are known locations that are very unlikely not to exist on a
&gt; host. But for installing a binary in these locations the user would need
&gt; root permissions... Are we OK to assume the user has root permissions on the
&gt; dev machine? Also, depending on the type of bouncing binary, we might need
&gt; to handle virtual addresses conflicts between first executable and our
&gt; interpreter.
&gt; - 3rd solution: based, partially, on Richard&apos;s solution. However, instead of
&gt; a bouncing binary, we have a soft link to the loader itself that gets set at
&gt; install time: /lib/ld-linux-poky -&gt;
&gt; &lt;path_to_our_sdk&gt;/lib/ld-linux-x86-64.so.2. So .interp section will be
&gt; hardcoded to: /lib/ld-linux-poky.  It needs, however, root permissions too
&gt; but it looks like it&apos;s the simplest of all.

I like the simplicity of it.

I&apos;d like to propose a multi-pronged approach with this:

a) We test the symlink relocation method, get that working and document it. We need pretty much everything we&apos;d need to do to make that work anyway for subsequent work such as ensuring RPATHS are relocated and symlinks are relative. We have this for -native packages but I&apos;m not sure its being applied to -nativesdk right now.

b) Investigate whether we can have the linker take a parameter to pad the interpreter field to a specific length, maybe with a NULL to terminate the name, then magic padding characters so any search/replace utility can spot them.

c) Assuming we can get b) working, write a relocation util, probably in a scripting lanaguage that can make the search/replacement.

Does that seem like a reasonable plan?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>22666</commentid>
    <comment_count>6</comment_count>
    <who name="Laurentiu Palcu">laurentiu.palcu</who>
    <bug_when>2012-06-28 13:06:01 +0000</bug_when>
    <thetext>(In reply to comment #5)
&gt; (In reply to comment #4)
&gt; &gt; I&apos;ve been doing a little bit of reaserch on both solutions and I might have
&gt; &gt; found a 3rd one which, in my opinion, is the simplest. Unless I got the
&gt; &gt; entire problem completely wrong: 
&gt; &gt; - I&apos;ll start with Jason&apos;s solution. Null padding the dynamic loader path
&gt; &gt; wouldn&apos;t be possible unless the linker itself is changed to do that by
&gt; &gt; default. An alternative to this would be to pass a very long pattern (as
&gt; &gt; Richard suggested) that would later be changed to our path. This is doable
&gt; &gt; but we would need some special tools at install time in order to change the
&gt; &gt; pattern in the path we want: readelf would be necessary to get .interp
&gt; &gt; offset in the ELF file(unless we want to write everything from scratch) and
&gt; &gt; a sed-like tool (bbe might be able to do that) to search/replace stuff in
&gt; &gt; binary files (an alternative would be to use a combination of head/tail and
&gt; &gt; temporary files).
&gt; 
&gt; Another option here is some kind of script, say in python or perl which
&gt; simply loads the file as a binary blob, looks for the magic interpreter
&gt; string within the first say 500 bytes of the file and then rewrites it. In
&gt; some ways this is pretty nasty but it would also be pretty effective.
&gt; 
&gt; &gt; Aditional tools mean that the user has to install them all
&gt; &gt; in order to complete SDK installation... Not very nice. Another option to
&gt; &gt; this would be to use the patchelf tool, compile it statically and use it at
&gt; &gt; install time to change the dynamic loader path;
&gt; &gt; - Richard&apos;s solution: First off, having a binary installed at a known
&gt; &gt; location means that we would need to put in a directory like /lib, /bin,
&gt; &gt; etc. These are known locations that are very unlikely not to exist on a
&gt; &gt; host. But for installing a binary in these locations the user would need
&gt; &gt; root permissions... Are we OK to assume the user has root permissions on the
&gt; &gt; dev machine? Also, depending on the type of bouncing binary, we might need
&gt; &gt; to handle virtual addresses conflicts between first executable and our
&gt; &gt; interpreter.
&gt; &gt; - 3rd solution: based, partially, on Richard&apos;s solution. However, instead of
&gt; &gt; a bouncing binary, we have a soft link to the loader itself that gets set at
&gt; &gt; install time: /lib/ld-linux-poky -&gt;
&gt; &gt; &lt;path_to_our_sdk&gt;/lib/ld-linux-x86-64.so.2. So .interp section will be
&gt; &gt; hardcoded to: /lib/ld-linux-poky.  It needs, however, root permissions too
&gt; &gt; but it looks like it&apos;s the simplest of all.
&gt; 
&gt; I like the simplicity of it.
&gt; 
&gt; I&apos;d like to propose a multi-pronged approach with this:
&gt; 
&gt; a) We test the symlink relocation method, get that working and document it.
&gt; We need pretty much everything we&apos;d need to do to make that work anyway for
&gt; subsequent work such as ensuring RPATHS are relocated and symlinks are
&gt; relative. We have this for -native packages but I&apos;m not sure its being
&gt; applied to -nativesdk right now.
So this is just a temporary solution?
&gt; 
&gt; b) Investigate whether we can have the linker take a parameter to pad the
&gt; interpreter field to a specific length, maybe with a NULL to terminate the
&gt; name, then magic padding characters so any search/replace utility can spot
&gt; them.
I couldn&apos;t find any way to pad the .interp field to the length we want using existing linker options... Unless we patch the linker.
&gt; 
&gt; c) Assuming we can get b) working, write a relocation util, probably in a
&gt; scripting lanaguage that can make the search/replacement.
If we&apos;re talking about sh/bash, it might be a little bit hard (not impossible though). If we use python, it might be easier but the users that don&apos;t build yocto themselves and don&apos;t have python installed will be forced to do that prior to installing the SDK. If this is acceptable, than I&apos;m for python.

&gt; 
&gt; Does that seem like a reasonable plan?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>22667</commentid>
    <comment_count>7</comment_count>
    <who name="Richard Purdie">richard.purdie</who>
    <bug_when>2012-06-28 13:49:54 +0000</bug_when>
    <thetext>(In reply to comment #6)
&gt; (In reply to comment #5)
&gt; &gt; (In reply to comment #4)
&gt; &gt; &gt; I&apos;ve been doing a little bit of reaserch on both solutions and I might have
&gt; &gt; &gt; found a 3rd one which, in my opinion, is the simplest. Unless I got the
&gt; &gt; &gt; entire problem completely wrong: 
&gt; &gt; &gt; - I&apos;ll start with Jason&apos;s solution. Null padding the dynamic loader path
&gt; &gt; &gt; wouldn&apos;t be possible unless the linker itself is changed to do that by
&gt; &gt; &gt; default. An alternative to this would be to pass a very long pattern (as
&gt; &gt; &gt; Richard suggested) that would later be changed to our path. This is doable
&gt; &gt; &gt; but we would need some special tools at install time in order to change the
&gt; &gt; &gt; pattern in the path we want: readelf would be necessary to get .interp
&gt; &gt; &gt; offset in the ELF file(unless we want to write everything from scratch) and
&gt; &gt; &gt; a sed-like tool (bbe might be able to do that) to search/replace stuff in
&gt; &gt; &gt; binary files (an alternative would be to use a combination of head/tail and
&gt; &gt; &gt; temporary files).
&gt; &gt; 
&gt; &gt; Another option here is some kind of script, say in python or perl which
&gt; &gt; simply loads the file as a binary blob, looks for the magic interpreter
&gt; &gt; string within the first say 500 bytes of the file and then rewrites it. In
&gt; &gt; some ways this is pretty nasty but it would also be pretty effective.
&gt; &gt; 
&gt; &gt; &gt; Aditional tools mean that the user has to install them all
&gt; &gt; &gt; in order to complete SDK installation... Not very nice. Another option to
&gt; &gt; &gt; this would be to use the patchelf tool, compile it statically and use it at
&gt; &gt; &gt; install time to change the dynamic loader path;
&gt; &gt; &gt; - Richard&apos;s solution: First off, having a binary installed at a known
&gt; &gt; &gt; location means that we would need to put in a directory like /lib, /bin,
&gt; &gt; &gt; etc. These are known locations that are very unlikely not to exist on a
&gt; &gt; &gt; host. But for installing a binary in these locations the user would need
&gt; &gt; &gt; root permissions... Are we OK to assume the user has root permissions on the
&gt; &gt; &gt; dev machine? Also, depending on the type of bouncing binary, we might need
&gt; &gt; &gt; to handle virtual addresses conflicts between first executable and our
&gt; &gt; &gt; interpreter.
&gt; &gt; &gt; - 3rd solution: based, partially, on Richard&apos;s solution. However, instead of
&gt; &gt; &gt; a bouncing binary, we have a soft link to the loader itself that gets set at
&gt; &gt; &gt; install time: /lib/ld-linux-poky -&gt;
&gt; &gt; &gt; &lt;path_to_our_sdk&gt;/lib/ld-linux-x86-64.so.2. So .interp section will be
&gt; &gt; &gt; hardcoded to: /lib/ld-linux-poky.  It needs, however, root permissions too
&gt; &gt; &gt; but it looks like it&apos;s the simplest of all.
&gt; &gt; 
&gt; &gt; I like the simplicity of it.
&gt; &gt; 
&gt; &gt; I&apos;d like to propose a multi-pronged approach with this:
&gt; &gt; 
&gt; &gt; a) We test the symlink relocation method, get that working and document it.
&gt; &gt; We need pretty much everything we&apos;d need to do to make that work anyway for
&gt; &gt; subsequent work such as ensuring RPATHS are relocated and symlinks are
&gt; &gt; relative. We have this for -native packages but I&apos;m not sure its being
&gt; &gt; applied to -nativesdk right now.
&gt; So this is just a temporary solution?

Its a stepping stone, yes. I haven&apos;t put timescales against any of these items, I&apos;m trying to figure out the long term plan, then we see how soon we can get each piece done.

So it might be temporary but might be what we ship for 1.3 for example, depending on time constraints.

&gt; &gt; b) Investigate whether we can have the linker take a parameter to pad the
&gt; &gt; interpreter field to a specific length, maybe with a NULL to terminate the
&gt; &gt; name, then magic padding characters so any search/replace utility can spot
&gt; &gt; them.
&gt; I couldn&apos;t find any way to pad the .interp field to the length we want using
&gt; existing linker options... Unless we patch the linker.

I&apos;m thinking we should patch the linker. We build it ourselves anyway and the patch shouldn&apos;t be too invasive. This issue is important enough that this makes sense.

&gt; &gt; c) Assuming we can get b) working, write a relocation util, probably in a
&gt; &gt; scripting lanaguage that can make the search/replacement.
&gt; If we&apos;re talking about sh/bash, it might be a little bit hard (not
&gt; impossible though).

I don&apos;t want to use shell for this.

&gt; If we use python, it might be easier but the users that
&gt; don&apos;t build yocto themselves and don&apos;t have python installed will be forced
&gt; to do that prior to installing the SDK. If this is acceptable, than I&apos;m for
&gt; python.

I think python is acceptable as long as we can work on old versions of python, say python 2.4. This is to allow people to install and relocate our &quot;external python&quot; tarball to meet the minimum bitbake python requirement of 2.6. I can&apos;t think of any issue with a 2.4 minimum version for something as simple as this script.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>23822</commentid>
    <comment_count>8</comment_count>
    <who name="Laurentiu Palcu">laurentiu.palcu</who>
    <bug_when>2012-08-06 10:32:02 +0000</bug_when>
    <thetext>Patches were merged to master:

http://git.yoctoproject.org/cgit.cgi/poky/commit/?id=e81441a92fff59d617f22387716f6c1a9da5a9af
http://git.yoctoproject.org/cgit.cgi/poky/commit/?id=77973e3004b9d3e2d5a59715e30d46e9351d0008
http://git.yoctoproject.org/cgit.cgi/poky/commit/?id=749b8a52c68500cca546d705b7ac81905c1fe0e7
http://git.yoctoproject.org/cgit.cgi/poky/commit/?id=44df019842bc83cdcf559ac64b989ab3c5febd6a
http://git.yoctoproject.org/cgit.cgi/poky/commit/?id=476ced15c244b5a4bb91cef59fdf7e3b5a981576
http://git.yoctoproject.org/cgit.cgi/poky/commit/?id=e3a13b8d93cdfe2fdb58ef84f6d58bbbcaeb7a05</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>24648</commentid>
    <comment_count>9</comment_count>
    <who name="Alexandru Georgescu">alexandru.c.georgescu</who>
    <bug_when>2012-08-30 08:40:01 +0000</bug_when>
    <thetext>Setting it to verified-fixed. The SDK installs in the desired location.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>