* Compiling 32bit executables on 64bit system with MUSL
@ 2018-09-02 13:01 John Found
2018-09-02 15:18 ` Szabolcs Nagy
0 siblings, 1 reply; 3+ messages in thread
From: John Found @ 2018-09-02 13:01 UTC (permalink / raw)
To: musl
[-- Attachment #1: Type: text/plain, Size: 1436 bytes --]
I was able to do it before, although with some hassle and questions in the mailing list.
But today I tried again and it seems the old tricks does not work now.
What I am doing:
1. Compile and install MUSL for i386:
$ sudo ln -s /usr/bin/ar /usr/bin/i386-ar
$ sudo ln -s /usr/bin/ranlib /usr/bin/i386-ranlib
$ ./configure --host=i386 CC="gcc -m32"
$ make
$ sudo make install
2. edit the file /usr/local/musl/bin/musl-gcc (removing double quotes):
exec ${REALGCC:-gcc -m32} "$@" -specs "/usr/local/musl/lib/musl-gcc.specs"
3. Change the file /usr/local/musl/lib/musl-gcc.specs to the attached in this message.
As I said, this procedure happened to work before.
But now, when trying to compile some file, the compilation failed with linker error message.
Here is some simple test:
$cat ./hello.c
#include <stdio.h>
int main()
{
printf("Hello, World!");
return 0;
}
$musl-gcc -o hello ./hello.c
/usr/bin/ld: /usr/lib/gcc/x86_64-pc-linux-gnu/8.2.0/32/crtbegin.o: direct GOT relocation R_386_GOT32X against `_ITM_deregisterTMCloneTable' without base register can not be used when making a shared object
/usr/bin/ld: final link failed: nonrepresentable section on output
collect2: error: ld returned 1 exit status
Actually my C programming skills are very low, so I can't even understand what the linker is talking about.
The version of GCC is 8.2.0;
Any help will be appreciated!
--
John Found
https://board.asm32.info
[-- Attachment #2: musl-gcc.specs --]
[-- Type: application/octet-stream, Size: 721 bytes --]
*asm:
--32
%rename cpp_options old_cpp_options
*cpp_options:
-nostdinc -isystem /usr/local/musl/include -isystem include%s %(old_cpp_options)
*cc1:
%(cc1_cpu) -m32 -nostdinc -isystem /usr/local/musl/include -isystem include%s
*link_libgcc:
-L/usr/local/musl/lib -L .%s
*libgcc:
32/libgcc.a%s %:if-exists(32/libgcc_eh.a%s)
*startfile:
%{!shared: /usr/local/musl/lib/%{pie:S}crt1.o} /usr/local/musl/lib/crti.o %{shared|pie:crtbeginS.o%s;:32/crtbegin.o%s}
*endfile:
%{shared|pie:crtendS.o%s;:32/crtend.o%s} /usr/local/musl/lib/crtn.o
*link:
-m elf_i386 -dynamic-linker /lib/ld-musl-i386.so.1 -nostdlib %{shared:-shared} %{static:-static} %{rdynamic:-export-dynamic}
*esp_link:
*esp_options:
*esp_cpp_options:
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Compiling 32bit executables on 64bit system with MUSL
2018-09-02 13:01 Compiling 32bit executables on 64bit system with MUSL John Found
@ 2018-09-02 15:18 ` Szabolcs Nagy
2018-09-02 16:11 ` John Found
0 siblings, 1 reply; 3+ messages in thread
From: Szabolcs Nagy @ 2018-09-02 15:18 UTC (permalink / raw)
To: musl
* John Found <johnfound@asm32.info> [2018-09-02 16:01:25 +0300]:
> $musl-gcc -o hello ./hello.c
> /usr/bin/ld: /usr/lib/gcc/x86_64-pc-linux-gnu/8.2.0/32/crtbegin.o: direct GOT relocation R_386_GOT32X against `_ITM_deregisterTMCloneTable' without base register can not be used when making a shared object
> /usr/bin/ld: final link failed: nonrepresentable section on output
> collect2: error: ld returned 1 exit status
>
> Actually my C programming skills are very low, so I can't even understand what the linker is talking about.
>
> The version of GCC is 8.2.0;
your toolchain is probably default-pie (gcc -v will
show --enable-default-pie)
this means linking an executable will be linked like
a shared library and all object files have to be
position independent, but your specs file uses
crtbegin.o, which is non-pie, instead of crtbeginS.o
so linking fails (try passing -no-pie at link time
to gcc).
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Compiling 32bit executables on 64bit system with MUSL
2018-09-02 15:18 ` Szabolcs Nagy
@ 2018-09-02 16:11 ` John Found
0 siblings, 0 replies; 3+ messages in thread
From: John Found @ 2018-09-02 16:11 UTC (permalink / raw)
To: musl
On Sun, 2 Sep 2018 17:18:01 +0200
Szabolcs Nagy <nsz@port70.net> wrote:
> * John Found <johnfound@asm32.info> [2018-09-02 16:01:25 +0300]:
> > $musl-gcc -o hello ./hello.c
> > /usr/bin/ld: /usr/lib/gcc/x86_64-pc-linux-gnu/8.2.0/32/crtbegin.o: direct GOT relocation R_386_GOT32X against `_ITM_deregisterTMCloneTable' without base register can not be used when making a shared object
> > /usr/bin/ld: final link failed: nonrepresentable section on output
> > collect2: error: ld returned 1 exit status
> >
> > Actually my C programming skills are very low, so I can't even understand what the linker is talking about.
> >
> > The version of GCC is 8.2.0;
>
> your toolchain is probably default-pie (gcc -v will
> show --enable-default-pie)
>
> this means linking an executable will be linked like
> a shared library and all object files have to be
> position independent, but your specs file uses
> crtbegin.o, which is non-pie, instead of crtbeginS.o
> so linking fails (try passing -no-pie at link time
> to gcc).
Instead of using -no-pie, I tried to replace crtbegin.o
with crtbeginS.o (and respective crtend.o to crtendS.o)
Is it a correct fix?
After this the simple hello world compiles and runs properly.
Now I am trying to compile bigger project (sqlite3 library)
with variable success.
In order to make it compile I was forced to use
"-fno-stack-protector" option. I am not sure whether or not
this is a MUSL issue. The errors was like:
sqlite3.c:(.text+0x106f): undefined reference to `__stack_chk_fail_local'
Is the used workaround correct?
Also, after compiling with -O3 the library compiles but not working then.
Which is strange, but probably an issue for the sqlite mailing list.
--
John Found <johnfound@asm32.info>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-09-02 16:11 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-02 13:01 Compiling 32bit executables on 64bit system with MUSL John Found
2018-09-02 15:18 ` Szabolcs Nagy
2018-09-02 16:11 ` 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).