Gentoo Archives: gentoo-alt

From: Michael Haubenwallner <haubi@g.o>
To: gentoo-alt@l.g.o
Subject: Re: [gentoo-alt] AIX linking adventure
Date: Tue, 08 Feb 2011 22:02:30
Message-Id: 4D51BD5F.1050406@gentoo.org
In Reply to: Re: [gentoo-alt] AIX linking adventure by Perry Smith
1 Hi Perry!
2
3 On 02/08/11 19:36, Perry Smith wrote:
4 > On Feb 8, 2011, at 2:49 AM, Michael Haubenwallner wrote:
5 >> On 02/08/2011 01:35 AM, Perry Smith wrote:
6 >>> I wrote a front end to AIX's ld command as well as a relink command I'm calling "rl".
7 >> Actually, in Prefix we already do wrap AIX' ld in sys-devel/binutils-config
8 >> to get the runpaths (the -blibpath argument) right.
9 >> There is an RFC[1] for the way I want to have shared libraries being created on AIX.
10 >> [1] http://lists.gnu.org/archive/html/libtool/2011-01/msg00023.html
11 >
12 > I am not on the libtool list. I did not read that thread yet but I will here shortly.
13
14 You might consider subscribing to that Gentoo bug[1], its URL refers
15 to the libtool thread, and I'm usually adding progress there.
16
17 [1] http://bugs.gentoo.org/show_bug.cgi?id=213277
18
19 > I need some "netiquette" help. Should I plop my thoughts / questions about that
20 > thread into this thread or start a new thread? I get confused either way :-) (Maybe
21 > I'm special that way.)
22
23 Eventually we can sort out your concerns here (first).
24
25 >>> https://github.com/pedz/aixbin
26 >>
27 >> Commenting on 'Readme.markdown' found there:
28 >> Why do you move '-blibpath' arguments to '-L' arguments?
29 >> IMO, the other way round would make more sense actually.
30 >> Why do you need 'rl' (relink) at all?
31 >
32 > For ruby, their libpath was a complete mistake.
33
34 Ohw, seems there's need to fix your view on the libpath/runpath issue,
35 as everything you describe here actually is how it should be done:
36
37 Usually, compilers are installed as part of the host system into somewhere
38 like /usr, where /usr/lib usually is the search path for any installed
39 library at linktime (called "linkpath", set via "-L" linker flag), and
40 either "/usr/lib:/lib" or even "/lib:/usr/lib" is the search path at
41 runtime (called "runpath", set via "-blibpath" linker flag).
42
43 > They did not include the path to gcc's library.
44
45 Nobody but the compiler and/or the system should know the system's and
46 compiler's library directories. It is up to the compiler-, linker- and
47 loader-setup to find the system's and especially the compiler's libraries
48 at both linktime and runtime.
49
50 This exactly is the (major) reason why in Prefix we do wrap the linker
51 (as well as the compiler) to get gcc's and Prefix' (being the (sub)system)
52 library directories into both linkpath and runpath.
53
54 > They did not have a -L /path/to/where/they/would/install
55
56 The currently built package's libraries must not be linked from the target
57 installation directory. Imagine an old version of a library is already
58 installed there, and you want to upgrade the package - as is the usual
59 case with package managers (being either humans or software).
60
61 And if there are dependent libraries, they either are installed in system's
62 library directories the compiler/linker setup knows anyway, or the package
63 manager should add their locations via something like LDFLAGS or the like.
64
65 So while the new binaries must _not_ be /linked/ against the already installed
66 libraries provided by another instance of the package just built, ...
67
68 > but they did have -blibpath:/path/to/where/they/would/install:/usr/lib:/lib
69
70 ..., at runtime (after installing) the libraries have to be /loaded/ from there.
71
72 One AIX specific thing here is that the AIX loader cannot be configured to
73 search additional directories, so the binaries have to contain the whole runpath.
74 While the linker does search /usr/lib and /lib at linktime, it will not add
75 these paths to the runpath when an explicit runpath is specified via -blibpath.
76 This is why "/usr/lib:/lib" is specified with -blibpath too.
77
78 > And... the executable would never work in the directory
79 > where it was built in. It would work only after the package was
80 > installed (moved). I don't know how they were going to do
81 > the "test" or "check" phase which I'm sure Ruby has.
82
83 They most likely set the LIBPATH environment variable to the local
84 library directory. This is one of the rare use cases where environment
85 variables like LD_LIBRARY_PATH, LIBPATH, SHLIB_PATH are useful.
86
87 > I took their mistake as a symptom as a general practice. i.e.
88 > the general population somehow thinks that libpath substitutes for
89 > -L and it does not. I'm interested to hear of your experience but
90 > I can't think of a time where open source understood what libpath
91 > (inside the object) could/should be used for.
92
93 Actually, the Ruby guys seem to have done it "right":
94 If you were using xlc (from /usr/bin), or even gcc from the
95 "AIX Toolbox for Linux applications", so both are "installed
96 with the host system", you might not have had any problem.
97
98 > The Ruby guys did have a fairly reasonable fear. They did not want
99 > to have just -L . and -L .., etc and not set the libpath because the -L .
100 > adds that to the internal libpath and that creates what they called a
101 > security risk.
102
103 The explicit '-blibpath' avoids recording the (relative) local library
104 paths passed via '-L' into the runpath:
105
106 *) Using buildtime paths (either relative or not) for -L, the linker is able to
107 find the new libraries (this is called "linktime"), before installation.
108 *) Using target paths (absolute only) for -blibpath, the loader is able to
109 find the installed library (this is called "runtime"), after installation.
110
111 > But, the problem is that the dot needs to be in the internal
112 > libpath while the executable is in the directory it was built in.
113
114 *) Using local paths (either relative or not) for LIBPATH, the loader is able to
115 find the new library (there is no such term "testtime"), before installation.
116
117 > The purpose for rt is after the install.
118
119 <snipped anything related to 'rt' (relink?), as it should be obsolete now>
120
121 > I also had a rather self imposed limitation to work around.
122 > I am trying to get "rvm" to work and rvm thinks it knows how to
123 > unpackage, configure, build, and install without any user
124 > intervention. To get that to work, I had to hook in at the ld
125 > point and then, after the fact, fix the resulting files after they
126 > are installed.
127
128 This actually is a not so uncommon problem:
129 It usually does not work that well using more than one package manager
130 at a time - portage and rvm in this case.
131
132 >>> I've used this only for Ruby -- and it was in fact Ruby that caused me to do this.
133 >>> Their out of the box system does not work at all for AIX if the prefix directory is not the same as GCC's.
134 >>> WIth this, I can now use rvm on AIX and do "rvm install 1.9.1" and it will complete successfully without my fingers leaving my hands.
135
136 Which directory (called "prefix") do you tell "rvm" to install to?
137 Have you tried this while having your Gentoo Prefix instance in your
138 environment (using /your/gentoo/prefix/startprefix)?
139
140 >> Haven't used/installed Ruby on any platform yet: What is 'rvm' ?
141 > rvm is "Ruby Version Manager". rvm allows completely independent
142 > versions of Ruby (1.8.7, 1.9.1, MacRuby, etc). Each version can have
143 > its own independent sets of gems (called gemsets) so an application
144 > can use its own version of Ruby and its own set of gems. I can set up
145 > an environment on my development laptop and then fairly easily replicate
146 > this environment on my staging server and production server. It solves
147 > many problems I have when trying to have three or four Rails apps
148 > on the same host. (sorry for the long winded reply).
149
150 Basically this also is what Gentoo Prefix is for - having multiple instances
151 of similar things set up on one machine. However, eventually it is possible
152 to have multiple Ruby versions within one instance of Gentoo Prefix (and even
153 Gentoo Linux) set up in some package-managed way (using portage as the
154 package manager instead of rvm).
155
156 >>> I mentioned this idea on this list before but it didn't fly very well.
157 >>> I'm not sure if it was completely understood.
158 >> I fail to find that post you're referring to. Has it been within one
159 >> of the threads we already created together, and I've overlooked it?
160 >
161 > I *think* this is the post but it got munged:
162 > http://archives.gentoo.org/gentoo-alt/msg_d16e4dce43974e6926eedf04a3b8fb36.xml
163 >
164 > My archive is this (snipped out).
165
166 Ok, found it in my archives too - for mailing list managers
167 it is easier to receive plain text mails, no html.
168
169 > The time stamp is Tue, Dec 14, 2010 at 6:25 PM (to the gentoo-alt list)
170 >
171 >> Also, the guy I'm talking to mentioned rtl_enable -s. I've not used it but it seems like it might make life a lot easier.
172
173 Still I do think we don't have any use for 'rtl_enable' when
174 we are able to /create/ corrent shared libraries firsthand.
175 rtl_enable is designed to "fix" shared objects for one's needs
176 when there is no sourcecode available.
177
178 >>> This is more of a proof of concept at this stage. I'm going to putter around and try and use it on other packages.
179 >>
180 >> For packages not aware of AIX at all:
181 >> How would this require their build systems to be patched?
182 >>
183 >>> "rl" could be enhanced to take "from" and "to" directories.
184
185 The above "rt" is a typo and should be "rl"?
186
187 >>> If you wanted to change files installed in /some/old/directory and put them into /some/new/directory, rl could easily modified do that.
188 >>
189 >> In which context do you need this use case?
190 >
191 > With putting absolute paths into the objects, we are effectively nullifying the possible benefit of the LIBPATH environment. I think we
192 > both agree that that benefit is questionable but others might like it. So if someone wants to move where I built a package from
193 > /usr/local to /opt, the first step would be to change the internal absolute paths to each dependency. There would be other obstacles too
194 > like any internal paths of the executables but often there are command line arguments to change those. e.g. you can give
195 > emacs directions on where to find its lisp files but you can not magically tell the loader where to find emacs' dependent libraries.
196 > A user once could via LIBPATH but that isn't going to work now with absolute internal paths. rl gives that possibly useful option back
197 > to the user.
198
199 Well, moving a binary package from /usr/local to /opt is a
200 completely different use case than the one above, which was:
201 compile, run from build directory, install (into /usr/local).
202
203 (replace "/usr/local/" by "/gentoo/prefix/usr/")
204
205 >> And how would you do that on Linux?
206 >
207 > I don't know squat about Linux.
208 > Part of my frustration is everyone appears to want to make AIX fit into the Linux way.
209
210 The linkpath/runpath problem isn't specific to Linux in any way, it is
211 an universal problem when managing packages - on /any/ operating system.
212
213 I did go through these /very/ same linkpath/runpath hell on Linux already,
214 and in Prefix we do the same linkpath/runpath trickery on /any/ platform.
215
216 Welcome to "rpath hell", "dll hell", "dependency hell", "distribution hell",
217 "<whatever> hell"!
218
219 The only problem AIX really does have is the lack of something like what is known as
220 "DT_SONAME" in ELF/SystemV-world[2], being immediately encoded into the shared objects.
221 The reason for this being a problem is not that ELF does have it, it is because
222 such a mechanism actually is necessary for managing packages.
223 However, it is possible to emulate the "DT_SONAME" thing with Import Files ...
224
225 [2] Linux, Solaris, (recent) HP-UX, *BSD, ...
226
227 > My objective is subtly but significantly different.
228 > I want to get open source packages onto AIX.
229
230 Same goal here.
231 However, Linux (as "the" open source platform these days) is "the"
232 reference platform open source packages most often are written for.
233
234 /haubi/
235 --
236 Michael Haubenwallner
237 Gentoo on a different level

Replies

Subject Author
Re: [gentoo-alt] AIX linking adventure Perry Smith <pedzsan@×××××.com>