mailing list of musl libc
 help / color / mirror / code / Atom feed
* 32 bit musl?
@ 2016-10-05 22:20 John Mudd
  2016-10-05 23:02 ` Rich Felker
                   ` (3 more replies)
  0 siblings, 4 replies; 12+ messages in thread
From: John Mudd @ 2016-10-05 22:20 UTC (permalink / raw)
  To: musl

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

I've been using musl on a 32-bit Linux to build 32-bit apps to run on 32
and 64-bit Linux machines. That works well.

I upgraded to a 64 bit development box. I've assumed I would just need to
use -m32 option and I could still build 32 bit apps on my 64 bit machine. I
tried it but it tries to mix 32 & 64 bit code. I guess I was naive.

It looks like I should build a cross compiler? I see several suggestions on
how to do this so I'm not confident this will work well. Or would it be
easier if I just installed a 32 bit Linux in a VM just for building 32 bit
apps with musl?

John

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

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

* Re: 32 bit musl?
  2016-10-05 22:20 32 bit musl? John Mudd
@ 2016-10-05 23:02 ` Rich Felker
  2016-10-06  0:24 ` Shiz
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 12+ messages in thread
From: Rich Felker @ 2016-10-05 23:02 UTC (permalink / raw)
  To: musl

On Wed, Oct 05, 2016 at 06:20:55PM -0400, John Mudd wrote:
> I've been using musl on a 32-bit Linux to build 32-bit apps to run on 32
> and 64-bit Linux machines. That works well.
> 
> I upgraded to a 64 bit development box. I've assumed I would just need to
> use -m32 option and I could still build 32 bit apps on my 64 bit machine. I
> tried it but it tries to mix 32 & 64 bit code. I guess I was naive.
> 
> It looks like I should build a cross compiler? I see several suggestions on
> how to do this so I'm not confident this will work well. Or would it be
> easier if I just installed a 32 bit Linux in a VM just for building 32 bit
> apps with musl?

GCC's multilib (-m32) is built on the assumption that the same set of
headers can be used. This is generally an invalid assumption, not just
for libc but for third-party libraries whose headers might be in the
include paths too. In principle you could hack on the gcc spec files
to get it to use different include paths for different ABIs, but a
dedicated cross compiler is an easier approach.

Rich


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

* Re: 32 bit musl?
  2016-10-05 22:20 32 bit musl? John Mudd
  2016-10-05 23:02 ` Rich Felker
@ 2016-10-06  0:24 ` Shiz
  2016-10-06  0:33   ` Rich Felker
  2016-10-06  7:21 ` Jens Staal
  2016-10-09  1:55 ` John Mudd
  3 siblings, 1 reply; 12+ messages in thread
From: Shiz @ 2016-10-06  0:24 UTC (permalink / raw)
  To: musl

As Rich noted, a cross-compiler is the easy way out here - GCC multilib has a number of assumptions that break under musl and likely elsewhere.
Since you seem unsure how to compile one, I’d recommend musl-cross-make[1].
You only need to edit a single variable in config.mak and run 'make && make install' to get a working toolchain.

- Shiz

[1]: https://github.com/richfelker/musl-cross-make

> On 06 Oct 2016, at 00:20, John Mudd <johnbmudd@gmail.com> wrote:
> 
> I've been using musl on a 32-bit Linux to build 32-bit apps to run on 32 and 64-bit Linux machines. That works well.
> 
> I upgraded to a 64 bit development box. I've assumed I would just need to use -m32 option and I could still build 32 bit apps on my 64 bit machine. I tried it but it tries to mix 32 & 64 bit code. I guess I was naive.
> 
> It looks like I should build a cross compiler? I see several suggestions on how to do this so I'm not confident this will work well. Or would it be easier if I just installed a 32 bit Linux in a VM just for building 32 bit apps with musl?
> 
> John



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

* Re: 32 bit musl?
  2016-10-06  0:24 ` Shiz
@ 2016-10-06  0:33   ` Rich Felker
  0 siblings, 0 replies; 12+ messages in thread
From: Rich Felker @ 2016-10-06  0:33 UTC (permalink / raw)
  To: musl

On Thu, Oct 06, 2016 at 02:24:43AM +0200, Shiz wrote:
> As Rich noted, a cross-compiler is the easy way out here - GCC multilib has a number of assumptions that break under musl and likely elsewhere.
> Since you seem unsure how to compile one, I’d recommend musl-cross-make[1].
> You only need to edit a single variable in config.mak and run 'make && make install' to get a working toolchain.

You can actually even skip editing/making config.mak with current
versions of mcm. I typically just do something like:

make TARGET=i686-linux-musl OUTPUT=[whatever] -j4 install

Rich


> [1]: https://github.com/richfelker/musl-cross-make
> 
> > On 06 Oct 2016, at 00:20, John Mudd <johnbmudd@gmail.com> wrote:
> > 
> > I've been using musl on a 32-bit Linux to build 32-bit apps to run
> > on 32 and 64-bit Linux machines. That works well.
> > 
> > I upgraded to a 64 bit development box. I've assumed I would just
> > need to use -m32 option and I could still build 32 bit apps on my
> > 64 bit machine. I tried it but it tries to mix 32 & 64 bit code. I
> > guess I was naive.
> > 
> > It looks like I should build a cross compiler? I see several
> > suggestions on how to do this so I'm not confident this will work
> > well. Or would it be easier if I just installed a 32 bit Linux in
> > a VM just for building 32 bit apps with musl?
> > 
> > John


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

* Re: 32 bit musl?
  2016-10-05 22:20 32 bit musl? John Mudd
  2016-10-05 23:02 ` Rich Felker
  2016-10-06  0:24 ` Shiz
@ 2016-10-06  7:21 ` Jens Staal
  2016-10-06 21:32   ` Rich Felker
  2016-10-09  1:55 ` John Mudd
  3 siblings, 1 reply; 12+ messages in thread
From: Jens Staal @ 2016-10-06  7:21 UTC (permalink / raw)
  To: musl

onsdag 5 oktober 2016 kl. 18:20:55 CEST skrev John Mudd:
> I upgraded to a 64 bit development box. I've assumed I would just need to
> use -m32 option and I could still build 32 bit apps on my 64 bit machine. I
> tried it but it tries to mix 32 & 64 bit code. I guess I was naive.

Slightly off-topic but out of curiosity: Would musl theoretically be possible 
to build/use on 16-bit "Linux" (ELKS) with ia16-gcc?



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

* Re: 32 bit musl?
  2016-10-06  7:21 ` Jens Staal
@ 2016-10-06 21:32   ` Rich Felker
  0 siblings, 0 replies; 12+ messages in thread
From: Rich Felker @ 2016-10-06 21:32 UTC (permalink / raw)
  To: musl

On Thu, Oct 06, 2016 at 09:21:29AM +0200, Jens Staal wrote:
> onsdag 5 oktober 2016 kl. 18:20:55 CEST skrev John Mudd:
> > I upgraded to a 64 bit development box. I've assumed I would just need to
> > use -m32 option and I could still build 32 bit apps on my 64 bit machine. I
> > tried it but it tries to mix 32 & 64 bit code. I guess I was naive.
> 
> Slightly off-topic but out of curiosity: Would musl theoretically be possible 
> to build/use on 16-bit "Linux" (ELKS) with ia16-gcc?

No. There may be a number of individual components you could use on
such a system, but musl implements, and as a whole makes assumptions
that will necessarily be true on, a POSIX-conforming (and somewhat
Linux-flavored) system. In particular POSIX requires 32-bit int. Even
if you had a 16-bit x86 target with 32-bit int, you would need an arch
target for it matching the ABI and things like how TLS works (but I
wonder if anyone ever even figured out TLS on ELKS).

Rich


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

* Re: 32 bit musl?
  2016-10-05 22:20 32 bit musl? John Mudd
                   ` (2 preceding siblings ...)
  2016-10-06  7:21 ` Jens Staal
@ 2016-10-09  1:55 ` John Mudd
  2016-10-09  9:36   ` Laurent Bercot
  2016-10-09 14:29   ` John Mudd
  3 siblings, 2 replies; 12+ messages in thread
From: John Mudd @ 2016-10-09  1:55 UTC (permalink / raw)
  To: musl

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

Many thanks for the help, Shiz and Rich! I've built gcc from source before
but it's a chore. Rich's musl-cross-make was magical. Much better solution
than using a 32-bit VM.

All I need were these  steps. The first two should be obvious but they
tripped me up.
    Make sure gcc AND g++ are installed.
    unset CC
    unzip musl-cross-make-master.zip
    cd musl-cross-make-master
    make TARGET=i686-linux-musl OUTPUT=$(pwd).install -j6 install

So this builds 32-bit executables that use musl libs. It kills two birds
with one stone. That's great.

But it appears to expect musl libc to be installed in /lib for dynamically
linked executables. That's not an option for me. Is there a way I can
override this?

On Wed, Oct 5, 2016 at 6:20 PM, John Mudd <johnbmudd@gmail.com> wrote:

> ...
> It looks like I should build a cross compiler? I see several suggestions
> on how to do this so I'm not confident this will work well. Or would it be
> easier if I just installed a 32 bit Linux in a VM just for building 32 bit
> apps with musl?
>
> John
>

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

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

* Re: Re: 32 bit musl?
  2016-10-09  1:55 ` John Mudd
@ 2016-10-09  9:36   ` Laurent Bercot
  2016-10-09 14:29   ` John Mudd
  1 sibling, 0 replies; 12+ messages in thread
From: Laurent Bercot @ 2016-10-09  9:36 UTC (permalink / raw)
  To: musl

>But it appears to expect musl libc to be installed in /lib for 
>dynamically linked executables. That's not an option for me. Is there a 
>way I can override this?

  You don't need to have the libc itself in /lib, you just need to have a
/lib/ld-musl-i386.so.1 symlink pointing to your 32-bit libc.so (i.e. 
only
the path to the dynamic linker is hardcoded).

  If you have additional 32-bit shared libraries, you can tell the
dynamic linker where to find them by listing their directories in the
/etc/ld-musl-i386.path file.

--
  Laurent



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

* Re: 32 bit musl?
  2016-10-09  1:55 ` John Mudd
  2016-10-09  9:36   ` Laurent Bercot
@ 2016-10-09 14:29   ` John Mudd
  2016-10-09 14:44     ` Szabolcs Nagy
  1 sibling, 1 reply; 12+ messages in thread
From: John Mudd @ 2016-10-09 14:29 UTC (permalink / raw)
  To: musl; +Cc: John Mudd

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

On Sat, Oct 8, 2016 at 9:55 PM, John Mudd <johnbmudd@gmail.com> wrote:

> Rich's musl-cross-make builds 32-bit executables that use musl libs. It
> kills two birds with one stone. That's great.
>
> But it appears to expect musl libc to be installed in /lib for dynamically
> linked executables. That's not an option for me. Is there a way I can
> override this?
>
>
Thanks Laurent, I used symbolic link in /lib for testing on my development
machine. That works well. But I don't have reasonable access to root user
when I deploy for production.

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

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

* Re: Re: 32 bit musl?
  2016-10-09 14:29   ` John Mudd
@ 2016-10-09 14:44     ` Szabolcs Nagy
  2016-10-09 15:10       ` Bobby Bingham
  0 siblings, 1 reply; 12+ messages in thread
From: Szabolcs Nagy @ 2016-10-09 14:44 UTC (permalink / raw)
  To: musl; +Cc: John Mudd

* John Mudd <johnbmudd@gmail.com> [2016-10-09 10:29:02 -0400]:
> On Sat, Oct 8, 2016 at 9:55 PM, John Mudd <johnbmudd@gmail.com> wrote:
> 
> > Rich's musl-cross-make builds 32-bit executables that use musl libs. It
> > kills two birds with one stone. That's great.
> >
> > But it appears to expect musl libc to be installed in /lib for dynamically
> > linked executables. That's not an option for me. Is there a way I can
> > override this?
> >
> >
> Thanks Laurent, I used symbolic link in /lib for testing on my development
> machine. That works well. But I don't have reasonable access to root user
> when I deploy for production.

deploy static linked binary or use explicit -Wl,-dynamic-linker


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

* Re: Re: 32 bit musl?
  2016-10-09 14:44     ` Szabolcs Nagy
@ 2016-10-09 15:10       ` Bobby Bingham
  2016-10-09 16:08         ` Rich Felker
  0 siblings, 1 reply; 12+ messages in thread
From: Bobby Bingham @ 2016-10-09 15:10 UTC (permalink / raw)
  To: musl, John Mudd

On Sun, Oct 09, 2016 at 04:44:44PM +0200, Szabolcs Nagy wrote:
> * John Mudd <johnbmudd@gmail.com> [2016-10-09 10:29:02 -0400]:
> > On Sat, Oct 8, 2016 at 9:55 PM, John Mudd <johnbmudd@gmail.com> wrote:
> > 
> > > Rich's musl-cross-make builds 32-bit executables that use musl libs. It
> > > kills two birds with one stone. That's great.
> > >
> > > But it appears to expect musl libc to be installed in /lib for dynamically
> > > linked executables. That's not an option for me. Is there a way I can
> > > override this?
> > >
> > >
> > Thanks Laurent, I used symbolic link in /lib for testing on my development
> > machine. That works well. But I don't have reasonable access to root user
> > when I deploy for production.
> 
> deploy static linked binary or use explicit -Wl,-dynamic-linker

Using -Wl,-dynamic-linker will result in binaries that will not run on
normal musl systems.

If you can deploy the musl libc alongside your program, you can invoke it
as `/path/to/libc.so /path/to/your/program`.  This can be done by a shell
script you also deploy.


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

* Re: Re: 32 bit musl?
  2016-10-09 15:10       ` Bobby Bingham
@ 2016-10-09 16:08         ` Rich Felker
  0 siblings, 0 replies; 12+ messages in thread
From: Rich Felker @ 2016-10-09 16:08 UTC (permalink / raw)
  To: Bobby Bingham; +Cc: musl, John Mudd

On Sun, Oct 09, 2016 at 10:10:36AM -0500, Bobby Bingham wrote:
> On Sun, Oct 09, 2016 at 04:44:44PM +0200, Szabolcs Nagy wrote:
> > * John Mudd <johnbmudd@gmail.com> [2016-10-09 10:29:02 -0400]:
> > > On Sat, Oct 8, 2016 at 9:55 PM, John Mudd <johnbmudd@gmail.com> wrote:
> > > 
> > > > Rich's musl-cross-make builds 32-bit executables that use musl libs. It
> > > > kills two birds with one stone. That's great.
> > > >
> > > > But it appears to expect musl libc to be installed in /lib for dynamically
> > > > linked executables. That's not an option for me. Is there a way I can
> > > > override this?
> > > >
> > > >
> > > Thanks Laurent, I used symbolic link in /lib for testing on my development
> > > machine. That works well. But I don't have reasonable access to root user
> > > when I deploy for production.
> > 
> > deploy static linked binary or use explicit -Wl,-dynamic-linker
> 
> Using -Wl,-dynamic-linker will result in binaries that will not run on
> normal musl systems.

It will also result in binaries that require the end user to have them
(or at least the dynamic linker part) installed in exactly the same
absolute path that you came up with when building them.

> If you can deploy the musl libc alongside your program, you can invoke it
> as `/path/to/libc.so /path/to/your/program`.  This can be done by a shell
> script you also deploy.

Indeed, this is the recommended approach for shipping dynamic-linked
binaries to be run on non-musl-based systems.

Rich


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

end of thread, other threads:[~2016-10-09 16:08 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-10-05 22:20 32 bit musl? John Mudd
2016-10-05 23:02 ` Rich Felker
2016-10-06  0:24 ` Shiz
2016-10-06  0:33   ` Rich Felker
2016-10-06  7:21 ` Jens Staal
2016-10-06 21:32   ` Rich Felker
2016-10-09  1:55 ` John Mudd
2016-10-09  9:36   ` Laurent Bercot
2016-10-09 14:29   ` John Mudd
2016-10-09 14:44     ` Szabolcs Nagy
2016-10-09 15:10       ` Bobby Bingham
2016-10-09 16:08         ` Rich Felker

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).