mailing list of musl libc
 help / color / mirror / code / Atom feed
* How to use MUSL without installing it?
@ 2018-09-03 20:24 John Found
  2018-09-04  9:40 ` Szabolcs Nagy
  0 siblings, 1 reply; 11+ messages in thread
From: John Found @ 2018-09-03 20:24 UTC (permalink / raw)
  To: musl

I am writing a script that to compile musl, then a program with musl, using the latest versions.

I am doing it following way:

mkdir muslsrc
tar --wildcards --strip-components 1 -C ./muslsrc/ -xzf ./musl*.tar.gz
cd muslsrc
ln -s /usr/bin/ar ./i386-ar
ln -s /usr/bin/ranlib ./i386-ranlib
./configure --prefix=../musl --host=i386 CC="gcc -m32 -O3"
make
make install
cd ..

Then I am compiling agains ./musl/ directory.

But after "make" I have all needed files in ./muslsrc/ directory.
Is it possible to use them directly instead of making fake "installation"?

-- 
John Found <johnfound@asm32.info>


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: How to use MUSL without installing it?
  2018-09-03 20:24 How to use MUSL without installing it? John Found
@ 2018-09-04  9:40 ` Szabolcs Nagy
  2018-09-04 11:34   ` John Found
  0 siblings, 1 reply; 11+ messages in thread
From: Szabolcs Nagy @ 2018-09-04  9:40 UTC (permalink / raw)
  To: musl

* John Found <johnfound@asm32.info> [2018-09-03 23:24:41 +0300]:
> I am writing a script that to compile musl, then a program with musl, using the latest versions.
> 
> I am doing it following way:
> 
> mkdir muslsrc
> tar --wildcards --strip-components 1 -C ./muslsrc/ -xzf ./musl*.tar.gz
> cd muslsrc
> ln -s /usr/bin/ar ./i386-ar
> ln -s /usr/bin/ranlib ./i386-ranlib
> ./configure --prefix=../musl --host=i386 CC="gcc -m32 -O3"

i think you need . in PATH for this to work

i think you can pass 'CROSS_COMPILE=' to configure
and then you don't need such symlinks.

> make
> make install
> cd ..
> 
> Then I am compiling agains ./musl/ directory.
> 
> But after "make" I have all needed files in ./muslsrc/ directory.
> Is it possible to use them directly instead of making fake "installation"?

no, the right way is to run make install
(DESTDIR and --prefix works the usual way)

there are only a small number of files that are copied
this way, if you directly use the build directory then
the target specific header files are not set up correctly,
i think you can hack that around with a bits symlink and
appropriate modifications to musl-gcc and the specs file,
but such hacks are not guaranteed to work in the future.


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: How to use MUSL without installing it?
  2018-09-04  9:40 ` Szabolcs Nagy
@ 2018-09-04 11:34   ` John Found
  2018-09-04 11:58     ` Szabolcs Nagy
  0 siblings, 1 reply; 11+ messages in thread
From: John Found @ 2018-09-04 11:34 UTC (permalink / raw)
  To: musl

On Tue, 4 Sep 2018 11:40:20 +0200
Szabolcs Nagy <nsz@port70.net> wrote:

> * John Found <johnfound@asm32.info> [2018-09-03 23:24:41 +0300]:
> > I am writing a script that to compile musl, then a program with musl, using the latest versions.
> > 
> > I am doing it following way:
> > 
> > mkdir muslsrc
> > tar --wildcards --strip-components 1 -C ./muslsrc/ -xzf ./musl*.tar.gz
> > cd muslsrc
> > ln -s /usr/bin/ar ./i386-ar
> > ln -s /usr/bin/ranlib ./i386-ranlib
> > ./configure --prefix=../musl --host=i386 CC="gcc -m32 -O3"
> 
> i think you need . in PATH for this to work

Well, it works this way actually.

> 
> i think you can pass 'CROSS_COMPILE=' to configure
> and then you don't need such symlinks.
> 
What value should I set CROSS_COMPILE to? i386?

> > make
> > make install
> > cd ..
> > 
> > Then I am compiling agains ./musl/ directory.
> > 
> > But after "make" I have all needed files in ./muslsrc/ directory.
> > Is it possible to use them directly instead of making fake "installation"?
> 
> no, the right way is to run make install
> (DESTDIR and --prefix works the usual way)
> there are only a small number of files that are copied
> this way, if you directly use the build directory then
> the target specific header files are not set up correctly,
> i think you can hack that around with a bits symlink and
> appropriate modifications to musl-gcc and the specs file,
> but such hacks are not guaranteed to work in the future.

Well, I will keep it the right way then. BTW, "make install"
tries to create symlink for ld-musl-i386.so in /usr/lib/ directory
How to prevent this attempt?

-- 
John Found <johnfound@asm32.info>


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: How to use MUSL without installing it?
  2018-09-04 11:34   ` John Found
@ 2018-09-04 11:58     ` Szabolcs Nagy
  2018-09-04 12:20       ` John Found
  2018-09-04 13:27       ` John Found
  0 siblings, 2 replies; 11+ messages in thread
From: Szabolcs Nagy @ 2018-09-04 11:58 UTC (permalink / raw)
  To: musl

* John Found <johnfound@asm32.info> [2018-09-04 14:34:39 +0300]:
> On Tue, 4 Sep 2018 11:40:20 +0200
> Szabolcs Nagy <nsz@port70.net> wrote:
> > i think you can pass 'CROSS_COMPILE=' to configure
> > and then you don't need such symlinks.
> > 
> What value should I set CROSS_COMPILE to? i386?
> 

leave it empty (by default it is '386-')
./configure --host=i386 CROSS_COMPILE=

> Well, I will keep it the right way then. BTW, "make install"
> tries to create symlink for ld-musl-i386.so in /usr/lib/ directory
> How to prevent this attempt?

if you don't use dynamic linking then --disable-shared

if you want to build dynamic linked executables that work
locally with your musl install, but not portable to other
musl systems then --syslibdir='$(prefix)/lib'
(then the binaries will use that path for the dynamic linker)

if you want to build dynamic linked executables that are
portable, but don't run locally, then ignore that failure
(it is not fatal, binaries will have standard dynamic linker
path, but your system will not have it set up)

if you want to build dynamic linked executables that are
portable and work locally, then you must have the dynamic
linker in /lib so you have to put the symlink there.


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: How to use MUSL without installing it?
  2018-09-04 11:58     ` Szabolcs Nagy
@ 2018-09-04 12:20       ` John Found
  2018-09-04 12:27         ` Rich Felker
  2018-09-04 13:27       ` John Found
  1 sibling, 1 reply; 11+ messages in thread
From: John Found @ 2018-09-04 12:20 UTC (permalink / raw)
  To: musl

On Tue, 4 Sep 2018 13:58:28 +0200
Szabolcs Nagy <nsz@port70.net> wrote:

> * John Found <johnfound@asm32.info> [2018-09-04 14:34:39 +0300]:
> > On Tue, 4 Sep 2018 11:40:20 +0200
> > Szabolcs Nagy <nsz@port70.net> wrote:
> > > i think you can pass 'CROSS_COMPILE=' to configure
> > > and then you don't need such symlinks.
> > > 
> > What value should I set CROSS_COMPILE to? i386?
> > 
> 
> leave it empty (by default it is '386-')
> ./configure --host=i386 CROSS_COMPILE=
> 
> > Well, I will keep it the right way then. BTW, "make install"
> > tries to create symlink for ld-musl-i386.so in /usr/lib/ directory
> > How to prevent this attempt?
> 
> if you don't use dynamic linking then --disable-shared
> 
> if you want to build dynamic linked executables that work
> locally with your musl install, but not portable to other
> musl systems then --syslibdir='$(prefix)/lib'
> (then the binaries will use that path for the dynamic linker)
> 
> if you want to build dynamic linked executables that are
> portable, but don't run locally, then ignore that failure
> (it is not fatal, binaries will have standard dynamic linker
> path, but your system will not have it set up)
> 
> if you want to build dynamic linked executables that are
> portable and work locally, then you must have the dynamic
> linker in /lib so you have to put the symlink there.

Thanks for this detailed explanation. It is very helpful.

Actually I am using dynamic linked executables, 
but I am setting the interpreter section to 
relative path: "./ld-musl-i386.so" and shiping
a portable package with my executable, sqlite3.so and 
ld-musl-i386.so in one directory. This way providing 
running on 64bit systems without installed 32bit libraries.

Regards
-- 
John Found <johnfound@asm32.info>


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: How to use MUSL without installing it?
  2018-09-04 12:20       ` John Found
@ 2018-09-04 12:27         ` Rich Felker
  2018-09-04 12:39           ` John Found
  2018-09-04 13:00           ` Jon Chesterfield
  0 siblings, 2 replies; 11+ messages in thread
From: Rich Felker @ 2018-09-04 12:27 UTC (permalink / raw)
  To: musl

On Tue, Sep 04, 2018 at 03:20:12PM +0300, John Found wrote:
> On Tue, 4 Sep 2018 13:58:28 +0200
> Szabolcs Nagy <nsz@port70.net> wrote:
> 
> > * John Found <johnfound@asm32.info> [2018-09-04 14:34:39 +0300]:
> > > On Tue, 4 Sep 2018 11:40:20 +0200
> > > Szabolcs Nagy <nsz@port70.net> wrote:
> > > > i think you can pass 'CROSS_COMPILE=' to configure
> > > > and then you don't need such symlinks.
> > > > 
> > > What value should I set CROSS_COMPILE to? i386?
> > > 
> > 
> > leave it empty (by default it is '386-')
> > ./configure --host=i386 CROSS_COMPILE=
> > 
> > > Well, I will keep it the right way then. BTW, "make install"
> > > tries to create symlink for ld-musl-i386.so in /usr/lib/ directory
> > > How to prevent this attempt?
> > 
> > if you don't use dynamic linking then --disable-shared
> > 
> > if you want to build dynamic linked executables that work
> > locally with your musl install, but not portable to other
> > musl systems then --syslibdir='$(prefix)/lib'
> > (then the binaries will use that path for the dynamic linker)
> > 
> > if you want to build dynamic linked executables that are
> > portable, but don't run locally, then ignore that failure
> > (it is not fatal, binaries will have standard dynamic linker
> > path, but your system will not have it set up)
> > 
> > if you want to build dynamic linked executables that are
> > portable and work locally, then you must have the dynamic
> > linker in /lib so you have to put the symlink there.
> 
> Thanks for this detailed explanation. It is very helpful.
> 
> Actually I am using dynamic linked executables, 
> but I am setting the interpreter section to 
> relative path: "./ld-musl-i386.so" and shiping
> a portable package with my executable, sqlite3.so and 
> ld-musl-i386.so in one directory. This way providing 
> running on 64bit systems without installed 32bit libraries.

This won't work -- a relative path is relative to the current working
directory, not the location of the executable. If you want users to be
able to invoke your program normally, you need to just provide a
wrapper script that does something like

	exec $(basedir)/ld-musl-i386.so --library-path ... -- $(basedir)/your_program.bin "$@"

I'm actually working on a design to allow direct invocation of
dynamic-linked programs without absolute dynamic linker paths, but it
will be a while before it's done and included in musl.

Rich


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: How to use MUSL without installing it?
  2018-09-04 12:27         ` Rich Felker
@ 2018-09-04 12:39           ` John Found
  2018-09-04 14:30             ` Rich Felker
  2018-09-04 13:00           ` Jon Chesterfield
  1 sibling, 1 reply; 11+ messages in thread
From: John Found @ 2018-09-04 12:39 UTC (permalink / raw)
  To: musl

On Tue, 4 Sep 2018 08:27:20 -0400
Rich Felker <dalias@libc.org> wrote:

> This won't work -- a relative path is relative to the current working
> directory, not the location of the executable. If you want users to be
> able to invoke your program normally, you need to just provide a
> wrapper script that does something like
> 
> 	exec $(basedir)/ld-musl-i386.so --library-path ... -- $(basedir)/your_program.bin "$@"
> 
> I'm actually working on a design to allow direct invocation of
> dynamic-linked programs without absolute dynamic linker paths, but it
> will be a while before it's done and included in musl.
> 
> Rich

It works like a charm. :) It is a back-end web application and it always
is started in it's own directory, as a service or from the web server.

I use this way, because when installing web applications on shared hosting,
the user can't install libraries to the system directories of the server.
He is limited only to the his document root.

-- 
John Found <johnfound@asm32.info>


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: How to use MUSL without installing it?
  2018-09-04 12:27         ` Rich Felker
  2018-09-04 12:39           ` John Found
@ 2018-09-04 13:00           ` Jon Chesterfield
  2018-09-04 14:38             ` Rich Felker
  1 sibling, 1 reply; 11+ messages in thread
From: Jon Chesterfield @ 2018-09-04 13:00 UTC (permalink / raw)
  To: musl

[-- Attachment #1: Type: text/plain, Size: 600 bytes --]

Hi Rich,

I think this would be a great feature. A relative path to the loader means
applications can run from wherever the user puts them. Currently achievable
with static linking.

I've been considering linking an application into the (modified) loader to
get a similar result. I think that's workable but haven't cut the code yet.

Could you sketch the design you have in mind?

Thanks,

Jon


I'm actually working on a design to allow direct invocation of
> dynamic-linked programs without absolute dynamic linker paths, but it
> will be a while before it's done and included in musl.
>
> Rich
>

[-- Attachment #2: Type: text/html, Size: 1107 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: How to use MUSL without installing it?
  2018-09-04 11:58     ` Szabolcs Nagy
  2018-09-04 12:20       ` John Found
@ 2018-09-04 13:27       ` John Found
  1 sibling, 0 replies; 11+ messages in thread
From: John Found @ 2018-09-04 13:27 UTC (permalink / raw)
  To: musl

On Tue, 4 Sep 2018 13:58:28 +0200
Szabolcs Nagy <nsz@port70.net> wrote:

> * John Found <johnfound@asm32.info> [2018-09-04 14:34:39 +0300]:
> > On Tue, 4 Sep 2018 11:40:20 +0200
> > Szabolcs Nagy <nsz@port70.net> wrote:
> > > i think you can pass 'CROSS_COMPILE=' to configure
> > > and then you don't need such symlinks.
> > > 
> > What value should I set CROSS_COMPILE to? i386?
> > 
> 
> leave it empty (by default it is '386-')
> ./configure --host=i386 CROSS_COMPILE=
> 

Unfortunately, it is not working this way.
I was able to make it compile without the symlinks only by
passing CROSS_COMPILE="/bin/"

The empty value falls back to the
default "i386" and is searching for "i386-ar" and so on.



> > Well, I will keep it the right way then. BTW, "make install"
> > tries to create symlink for ld-musl-i386.so in /usr/lib/ directory
> > How to prevent this attempt?
> 
> if you don't use dynamic linking then --disable-shared
> 
> if you want to build dynamic linked executables that work
> locally with your musl install, but not portable to other
> musl systems then --syslibdir='$(prefix)/lib'
> (then the binaries will use that path for the dynamic linker)
> 
> if you want to build dynamic linked executables that are
> portable, but don't run locally, then ignore that failure
> (it is not fatal, binaries will have standard dynamic linker
> path, but your system will not have it set up)
> 
> if you want to build dynamic linked executables that are
> portable and work locally, then you must have the dynamic
> linker in /lib so you have to put the symlink there.


-- 
John Found <johnfound@asm32.info>


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: How to use MUSL without installing it?
  2018-09-04 12:39           ` John Found
@ 2018-09-04 14:30             ` Rich Felker
  0 siblings, 0 replies; 11+ messages in thread
From: Rich Felker @ 2018-09-04 14:30 UTC (permalink / raw)
  To: musl

On Tue, Sep 04, 2018 at 03:39:10PM +0300, John Found wrote:
> On Tue, 4 Sep 2018 08:27:20 -0400
> Rich Felker <dalias@libc.org> wrote:
> 
> > This won't work -- a relative path is relative to the current working
> > directory, not the location of the executable. If you want users to be
> > able to invoke your program normally, you need to just provide a
> > wrapper script that does something like
> > 
> > 	exec $(basedir)/ld-musl-i386.so --library-path ... -- $(basedir)/your_program.bin "$@"
> > 
> > I'm actually working on a design to allow direct invocation of
> > dynamic-linked programs without absolute dynamic linker paths, but it
> > will be a while before it's done and included in musl.
> 
> It works like a charm. :) It is a back-end web application and it always
> is started in it's own directory, as a service or from the web server.
> 
> I use this way, because when installing web applications on shared hosting,
> the user can't install libraries to the system directories of the server.
> He is limited only to the his document root.

OK, it works for your usage case but not in general. :)

Rich


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: How to use MUSL without installing it?
  2018-09-04 13:00           ` Jon Chesterfield
@ 2018-09-04 14:38             ` Rich Felker
  0 siblings, 0 replies; 11+ messages in thread
From: Rich Felker @ 2018-09-04 14:38 UTC (permalink / raw)
  To: musl

On Tue, Sep 04, 2018 at 02:00:03PM +0100, Jon Chesterfield wrote:
> Hi Rich,
> 
> I think this would be a great feature. A relative path to the loader means
> applications can run from wherever the user puts them. Currently achievable
> with static linking.
> 
> I've been considering linking an application into the (modified) loader to
> get a similar result. I think that's workable but haven't cut the code yet.
> 
> Could you sketch the design you have in mind?

The basic idea is not to have a PT_INTERP, and instead work like
static pie or the dynamic linker's entry point, where the entry point
code is responsible for self-relocation. It would then locate itself
(depends on /proc!), construct the ldso pathname relative to itself,
mmap ldso, patch up argv to match what ldso would get from the kernel,
and jump to ldso's entry point.

Unfortunately that would result in the main program partly being
relocated twice, and relocation is not idempotent on archs that use
REL style relocations, only ones that use RELA. So before passing off
execution to ldso, there needs to be a step that reverses all the
relocations that were already performed to put the main program back
in a pristine state. This could possibly be done with MADV_DONTNEED
but I don't like relying on that...

Rich


> I'm actually working on a design to allow direct invocation of
> > dynamic-linked programs without absolute dynamic linker paths, but it
> > will be a while before it's done and included in musl.
> >
> > Rich
> >


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2018-09-04 14:38 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-03 20:24 How to use MUSL without installing it? John Found
2018-09-04  9:40 ` Szabolcs Nagy
2018-09-04 11:34   ` John Found
2018-09-04 11:58     ` Szabolcs Nagy
2018-09-04 12:20       ` John Found
2018-09-04 12:27         ` Rich Felker
2018-09-04 12:39           ` John Found
2018-09-04 14:30             ` Rich Felker
2018-09-04 13:00           ` Jon Chesterfield
2018-09-04 14:38             ` Rich Felker
2018-09-04 13:27       ` John Found

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).