Options for fixing paths in apps.?

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Message
Author
User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#16 Post by technosaurus »

You can usually enable c/ldflags by
CFLAGS="-Os ..." LDFLAGS="-Wl,-Os,-s,..." ./configure ...
Other times configure will ignore your request and you have to edit the makefile(s)

If devx is installed
echo /lib/*.so /usr/lib/*.so /usr/X11/lib/*.so ¦tr " " "\n"
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#17 Post by sunburnt »

technosaurus; I appreciate the help, but I`m still puzzled... "enable c/ldflags"
What you`re saying is: In a term. type:

Code: Select all

CFLAGS="-Os..."
LDFLAGS="-Wl,-Os,-s,..."
./configure ... 
Where "..." is more options being assigned to the variable?
I`ve read on compiling but nothing has said anything about what you say.
Where do I read about this stuff, the variables, options, and what they do?
I assume with the right options an all-in-one exec. is possible?

You say you`ve worked with magic ermine? You have a non-trial copy?
I`m thinking it would solve all of this hassle with all apps.... Am I correct?
How much do they want for it? I assume to buy it means use for anything.

# Why is devx needed to list all of the lib. files?
I noticed a while back that not all libs. end in ".so", what about them?
Like: " libblkid.so.1.1.0 " and it`s link: " libblkid.so.1 ".

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#18 Post by technosaurus »

>>technosaurus; I appreciate the help, but I`m still puzzled... "enable c/ldflags"
What you`re saying is: In a term. type:

Code: Select all

CFLAGS="-Os..." \
LDFLAGS="-Wl,-Os,-s,..." \
./configure ... 
Where "..." is more options being assigned to the variable?
I`ve read on compiling but nothing has said anything about what you say.
Where do I read about this stuff, the variables, options, and what they do?
I assume with the right options an all-in-one exec. is possible?

<<fixed above ( no return between flags)
I read the gcc/ld options from gcc.gnu.org and manpages

>>You say you`ve worked with magic ermine? You have a non-trial copy?
I`m thinking it would solve all of this hassle with all apps.... Am I correct?
How much do they want for it? I assume to buy it means use for anything.

<<I asked the developer questions about adding resource files (ex. /usr/share/package/* and how to exclude libs, etc... and she sent me a license (she also does a tool called statifier that is similar and gpl)

>># Why is devx needed to list all of the lib. files?
I noticed a while back that not all libs. end in ".so", what about them?
Like: " libblkid.so.1.1.0 " and it`s link: " libblkid.so.1 ".

<< it isn't, but using *.so.* will have a lot of dupes


Edit...
I posted a sfs tool that may do do what you want.

http://murga-linux.com/puppy/viewtopic.php?t=70804
It is not alpha yet, but works
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#19 Post by sunburnt »

Okay... What a silly thought, that it`d be just the way you wrote it...
I`m going to look at statifier and hopefully find out what it does.

I looked at the page you posted for an sfs tool, but the thread is for jwm menus.

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#20 Post by technosaurus »

Normally, when you link with say -lfoo the linker will look through $LS_LIBRARY_PATH (a colon separated list of library locations) for libfoo.so and then try libfoo.a and move on to the next dir (footnote, this causes many pets compiled in 4.3.x? ...honestly I forget which puppy... to get libz.a to be compiled in statically because there is a libz.a in /lib but the libs.so is in /usr/lib, which comes after /lib)
Adding -static or -Bstatic reverses the preference, I think one goes through the entire $LS_LIBRARY_PATH looking for libfoo.a before even trying libfoo.so (not 100% sure ... I have to look them up when I use them)

In contrast --enable-static just tells autotools to build a static library (whichis really just an archive of the object files). By default, many programs will still build and link against its own internal shared libraries, unless you also use --disable-shared. The same goes for library packages, but the quick & dirty way to force any library to be compiled in statically, is to simply delete the libfoo.so symlink (provided you have libfoo.a, that is).

My last post in jwm_tools is a script I call frugalunion, it mounts any filesystem supported by busybox mount (includes squashfs and many others) then links or copies files as appropriate and runs the program(s) that have .desktop files. Running it again will remove the links/files and unmounts. (I use busybox mount because it will handle loops automatically, while the full mount doesn't.)
I still want to add code to copy vs link everything in $HOME and remove the dependency on rox.
It is designed to work basically like magic ermine. My only note of caution would be to limit the .desktop files (you could make a quick GUI in yad, xdialog or gtkdialog to select one ... I am thinking libre office)
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#21 Post by sunburnt »

Many thanks technosaurus; Still lots of reading, still not clear on concepts...

You say: (I use busybox mount as it handles loops automatically, full mount doesn't.)
You mean it auto. creates loop devices? Or something else?

I`ve been messing with Statifier and I`m amazed by the lack of instructions.
Lots of text files on how it works, but nothing about how to use it !!!
Does it use binaries? Or does it compile the app. first? ( compile I think )
Does it build from the file tree, or a single dir. with everything in it?
It only packs the exec. and it`s libraries, nothing else. Not enough...
Only Magic Ermine Pro packs all the files. And no price... Of course...

# Maybe modify Statifier to include all files in a dir. with the exec.?
This would allow total control of what goes into the final exec. file.

# She hard coded a library path, is that common? ( a BIG problem )
..... ( I put her libs in: /root/my-applications/lib and it failed. )

# I think your compile method is the best bet.

1) Will libraries put in the squash file work? The other files do...
..... So does the exec. look in it`s own compiled tree first for libraries?
..... If the libs. paths aren`t hard coded, then LD_LIBRARY_PATH. So no?

2) I`m still not clear on how to static compile an app., some apps. may need it.
..... Like the last Q, libs. are included. But the exec. only looks in it`s own tree?

3) Do you know much about apt-get? I need the download and dep. parts.
..... It`d be nice if it would download source packages to a dir. to compile.
..... ( Binary files would be great, but they aren`t going to work in a Squash.)

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#22 Post by technosaurus »

Busybox does actually automagically create loops, where standard mount requires -o loop etc.... to be added. This allow using more than just a squashfs (it is portable to ext2,3,4 and other file system images that busybox can mount ... like a pupsave file or ISO image.)

I don't think there are any plans to add magic ermine functions to statifier.
M.e. basically sets up a virtual file system within, the executable that you see is really a wrapper around the vfs that mounts it and runs the executable inside ... and here was the big killer for me - the resulting binaries are not upx-able and it cannot use upx'd binaries to build from. I figured if I am going to use an external program for compression, I may as well use squash-xz + a wrapper.

Squash is just a compressed read only file system. In standard puppy everything is united into one filesystem and its like a stack of transparencies ... the user only sees the uppermost (last loaded) file (if someone accidentally includes their foobar files in an sfs, yours may _appear_ to be replaced, but they are just masked by a higher layer of the transparency stack. So the short answer is yes included libs will work, but ... don't fubar someone's foobar. I don't like my files being clobbered by a package - which is mainly why I wrote my own loader that doesn't (allowing clobbers or even making auto-backups is just a couple extra args though)

I don't know enough to be able to _replace_ magic ermine. The only project that comes to mind that I have been looking at is LRC linux resource compiler (i have only recently learned of it and not used it yet.) There is also a tool that compiles scripts into a binary called shc (it is still a script though) ... this would make a good thesis project.

Re:apt @goingnuts did add apt support
http://www.goingnuts.dk/linux.asp#APT
(not sure why binary files won't work, what did you mean?)
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#23 Post by technosaurus »

Double post
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

big_bass
Posts: 1740
Joined: Mon 13 Aug 2007, 12:21

#24 Post by big_bass »

Hey I am no expert on this but I was bored and needed something to do .... I discovered how to do this pretty easily though
in a short time with patchelf
http://nixos.org/patchelf.html


the documents are not easy to follow
so I listed what I did to get a working example going


first I made a directory called saved and copied a bin to /saved so as not to bork any real bin
I used tee as this example

then I made a new directory called /my

I copied ld-2.6.1.so and ld-linux.so.2 symlink to the new /my folder

open a terminal in /my and made a new symlink just added a my- to the name to see the difference

Code: Select all

ln -sf  my-ld-2.6.1.so my-ld-linux.so.2
now run load to see that the last line says /lib/ld-linux.so.2 (0xb80d0000)

Code: Select all

 ldd /saved/tee
        linux-gate.so.1 =>  (0xffffe000)
        libcrypt.so.1 => /lib/libcrypt.so.1 (0xb80a2000)
        libm.so.6 => /lib/libm.so.6 (0xb8080000)
        libc.so.6 => /lib/libc.so.6 (0xb7f85000)
        /lib/ld-linux.so.2 (0xb80d0000)


#run the command to set the new path of the lib

Code: Select all

 patchelf --set-interpreter /my/lib/my-ld-linux.so.2 /saved/tee

Code: Select all

ldd /saved/tee                                                
        linux-gate.so.1 =>  (0xffffe000)
        libcrypt.so.1 => /lib/libcrypt.so.1 (0xb8052000)
        libm.so.6 => /lib/libm.so.6 (0xb8030000)
        libc.so.6 => /lib/libc.so.6 (0xb7f35000)
        /my/lib/my-ld-linux.so.2 (0xb8080000)
# now notice that the last line has changed to reflect /my/lib/my-ld-linux.so.2 (0xb80c0000)


cool stuff :D
Joe

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#25 Post by sunburnt »

big_bass; So patchelf patches one lib`s path in one exec at a time.
And run again on the same exec but for a different lib it will fix it`s path also?
So you can step through the exec`s lib deps adding them to a Squash or not.
Being as it does one at a time, all of the lib`s paths can be controlled.!

I wonder if it can change the RPATH for other deps, like icons, configs., etc.
If so then no compiling`s needed!!! Just walk through the apps. dep tree to fix.
If not then I`ll still have to compile the app., but the libs can be added at will !

I`m wondering why a lib. has an RPATH, unless it uses another lib. of course.
NOTE: Read up on this and libs. seldomly have paths to other libs.

It`s truly amazing to see all the different ideas and tools that have been made!
I just downloaded it and I`m going to be up all night trying it out. Thanks... Terry
Last edited by sunburnt on Sun 04 Sep 2011, 22:01, edited 4 times in total.

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#26 Post by sunburnt »

technosaurus; An apt-get binary won`t work like how you showed me.
xmahjongg didn`t work from a squash until I compiled it with --prefix

I ment "auto. create new loop devices" ( maybe that`s what you ment too ).
Puppy use to have very few, now it has 10, but still not nearly enough.
# So busybox creates loop devices if they`re needed and then mounts?

# My target OS design doesn`t have a unionFS, that`s why all this trouble.
So apps. must work from a differently located tree than normal, in a squash.

The plan... No union, / is in initramfs, links for r-o dirs. and persistant r-w dirs.
# R-O are links in / pointing to dirs. in squash file: /bin, /lib, /opt, /sbin, /usr
# R-W persistant are links in / to partition dirs.: /etc, /lost+found, /root, /home
# R-W non-persistant are dirs. in /: /dev, /mnt, /proc, /sys, /tmp, /var
The read-write non-persistant dirs. are small so the setup uses little ram.
Libs can be in squash file or not, if not they`re added to partition dir. in path.

# Now I need to do a statistical analysis of most app`s. dependencies.
Commonly used big libs stay separate, small seldom used libs in the apps.
I think it`s safe to say that any libs. in Puppy are pretty commonly used.

Yep, I was thinking a temp. union "install layer" on top would catch apt-get files.
Then it`d be easy to gather them up through the layer`s mount point, none missed.

I`ve had shc for awhile, but never have played with it. More to do...
I`ve been working with GatorDog`s BaCon and HUG and I rather like it.
Last edited by sunburnt on Sun 04 Sep 2011, 22:03, edited 1 time in total.

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#27 Post by sunburnt »

I`m wondering what "configure --prefix ..." does to displace the file tree.
There`s something it`s setting in how the exec looks for it`s other dep. files.
# Surely it doesn`t parse the C code and patch all the path references?

patchelf sets RPATH , which is only for execs and libs, not other deps.
readelf shows binary file header info. ( I think ) for execs and libs.
NOTE: I used readelf on many of Puppy`s execs. and they haven`t any RPATH.

What is it that "configure --prefix ..." sets to fix the exec`s path-to-otherFiles ?
# I`m wondering if it could be just patched in binary files like patchelf does.

I ran: readelf -a mah-jong
It didn`t show any sort of "prepath" that I could see. What`s being set?

big_bass
Posts: 1740
Joined: Mon 13 Aug 2007, 12:21

#28 Post by big_bass »

there is another way to edit the binary

this is a great tool it is used mostly for just string changes
but it has the built in power to also edit binaries
whereas patchelf is for made just for binary edits in mind

I compiled this there are docs inside *I made a minor edit to make to use /usr instead of /usr/local
http://www.puppy2.org/slaxer/replace-2. ... 1_SLXR.tgz
replace has some major advantages over both sed and rpl, particularly the
auto-detection of binaries and the subsequent correct handling of replacements
within binary files. This is a noticeable flaw in rpl because it has the
recursive capability to destroy your binary files if you specify -r and supply
an old string with a different length to the new string. Somewhat surprisingly,
this destructive timebomb isn't mentioned anywhere in the rpl documentation
or source code !
EXAMPLES
To make an executable use /usr/lib/libc.1 instead of /usr/lib/libc.2
(note that this is "risky" and may lead to run-time problems for the
executable
, but it's one way to try to run an HP-UX 11.00 binary on
HP-UX 10.20 !):

replace -bv /usr/lib/libc.2 /usr/lib/libc.1 filename

make backups of all binaries you plan to edit before hacking away

Joe

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#29 Post by technosaurus »

If you replace a string in a binary (or library) it _must_ be the same length. I normally use strings, grep and sed to make minor changes (like changing the version # in libflashplayer.so)

If you _must_ have a different length string you will need a tool(s) to fix the global offset table... if such a thing exists.
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#30 Post by sunburnt »

big_bass; I figured that the --prefix item in a binary was text, as muggins said:
If you compile with --prefix=/usr/local option, turma can read this in the binary.

But if "replace" can change lib. paths like patchelf does, then they`re text also.
I`m reading about replace, and it looks to be much like sed, a text editor.

# I suppose I should make turma work so I can look at this stuff for myself.


technosaurus; I think patchelf docs. stated that it padded empty space,
and added another (4k ?) block if it went over the current space in the binary.

I`m not sure about a global offset table... I`ve read so much it`s starting to mix.

##### One thing`s certain, before modding a file make a backup!

Post Reply