mailing list of musl libc
 help / color / mirror / code / Atom feed
* Illegal instruction in __copy_tls()
@ 2019-06-05 18:16 tenspd137 .
  2019-06-05 18:37 ` Rich Felker
  0 siblings, 1 reply; 13+ messages in thread
From: tenspd137 . @ 2019-06-05 18:16 UTC (permalink / raw)
  To: musl

Hi all

I am using musl 1.1.22 with in a cross toolchain to create static
binaries on my machine.  I am running gentoo linux and used their
crossdev tool to create the cross compiler (x86_64-pc-linux-musl).  I
created a small hello world app:

#include <stdio.h>
int main(int argc, char **argv)
{printf("Hello MUSL\n");}

and compiled with:

x86_64-pc-linux-musl-gcc -v -static -Os -g hello.c

Built and runs fine on local machine, but when I put the binary on
another machine, it dumped the core with an ilegal instruction.  gdb
claims illegal instruction in __copy_tls().

I have been able to compile this program after building the musl-gcc
wrapper and it works on both machines, but I need the cross toolchain
for C++ support.  The -v in the commandline above prints messages that
indicate it is using musl from what I can tell.

Can anyone point me in the right direction or help me figure out what
I am missing?

Thanks!


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

* Re: Illegal instruction in __copy_tls()
  2019-06-05 18:16 Illegal instruction in __copy_tls() tenspd137 .
@ 2019-06-05 18:37 ` Rich Felker
  2019-06-05 19:53   ` tenspd137 .
  0 siblings, 1 reply; 13+ messages in thread
From: Rich Felker @ 2019-06-05 18:37 UTC (permalink / raw)
  To: tenspd137 .; +Cc: musl

On Wed, Jun 05, 2019 at 12:16:39PM -0600, tenspd137 . wrote:
> Hi all
> 
> I am using musl 1.1.22 with in a cross toolchain to create static
> binaries on my machine.  I am running gentoo linux and used their
> crossdev tool to create the cross compiler (x86_64-pc-linux-musl).  I
> created a small hello world app:
> 
> #include <stdio.h>
> int main(int argc, char **argv)
> {printf("Hello MUSL\n");}
> 
> and compiled with:
> 
> x86_64-pc-linux-musl-gcc -v -static -Os -g hello.c
> 
> Built and runs fine on local machine, but when I put the binary on
> another machine, it dumped the core with an ilegal instruction.  gdb
> claims illegal instruction in __copy_tls().
> 
> I have been able to compile this program after building the musl-gcc
> wrapper and it works on both machines, but I need the cross toolchain
> for C++ support.  The -v in the commandline above prints messages that
> indicate it is using musl from what I can tell.
> 
> Can anyone point me in the right direction or help me figure out what
> I am missing?

Can you show the gdb backtrace, disassembly at the point of crash, and
an strace leading up to it?

My best guess is that your toolchain is producing binaries for some
non-baseline level of x86_64 ISA, and the machine you're trying to run
it on does not support some of the instructions used.

Rich


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

* Re: Illegal instruction in __copy_tls()
  2019-06-05 18:37 ` Rich Felker
@ 2019-06-05 19:53   ` tenspd137 .
  2019-06-05 20:07     ` Rich Felker
  0 siblings, 1 reply; 13+ messages in thread
From: tenspd137 . @ 2019-06-05 19:53 UTC (permalink / raw)
  To: Rich Felker; +Cc: musl

Sure -

strace -d -v ./a.out:
strace: ptrace_setoptions = 0x51
strace: new tcb for pid 26302, active tcbs:1
strace: [wait(0x80137f) = 26302] WIFSTOPPED,sig=SIGSTOP,EVENT_STOP (128)
strace: pid 26302 has TCB_STARTUP, initializing it
strace: [wait(0x80057f) = 26302] WIFSTOPPED,sig=SIGTRAP,EVENT_STOP (128)
strace: [wait(0x00127f) = 26302] WIFSTOPPED,sig=SIGCONT
strace: [wait(0x00857f) = 26302] WIFSTOPPED,sig=133
execve("./a.out", ["./a.out"], ["SSH_CONNECTION=15.86.136.27 5196"...,
"LANG=en_US.UTF-8", "XDG_SESSION_ID=41", "USER=dayd",
"PWD=/home/dayd/projects/musl-tes"..., "HOME=/home/dayd",
"SSH_CLIENT=xx.xxx.xxx.xx 51960 22", "CCACHE_DIR=/ssd/dayd/.ccache",
"VMWARE_USE_SHIPPED_GTK=yes", "XDG_DATA_DIRS=/usr/local/share:/"...,
"USECCACHE=ON", "SSH_TTY=/dev/pts/2", "MAIL=/var/mail/dayd",
"TERM=rxvt-unicode-256color", "SHELL=/bin/bash", "SHLVL=1",
"PYTHONPATH=:/home/dayd/projects/"..., "LOGNAME=dayd",
"DBUS_SESSION_BUS_ADDRESS=unix:pa"...,
"XDG_RUNTIME_DIR=/run/user/6686",
"PATH=/usr/lib/ccache/bin/:/usr/l"..., "USEDISTCC=OFF",
"_=/usr/bin/strace", "OLDPWD=/home/dayd/projects"]strace:
[wait(0x04057f) = 26302] WIFSTOPPED,sig=SIGTRAP,EVENT_EXEC (4)
strace: [wait(0x00857f) = 26302] WIFSTOPPED,sig=133
) = 0
strace: [wait(0x00047f) = 26302] WIFSTOPPED,sig=SIGILL
--- SIGILL {si_signo=SIGILL, si_code=ILL_ILLOPN, si_addr=0x40169e} ---
strace: [wait(0x06057f) = 26302] WIFSTOPPED,sig=SIGTRAP,EVENT_EXIT (6)
strace: [wait(0x000084) = 26302] WIFSIGNALED,core,sig=SIGILL
+++ killed by SIGILL (core dumped) +++
strace: dropped tcb for pid 26302, 0 remain
Illegal instruction (core dumped)
******************************************************************************************
(gdb) bt
#0  0x00000000004016ae in __copy_tls ()
#1  0x0000000000000000 in ?? ()
*****************************************************************************************

(gdb) disassemble
Dump of assembler code for function __copy_tls:
   0x0000000000401680 <+0>:    push   %r13
   0x0000000000401682 <+2>:    mov    %rdi,%r13
   0x0000000000401685 <+5>:    push   %r12
   0x0000000000401687 <+7>:    push   %rbp
   0x0000000000401688 <+8>:    push   %rbx
   0x0000000000401689 <+9>:    sub    $0x8,%rsp
   0x000000000040168d <+13>:    mov    0x410c(%rip),%rax        #
0x4057a0 <__libc+32>
   0x0000000000401694 <+20>:    mov    0x410d(%rip),%rcx        #
0x4057a8 <__libc+40>
   0x000000000040169b <+27>:    mov    0x40f6(%rip),%rbx        #
0x405798 <__libc+24>
   0x00000000004016a2 <+34>:    lea    -0xe0(%rdi,%rax,1),%rax
   0x00000000004016aa <+42>:    lea    -0x1(%rcx),%r12
=> 0x00000000004016ae <+46>:    andn   %rax,%r12,%r12
   0x00000000004016b3 <+51>:    test   %rbx,%rbx
   0x00000000004016b6 <+54>:    je     0x4016eb <__copy_tls+107>
   0x00000000004016b8 <+56>:    lea    0x8(%rdi),%rbp
   0x00000000004016bc <+60>:    nopl   0x0(%rax)
   0x00000000004016c0 <+64>:    mov    %r12,%rax
   0x00000000004016c3 <+67>:    sub    0x28(%rbx),%rax
   0x00000000004016c7 <+71>:    mov    %rax,0x0(%rbp)
   0x00000000004016cb <+75>:    mov    0x8(%rbx),%rsi
   0x00000000004016cf <+79>:    mov    %r12,%rdi
   0x00000000004016d2 <+82>:    mov    0x10(%rbx),%rdx
   0x00000000004016d6 <+86>:    sub    0x28(%rbx),%rdi
   0x00000000004016da <+90>:    callq  0x401e3c <memcpy>
   0x00000000004016df <+95>:    mov    (%rbx),%rbx
   0x00000000004016e2 <+98>:    add    $0x8,%rbp
   0x00000000004016e6 <+102>:    test   %rbx,%rbx
   0x00000000004016e9 <+105>:    jne    0x4016c0 <__copy_tls+64>
   0x00000000004016eb <+107>:    mov    0x40be(%rip),%rax        #
0x4057b0 <__libc+48>
   0x00000000004016f2 <+114>:    mov    %rax,0x0(%r13)
   0x00000000004016f6 <+118>:    mov    %r13,0xd8(%r12)
   0x00000000004016fe <+126>:    mov    %r13,0x8(%r12)
   0x0000000000401703 <+131>:    add    $0x8,%rsp
   0x0000000000401707 <+135>:    mov    %r12,%rax
   0x000000000040170a <+138>:    pop    %rbx
   0x000000000040170b <+139>:    pop    %rbp
   0x000000000040170c <+140>:    pop    %r12
   0x000000000040170e <+142>:    pop    %r13
   0x0000000000401710 <+144>:    retq
End of assembler dump.

***********************************************************************************

as a bonus (I thought this might also help):
(%:~/projects/musl-test)┌- x86_64-pc-linux-musl-gcc -v -static -O0 -g
hello.c
Using built-in specs.
COLLECT_GCC=x86_64-pc-linux-musl-gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-pc-linux-musl/9.1.0/lto-wrapper
Target: x86_64-pc-linux-musl
Configured with:
/var/tmp/portage/cross-x86_64-pc-linux-musl/gcc-9.1.0/work/gcc-9.1.0/configure
--host=x86_64-pc-linux-gnu --target=x86_64-pc-linux-musl
--build=x86_64-pc-linux-gnu --prefix=/usr
--bindir=/usr/x86_64-pc-linux-gnu/x86_64-pc-linux-musl/gcc-bin/9.1.0
--includedir=/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/include
--datadir=/usr/share/gcc-data/x86_64-pc-linux-musl/9.1.0
--mandir=/usr/share/gcc-data/x86_64-pc-linux-musl/9.1.0/man
--infodir=/usr/share/gcc-data/x86_64-pc-linux-musl/9.1.0/info
--with-gxx-include-dir=/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/include/g++-v9
--with-python-dir=/share/gcc-data/x86_64-pc-linux-musl/9.1.0/python
--enable-languages=c,c++,fortran --enable-obsolete --enable-secureplt
--disable-werror --with-system-zlib --enable-nls
--without-included-gettext --enable-checking=release
--with-bugurl=https://bugs.gentoo.org/ --with-pkgversion='Gentoo 9.1.0
p1.0' --disable-esp --enable-libstdcxx-time
--enable-poison-system-directories
--with-sysroot=/usr/x86_64-pc-linux-musl --disable-bootstrap
--enable-__cxa_atexit --disable-multilib --with-multilib-list=m64
--disable-altivec --disable-fixed-point --enable-targets=all
--enable-libgomp --disable-libmudflap --disable-libssp
--disable-systemtap --disable-vtable-verify --disable-libvtv
--enable-lto --without-isl --disable-libsanitizer --enable-default-pie
--enable-default-ssp
Thread model: posix
gcc version 9.1.0 (Gentoo 9.1.0 p1.0)
COLLECT_GCC_OPTIONS='-v' '-static' '-O0' '-g' '-mtune=generic' '-march=x86-64'
 /usr/libexec/gcc/x86_64-pc-linux-musl/9.1.0/cc1 -quiet -v hello.c
-quiet -dumpbase hello.c -mtune=generic -march=x86-64 -auxbase hello
-g -O0 -version -o /tmp/ccoTkh38.s
GNU C17 (Gentoo 9.1.0 p1.0) version 9.1.0 (x86_64-pc-linux-musl)
    compiled by GNU C version 8.3.0, GMP version 6.1.2, MPFR version
4.0.2, MPC version 1.1.0, isl version none
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "/usr/x86_64-pc-linux-musl/usr/local/include"
ignoring nonexistent directory
"/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/../../../../x86_64-pc-linux-musl/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/x86_64-pc-linux-musl/usr/include
 /usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/include
End of search list.
GNU C17 (Gentoo 9.1.0 p1.0) version 9.1.0 (x86_64-pc-linux-musl)
    compiled by GNU C version 8.3.0, GMP version 6.1.2, MPFR version
4.0.2, MPC version 1.1.0, isl version none
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: a3183e5f435d1938198d432af6db159b
COLLECT_GCC_OPTIONS='-v' '-static' '-O0' '-g' '-mtune=generic' '-march=x86-64'
 /usr/libexec/gcc/x86_64-pc-linux-musl/as -v --64 -o /tmp/ccHq7CL6.o
/tmp/ccoTkh38.s
GNU assembler version 2.32.0 (x86_64-pc-linux-musl) using BFD version
(Gentoo 2.32 p2) 2.32.0
COMPILER_PATH=/usr/libexec/gcc/x86_64-pc-linux-musl/9.1.0/:/usr/libexec/gcc/x86_64-pc-linux-musl/9.1.0/:/usr/libexec/gcc/x86_64-pc-linux-musl/:/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/:/usr/lib/gcc/x86_64-pc-linux-musl/
LIBRARY_PATH=/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/:/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/../../../../x86_64-pc-linux-musl/lib/:/usr/x86_64-pc-linux-musl/lib/:/usr/x86_64-pc-linux-musl/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-static' '-O0' '-g' '-mtune=generic' '-march=x86-64'
 /usr/libexec/gcc/x86_64-pc-linux-musl/9.1.0/collect2 -plugin
/usr/libexec/gcc/x86_64-pc-linux-musl/9.1.0/liblto_plugin.so
-plugin-opt=/usr/libexec/gcc/x86_64-pc-linux-musl/9.1.0/lto-wrapper
-plugin-opt=-fresolution=/tmp/ccWcifv4.res
-plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_eh
-plugin-opt=-pass-through=-lc --sysroot=/usr/x86_64-pc-linux-musl -m
elf_x86_64 -static /usr/x86_64-pc-linux-musl/usr/lib/crt1.o
/usr/x86_64-pc-linux-musl/usr/lib/crti.o
/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/crtbeginT.o
-L/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0
-L/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/../../../../x86_64-pc-linux-musl/lib
-L/usr/x86_64-pc-linux-musl/lib -L/usr/x86_64-pc-linux-musl/usr/lib
/tmp/ccHq7CL6.o --start-group -lgcc -lgcc_eh -lc --end-group
/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/crtend.o
/usr/x86_64-pc-linux-musl/usr/lib/crtn.o
COLLECT_GCC_OPTIONS='-v' '-static' '-O0' '-g' '-mtune=generic' '-march=x86-64'

mtune=generic and march=x86-64 suggests it isn't trying to do
something weird on the compile computer.

Also, if I messed up and am not giving you what you are asking for,
please let me know and I will grab it.

Thanks!

On Wed, Jun 5, 2019 at 12:37 PM Rich Felker <dalias@libc.org> wrote:
>
> On Wed, Jun 05, 2019 at 12:16:39PM -0600, tenspd137 . wrote:
> > Hi all
> >
> > I am using musl 1.1.22 with in a cross toolchain to create static
> > binaries on my machine.  I am running gentoo linux and used their
> > crossdev tool to create the cross compiler (x86_64-pc-linux-musl).  I
> > created a small hello world app:
> >
> > #include <stdio.h>
> > int main(int argc, char **argv)
> > {printf("Hello MUSL\n");}
> >
> > and compiled with:
> >
> > x86_64-pc-linux-musl-gcc -v -static -Os -g hello.c
> >
> > Built and runs fine on local machine, but when I put the binary on
> > another machine, it dumped the core with an ilegal instruction.  gdb
> > claims illegal instruction in __copy_tls().
> >
> > I have been able to compile this program after building the musl-gcc
> > wrapper and it works on both machines, but I need the cross toolchain
> > for C++ support.  The -v in the commandline above prints messages that
> > indicate it is using musl from what I can tell.
> >
> > Can anyone point me in the right direction or help me figure out what
> > I am missing?
>
> Can you show the gdb backtrace, disassembly at the point of crash, and
> an strace leading up to it?
>
> My best guess is that your toolchain is producing binaries for some
> non-baseline level of x86_64 ISA, and the machine you're trying to run
> it on does not support some of the instructions used.
>
> Rich


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

* Re: Illegal instruction in __copy_tls()
  2019-06-05 19:53   ` tenspd137 .
@ 2019-06-05 20:07     ` Rich Felker
  2019-06-05 21:27       ` tenspd137 .
  0 siblings, 1 reply; 13+ messages in thread
From: Rich Felker @ 2019-06-05 20:07 UTC (permalink / raw)
  To: tenspd137 .; +Cc: musl

On Wed, Jun 05, 2019 at 01:53:58PM -0600, tenspd137 . wrote:
> Sure -
> 
> strace -d -v ./a.out:
> strace: ptrace_setoptions = 0x51
> strace: new tcb for pid 26302, active tcbs:1
> strace: [wait(0x80137f) = 26302] WIFSTOPPED,sig=SIGSTOP,EVENT_STOP (128)
> strace: pid 26302 has TCB_STARTUP, initializing it
> strace: [wait(0x80057f) = 26302] WIFSTOPPED,sig=SIGTRAP,EVENT_STOP (128)
> strace: [wait(0x00127f) = 26302] WIFSTOPPED,sig=SIGCONT
> strace: [wait(0x00857f) = 26302] WIFSTOPPED,sig=133
> execve("./a.out", ["./a.out"], ["SSH_CONNECTION=15.86.136.27 5196"...,
> "LANG=en_US.UTF-8", "XDG_SESSION_ID=41", "USER=dayd",
> "PWD=/home/dayd/projects/musl-tes"..., "HOME=/home/dayd",
> "SSH_CLIENT=xx.xxx.xxx.xx 51960 22", "CCACHE_DIR=/ssd/dayd/.ccache",
> "VMWARE_USE_SHIPPED_GTK=yes", "XDG_DATA_DIRS=/usr/local/share:/"...,
> "USECCACHE=ON", "SSH_TTY=/dev/pts/2", "MAIL=/var/mail/dayd",
> "TERM=rxvt-unicode-256color", "SHELL=/bin/bash", "SHLVL=1",
> "PYTHONPATH=:/home/dayd/projects/"..., "LOGNAME=dayd",
> "DBUS_SESSION_BUS_ADDRESS=unix:pa"...,
> "XDG_RUNTIME_DIR=/run/user/6686",
> "PATH=/usr/lib/ccache/bin/:/usr/l"..., "USEDISTCC=OFF",
> "_=/usr/bin/strace", "OLDPWD=/home/dayd/projects"]strace:
> [wait(0x04057f) = 26302] WIFSTOPPED,sig=SIGTRAP,EVENT_EXEC (4)
> strace: [wait(0x00857f) = 26302] WIFSTOPPED,sig=133
> ) = 0
> strace: [wait(0x00047f) = 26302] WIFSTOPPED,sig=SIGILL
> --- SIGILL {si_signo=SIGILL, si_code=ILL_ILLOPN, si_addr=0x40169e} ---
> strace: [wait(0x06057f) = 26302] WIFSTOPPED,sig=SIGTRAP,EVENT_EXIT (6)
> strace: [wait(0x000084) = 26302] WIFSIGNALED,core,sig=SIGILL
> +++ killed by SIGILL (core dumped) +++
> strace: dropped tcb for pid 26302, 0 remain
> Illegal instruction (core dumped)
> ******************************************************************************************
> (gdb) bt
> #0  0x00000000004016ae in __copy_tls ()
> #1  0x0000000000000000 in ?? ()
> *****************************************************************************************
> 
> (gdb) disassemble
> Dump of assembler code for function __copy_tls:
>    0x0000000000401680 <+0>:    push   %r13
>    0x0000000000401682 <+2>:    mov    %rdi,%r13
>    0x0000000000401685 <+5>:    push   %r12
>    0x0000000000401687 <+7>:    push   %rbp
>    0x0000000000401688 <+8>:    push   %rbx
>    0x0000000000401689 <+9>:    sub    $0x8,%rsp
>    0x000000000040168d <+13>:    mov    0x410c(%rip),%rax        #
> 0x4057a0 <__libc+32>
>    0x0000000000401694 <+20>:    mov    0x410d(%rip),%rcx        #
> 0x4057a8 <__libc+40>
>    0x000000000040169b <+27>:    mov    0x40f6(%rip),%rbx        #
> 0x405798 <__libc+24>
>    0x00000000004016a2 <+34>:    lea    -0xe0(%rdi,%rax,1),%rax
>    0x00000000004016aa <+42>:    lea    -0x1(%rcx),%r12
> => 0x00000000004016ae <+46>:    andn   %rax,%r12,%r12

This instruction, andn, is not in the base x86_64 ISA. It's part of
the BMI1 extension:

https://en.wikipedia.org/wiki/Bit_Manipulation_Instruction_Sets#BMI1_(Bit_Manipulation_Instruction_Set_1)

Apparently Gentoo is providing cross compilers that default to
producing "native ISA level" code for the host, rather than baseline
ISA for the target. But:

> as a bonus (I thought this might also help):
> (%:~/projects/musl-test)┌- x86_64-pc-linux-musl-gcc -v -static -O0 -g
> hello.c
> Using built-in specs.
> COLLECT_GCC=x86_64-pc-linux-musl-gcc
> COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-pc-linux-musl/9.1.0/lto-wrapper
> Target: x86_64-pc-linux-musl
> Configured with:
> /var/tmp/portage/cross-x86_64-pc-linux-musl/gcc-9.1.0/work/gcc-9.1.0/configure
> --host=x86_64-pc-linux-gnu --target=x86_64-pc-linux-musl
> --build=x86_64-pc-linux-gnu --prefix=/usr
> --bindir=/usr/x86_64-pc-linux-gnu/x86_64-pc-linux-musl/gcc-bin/9.1.0
> --includedir=/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/include
> --datadir=/usr/share/gcc-data/x86_64-pc-linux-musl/9.1.0
> --mandir=/usr/share/gcc-data/x86_64-pc-linux-musl/9.1.0/man
> --infodir=/usr/share/gcc-data/x86_64-pc-linux-musl/9.1.0/info
> --with-gxx-include-dir=/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/include/g++-v9
> --with-python-dir=/share/gcc-data/x86_64-pc-linux-musl/9.1.0/python
> --enable-languages=c,c++,fortran --enable-obsolete --enable-secureplt
> --disable-werror --with-system-zlib --enable-nls
> --without-included-gettext --enable-checking=release
> --with-bugurl=https://bugs.gentoo.org/ --with-pkgversion='Gentoo 9.1.0
> p1.0' --disable-esp --enable-libstdcxx-time
> --enable-poison-system-directories
> --with-sysroot=/usr/x86_64-pc-linux-musl --disable-bootstrap
> --enable-__cxa_atexit --disable-multilib --with-multilib-list=m64
> --disable-altivec --disable-fixed-point --enable-targets=all
> --enable-libgomp --disable-libmudflap --disable-libssp
> --disable-systemtap --disable-vtable-verify --disable-libvtv
> --enable-lto --without-isl --disable-libsanitizer --enable-default-pie
> --enable-default-ssp
> Thread model: posix
> gcc version 9.1.0 (Gentoo 9.1.0 p1.0)
> COLLECT_GCC_OPTIONS='-v' '-static' '-O0' '-g' '-mtune=generic' '-march=x86-64'
>  /usr/libexec/gcc/x86_64-pc-linux-musl/9.1.0/cc1 -quiet -v hello.c
> -quiet -dumpbase hello.c -mtune=generic -march=x86-64 -auxbase hello
> -g -O0 -version -o /tmp/ccoTkh38.s
> GNU C17 (Gentoo 9.1.0 p1.0) version 9.1.0 (x86_64-pc-linux-musl)
>     compiled by GNU C version 8.3.0, GMP version 6.1.2, MPFR version
> 4.0.2, MPC version 1.1.0, isl version none
> GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
> ignoring nonexistent directory "/usr/x86_64-pc-linux-musl/usr/local/include"
> ignoring nonexistent directory
> "/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/../../../../x86_64-pc-linux-musl/include"
> #include "..." search starts here:
> #include <...> search starts here:
>  /usr/x86_64-pc-linux-musl/usr/include
>  /usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/include
> End of search list.
> GNU C17 (Gentoo 9.1.0 p1.0) version 9.1.0 (x86_64-pc-linux-musl)
>     compiled by GNU C version 8.3.0, GMP version 6.1.2, MPFR version
> 4.0.2, MPC version 1.1.0, isl version none
> GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
> Compiler executable checksum: a3183e5f435d1938198d432af6db159b
> COLLECT_GCC_OPTIONS='-v' '-static' '-O0' '-g' '-mtune=generic' '-march=x86-64'
>  /usr/libexec/gcc/x86_64-pc-linux-musl/as -v --64 -o /tmp/ccHq7CL6.o
> /tmp/ccoTkh38.s
> GNU assembler version 2.32.0 (x86_64-pc-linux-musl) using BFD version
> (Gentoo 2.32 p2) 2.32.0
> COMPILER_PATH=/usr/libexec/gcc/x86_64-pc-linux-musl/9.1.0/:/usr/libexec/gcc/x86_64-pc-linux-musl/9.1.0/:/usr/libexec/gcc/x86_64-pc-linux-musl/:/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/:/usr/lib/gcc/x86_64-pc-linux-musl/
> LIBRARY_PATH=/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/:/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/../../../../x86_64-pc-linux-musl/lib/:/usr/x86_64-pc-linux-musl/lib/:/usr/x86_64-pc-linux-musl/usr/lib/
> COLLECT_GCC_OPTIONS='-v' '-static' '-O0' '-g' '-mtune=generic' '-march=x86-64'
>  /usr/libexec/gcc/x86_64-pc-linux-musl/9.1.0/collect2 -plugin
> /usr/libexec/gcc/x86_64-pc-linux-musl/9.1.0/liblto_plugin.so
> -plugin-opt=/usr/libexec/gcc/x86_64-pc-linux-musl/9.1.0/lto-wrapper
> -plugin-opt=-fresolution=/tmp/ccWcifv4.res
> -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_eh
> -plugin-opt=-pass-through=-lc --sysroot=/usr/x86_64-pc-linux-musl -m
> elf_x86_64 -static /usr/x86_64-pc-linux-musl/usr/lib/crt1.o
> /usr/x86_64-pc-linux-musl/usr/lib/crti.o
> /usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/crtbeginT.o
> -L/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0
> -L/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/../../../../x86_64-pc-linux-musl/lib
> -L/usr/x86_64-pc-linux-musl/lib -L/usr/x86_64-pc-linux-musl/usr/lib
> /tmp/ccHq7CL6.o --start-group -lgcc -lgcc_eh -lc --end-group
> /usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/crtend.o
> /usr/x86_64-pc-linux-musl/usr/lib/crtn.o
> COLLECT_GCC_OPTIONS='-v' '-static' '-O0' '-g' '-mtune=generic' '-march=x86-64'
> 
> mtune=generic and march=x86-64 suggests it isn't trying to do
> something weird on the compile computer.

Indeed, it looks like the default is right. So you probably need to
check how musl was built. Is it also a package provided by Gentoo, and
did they perhaps use -march=native even though it's being cross
compiled?

Rich


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

* Re: Illegal instruction in __copy_tls()
  2019-06-05 20:07     ` Rich Felker
@ 2019-06-05 21:27       ` tenspd137 .
  2019-06-05 21:56         ` Michael Everitt
  0 siblings, 1 reply; 13+ messages in thread
From: tenspd137 . @ 2019-06-05 21:27 UTC (permalink / raw)
  To: Rich Felker; +Cc: musl

Thanks!  That was indeed the problem.  I had march=native for all
portage related stuff set, and my guess is that crossdev read that to
start.  I removed that, reran the crossdev tool to buiild the cross
toolchain, and can now build static binaries that run on different
systems.

Much appreciated!

-C

On Wed, Jun 5, 2019 at 2:07 PM Rich Felker <dalias@libc.org> wrote:
>
> On Wed, Jun 05, 2019 at 01:53:58PM -0600, tenspd137 . wrote:
> > Sure -
> >
> > strace -d -v ./a.out:
> > strace: ptrace_setoptions = 0x51
> > strace: new tcb for pid 26302, active tcbs:1
> > strace: [wait(0x80137f) = 26302] WIFSTOPPED,sig=SIGSTOP,EVENT_STOP (128)
> > strace: pid 26302 has TCB_STARTUP, initializing it
> > strace: [wait(0x80057f) = 26302] WIFSTOPPED,sig=SIGTRAP,EVENT_STOP (128)
> > strace: [wait(0x00127f) = 26302] WIFSTOPPED,sig=SIGCONT
> > strace: [wait(0x00857f) = 26302] WIFSTOPPED,sig=133
> > execve("./a.out", ["./a.out"], ["SSH_CONNECTION=15.86.136.27 5196"...,
> > "LANG=en_US.UTF-8", "XDG_SESSION_ID=41", "USER=dayd",
> > "PWD=/home/dayd/projects/musl-tes"..., "HOME=/home/dayd",
> > "SSH_CLIENT=xx.xxx.xxx.xx 51960 22", "CCACHE_DIR=/ssd/dayd/.ccache",
> > "VMWARE_USE_SHIPPED_GTK=yes", "XDG_DATA_DIRS=/usr/local/share:/"...,
> > "USECCACHE=ON", "SSH_TTY=/dev/pts/2", "MAIL=/var/mail/dayd",
> > "TERM=rxvt-unicode-256color", "SHELL=/bin/bash", "SHLVL=1",
> > "PYTHONPATH=:/home/dayd/projects/"..., "LOGNAME=dayd",
> > "DBUS_SESSION_BUS_ADDRESS=unix:pa"...,
> > "XDG_RUNTIME_DIR=/run/user/6686",
> > "PATH=/usr/lib/ccache/bin/:/usr/l"..., "USEDISTCC=OFF",
> > "_=/usr/bin/strace", "OLDPWD=/home/dayd/projects"]strace:
> > [wait(0x04057f) = 26302] WIFSTOPPED,sig=SIGTRAP,EVENT_EXEC (4)
> > strace: [wait(0x00857f) = 26302] WIFSTOPPED,sig=133
> > ) = 0
> > strace: [wait(0x00047f) = 26302] WIFSTOPPED,sig=SIGILL
> > --- SIGILL {si_signo=SIGILL, si_code=ILL_ILLOPN, si_addr=0x40169e} ---
> > strace: [wait(0x06057f) = 26302] WIFSTOPPED,sig=SIGTRAP,EVENT_EXIT (6)
> > strace: [wait(0x000084) = 26302] WIFSIGNALED,core,sig=SIGILL
> > +++ killed by SIGILL (core dumped) +++
> > strace: dropped tcb for pid 26302, 0 remain
> > Illegal instruction (core dumped)
> > ******************************************************************************************
> > (gdb) bt
> > #0  0x00000000004016ae in __copy_tls ()
> > #1  0x0000000000000000 in ?? ()
> > *****************************************************************************************
> >
> > (gdb) disassemble
> > Dump of assembler code for function __copy_tls:
> >    0x0000000000401680 <+0>:    push   %r13
> >    0x0000000000401682 <+2>:    mov    %rdi,%r13
> >    0x0000000000401685 <+5>:    push   %r12
> >    0x0000000000401687 <+7>:    push   %rbp
> >    0x0000000000401688 <+8>:    push   %rbx
> >    0x0000000000401689 <+9>:    sub    $0x8,%rsp
> >    0x000000000040168d <+13>:    mov    0x410c(%rip),%rax        #
> > 0x4057a0 <__libc+32>
> >    0x0000000000401694 <+20>:    mov    0x410d(%rip),%rcx        #
> > 0x4057a8 <__libc+40>
> >    0x000000000040169b <+27>:    mov    0x40f6(%rip),%rbx        #
> > 0x405798 <__libc+24>
> >    0x00000000004016a2 <+34>:    lea    -0xe0(%rdi,%rax,1),%rax
> >    0x00000000004016aa <+42>:    lea    -0x1(%rcx),%r12
> > => 0x00000000004016ae <+46>:    andn   %rax,%r12,%r12
>
> This instruction, andn, is not in the base x86_64 ISA. It's part of
> the BMI1 extension:
>
> https://en.wikipedia.org/wiki/Bit_Manipulation_Instruction_Sets#BMI1_(Bit_Manipulation_Instruction_Set_1)
>
> Apparently Gentoo is providing cross compilers that default to
> producing "native ISA level" code for the host, rather than baseline
> ISA for the target. But:
>
> > as a bonus (I thought this might also help):
> > (%:~/projects/musl-test)┌- x86_64-pc-linux-musl-gcc -v -static -O0 -g
> > hello.c
> > Using built-in specs.
> > COLLECT_GCC=x86_64-pc-linux-musl-gcc
> > COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-pc-linux-musl/9.1.0/lto-wrapper
> > Target: x86_64-pc-linux-musl
> > Configured with:
> > /var/tmp/portage/cross-x86_64-pc-linux-musl/gcc-9.1.0/work/gcc-9.1.0/configure
> > --host=x86_64-pc-linux-gnu --target=x86_64-pc-linux-musl
> > --build=x86_64-pc-linux-gnu --prefix=/usr
> > --bindir=/usr/x86_64-pc-linux-gnu/x86_64-pc-linux-musl/gcc-bin/9.1.0
> > --includedir=/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/include
> > --datadir=/usr/share/gcc-data/x86_64-pc-linux-musl/9.1.0
> > --mandir=/usr/share/gcc-data/x86_64-pc-linux-musl/9.1.0/man
> > --infodir=/usr/share/gcc-data/x86_64-pc-linux-musl/9.1.0/info
> > --with-gxx-include-dir=/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/include/g++-v9
> > --with-python-dir=/share/gcc-data/x86_64-pc-linux-musl/9.1.0/python
> > --enable-languages=c,c++,fortran --enable-obsolete --enable-secureplt
> > --disable-werror --with-system-zlib --enable-nls
> > --without-included-gettext --enable-checking=release
> > --with-bugurl=https://bugs.gentoo.org/ --with-pkgversion='Gentoo 9.1.0
> > p1.0' --disable-esp --enable-libstdcxx-time
> > --enable-poison-system-directories
> > --with-sysroot=/usr/x86_64-pc-linux-musl --disable-bootstrap
> > --enable-__cxa_atexit --disable-multilib --with-multilib-list=m64
> > --disable-altivec --disable-fixed-point --enable-targets=all
> > --enable-libgomp --disable-libmudflap --disable-libssp
> > --disable-systemtap --disable-vtable-verify --disable-libvtv
> > --enable-lto --without-isl --disable-libsanitizer --enable-default-pie
> > --enable-default-ssp
> > Thread model: posix
> > gcc version 9.1.0 (Gentoo 9.1.0 p1.0)
> > COLLECT_GCC_OPTIONS='-v' '-static' '-O0' '-g' '-mtune=generic' '-march=x86-64'
> >  /usr/libexec/gcc/x86_64-pc-linux-musl/9.1.0/cc1 -quiet -v hello.c
> > -quiet -dumpbase hello.c -mtune=generic -march=x86-64 -auxbase hello
> > -g -O0 -version -o /tmp/ccoTkh38.s
> > GNU C17 (Gentoo 9.1.0 p1.0) version 9.1.0 (x86_64-pc-linux-musl)
> >     compiled by GNU C version 8.3.0, GMP version 6.1.2, MPFR version
> > 4.0.2, MPC version 1.1.0, isl version none
> > GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
> > ignoring nonexistent directory "/usr/x86_64-pc-linux-musl/usr/local/include"
> > ignoring nonexistent directory
> > "/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/../../../../x86_64-pc-linux-musl/include"
> > #include "..." search starts here:
> > #include <...> search starts here:
> >  /usr/x86_64-pc-linux-musl/usr/include
> >  /usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/include
> > End of search list.
> > GNU C17 (Gentoo 9.1.0 p1.0) version 9.1.0 (x86_64-pc-linux-musl)
> >     compiled by GNU C version 8.3.0, GMP version 6.1.2, MPFR version
> > 4.0.2, MPC version 1.1.0, isl version none
> > GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
> > Compiler executable checksum: a3183e5f435d1938198d432af6db159b
> > COLLECT_GCC_OPTIONS='-v' '-static' '-O0' '-g' '-mtune=generic' '-march=x86-64'
> >  /usr/libexec/gcc/x86_64-pc-linux-musl/as -v --64 -o /tmp/ccHq7CL6.o
> > /tmp/ccoTkh38.s
> > GNU assembler version 2.32.0 (x86_64-pc-linux-musl) using BFD version
> > (Gentoo 2.32 p2) 2.32.0
> > COMPILER_PATH=/usr/libexec/gcc/x86_64-pc-linux-musl/9.1.0/:/usr/libexec/gcc/x86_64-pc-linux-musl/9.1.0/:/usr/libexec/gcc/x86_64-pc-linux-musl/:/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/:/usr/lib/gcc/x86_64-pc-linux-musl/
> > LIBRARY_PATH=/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/:/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/../../../../x86_64-pc-linux-musl/lib/:/usr/x86_64-pc-linux-musl/lib/:/usr/x86_64-pc-linux-musl/usr/lib/
> > COLLECT_GCC_OPTIONS='-v' '-static' '-O0' '-g' '-mtune=generic' '-march=x86-64'
> >  /usr/libexec/gcc/x86_64-pc-linux-musl/9.1.0/collect2 -plugin
> > /usr/libexec/gcc/x86_64-pc-linux-musl/9.1.0/liblto_plugin.so
> > -plugin-opt=/usr/libexec/gcc/x86_64-pc-linux-musl/9.1.0/lto-wrapper
> > -plugin-opt=-fresolution=/tmp/ccWcifv4.res
> > -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_eh
> > -plugin-opt=-pass-through=-lc --sysroot=/usr/x86_64-pc-linux-musl -m
> > elf_x86_64 -static /usr/x86_64-pc-linux-musl/usr/lib/crt1.o
> > /usr/x86_64-pc-linux-musl/usr/lib/crti.o
> > /usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/crtbeginT.o
> > -L/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0
> > -L/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/../../../../x86_64-pc-linux-musl/lib
> > -L/usr/x86_64-pc-linux-musl/lib -L/usr/x86_64-pc-linux-musl/usr/lib
> > /tmp/ccHq7CL6.o --start-group -lgcc -lgcc_eh -lc --end-group
> > /usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/crtend.o
> > /usr/x86_64-pc-linux-musl/usr/lib/crtn.o
> > COLLECT_GCC_OPTIONS='-v' '-static' '-O0' '-g' '-mtune=generic' '-march=x86-64'
> >
> > mtune=generic and march=x86-64 suggests it isn't trying to do
> > something weird on the compile computer.
>
> Indeed, it looks like the default is right. So you probably need to
> check how musl was built. Is it also a package provided by Gentoo, and
> did they perhaps use -march=native even though it's being cross
> compiled?
>
> Rich


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

* Re: Illegal instruction in __copy_tls()
  2019-06-05 21:27       ` tenspd137 .
@ 2019-06-05 21:56         ` Michael Everitt
  2019-06-05 23:09           ` tenspd137 .
  0 siblings, 1 reply; 13+ messages in thread
From: Michael Everitt @ 2019-06-05 21:56 UTC (permalink / raw)
  To: musl


[-- Attachment #1.1: Type: text/plain, Size: 9470 bytes --]

In your /usr/${CTARGET}/etc/portage/make.conf you can set appropriate
target flags there. But using 'march=native' is going to catch you out a
lot cross-compiling anything ... :) At least if you've got it set to
something, you're going to see errors that point immediately to your CFLAGS
when/if it goes wrong!

Michael.

On 05/06/19 22:27, tenspd137 . wrote:
> Thanks!  That was indeed the problem.  I had march=native for all
> portage related stuff set, and my guess is that crossdev read that to
> start.  I removed that, reran the crossdev tool to buiild the cross
> toolchain, and can now build static binaries that run on different
> systems.
>
> Much appreciated!
>
> -C
>
> On Wed, Jun 5, 2019 at 2:07 PM Rich Felker <dalias@libc.org> wrote:
>> On Wed, Jun 05, 2019 at 01:53:58PM -0600, tenspd137 . wrote:
>>> Sure -
>>>
>>> strace -d -v ./a.out:
>>> strace: ptrace_setoptions = 0x51
>>> strace: new tcb for pid 26302, active tcbs:1
>>> strace: [wait(0x80137f) = 26302] WIFSTOPPED,sig=SIGSTOP,EVENT_STOP (128)
>>> strace: pid 26302 has TCB_STARTUP, initializing it
>>> strace: [wait(0x80057f) = 26302] WIFSTOPPED,sig=SIGTRAP,EVENT_STOP (128)
>>> strace: [wait(0x00127f) = 26302] WIFSTOPPED,sig=SIGCONT
>>> strace: [wait(0x00857f) = 26302] WIFSTOPPED,sig=133
>>> execve("./a.out", ["./a.out"], ["SSH_CONNECTION=15.86.136.27 5196"...,
>>> "LANG=en_US.UTF-8", "XDG_SESSION_ID=41", "USER=dayd",
>>> "PWD=/home/dayd/projects/musl-tes"..., "HOME=/home/dayd",
>>> "SSH_CLIENT=xx.xxx.xxx.xx 51960 22", "CCACHE_DIR=/ssd/dayd/.ccache",
>>> "VMWARE_USE_SHIPPED_GTK=yes", "XDG_DATA_DIRS=/usr/local/share:/"...,
>>> "USECCACHE=ON", "SSH_TTY=/dev/pts/2", "MAIL=/var/mail/dayd",
>>> "TERM=rxvt-unicode-256color", "SHELL=/bin/bash", "SHLVL=1",
>>> "PYTHONPATH=:/home/dayd/projects/"..., "LOGNAME=dayd",
>>> "DBUS_SESSION_BUS_ADDRESS=unix:pa"...,
>>> "XDG_RUNTIME_DIR=/run/user/6686",
>>> "PATH=/usr/lib/ccache/bin/:/usr/l"..., "USEDISTCC=OFF",
>>> "_=/usr/bin/strace", "OLDPWD=/home/dayd/projects"]strace:
>>> [wait(0x04057f) = 26302] WIFSTOPPED,sig=SIGTRAP,EVENT_EXEC (4)
>>> strace: [wait(0x00857f) = 26302] WIFSTOPPED,sig=133
>>> ) = 0
>>> strace: [wait(0x00047f) = 26302] WIFSTOPPED,sig=SIGILL
>>> --- SIGILL {si_signo=SIGILL, si_code=ILL_ILLOPN, si_addr=0x40169e} ---
>>> strace: [wait(0x06057f) = 26302] WIFSTOPPED,sig=SIGTRAP,EVENT_EXIT (6)
>>> strace: [wait(0x000084) = 26302] WIFSIGNALED,core,sig=SIGILL
>>> +++ killed by SIGILL (core dumped) +++
>>> strace: dropped tcb for pid 26302, 0 remain
>>> Illegal instruction (core dumped)
>>> ******************************************************************************************
>>> (gdb) bt
>>> #0  0x00000000004016ae in __copy_tls ()
>>> #1  0x0000000000000000 in ?? ()
>>> *****************************************************************************************
>>>
>>> (gdb) disassemble
>>> Dump of assembler code for function __copy_tls:
>>>    0x0000000000401680 <+0>:    push   %r13
>>>    0x0000000000401682 <+2>:    mov    %rdi,%r13
>>>    0x0000000000401685 <+5>:    push   %r12
>>>    0x0000000000401687 <+7>:    push   %rbp
>>>    0x0000000000401688 <+8>:    push   %rbx
>>>    0x0000000000401689 <+9>:    sub    $0x8,%rsp
>>>    0x000000000040168d <+13>:    mov    0x410c(%rip),%rax        #
>>> 0x4057a0 <__libc+32>
>>>    0x0000000000401694 <+20>:    mov    0x410d(%rip),%rcx        #
>>> 0x4057a8 <__libc+40>
>>>    0x000000000040169b <+27>:    mov    0x40f6(%rip),%rbx        #
>>> 0x405798 <__libc+24>
>>>    0x00000000004016a2 <+34>:    lea    -0xe0(%rdi,%rax,1),%rax
>>>    0x00000000004016aa <+42>:    lea    -0x1(%rcx),%r12
>>> => 0x00000000004016ae <+46>:    andn   %rax,%r12,%r12
>> This instruction, andn, is not in the base x86_64 ISA. It's part of
>> the BMI1 extension:
>>
>> https://en.wikipedia.org/wiki/Bit_Manipulation_Instruction_Sets#BMI1_(Bit_Manipulation_Instruction_Set_1)
>>
>> Apparently Gentoo is providing cross compilers that default to
>> producing "native ISA level" code for the host, rather than baseline
>> ISA for the target. But:
>>
>>> as a bonus (I thought this might also help):
>>> (%:~/projects/musl-test)┌- x86_64-pc-linux-musl-gcc -v -static -O0 -g
>>> hello.c
>>> Using built-in specs.
>>> COLLECT_GCC=x86_64-pc-linux-musl-gcc
>>> COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-pc-linux-musl/9.1.0/lto-wrapper
>>> Target: x86_64-pc-linux-musl
>>> Configured with:
>>> /var/tmp/portage/cross-x86_64-pc-linux-musl/gcc-9.1.0/work/gcc-9.1.0/configure
>>> --host=x86_64-pc-linux-gnu --target=x86_64-pc-linux-musl
>>> --build=x86_64-pc-linux-gnu --prefix=/usr
>>> --bindir=/usr/x86_64-pc-linux-gnu/x86_64-pc-linux-musl/gcc-bin/9.1.0
>>> --includedir=/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/include
>>> --datadir=/usr/share/gcc-data/x86_64-pc-linux-musl/9.1.0
>>> --mandir=/usr/share/gcc-data/x86_64-pc-linux-musl/9.1.0/man
>>> --infodir=/usr/share/gcc-data/x86_64-pc-linux-musl/9.1.0/info
>>> --with-gxx-include-dir=/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/include/g++-v9
>>> --with-python-dir=/share/gcc-data/x86_64-pc-linux-musl/9.1.0/python
>>> --enable-languages=c,c++,fortran --enable-obsolete --enable-secureplt
>>> --disable-werror --with-system-zlib --enable-nls
>>> --without-included-gettext --enable-checking=release
>>> --with-bugurl=https://bugs.gentoo.org/ --with-pkgversion='Gentoo 9.1.0
>>> p1.0' --disable-esp --enable-libstdcxx-time
>>> --enable-poison-system-directories
>>> --with-sysroot=/usr/x86_64-pc-linux-musl --disable-bootstrap
>>> --enable-__cxa_atexit --disable-multilib --with-multilib-list=m64
>>> --disable-altivec --disable-fixed-point --enable-targets=all
>>> --enable-libgomp --disable-libmudflap --disable-libssp
>>> --disable-systemtap --disable-vtable-verify --disable-libvtv
>>> --enable-lto --without-isl --disable-libsanitizer --enable-default-pie
>>> --enable-default-ssp
>>> Thread model: posix
>>> gcc version 9.1.0 (Gentoo 9.1.0 p1.0)
>>> COLLECT_GCC_OPTIONS='-v' '-static' '-O0' '-g' '-mtune=generic' '-march=x86-64'
>>>  /usr/libexec/gcc/x86_64-pc-linux-musl/9.1.0/cc1 -quiet -v hello.c
>>> -quiet -dumpbase hello.c -mtune=generic -march=x86-64 -auxbase hello
>>> -g -O0 -version -o /tmp/ccoTkh38.s
>>> GNU C17 (Gentoo 9.1.0 p1.0) version 9.1.0 (x86_64-pc-linux-musl)
>>>     compiled by GNU C version 8.3.0, GMP version 6.1.2, MPFR version
>>> 4.0.2, MPC version 1.1.0, isl version none
>>> GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
>>> ignoring nonexistent directory "/usr/x86_64-pc-linux-musl/usr/local/include"
>>> ignoring nonexistent directory
>>> "/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/../../../../x86_64-pc-linux-musl/include"
>>> #include "..." search starts here:
>>> #include <...> search starts here:
>>>  /usr/x86_64-pc-linux-musl/usr/include
>>>  /usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/include
>>> End of search list.
>>> GNU C17 (Gentoo 9.1.0 p1.0) version 9.1.0 (x86_64-pc-linux-musl)
>>>     compiled by GNU C version 8.3.0, GMP version 6.1.2, MPFR version
>>> 4.0.2, MPC version 1.1.0, isl version none
>>> GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
>>> Compiler executable checksum: a3183e5f435d1938198d432af6db159b
>>> COLLECT_GCC_OPTIONS='-v' '-static' '-O0' '-g' '-mtune=generic' '-march=x86-64'
>>>  /usr/libexec/gcc/x86_64-pc-linux-musl/as -v --64 -o /tmp/ccHq7CL6.o
>>> /tmp/ccoTkh38.s
>>> GNU assembler version 2.32.0 (x86_64-pc-linux-musl) using BFD version
>>> (Gentoo 2.32 p2) 2.32.0
>>> COMPILER_PATH=/usr/libexec/gcc/x86_64-pc-linux-musl/9.1.0/:/usr/libexec/gcc/x86_64-pc-linux-musl/9.1.0/:/usr/libexec/gcc/x86_64-pc-linux-musl/:/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/:/usr/lib/gcc/x86_64-pc-linux-musl/
>>> LIBRARY_PATH=/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/:/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/../../../../x86_64-pc-linux-musl/lib/:/usr/x86_64-pc-linux-musl/lib/:/usr/x86_64-pc-linux-musl/usr/lib/
>>> COLLECT_GCC_OPTIONS='-v' '-static' '-O0' '-g' '-mtune=generic' '-march=x86-64'
>>>  /usr/libexec/gcc/x86_64-pc-linux-musl/9.1.0/collect2 -plugin
>>> /usr/libexec/gcc/x86_64-pc-linux-musl/9.1.0/liblto_plugin.so
>>> -plugin-opt=/usr/libexec/gcc/x86_64-pc-linux-musl/9.1.0/lto-wrapper
>>> -plugin-opt=-fresolution=/tmp/ccWcifv4.res
>>> -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_eh
>>> -plugin-opt=-pass-through=-lc --sysroot=/usr/x86_64-pc-linux-musl -m
>>> elf_x86_64 -static /usr/x86_64-pc-linux-musl/usr/lib/crt1.o
>>> /usr/x86_64-pc-linux-musl/usr/lib/crti.o
>>> /usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/crtbeginT.o
>>> -L/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0
>>> -L/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/../../../../x86_64-pc-linux-musl/lib
>>> -L/usr/x86_64-pc-linux-musl/lib -L/usr/x86_64-pc-linux-musl/usr/lib
>>> /tmp/ccHq7CL6.o --start-group -lgcc -lgcc_eh -lc --end-group
>>> /usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/crtend.o
>>> /usr/x86_64-pc-linux-musl/usr/lib/crtn.o
>>> COLLECT_GCC_OPTIONS='-v' '-static' '-O0' '-g' '-mtune=generic' '-march=x86-64'
>>>
>>> mtune=generic and march=x86-64 suggests it isn't trying to do
>>> something weird on the compile computer.
>> Indeed, it looks like the default is right. So you probably need to
>> check how musl was built. Is it also a package provided by Gentoo, and
>> did they perhaps use -march=native even though it's being cross
>> compiled?
>>
>> Rich



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 801 bytes --]

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

* Re: Illegal instruction in __copy_tls()
  2019-06-05 21:56         ` Michael Everitt
@ 2019-06-05 23:09           ` tenspd137 .
  2019-06-05 23:32             ` tenspd137 .
  0 siblings, 1 reply; 13+ messages in thread
From: tenspd137 . @ 2019-06-05 23:09 UTC (permalink / raw)
  To: musl

I probably don't fully understand how it works.  In
/etc/x86_64-pc-linux-musl/etc.portage/make.conf, march is not
specified.  It is specified in /etc/portage/make.conf.  When I removed
it from there, things worked.  Then I just put it back after using
crossdev to make x86_64-pc-linux-musl-*.

Either way, loads of fun :)

Thanks!

-C

On Wed, Jun 5, 2019 at 3:56 PM Michael Everitt <m.j.everitt@iee.org> wrote:
>
> In your /usr/${CTARGET}/etc/portage/make.conf you can set appropriate
> target flags there. But using 'march=native' is going to catch you out a
> lot cross-compiling anything ... :) At least if you've got it set to
> something, you're going to see errors that point immediately to your CFLAGS
> when/if it goes wrong!
>
> Michael.
>
> On 05/06/19 22:27, tenspd137 . wrote:
> > Thanks!  That was indeed the problem.  I had march=native for all
> > portage related stuff set, and my guess is that crossdev read that to
> > start.  I removed that, reran the crossdev tool to buiild the cross
> > toolchain, and can now build static binaries that run on different
> > systems.
> >
> > Much appreciated!
> >
> > -C
> >
> > On Wed, Jun 5, 2019 at 2:07 PM Rich Felker <dalias@libc.org> wrote:
> >> On Wed, Jun 05, 2019 at 01:53:58PM -0600, tenspd137 . wrote:
> >>> Sure -
> >>>
> >>> strace -d -v ./a.out:
> >>> strace: ptrace_setoptions = 0x51
> >>> strace: new tcb for pid 26302, active tcbs:1
> >>> strace: [wait(0x80137f) = 26302] WIFSTOPPED,sig=SIGSTOP,EVENT_STOP (128)
> >>> strace: pid 26302 has TCB_STARTUP, initializing it
> >>> strace: [wait(0x80057f) = 26302] WIFSTOPPED,sig=SIGTRAP,EVENT_STOP (128)
> >>> strace: [wait(0x00127f) = 26302] WIFSTOPPED,sig=SIGCONT
> >>> strace: [wait(0x00857f) = 26302] WIFSTOPPED,sig=133
> >>> execve("./a.out", ["./a.out"], ["SSH_CONNECTION=15.86.136.27 5196"...,
> >>> "LANG=en_US.UTF-8", "XDG_SESSION_ID=41", "USER=dayd",
> >>> "PWD=/home/dayd/projects/musl-tes"..., "HOME=/home/dayd",
> >>> "SSH_CLIENT=xx.xxx.xxx.xx 51960 22", "CCACHE_DIR=/ssd/dayd/.ccache",
> >>> "VMWARE_USE_SHIPPED_GTK=yes", "XDG_DATA_DIRS=/usr/local/share:/"...,
> >>> "USECCACHE=ON", "SSH_TTY=/dev/pts/2", "MAIL=/var/mail/dayd",
> >>> "TERM=rxvt-unicode-256color", "SHELL=/bin/bash", "SHLVL=1",
> >>> "PYTHONPATH=:/home/dayd/projects/"..., "LOGNAME=dayd",
> >>> "DBUS_SESSION_BUS_ADDRESS=unix:pa"...,
> >>> "XDG_RUNTIME_DIR=/run/user/6686",
> >>> "PATH=/usr/lib/ccache/bin/:/usr/l"..., "USEDISTCC=OFF",
> >>> "_=/usr/bin/strace", "OLDPWD=/home/dayd/projects"]strace:
> >>> [wait(0x04057f) = 26302] WIFSTOPPED,sig=SIGTRAP,EVENT_EXEC (4)
> >>> strace: [wait(0x00857f) = 26302] WIFSTOPPED,sig=133
> >>> ) = 0
> >>> strace: [wait(0x00047f) = 26302] WIFSTOPPED,sig=SIGILL
> >>> --- SIGILL {si_signo=SIGILL, si_code=ILL_ILLOPN, si_addr=0x40169e} ---
> >>> strace: [wait(0x06057f) = 26302] WIFSTOPPED,sig=SIGTRAP,EVENT_EXIT (6)
> >>> strace: [wait(0x000084) = 26302] WIFSIGNALED,core,sig=SIGILL
> >>> +++ killed by SIGILL (core dumped) +++
> >>> strace: dropped tcb for pid 26302, 0 remain
> >>> Illegal instruction (core dumped)
> >>> ******************************************************************************************
> >>> (gdb) bt
> >>> #0  0x00000000004016ae in __copy_tls ()
> >>> #1  0x0000000000000000 in ?? ()
> >>> *****************************************************************************************
> >>>
> >>> (gdb) disassemble
> >>> Dump of assembler code for function __copy_tls:
> >>>    0x0000000000401680 <+0>:    push   %r13
> >>>    0x0000000000401682 <+2>:    mov    %rdi,%r13
> >>>    0x0000000000401685 <+5>:    push   %r12
> >>>    0x0000000000401687 <+7>:    push   %rbp
> >>>    0x0000000000401688 <+8>:    push   %rbx
> >>>    0x0000000000401689 <+9>:    sub    $0x8,%rsp
> >>>    0x000000000040168d <+13>:    mov    0x410c(%rip),%rax        #
> >>> 0x4057a0 <__libc+32>
> >>>    0x0000000000401694 <+20>:    mov    0x410d(%rip),%rcx        #
> >>> 0x4057a8 <__libc+40>
> >>>    0x000000000040169b <+27>:    mov    0x40f6(%rip),%rbx        #
> >>> 0x405798 <__libc+24>
> >>>    0x00000000004016a2 <+34>:    lea    -0xe0(%rdi,%rax,1),%rax
> >>>    0x00000000004016aa <+42>:    lea    -0x1(%rcx),%r12
> >>> => 0x00000000004016ae <+46>:    andn   %rax,%r12,%r12
> >> This instruction, andn, is not in the base x86_64 ISA. It's part of
> >> the BMI1 extension:
> >>
> >> https://en.wikipedia.org/wiki/Bit_Manipulation_Instruction_Sets#BMI1_(Bit_Manipulation_Instruction_Set_1)
> >>
> >> Apparently Gentoo is providing cross compilers that default to
> >> producing "native ISA level" code for the host, rather than baseline
> >> ISA for the target. But:
> >>
> >>> as a bonus (I thought this might also help):
> >>> (%:~/projects/musl-test)┌- x86_64-pc-linux-musl-gcc -v -static -O0 -g
> >>> hello.c
> >>> Using built-in specs.
> >>> COLLECT_GCC=x86_64-pc-linux-musl-gcc
> >>> COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-pc-linux-musl/9.1.0/lto-wrapper
> >>> Target: x86_64-pc-linux-musl
> >>> Configured with:
> >>> /var/tmp/portage/cross-x86_64-pc-linux-musl/gcc-9.1.0/work/gcc-9.1.0/configure
> >>> --host=x86_64-pc-linux-gnu --target=x86_64-pc-linux-musl
> >>> --build=x86_64-pc-linux-gnu --prefix=/usr
> >>> --bindir=/usr/x86_64-pc-linux-gnu/x86_64-pc-linux-musl/gcc-bin/9.1.0
> >>> --includedir=/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/include
> >>> --datadir=/usr/share/gcc-data/x86_64-pc-linux-musl/9.1.0
> >>> --mandir=/usr/share/gcc-data/x86_64-pc-linux-musl/9.1.0/man
> >>> --infodir=/usr/share/gcc-data/x86_64-pc-linux-musl/9.1.0/info
> >>> --with-gxx-include-dir=/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/include/g++-v9
> >>> --with-python-dir=/share/gcc-data/x86_64-pc-linux-musl/9.1.0/python
> >>> --enable-languages=c,c++,fortran --enable-obsolete --enable-secureplt
> >>> --disable-werror --with-system-zlib --enable-nls
> >>> --without-included-gettext --enable-checking=release
> >>> --with-bugurl=https://bugs.gentoo.org/ --with-pkgversion='Gentoo 9.1.0
> >>> p1.0' --disable-esp --enable-libstdcxx-time
> >>> --enable-poison-system-directories
> >>> --with-sysroot=/usr/x86_64-pc-linux-musl --disable-bootstrap
> >>> --enable-__cxa_atexit --disable-multilib --with-multilib-list=m64
> >>> --disable-altivec --disable-fixed-point --enable-targets=all
> >>> --enable-libgomp --disable-libmudflap --disable-libssp
> >>> --disable-systemtap --disable-vtable-verify --disable-libvtv
> >>> --enable-lto --without-isl --disable-libsanitizer --enable-default-pie
> >>> --enable-default-ssp
> >>> Thread model: posix
> >>> gcc version 9.1.0 (Gentoo 9.1.0 p1.0)
> >>> COLLECT_GCC_OPTIONS='-v' '-static' '-O0' '-g' '-mtune=generic' '-march=x86-64'
> >>>  /usr/libexec/gcc/x86_64-pc-linux-musl/9.1.0/cc1 -quiet -v hello.c
> >>> -quiet -dumpbase hello.c -mtune=generic -march=x86-64 -auxbase hello
> >>> -g -O0 -version -o /tmp/ccoTkh38.s
> >>> GNU C17 (Gentoo 9.1.0 p1.0) version 9.1.0 (x86_64-pc-linux-musl)
> >>>     compiled by GNU C version 8.3.0, GMP version 6.1.2, MPFR version
> >>> 4.0.2, MPC version 1.1.0, isl version none
> >>> GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
> >>> ignoring nonexistent directory "/usr/x86_64-pc-linux-musl/usr/local/include"
> >>> ignoring nonexistent directory
> >>> "/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/../../../../x86_64-pc-linux-musl/include"
> >>> #include "..." search starts here:
> >>> #include <...> search starts here:
> >>>  /usr/x86_64-pc-linux-musl/usr/include
> >>>  /usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/include
> >>> End of search list.
> >>> GNU C17 (Gentoo 9.1.0 p1.0) version 9.1.0 (x86_64-pc-linux-musl)
> >>>     compiled by GNU C version 8.3.0, GMP version 6.1.2, MPFR version
> >>> 4.0.2, MPC version 1.1.0, isl version none
> >>> GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
> >>> Compiler executable checksum: a3183e5f435d1938198d432af6db159b
> >>> COLLECT_GCC_OPTIONS='-v' '-static' '-O0' '-g' '-mtune=generic' '-march=x86-64'
> >>>  /usr/libexec/gcc/x86_64-pc-linux-musl/as -v --64 -o /tmp/ccHq7CL6.o
> >>> /tmp/ccoTkh38.s
> >>> GNU assembler version 2.32.0 (x86_64-pc-linux-musl) using BFD version
> >>> (Gentoo 2.32 p2) 2.32.0
> >>> COMPILER_PATH=/usr/libexec/gcc/x86_64-pc-linux-musl/9.1.0/:/usr/libexec/gcc/x86_64-pc-linux-musl/9.1.0/:/usr/libexec/gcc/x86_64-pc-linux-musl/:/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/:/usr/lib/gcc/x86_64-pc-linux-musl/
> >>> LIBRARY_PATH=/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/:/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/../../../../x86_64-pc-linux-musl/lib/:/usr/x86_64-pc-linux-musl/lib/:/usr/x86_64-pc-linux-musl/usr/lib/
> >>> COLLECT_GCC_OPTIONS='-v' '-static' '-O0' '-g' '-mtune=generic' '-march=x86-64'
> >>>  /usr/libexec/gcc/x86_64-pc-linux-musl/9.1.0/collect2 -plugin
> >>> /usr/libexec/gcc/x86_64-pc-linux-musl/9.1.0/liblto_plugin.so
> >>> -plugin-opt=/usr/libexec/gcc/x86_64-pc-linux-musl/9.1.0/lto-wrapper
> >>> -plugin-opt=-fresolution=/tmp/ccWcifv4.res
> >>> -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_eh
> >>> -plugin-opt=-pass-through=-lc --sysroot=/usr/x86_64-pc-linux-musl -m
> >>> elf_x86_64 -static /usr/x86_64-pc-linux-musl/usr/lib/crt1.o
> >>> /usr/x86_64-pc-linux-musl/usr/lib/crti.o
> >>> /usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/crtbeginT.o
> >>> -L/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0
> >>> -L/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/../../../../x86_64-pc-linux-musl/lib
> >>> -L/usr/x86_64-pc-linux-musl/lib -L/usr/x86_64-pc-linux-musl/usr/lib
> >>> /tmp/ccHq7CL6.o --start-group -lgcc -lgcc_eh -lc --end-group
> >>> /usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/crtend.o
> >>> /usr/x86_64-pc-linux-musl/usr/lib/crtn.o
> >>> COLLECT_GCC_OPTIONS='-v' '-static' '-O0' '-g' '-mtune=generic' '-march=x86-64'
> >>>
> >>> mtune=generic and march=x86-64 suggests it isn't trying to do
> >>> something weird on the compile computer.
> >> Indeed, it looks like the default is right. So you probably need to
> >> check how musl was built. Is it also a package provided by Gentoo, and
> >> did they perhaps use -march=native even though it's being cross
> >> compiled?
> >>
> >> Rich
>
>


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

* Re: Illegal instruction in __copy_tls()
  2019-06-05 23:09           ` tenspd137 .
@ 2019-06-05 23:32             ` tenspd137 .
  2019-06-05 23:34               ` Michael Everitt
  0 siblings, 1 reply; 13+ messages in thread
From: tenspd137 . @ 2019-06-05 23:32 UTC (permalink / raw)
  To: musl

Quick question - anyone know how to make a crossdev crosscompiler
multilib so I can use -m32 when I compile?

Thanks!

On Wed, Jun 5, 2019 at 5:09 PM tenspd137 . <dcday137@gmail.com> wrote:
>
> I probably don't fully understand how it works.  In
> /etc/x86_64-pc-linux-musl/etc.portage/make.conf, march is not
> specified.  It is specified in /etc/portage/make.conf.  When I removed
> it from there, things worked.  Then I just put it back after using
> crossdev to make x86_64-pc-linux-musl-*.
>
> Either way, loads of fun :)
>
> Thanks!
>
> -C
>
> On Wed, Jun 5, 2019 at 3:56 PM Michael Everitt <m.j.everitt@iee.org> wrote:
> >
> > In your /usr/${CTARGET}/etc/portage/make.conf you can set appropriate
> > target flags there. But using 'march=native' is going to catch you out a
> > lot cross-compiling anything ... :) At least if you've got it set to
> > something, you're going to see errors that point immediately to your CFLAGS
> > when/if it goes wrong!
> >
> > Michael.
> >
> > On 05/06/19 22:27, tenspd137 . wrote:
> > > Thanks!  That was indeed the problem.  I had march=native for all
> > > portage related stuff set, and my guess is that crossdev read that to
> > > start.  I removed that, reran the crossdev tool to buiild the cross
> > > toolchain, and can now build static binaries that run on different
> > > systems.
> > >
> > > Much appreciated!
> > >
> > > -C
> > >
> > > On Wed, Jun 5, 2019 at 2:07 PM Rich Felker <dalias@libc.org> wrote:
> > >> On Wed, Jun 05, 2019 at 01:53:58PM -0600, tenspd137 . wrote:
> > >>> Sure -
> > >>>
> > >>> strace -d -v ./a.out:
> > >>> strace: ptrace_setoptions = 0x51
> > >>> strace: new tcb for pid 26302, active tcbs:1
> > >>> strace: [wait(0x80137f) = 26302] WIFSTOPPED,sig=SIGSTOP,EVENT_STOP (128)
> > >>> strace: pid 26302 has TCB_STARTUP, initializing it
> > >>> strace: [wait(0x80057f) = 26302] WIFSTOPPED,sig=SIGTRAP,EVENT_STOP (128)
> > >>> strace: [wait(0x00127f) = 26302] WIFSTOPPED,sig=SIGCONT
> > >>> strace: [wait(0x00857f) = 26302] WIFSTOPPED,sig=133
> > >>> execve("./a.out", ["./a.out"], ["SSH_CONNECTION=15.86.136.27 5196"...,
> > >>> "LANG=en_US.UTF-8", "XDG_SESSION_ID=41", "USER=dayd",
> > >>> "PWD=/home/dayd/projects/musl-tes"..., "HOME=/home/dayd",
> > >>> "SSH_CLIENT=xx.xxx.xxx.xx 51960 22", "CCACHE_DIR=/ssd/dayd/.ccache",
> > >>> "VMWARE_USE_SHIPPED_GTK=yes", "XDG_DATA_DIRS=/usr/local/share:/"...,
> > >>> "USECCACHE=ON", "SSH_TTY=/dev/pts/2", "MAIL=/var/mail/dayd",
> > >>> "TERM=rxvt-unicode-256color", "SHELL=/bin/bash", "SHLVL=1",
> > >>> "PYTHONPATH=:/home/dayd/projects/"..., "LOGNAME=dayd",
> > >>> "DBUS_SESSION_BUS_ADDRESS=unix:pa"...,
> > >>> "XDG_RUNTIME_DIR=/run/user/6686",
> > >>> "PATH=/usr/lib/ccache/bin/:/usr/l"..., "USEDISTCC=OFF",
> > >>> "_=/usr/bin/strace", "OLDPWD=/home/dayd/projects"]strace:
> > >>> [wait(0x04057f) = 26302] WIFSTOPPED,sig=SIGTRAP,EVENT_EXEC (4)
> > >>> strace: [wait(0x00857f) = 26302] WIFSTOPPED,sig=133
> > >>> ) = 0
> > >>> strace: [wait(0x00047f) = 26302] WIFSTOPPED,sig=SIGILL
> > >>> --- SIGILL {si_signo=SIGILL, si_code=ILL_ILLOPN, si_addr=0x40169e} ---
> > >>> strace: [wait(0x06057f) = 26302] WIFSTOPPED,sig=SIGTRAP,EVENT_EXIT (6)
> > >>> strace: [wait(0x000084) = 26302] WIFSIGNALED,core,sig=SIGILL
> > >>> +++ killed by SIGILL (core dumped) +++
> > >>> strace: dropped tcb for pid 26302, 0 remain
> > >>> Illegal instruction (core dumped)
> > >>> ******************************************************************************************
> > >>> (gdb) bt
> > >>> #0  0x00000000004016ae in __copy_tls ()
> > >>> #1  0x0000000000000000 in ?? ()
> > >>> *****************************************************************************************
> > >>>
> > >>> (gdb) disassemble
> > >>> Dump of assembler code for function __copy_tls:
> > >>>    0x0000000000401680 <+0>:    push   %r13
> > >>>    0x0000000000401682 <+2>:    mov    %rdi,%r13
> > >>>    0x0000000000401685 <+5>:    push   %r12
> > >>>    0x0000000000401687 <+7>:    push   %rbp
> > >>>    0x0000000000401688 <+8>:    push   %rbx
> > >>>    0x0000000000401689 <+9>:    sub    $0x8,%rsp
> > >>>    0x000000000040168d <+13>:    mov    0x410c(%rip),%rax        #
> > >>> 0x4057a0 <__libc+32>
> > >>>    0x0000000000401694 <+20>:    mov    0x410d(%rip),%rcx        #
> > >>> 0x4057a8 <__libc+40>
> > >>>    0x000000000040169b <+27>:    mov    0x40f6(%rip),%rbx        #
> > >>> 0x405798 <__libc+24>
> > >>>    0x00000000004016a2 <+34>:    lea    -0xe0(%rdi,%rax,1),%rax
> > >>>    0x00000000004016aa <+42>:    lea    -0x1(%rcx),%r12
> > >>> => 0x00000000004016ae <+46>:    andn   %rax,%r12,%r12
> > >> This instruction, andn, is not in the base x86_64 ISA. It's part of
> > >> the BMI1 extension:
> > >>
> > >> https://en.wikipedia.org/wiki/Bit_Manipulation_Instruction_Sets#BMI1_(Bit_Manipulation_Instruction_Set_1)
> > >>
> > >> Apparently Gentoo is providing cross compilers that default to
> > >> producing "native ISA level" code for the host, rather than baseline
> > >> ISA for the target. But:
> > >>
> > >>> as a bonus (I thought this might also help):
> > >>> (%:~/projects/musl-test)┌- x86_64-pc-linux-musl-gcc -v -static -O0 -g
> > >>> hello.c
> > >>> Using built-in specs.
> > >>> COLLECT_GCC=x86_64-pc-linux-musl-gcc
> > >>> COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-pc-linux-musl/9.1.0/lto-wrapper
> > >>> Target: x86_64-pc-linux-musl
> > >>> Configured with:
> > >>> /var/tmp/portage/cross-x86_64-pc-linux-musl/gcc-9.1.0/work/gcc-9.1.0/configure
> > >>> --host=x86_64-pc-linux-gnu --target=x86_64-pc-linux-musl
> > >>> --build=x86_64-pc-linux-gnu --prefix=/usr
> > >>> --bindir=/usr/x86_64-pc-linux-gnu/x86_64-pc-linux-musl/gcc-bin/9.1.0
> > >>> --includedir=/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/include
> > >>> --datadir=/usr/share/gcc-data/x86_64-pc-linux-musl/9.1.0
> > >>> --mandir=/usr/share/gcc-data/x86_64-pc-linux-musl/9.1.0/man
> > >>> --infodir=/usr/share/gcc-data/x86_64-pc-linux-musl/9.1.0/info
> > >>> --with-gxx-include-dir=/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/include/g++-v9
> > >>> --with-python-dir=/share/gcc-data/x86_64-pc-linux-musl/9.1.0/python
> > >>> --enable-languages=c,c++,fortran --enable-obsolete --enable-secureplt
> > >>> --disable-werror --with-system-zlib --enable-nls
> > >>> --without-included-gettext --enable-checking=release
> > >>> --with-bugurl=https://bugs.gentoo.org/ --with-pkgversion='Gentoo 9.1.0
> > >>> p1.0' --disable-esp --enable-libstdcxx-time
> > >>> --enable-poison-system-directories
> > >>> --with-sysroot=/usr/x86_64-pc-linux-musl --disable-bootstrap
> > >>> --enable-__cxa_atexit --disable-multilib --with-multilib-list=m64
> > >>> --disable-altivec --disable-fixed-point --enable-targets=all
> > >>> --enable-libgomp --disable-libmudflap --disable-libssp
> > >>> --disable-systemtap --disable-vtable-verify --disable-libvtv
> > >>> --enable-lto --without-isl --disable-libsanitizer --enable-default-pie
> > >>> --enable-default-ssp
> > >>> Thread model: posix
> > >>> gcc version 9.1.0 (Gentoo 9.1.0 p1.0)
> > >>> COLLECT_GCC_OPTIONS='-v' '-static' '-O0' '-g' '-mtune=generic' '-march=x86-64'
> > >>>  /usr/libexec/gcc/x86_64-pc-linux-musl/9.1.0/cc1 -quiet -v hello.c
> > >>> -quiet -dumpbase hello.c -mtune=generic -march=x86-64 -auxbase hello
> > >>> -g -O0 -version -o /tmp/ccoTkh38.s
> > >>> GNU C17 (Gentoo 9.1.0 p1.0) version 9.1.0 (x86_64-pc-linux-musl)
> > >>>     compiled by GNU C version 8.3.0, GMP version 6.1.2, MPFR version
> > >>> 4.0.2, MPC version 1.1.0, isl version none
> > >>> GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
> > >>> ignoring nonexistent directory "/usr/x86_64-pc-linux-musl/usr/local/include"
> > >>> ignoring nonexistent directory
> > >>> "/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/../../../../x86_64-pc-linux-musl/include"
> > >>> #include "..." search starts here:
> > >>> #include <...> search starts here:
> > >>>  /usr/x86_64-pc-linux-musl/usr/include
> > >>>  /usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/include
> > >>> End of search list.
> > >>> GNU C17 (Gentoo 9.1.0 p1.0) version 9.1.0 (x86_64-pc-linux-musl)
> > >>>     compiled by GNU C version 8.3.0, GMP version 6.1.2, MPFR version
> > >>> 4.0.2, MPC version 1.1.0, isl version none
> > >>> GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
> > >>> Compiler executable checksum: a3183e5f435d1938198d432af6db159b
> > >>> COLLECT_GCC_OPTIONS='-v' '-static' '-O0' '-g' '-mtune=generic' '-march=x86-64'
> > >>>  /usr/libexec/gcc/x86_64-pc-linux-musl/as -v --64 -o /tmp/ccHq7CL6.o
> > >>> /tmp/ccoTkh38.s
> > >>> GNU assembler version 2.32.0 (x86_64-pc-linux-musl) using BFD version
> > >>> (Gentoo 2.32 p2) 2.32.0
> > >>> COMPILER_PATH=/usr/libexec/gcc/x86_64-pc-linux-musl/9.1.0/:/usr/libexec/gcc/x86_64-pc-linux-musl/9.1.0/:/usr/libexec/gcc/x86_64-pc-linux-musl/:/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/:/usr/lib/gcc/x86_64-pc-linux-musl/
> > >>> LIBRARY_PATH=/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/:/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/../../../../x86_64-pc-linux-musl/lib/:/usr/x86_64-pc-linux-musl/lib/:/usr/x86_64-pc-linux-musl/usr/lib/
> > >>> COLLECT_GCC_OPTIONS='-v' '-static' '-O0' '-g' '-mtune=generic' '-march=x86-64'
> > >>>  /usr/libexec/gcc/x86_64-pc-linux-musl/9.1.0/collect2 -plugin
> > >>> /usr/libexec/gcc/x86_64-pc-linux-musl/9.1.0/liblto_plugin.so
> > >>> -plugin-opt=/usr/libexec/gcc/x86_64-pc-linux-musl/9.1.0/lto-wrapper
> > >>> -plugin-opt=-fresolution=/tmp/ccWcifv4.res
> > >>> -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_eh
> > >>> -plugin-opt=-pass-through=-lc --sysroot=/usr/x86_64-pc-linux-musl -m
> > >>> elf_x86_64 -static /usr/x86_64-pc-linux-musl/usr/lib/crt1.o
> > >>> /usr/x86_64-pc-linux-musl/usr/lib/crti.o
> > >>> /usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/crtbeginT.o
> > >>> -L/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0
> > >>> -L/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/../../../../x86_64-pc-linux-musl/lib
> > >>> -L/usr/x86_64-pc-linux-musl/lib -L/usr/x86_64-pc-linux-musl/usr/lib
> > >>> /tmp/ccHq7CL6.o --start-group -lgcc -lgcc_eh -lc --end-group
> > >>> /usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/crtend.o
> > >>> /usr/x86_64-pc-linux-musl/usr/lib/crtn.o
> > >>> COLLECT_GCC_OPTIONS='-v' '-static' '-O0' '-g' '-mtune=generic' '-march=x86-64'
> > >>>
> > >>> mtune=generic and march=x86-64 suggests it isn't trying to do
> > >>> something weird on the compile computer.
> > >> Indeed, it looks like the default is right. So you probably need to
> > >> check how musl was built. Is it also a package provided by Gentoo, and
> > >> did they perhaps use -march=native even though it's being cross
> > >> compiled?
> > >>
> > >> Rich
> >
> >


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

* Re: Illegal instruction in __copy_tls()
  2019-06-05 23:32             ` tenspd137 .
@ 2019-06-05 23:34               ` Michael Everitt
  2019-06-05 23:37                 ` tenspd137 .
  0 siblings, 1 reply; 13+ messages in thread
From: Michael Everitt @ 2019-06-05 23:34 UTC (permalink / raw)
  To: musl


[-- Attachment #1.1: Type: text/plain, Size: 10747 bytes --]

Musl doesn't support multilib ... :] fyi

On 06/06/19 00:32, tenspd137 . wrote:
> Quick question - anyone know how to make a crossdev crosscompiler
> multilib so I can use -m32 when I compile?
>
> Thanks!
>
> On Wed, Jun 5, 2019 at 5:09 PM tenspd137 . <dcday137@gmail.com> wrote:
>> I probably don't fully understand how it works.  In
>> /etc/x86_64-pc-linux-musl/etc.portage/make.conf, march is not
>> specified.  It is specified in /etc/portage/make.conf.  When I removed
>> it from there, things worked.  Then I just put it back after using
>> crossdev to make x86_64-pc-linux-musl-*.
>>
>> Either way, loads of fun :)
>>
>> Thanks!
>>
>> -C
>>
>> On Wed, Jun 5, 2019 at 3:56 PM Michael Everitt <m.j.everitt@iee.org> wrote:
>>> In your /usr/${CTARGET}/etc/portage/make.conf you can set appropriate
>>> target flags there. But using 'march=native' is going to catch you out a
>>> lot cross-compiling anything ... :) At least if you've got it set to
>>> something, you're going to see errors that point immediately to your CFLAGS
>>> when/if it goes wrong!
>>>
>>> Michael.
>>>
>>> On 05/06/19 22:27, tenspd137 . wrote:
>>>> Thanks!  That was indeed the problem.  I had march=native for all
>>>> portage related stuff set, and my guess is that crossdev read that to
>>>> start.  I removed that, reran the crossdev tool to buiild the cross
>>>> toolchain, and can now build static binaries that run on different
>>>> systems.
>>>>
>>>> Much appreciated!
>>>>
>>>> -C
>>>>
>>>> On Wed, Jun 5, 2019 at 2:07 PM Rich Felker <dalias@libc.org> wrote:
>>>>> On Wed, Jun 05, 2019 at 01:53:58PM -0600, tenspd137 . wrote:
>>>>>> Sure -
>>>>>>
>>>>>> strace -d -v ./a.out:
>>>>>> strace: ptrace_setoptions = 0x51
>>>>>> strace: new tcb for pid 26302, active tcbs:1
>>>>>> strace: [wait(0x80137f) = 26302] WIFSTOPPED,sig=SIGSTOP,EVENT_STOP (128)
>>>>>> strace: pid 26302 has TCB_STARTUP, initializing it
>>>>>> strace: [wait(0x80057f) = 26302] WIFSTOPPED,sig=SIGTRAP,EVENT_STOP (128)
>>>>>> strace: [wait(0x00127f) = 26302] WIFSTOPPED,sig=SIGCONT
>>>>>> strace: [wait(0x00857f) = 26302] WIFSTOPPED,sig=133
>>>>>> execve("./a.out", ["./a.out"], ["SSH_CONNECTION=15.86.136.27 5196"...,
>>>>>> "LANG=en_US.UTF-8", "XDG_SESSION_ID=41", "USER=dayd",
>>>>>> "PWD=/home/dayd/projects/musl-tes"..., "HOME=/home/dayd",
>>>>>> "SSH_CLIENT=xx.xxx.xxx.xx 51960 22", "CCACHE_DIR=/ssd/dayd/.ccache",
>>>>>> "VMWARE_USE_SHIPPED_GTK=yes", "XDG_DATA_DIRS=/usr/local/share:/"...,
>>>>>> "USECCACHE=ON", "SSH_TTY=/dev/pts/2", "MAIL=/var/mail/dayd",
>>>>>> "TERM=rxvt-unicode-256color", "SHELL=/bin/bash", "SHLVL=1",
>>>>>> "PYTHONPATH=:/home/dayd/projects/"..., "LOGNAME=dayd",
>>>>>> "DBUS_SESSION_BUS_ADDRESS=unix:pa"...,
>>>>>> "XDG_RUNTIME_DIR=/run/user/6686",
>>>>>> "PATH=/usr/lib/ccache/bin/:/usr/l"..., "USEDISTCC=OFF",
>>>>>> "_=/usr/bin/strace", "OLDPWD=/home/dayd/projects"]strace:
>>>>>> [wait(0x04057f) = 26302] WIFSTOPPED,sig=SIGTRAP,EVENT_EXEC (4)
>>>>>> strace: [wait(0x00857f) = 26302] WIFSTOPPED,sig=133
>>>>>> ) = 0
>>>>>> strace: [wait(0x00047f) = 26302] WIFSTOPPED,sig=SIGILL
>>>>>> --- SIGILL {si_signo=SIGILL, si_code=ILL_ILLOPN, si_addr=0x40169e} ---
>>>>>> strace: [wait(0x06057f) = 26302] WIFSTOPPED,sig=SIGTRAP,EVENT_EXIT (6)
>>>>>> strace: [wait(0x000084) = 26302] WIFSIGNALED,core,sig=SIGILL
>>>>>> +++ killed by SIGILL (core dumped) +++
>>>>>> strace: dropped tcb for pid 26302, 0 remain
>>>>>> Illegal instruction (core dumped)
>>>>>> ******************************************************************************************
>>>>>> (gdb) bt
>>>>>> #0  0x00000000004016ae in __copy_tls ()
>>>>>> #1  0x0000000000000000 in ?? ()
>>>>>> *****************************************************************************************
>>>>>>
>>>>>> (gdb) disassemble
>>>>>> Dump of assembler code for function __copy_tls:
>>>>>>    0x0000000000401680 <+0>:    push   %r13
>>>>>>    0x0000000000401682 <+2>:    mov    %rdi,%r13
>>>>>>    0x0000000000401685 <+5>:    push   %r12
>>>>>>    0x0000000000401687 <+7>:    push   %rbp
>>>>>>    0x0000000000401688 <+8>:    push   %rbx
>>>>>>    0x0000000000401689 <+9>:    sub    $0x8,%rsp
>>>>>>    0x000000000040168d <+13>:    mov    0x410c(%rip),%rax        #
>>>>>> 0x4057a0 <__libc+32>
>>>>>>    0x0000000000401694 <+20>:    mov    0x410d(%rip),%rcx        #
>>>>>> 0x4057a8 <__libc+40>
>>>>>>    0x000000000040169b <+27>:    mov    0x40f6(%rip),%rbx        #
>>>>>> 0x405798 <__libc+24>
>>>>>>    0x00000000004016a2 <+34>:    lea    -0xe0(%rdi,%rax,1),%rax
>>>>>>    0x00000000004016aa <+42>:    lea    -0x1(%rcx),%r12
>>>>>> => 0x00000000004016ae <+46>:    andn   %rax,%r12,%r12
>>>>> This instruction, andn, is not in the base x86_64 ISA. It's part of
>>>>> the BMI1 extension:
>>>>>
>>>>> https://en.wikipedia.org/wiki/Bit_Manipulation_Instruction_Sets#BMI1_(Bit_Manipulation_Instruction_Set_1)
>>>>>
>>>>> Apparently Gentoo is providing cross compilers that default to
>>>>> producing "native ISA level" code for the host, rather than baseline
>>>>> ISA for the target. But:
>>>>>
>>>>>> as a bonus (I thought this might also help):
>>>>>> (%:~/projects/musl-test)┌- x86_64-pc-linux-musl-gcc -v -static -O0 -g
>>>>>> hello.c
>>>>>> Using built-in specs.
>>>>>> COLLECT_GCC=x86_64-pc-linux-musl-gcc
>>>>>> COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-pc-linux-musl/9.1.0/lto-wrapper
>>>>>> Target: x86_64-pc-linux-musl
>>>>>> Configured with:
>>>>>> /var/tmp/portage/cross-x86_64-pc-linux-musl/gcc-9.1.0/work/gcc-9.1.0/configure
>>>>>> --host=x86_64-pc-linux-gnu --target=x86_64-pc-linux-musl
>>>>>> --build=x86_64-pc-linux-gnu --prefix=/usr
>>>>>> --bindir=/usr/x86_64-pc-linux-gnu/x86_64-pc-linux-musl/gcc-bin/9.1.0
>>>>>> --includedir=/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/include
>>>>>> --datadir=/usr/share/gcc-data/x86_64-pc-linux-musl/9.1.0
>>>>>> --mandir=/usr/share/gcc-data/x86_64-pc-linux-musl/9.1.0/man
>>>>>> --infodir=/usr/share/gcc-data/x86_64-pc-linux-musl/9.1.0/info
>>>>>> --with-gxx-include-dir=/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/include/g++-v9
>>>>>> --with-python-dir=/share/gcc-data/x86_64-pc-linux-musl/9.1.0/python
>>>>>> --enable-languages=c,c++,fortran --enable-obsolete --enable-secureplt
>>>>>> --disable-werror --with-system-zlib --enable-nls
>>>>>> --without-included-gettext --enable-checking=release
>>>>>> --with-bugurl=https://bugs.gentoo.org/ --with-pkgversion='Gentoo 9.1.0
>>>>>> p1.0' --disable-esp --enable-libstdcxx-time
>>>>>> --enable-poison-system-directories
>>>>>> --with-sysroot=/usr/x86_64-pc-linux-musl --disable-bootstrap
>>>>>> --enable-__cxa_atexit --disable-multilib --with-multilib-list=m64
>>>>>> --disable-altivec --disable-fixed-point --enable-targets=all
>>>>>> --enable-libgomp --disable-libmudflap --disable-libssp
>>>>>> --disable-systemtap --disable-vtable-verify --disable-libvtv
>>>>>> --enable-lto --without-isl --disable-libsanitizer --enable-default-pie
>>>>>> --enable-default-ssp
>>>>>> Thread model: posix
>>>>>> gcc version 9.1.0 (Gentoo 9.1.0 p1.0)
>>>>>> COLLECT_GCC_OPTIONS='-v' '-static' '-O0' '-g' '-mtune=generic' '-march=x86-64'
>>>>>>  /usr/libexec/gcc/x86_64-pc-linux-musl/9.1.0/cc1 -quiet -v hello.c
>>>>>> -quiet -dumpbase hello.c -mtune=generic -march=x86-64 -auxbase hello
>>>>>> -g -O0 -version -o /tmp/ccoTkh38.s
>>>>>> GNU C17 (Gentoo 9.1.0 p1.0) version 9.1.0 (x86_64-pc-linux-musl)
>>>>>>     compiled by GNU C version 8.3.0, GMP version 6.1.2, MPFR version
>>>>>> 4.0.2, MPC version 1.1.0, isl version none
>>>>>> GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
>>>>>> ignoring nonexistent directory "/usr/x86_64-pc-linux-musl/usr/local/include"
>>>>>> ignoring nonexistent directory
>>>>>> "/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/../../../../x86_64-pc-linux-musl/include"
>>>>>> #include "..." search starts here:
>>>>>> #include <...> search starts here:
>>>>>>  /usr/x86_64-pc-linux-musl/usr/include
>>>>>>  /usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/include
>>>>>> End of search list.
>>>>>> GNU C17 (Gentoo 9.1.0 p1.0) version 9.1.0 (x86_64-pc-linux-musl)
>>>>>>     compiled by GNU C version 8.3.0, GMP version 6.1.2, MPFR version
>>>>>> 4.0.2, MPC version 1.1.0, isl version none
>>>>>> GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
>>>>>> Compiler executable checksum: a3183e5f435d1938198d432af6db159b
>>>>>> COLLECT_GCC_OPTIONS='-v' '-static' '-O0' '-g' '-mtune=generic' '-march=x86-64'
>>>>>>  /usr/libexec/gcc/x86_64-pc-linux-musl/as -v --64 -o /tmp/ccHq7CL6.o
>>>>>> /tmp/ccoTkh38.s
>>>>>> GNU assembler version 2.32.0 (x86_64-pc-linux-musl) using BFD version
>>>>>> (Gentoo 2.32 p2) 2.32.0
>>>>>> COMPILER_PATH=/usr/libexec/gcc/x86_64-pc-linux-musl/9.1.0/:/usr/libexec/gcc/x86_64-pc-linux-musl/9.1.0/:/usr/libexec/gcc/x86_64-pc-linux-musl/:/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/:/usr/lib/gcc/x86_64-pc-linux-musl/
>>>>>> LIBRARY_PATH=/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/:/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/../../../../x86_64-pc-linux-musl/lib/:/usr/x86_64-pc-linux-musl/lib/:/usr/x86_64-pc-linux-musl/usr/lib/
>>>>>> COLLECT_GCC_OPTIONS='-v' '-static' '-O0' '-g' '-mtune=generic' '-march=x86-64'
>>>>>>  /usr/libexec/gcc/x86_64-pc-linux-musl/9.1.0/collect2 -plugin
>>>>>> /usr/libexec/gcc/x86_64-pc-linux-musl/9.1.0/liblto_plugin.so
>>>>>> -plugin-opt=/usr/libexec/gcc/x86_64-pc-linux-musl/9.1.0/lto-wrapper
>>>>>> -plugin-opt=-fresolution=/tmp/ccWcifv4.res
>>>>>> -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_eh
>>>>>> -plugin-opt=-pass-through=-lc --sysroot=/usr/x86_64-pc-linux-musl -m
>>>>>> elf_x86_64 -static /usr/x86_64-pc-linux-musl/usr/lib/crt1.o
>>>>>> /usr/x86_64-pc-linux-musl/usr/lib/crti.o
>>>>>> /usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/crtbeginT.o
>>>>>> -L/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0
>>>>>> -L/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/../../../../x86_64-pc-linux-musl/lib
>>>>>> -L/usr/x86_64-pc-linux-musl/lib -L/usr/x86_64-pc-linux-musl/usr/lib
>>>>>> /tmp/ccHq7CL6.o --start-group -lgcc -lgcc_eh -lc --end-group
>>>>>> /usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/crtend.o
>>>>>> /usr/x86_64-pc-linux-musl/usr/lib/crtn.o
>>>>>> COLLECT_GCC_OPTIONS='-v' '-static' '-O0' '-g' '-mtune=generic' '-march=x86-64'
>>>>>>
>>>>>> mtune=generic and march=x86-64 suggests it isn't trying to do
>>>>>> something weird on the compile computer.
>>>>> Indeed, it looks like the default is right. So you probably need to
>>>>> check how musl was built. Is it also a package provided by Gentoo, and
>>>>> did they perhaps use -march=native even though it's being cross
>>>>> compiled?
>>>>>
>>>>> Rich
>>>



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 801 bytes --]

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

* Re: Illegal instruction in __copy_tls()
  2019-06-05 23:34               ` Michael Everitt
@ 2019-06-05 23:37                 ` tenspd137 .
  2019-06-05 23:41                   ` tenspd137 .
  2019-06-06  0:24                   ` Rich Felker
  0 siblings, 2 replies; 13+ messages in thread
From: tenspd137 . @ 2019-06-05 23:37 UTC (permalink / raw)
  To: musl

bummer....  Hmm - I wonder if an i686 cross compiler would work?

On Wed, Jun 5, 2019 at 5:34 PM Michael Everitt <m.j.everitt@iee.org> wrote:
>
> Musl doesn't support multilib ... :] fyi
>
> On 06/06/19 00:32, tenspd137 . wrote:
> > Quick question - anyone know how to make a crossdev crosscompiler
> > multilib so I can use -m32 when I compile?
> >
> > Thanks!
> >
> > On Wed, Jun 5, 2019 at 5:09 PM tenspd137 . <dcday137@gmail.com> wrote:
> >> I probably don't fully understand how it works.  In
> >> /etc/x86_64-pc-linux-musl/etc.portage/make.conf, march is not
> >> specified.  It is specified in /etc/portage/make.conf.  When I removed
> >> it from there, things worked.  Then I just put it back after using
> >> crossdev to make x86_64-pc-linux-musl-*.
> >>
> >> Either way, loads of fun :)
> >>
> >> Thanks!
> >>
> >> -C
> >>
> >> On Wed, Jun 5, 2019 at 3:56 PM Michael Everitt <m.j.everitt@iee.org> wrote:
> >>> In your /usr/${CTARGET}/etc/portage/make.conf you can set appropriate
> >>> target flags there. But using 'march=native' is going to catch you out a
> >>> lot cross-compiling anything ... :) At least if you've got it set to
> >>> something, you're going to see errors that point immediately to your CFLAGS
> >>> when/if it goes wrong!
> >>>
> >>> Michael.
> >>>
> >>> On 05/06/19 22:27, tenspd137 . wrote:
> >>>> Thanks!  That was indeed the problem.  I had march=native for all
> >>>> portage related stuff set, and my guess is that crossdev read that to
> >>>> start.  I removed that, reran the crossdev tool to buiild the cross
> >>>> toolchain, and can now build static binaries that run on different
> >>>> systems.
> >>>>
> >>>> Much appreciated!
> >>>>
> >>>> -C
> >>>>
> >>>> On Wed, Jun 5, 2019 at 2:07 PM Rich Felker <dalias@libc.org> wrote:
> >>>>> On Wed, Jun 05, 2019 at 01:53:58PM -0600, tenspd137 . wrote:
> >>>>>> Sure -
> >>>>>>
> >>>>>> strace -d -v ./a.out:
> >>>>>> strace: ptrace_setoptions = 0x51
> >>>>>> strace: new tcb for pid 26302, active tcbs:1
> >>>>>> strace: [wait(0x80137f) = 26302] WIFSTOPPED,sig=SIGSTOP,EVENT_STOP (128)
> >>>>>> strace: pid 26302 has TCB_STARTUP, initializing it
> >>>>>> strace: [wait(0x80057f) = 26302] WIFSTOPPED,sig=SIGTRAP,EVENT_STOP (128)
> >>>>>> strace: [wait(0x00127f) = 26302] WIFSTOPPED,sig=SIGCONT
> >>>>>> strace: [wait(0x00857f) = 26302] WIFSTOPPED,sig=133
> >>>>>> execve("./a.out", ["./a.out"], ["SSH_CONNECTION=15.86.136.27 5196"...,
> >>>>>> "LANG=en_US.UTF-8", "XDG_SESSION_ID=41", "USER=dayd",
> >>>>>> "PWD=/home/dayd/projects/musl-tes"..., "HOME=/home/dayd",
> >>>>>> "SSH_CLIENT=xx.xxx.xxx.xx 51960 22", "CCACHE_DIR=/ssd/dayd/.ccache",
> >>>>>> "VMWARE_USE_SHIPPED_GTK=yes", "XDG_DATA_DIRS=/usr/local/share:/"...,
> >>>>>> "USECCACHE=ON", "SSH_TTY=/dev/pts/2", "MAIL=/var/mail/dayd",
> >>>>>> "TERM=rxvt-unicode-256color", "SHELL=/bin/bash", "SHLVL=1",
> >>>>>> "PYTHONPATH=:/home/dayd/projects/"..., "LOGNAME=dayd",
> >>>>>> "DBUS_SESSION_BUS_ADDRESS=unix:pa"...,
> >>>>>> "XDG_RUNTIME_DIR=/run/user/6686",
> >>>>>> "PATH=/usr/lib/ccache/bin/:/usr/l"..., "USEDISTCC=OFF",
> >>>>>> "_=/usr/bin/strace", "OLDPWD=/home/dayd/projects"]strace:
> >>>>>> [wait(0x04057f) = 26302] WIFSTOPPED,sig=SIGTRAP,EVENT_EXEC (4)
> >>>>>> strace: [wait(0x00857f) = 26302] WIFSTOPPED,sig=133
> >>>>>> ) = 0
> >>>>>> strace: [wait(0x00047f) = 26302] WIFSTOPPED,sig=SIGILL
> >>>>>> --- SIGILL {si_signo=SIGILL, si_code=ILL_ILLOPN, si_addr=0x40169e} ---
> >>>>>> strace: [wait(0x06057f) = 26302] WIFSTOPPED,sig=SIGTRAP,EVENT_EXIT (6)
> >>>>>> strace: [wait(0x000084) = 26302] WIFSIGNALED,core,sig=SIGILL
> >>>>>> +++ killed by SIGILL (core dumped) +++
> >>>>>> strace: dropped tcb for pid 26302, 0 remain
> >>>>>> Illegal instruction (core dumped)
> >>>>>> ******************************************************************************************
> >>>>>> (gdb) bt
> >>>>>> #0  0x00000000004016ae in __copy_tls ()
> >>>>>> #1  0x0000000000000000 in ?? ()
> >>>>>> *****************************************************************************************
> >>>>>>
> >>>>>> (gdb) disassemble
> >>>>>> Dump of assembler code for function __copy_tls:
> >>>>>>    0x0000000000401680 <+0>:    push   %r13
> >>>>>>    0x0000000000401682 <+2>:    mov    %rdi,%r13
> >>>>>>    0x0000000000401685 <+5>:    push   %r12
> >>>>>>    0x0000000000401687 <+7>:    push   %rbp
> >>>>>>    0x0000000000401688 <+8>:    push   %rbx
> >>>>>>    0x0000000000401689 <+9>:    sub    $0x8,%rsp
> >>>>>>    0x000000000040168d <+13>:    mov    0x410c(%rip),%rax        #
> >>>>>> 0x4057a0 <__libc+32>
> >>>>>>    0x0000000000401694 <+20>:    mov    0x410d(%rip),%rcx        #
> >>>>>> 0x4057a8 <__libc+40>
> >>>>>>    0x000000000040169b <+27>:    mov    0x40f6(%rip),%rbx        #
> >>>>>> 0x405798 <__libc+24>
> >>>>>>    0x00000000004016a2 <+34>:    lea    -0xe0(%rdi,%rax,1),%rax
> >>>>>>    0x00000000004016aa <+42>:    lea    -0x1(%rcx),%r12
> >>>>>> => 0x00000000004016ae <+46>:    andn   %rax,%r12,%r12
> >>>>> This instruction, andn, is not in the base x86_64 ISA. It's part of
> >>>>> the BMI1 extension:
> >>>>>
> >>>>> https://en.wikipedia.org/wiki/Bit_Manipulation_Instruction_Sets#BMI1_(Bit_Manipulation_Instruction_Set_1)
> >>>>>
> >>>>> Apparently Gentoo is providing cross compilers that default to
> >>>>> producing "native ISA level" code for the host, rather than baseline
> >>>>> ISA for the target. But:
> >>>>>
> >>>>>> as a bonus (I thought this might also help):
> >>>>>> (%:~/projects/musl-test)┌- x86_64-pc-linux-musl-gcc -v -static -O0 -g
> >>>>>> hello.c
> >>>>>> Using built-in specs.
> >>>>>> COLLECT_GCC=x86_64-pc-linux-musl-gcc
> >>>>>> COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-pc-linux-musl/9.1.0/lto-wrapper
> >>>>>> Target: x86_64-pc-linux-musl
> >>>>>> Configured with:
> >>>>>> /var/tmp/portage/cross-x86_64-pc-linux-musl/gcc-9.1.0/work/gcc-9.1.0/configure
> >>>>>> --host=x86_64-pc-linux-gnu --target=x86_64-pc-linux-musl
> >>>>>> --build=x86_64-pc-linux-gnu --prefix=/usr
> >>>>>> --bindir=/usr/x86_64-pc-linux-gnu/x86_64-pc-linux-musl/gcc-bin/9.1.0
> >>>>>> --includedir=/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/include
> >>>>>> --datadir=/usr/share/gcc-data/x86_64-pc-linux-musl/9.1.0
> >>>>>> --mandir=/usr/share/gcc-data/x86_64-pc-linux-musl/9.1.0/man
> >>>>>> --infodir=/usr/share/gcc-data/x86_64-pc-linux-musl/9.1.0/info
> >>>>>> --with-gxx-include-dir=/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/include/g++-v9
> >>>>>> --with-python-dir=/share/gcc-data/x86_64-pc-linux-musl/9.1.0/python
> >>>>>> --enable-languages=c,c++,fortran --enable-obsolete --enable-secureplt
> >>>>>> --disable-werror --with-system-zlib --enable-nls
> >>>>>> --without-included-gettext --enable-checking=release
> >>>>>> --with-bugurl=https://bugs.gentoo.org/ --with-pkgversion='Gentoo 9.1.0
> >>>>>> p1.0' --disable-esp --enable-libstdcxx-time
> >>>>>> --enable-poison-system-directories
> >>>>>> --with-sysroot=/usr/x86_64-pc-linux-musl --disable-bootstrap
> >>>>>> --enable-__cxa_atexit --disable-multilib --with-multilib-list=m64
> >>>>>> --disable-altivec --disable-fixed-point --enable-targets=all
> >>>>>> --enable-libgomp --disable-libmudflap --disable-libssp
> >>>>>> --disable-systemtap --disable-vtable-verify --disable-libvtv
> >>>>>> --enable-lto --without-isl --disable-libsanitizer --enable-default-pie
> >>>>>> --enable-default-ssp
> >>>>>> Thread model: posix
> >>>>>> gcc version 9.1.0 (Gentoo 9.1.0 p1.0)
> >>>>>> COLLECT_GCC_OPTIONS='-v' '-static' '-O0' '-g' '-mtune=generic' '-march=x86-64'
> >>>>>>  /usr/libexec/gcc/x86_64-pc-linux-musl/9.1.0/cc1 -quiet -v hello.c
> >>>>>> -quiet -dumpbase hello.c -mtune=generic -march=x86-64 -auxbase hello
> >>>>>> -g -O0 -version -o /tmp/ccoTkh38.s
> >>>>>> GNU C17 (Gentoo 9.1.0 p1.0) version 9.1.0 (x86_64-pc-linux-musl)
> >>>>>>     compiled by GNU C version 8.3.0, GMP version 6.1.2, MPFR version
> >>>>>> 4.0.2, MPC version 1.1.0, isl version none
> >>>>>> GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
> >>>>>> ignoring nonexistent directory "/usr/x86_64-pc-linux-musl/usr/local/include"
> >>>>>> ignoring nonexistent directory
> >>>>>> "/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/../../../../x86_64-pc-linux-musl/include"
> >>>>>> #include "..." search starts here:
> >>>>>> #include <...> search starts here:
> >>>>>>  /usr/x86_64-pc-linux-musl/usr/include
> >>>>>>  /usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/include
> >>>>>> End of search list.
> >>>>>> GNU C17 (Gentoo 9.1.0 p1.0) version 9.1.0 (x86_64-pc-linux-musl)
> >>>>>>     compiled by GNU C version 8.3.0, GMP version 6.1.2, MPFR version
> >>>>>> 4.0.2, MPC version 1.1.0, isl version none
> >>>>>> GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
> >>>>>> Compiler executable checksum: a3183e5f435d1938198d432af6db159b
> >>>>>> COLLECT_GCC_OPTIONS='-v' '-static' '-O0' '-g' '-mtune=generic' '-march=x86-64'
> >>>>>>  /usr/libexec/gcc/x86_64-pc-linux-musl/as -v --64 -o /tmp/ccHq7CL6.o
> >>>>>> /tmp/ccoTkh38.s
> >>>>>> GNU assembler version 2.32.0 (x86_64-pc-linux-musl) using BFD version
> >>>>>> (Gentoo 2.32 p2) 2.32.0
> >>>>>> COMPILER_PATH=/usr/libexec/gcc/x86_64-pc-linux-musl/9.1.0/:/usr/libexec/gcc/x86_64-pc-linux-musl/9.1.0/:/usr/libexec/gcc/x86_64-pc-linux-musl/:/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/:/usr/lib/gcc/x86_64-pc-linux-musl/
> >>>>>> LIBRARY_PATH=/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/:/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/../../../../x86_64-pc-linux-musl/lib/:/usr/x86_64-pc-linux-musl/lib/:/usr/x86_64-pc-linux-musl/usr/lib/
> >>>>>> COLLECT_GCC_OPTIONS='-v' '-static' '-O0' '-g' '-mtune=generic' '-march=x86-64'
> >>>>>>  /usr/libexec/gcc/x86_64-pc-linux-musl/9.1.0/collect2 -plugin
> >>>>>> /usr/libexec/gcc/x86_64-pc-linux-musl/9.1.0/liblto_plugin.so
> >>>>>> -plugin-opt=/usr/libexec/gcc/x86_64-pc-linux-musl/9.1.0/lto-wrapper
> >>>>>> -plugin-opt=-fresolution=/tmp/ccWcifv4.res
> >>>>>> -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_eh
> >>>>>> -plugin-opt=-pass-through=-lc --sysroot=/usr/x86_64-pc-linux-musl -m
> >>>>>> elf_x86_64 -static /usr/x86_64-pc-linux-musl/usr/lib/crt1.o
> >>>>>> /usr/x86_64-pc-linux-musl/usr/lib/crti.o
> >>>>>> /usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/crtbeginT.o
> >>>>>> -L/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0
> >>>>>> -L/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/../../../../x86_64-pc-linux-musl/lib
> >>>>>> -L/usr/x86_64-pc-linux-musl/lib -L/usr/x86_64-pc-linux-musl/usr/lib
> >>>>>> /tmp/ccHq7CL6.o --start-group -lgcc -lgcc_eh -lc --end-group
> >>>>>> /usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/crtend.o
> >>>>>> /usr/x86_64-pc-linux-musl/usr/lib/crtn.o
> >>>>>> COLLECT_GCC_OPTIONS='-v' '-static' '-O0' '-g' '-mtune=generic' '-march=x86-64'
> >>>>>>
> >>>>>> mtune=generic and march=x86-64 suggests it isn't trying to do
> >>>>>> something weird on the compile computer.
> >>>>> Indeed, it looks like the default is right. So you probably need to
> >>>>> check how musl was built. Is it also a package provided by Gentoo, and
> >>>>> did they perhaps use -march=native even though it's being cross
> >>>>> compiled?
> >>>>>
> >>>>> Rich
> >>>
>
>


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

* Re: Illegal instruction in __copy_tls()
  2019-06-05 23:37                 ` tenspd137 .
@ 2019-06-05 23:41                   ` tenspd137 .
  2019-06-06  0:24                   ` Rich Felker
  1 sibling, 0 replies; 13+ messages in thread
From: tenspd137 . @ 2019-06-05 23:41 UTC (permalink / raw)
  To: musl

Unfortunatley, I have the task of compiling something that needs to be
32 bit and run it on an x86_64, and I need to be able to make it
static.  *sigh*

On Wed, Jun 5, 2019 at 5:37 PM tenspd137 . <dcday137@gmail.com> wrote:
>
> bummer....  Hmm - I wonder if an i686 cross compiler would work?
>
> On Wed, Jun 5, 2019 at 5:34 PM Michael Everitt <m.j.everitt@iee.org> wrote:
> >
> > Musl doesn't support multilib ... :] fyi
> >
> > On 06/06/19 00:32, tenspd137 . wrote:
> > > Quick question - anyone know how to make a crossdev crosscompiler
> > > multilib so I can use -m32 when I compile?
> > >
> > > Thanks!
> > >
> > > On Wed, Jun 5, 2019 at 5:09 PM tenspd137 . <dcday137@gmail.com> wrote:
> > >> I probably don't fully understand how it works.  In
> > >> /etc/x86_64-pc-linux-musl/etc.portage/make.conf, march is not
> > >> specified.  It is specified in /etc/portage/make.conf.  When I removed
> > >> it from there, things worked.  Then I just put it back after using
> > >> crossdev to make x86_64-pc-linux-musl-*.
> > >>
> > >> Either way, loads of fun :)
> > >>
> > >> Thanks!
> > >>
> > >> -C
> > >>
> > >> On Wed, Jun 5, 2019 at 3:56 PM Michael Everitt <m.j.everitt@iee.org> wrote:
> > >>> In your /usr/${CTARGET}/etc/portage/make.conf you can set appropriate
> > >>> target flags there. But using 'march=native' is going to catch you out a
> > >>> lot cross-compiling anything ... :) At least if you've got it set to
> > >>> something, you're going to see errors that point immediately to your CFLAGS
> > >>> when/if it goes wrong!
> > >>>
> > >>> Michael.
> > >>>
> > >>> On 05/06/19 22:27, tenspd137 . wrote:
> > >>>> Thanks!  That was indeed the problem.  I had march=native for all
> > >>>> portage related stuff set, and my guess is that crossdev read that to
> > >>>> start.  I removed that, reran the crossdev tool to buiild the cross
> > >>>> toolchain, and can now build static binaries that run on different
> > >>>> systems.
> > >>>>
> > >>>> Much appreciated!
> > >>>>
> > >>>> -C
> > >>>>
> > >>>> On Wed, Jun 5, 2019 at 2:07 PM Rich Felker <dalias@libc.org> wrote:
> > >>>>> On Wed, Jun 05, 2019 at 01:53:58PM -0600, tenspd137 . wrote:
> > >>>>>> Sure -
> > >>>>>>
> > >>>>>> strace -d -v ./a.out:
> > >>>>>> strace: ptrace_setoptions = 0x51
> > >>>>>> strace: new tcb for pid 26302, active tcbs:1
> > >>>>>> strace: [wait(0x80137f) = 26302] WIFSTOPPED,sig=SIGSTOP,EVENT_STOP (128)
> > >>>>>> strace: pid 26302 has TCB_STARTUP, initializing it
> > >>>>>> strace: [wait(0x80057f) = 26302] WIFSTOPPED,sig=SIGTRAP,EVENT_STOP (128)
> > >>>>>> strace: [wait(0x00127f) = 26302] WIFSTOPPED,sig=SIGCONT
> > >>>>>> strace: [wait(0x00857f) = 26302] WIFSTOPPED,sig=133
> > >>>>>> execve("./a.out", ["./a.out"], ["SSH_CONNECTION=15.86.136.27 5196"...,
> > >>>>>> "LANG=en_US.UTF-8", "XDG_SESSION_ID=41", "USER=dayd",
> > >>>>>> "PWD=/home/dayd/projects/musl-tes"..., "HOME=/home/dayd",
> > >>>>>> "SSH_CLIENT=xx.xxx.xxx.xx 51960 22", "CCACHE_DIR=/ssd/dayd/.ccache",
> > >>>>>> "VMWARE_USE_SHIPPED_GTK=yes", "XDG_DATA_DIRS=/usr/local/share:/"...,
> > >>>>>> "USECCACHE=ON", "SSH_TTY=/dev/pts/2", "MAIL=/var/mail/dayd",
> > >>>>>> "TERM=rxvt-unicode-256color", "SHELL=/bin/bash", "SHLVL=1",
> > >>>>>> "PYTHONPATH=:/home/dayd/projects/"..., "LOGNAME=dayd",
> > >>>>>> "DBUS_SESSION_BUS_ADDRESS=unix:pa"...,
> > >>>>>> "XDG_RUNTIME_DIR=/run/user/6686",
> > >>>>>> "PATH=/usr/lib/ccache/bin/:/usr/l"..., "USEDISTCC=OFF",
> > >>>>>> "_=/usr/bin/strace", "OLDPWD=/home/dayd/projects"]strace:
> > >>>>>> [wait(0x04057f) = 26302] WIFSTOPPED,sig=SIGTRAP,EVENT_EXEC (4)
> > >>>>>> strace: [wait(0x00857f) = 26302] WIFSTOPPED,sig=133
> > >>>>>> ) = 0
> > >>>>>> strace: [wait(0x00047f) = 26302] WIFSTOPPED,sig=SIGILL
> > >>>>>> --- SIGILL {si_signo=SIGILL, si_code=ILL_ILLOPN, si_addr=0x40169e} ---
> > >>>>>> strace: [wait(0x06057f) = 26302] WIFSTOPPED,sig=SIGTRAP,EVENT_EXIT (6)
> > >>>>>> strace: [wait(0x000084) = 26302] WIFSIGNALED,core,sig=SIGILL
> > >>>>>> +++ killed by SIGILL (core dumped) +++
> > >>>>>> strace: dropped tcb for pid 26302, 0 remain
> > >>>>>> Illegal instruction (core dumped)
> > >>>>>> ******************************************************************************************
> > >>>>>> (gdb) bt
> > >>>>>> #0  0x00000000004016ae in __copy_tls ()
> > >>>>>> #1  0x0000000000000000 in ?? ()
> > >>>>>> *****************************************************************************************
> > >>>>>>
> > >>>>>> (gdb) disassemble
> > >>>>>> Dump of assembler code for function __copy_tls:
> > >>>>>>    0x0000000000401680 <+0>:    push   %r13
> > >>>>>>    0x0000000000401682 <+2>:    mov    %rdi,%r13
> > >>>>>>    0x0000000000401685 <+5>:    push   %r12
> > >>>>>>    0x0000000000401687 <+7>:    push   %rbp
> > >>>>>>    0x0000000000401688 <+8>:    push   %rbx
> > >>>>>>    0x0000000000401689 <+9>:    sub    $0x8,%rsp
> > >>>>>>    0x000000000040168d <+13>:    mov    0x410c(%rip),%rax        #
> > >>>>>> 0x4057a0 <__libc+32>
> > >>>>>>    0x0000000000401694 <+20>:    mov    0x410d(%rip),%rcx        #
> > >>>>>> 0x4057a8 <__libc+40>
> > >>>>>>    0x000000000040169b <+27>:    mov    0x40f6(%rip),%rbx        #
> > >>>>>> 0x405798 <__libc+24>
> > >>>>>>    0x00000000004016a2 <+34>:    lea    -0xe0(%rdi,%rax,1),%rax
> > >>>>>>    0x00000000004016aa <+42>:    lea    -0x1(%rcx),%r12
> > >>>>>> => 0x00000000004016ae <+46>:    andn   %rax,%r12,%r12
> > >>>>> This instruction, andn, is not in the base x86_64 ISA. It's part of
> > >>>>> the BMI1 extension:
> > >>>>>
> > >>>>> https://en.wikipedia.org/wiki/Bit_Manipulation_Instruction_Sets#BMI1_(Bit_Manipulation_Instruction_Set_1)
> > >>>>>
> > >>>>> Apparently Gentoo is providing cross compilers that default to
> > >>>>> producing "native ISA level" code for the host, rather than baseline
> > >>>>> ISA for the target. But:
> > >>>>>
> > >>>>>> as a bonus (I thought this might also help):
> > >>>>>> (%:~/projects/musl-test)┌- x86_64-pc-linux-musl-gcc -v -static -O0 -g
> > >>>>>> hello.c
> > >>>>>> Using built-in specs.
> > >>>>>> COLLECT_GCC=x86_64-pc-linux-musl-gcc
> > >>>>>> COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-pc-linux-musl/9.1.0/lto-wrapper
> > >>>>>> Target: x86_64-pc-linux-musl
> > >>>>>> Configured with:
> > >>>>>> /var/tmp/portage/cross-x86_64-pc-linux-musl/gcc-9.1.0/work/gcc-9.1.0/configure
> > >>>>>> --host=x86_64-pc-linux-gnu --target=x86_64-pc-linux-musl
> > >>>>>> --build=x86_64-pc-linux-gnu --prefix=/usr
> > >>>>>> --bindir=/usr/x86_64-pc-linux-gnu/x86_64-pc-linux-musl/gcc-bin/9.1.0
> > >>>>>> --includedir=/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/include
> > >>>>>> --datadir=/usr/share/gcc-data/x86_64-pc-linux-musl/9.1.0
> > >>>>>> --mandir=/usr/share/gcc-data/x86_64-pc-linux-musl/9.1.0/man
> > >>>>>> --infodir=/usr/share/gcc-data/x86_64-pc-linux-musl/9.1.0/info
> > >>>>>> --with-gxx-include-dir=/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/include/g++-v9
> > >>>>>> --with-python-dir=/share/gcc-data/x86_64-pc-linux-musl/9.1.0/python
> > >>>>>> --enable-languages=c,c++,fortran --enable-obsolete --enable-secureplt
> > >>>>>> --disable-werror --with-system-zlib --enable-nls
> > >>>>>> --without-included-gettext --enable-checking=release
> > >>>>>> --with-bugurl=https://bugs.gentoo.org/ --with-pkgversion='Gentoo 9.1.0
> > >>>>>> p1.0' --disable-esp --enable-libstdcxx-time
> > >>>>>> --enable-poison-system-directories
> > >>>>>> --with-sysroot=/usr/x86_64-pc-linux-musl --disable-bootstrap
> > >>>>>> --enable-__cxa_atexit --disable-multilib --with-multilib-list=m64
> > >>>>>> --disable-altivec --disable-fixed-point --enable-targets=all
> > >>>>>> --enable-libgomp --disable-libmudflap --disable-libssp
> > >>>>>> --disable-systemtap --disable-vtable-verify --disable-libvtv
> > >>>>>> --enable-lto --without-isl --disable-libsanitizer --enable-default-pie
> > >>>>>> --enable-default-ssp
> > >>>>>> Thread model: posix
> > >>>>>> gcc version 9.1.0 (Gentoo 9.1.0 p1.0)
> > >>>>>> COLLECT_GCC_OPTIONS='-v' '-static' '-O0' '-g' '-mtune=generic' '-march=x86-64'
> > >>>>>>  /usr/libexec/gcc/x86_64-pc-linux-musl/9.1.0/cc1 -quiet -v hello.c
> > >>>>>> -quiet -dumpbase hello.c -mtune=generic -march=x86-64 -auxbase hello
> > >>>>>> -g -O0 -version -o /tmp/ccoTkh38.s
> > >>>>>> GNU C17 (Gentoo 9.1.0 p1.0) version 9.1.0 (x86_64-pc-linux-musl)
> > >>>>>>     compiled by GNU C version 8.3.0, GMP version 6.1.2, MPFR version
> > >>>>>> 4.0.2, MPC version 1.1.0, isl version none
> > >>>>>> GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
> > >>>>>> ignoring nonexistent directory "/usr/x86_64-pc-linux-musl/usr/local/include"
> > >>>>>> ignoring nonexistent directory
> > >>>>>> "/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/../../../../x86_64-pc-linux-musl/include"
> > >>>>>> #include "..." search starts here:
> > >>>>>> #include <...> search starts here:
> > >>>>>>  /usr/x86_64-pc-linux-musl/usr/include
> > >>>>>>  /usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/include
> > >>>>>> End of search list.
> > >>>>>> GNU C17 (Gentoo 9.1.0 p1.0) version 9.1.0 (x86_64-pc-linux-musl)
> > >>>>>>     compiled by GNU C version 8.3.0, GMP version 6.1.2, MPFR version
> > >>>>>> 4.0.2, MPC version 1.1.0, isl version none
> > >>>>>> GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
> > >>>>>> Compiler executable checksum: a3183e5f435d1938198d432af6db159b
> > >>>>>> COLLECT_GCC_OPTIONS='-v' '-static' '-O0' '-g' '-mtune=generic' '-march=x86-64'
> > >>>>>>  /usr/libexec/gcc/x86_64-pc-linux-musl/as -v --64 -o /tmp/ccHq7CL6.o
> > >>>>>> /tmp/ccoTkh38.s
> > >>>>>> GNU assembler version 2.32.0 (x86_64-pc-linux-musl) using BFD version
> > >>>>>> (Gentoo 2.32 p2) 2.32.0
> > >>>>>> COMPILER_PATH=/usr/libexec/gcc/x86_64-pc-linux-musl/9.1.0/:/usr/libexec/gcc/x86_64-pc-linux-musl/9.1.0/:/usr/libexec/gcc/x86_64-pc-linux-musl/:/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/:/usr/lib/gcc/x86_64-pc-linux-musl/
> > >>>>>> LIBRARY_PATH=/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/:/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/../../../../x86_64-pc-linux-musl/lib/:/usr/x86_64-pc-linux-musl/lib/:/usr/x86_64-pc-linux-musl/usr/lib/
> > >>>>>> COLLECT_GCC_OPTIONS='-v' '-static' '-O0' '-g' '-mtune=generic' '-march=x86-64'
> > >>>>>>  /usr/libexec/gcc/x86_64-pc-linux-musl/9.1.0/collect2 -plugin
> > >>>>>> /usr/libexec/gcc/x86_64-pc-linux-musl/9.1.0/liblto_plugin.so
> > >>>>>> -plugin-opt=/usr/libexec/gcc/x86_64-pc-linux-musl/9.1.0/lto-wrapper
> > >>>>>> -plugin-opt=-fresolution=/tmp/ccWcifv4.res
> > >>>>>> -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_eh
> > >>>>>> -plugin-opt=-pass-through=-lc --sysroot=/usr/x86_64-pc-linux-musl -m
> > >>>>>> elf_x86_64 -static /usr/x86_64-pc-linux-musl/usr/lib/crt1.o
> > >>>>>> /usr/x86_64-pc-linux-musl/usr/lib/crti.o
> > >>>>>> /usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/crtbeginT.o
> > >>>>>> -L/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0
> > >>>>>> -L/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/../../../../x86_64-pc-linux-musl/lib
> > >>>>>> -L/usr/x86_64-pc-linux-musl/lib -L/usr/x86_64-pc-linux-musl/usr/lib
> > >>>>>> /tmp/ccHq7CL6.o --start-group -lgcc -lgcc_eh -lc --end-group
> > >>>>>> /usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/crtend.o
> > >>>>>> /usr/x86_64-pc-linux-musl/usr/lib/crtn.o
> > >>>>>> COLLECT_GCC_OPTIONS='-v' '-static' '-O0' '-g' '-mtune=generic' '-march=x86-64'
> > >>>>>>
> > >>>>>> mtune=generic and march=x86-64 suggests it isn't trying to do
> > >>>>>> something weird on the compile computer.
> > >>>>> Indeed, it looks like the default is right. So you probably need to
> > >>>>> check how musl was built. Is it also a package provided by Gentoo, and
> > >>>>> did they perhaps use -march=native even though it's being cross
> > >>>>> compiled?
> > >>>>>
> > >>>>> Rich
> > >>>
> >
> >


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

* Re: Illegal instruction in __copy_tls()
  2019-06-05 23:37                 ` tenspd137 .
  2019-06-05 23:41                   ` tenspd137 .
@ 2019-06-06  0:24                   ` Rich Felker
  2019-06-06  0:34                     ` tenspd137 .
  1 sibling, 1 reply; 13+ messages in thread
From: Rich Felker @ 2019-06-06  0:24 UTC (permalink / raw)
  To: tenspd137 .; +Cc: musl

On Wed, Jun 05, 2019 at 05:37:49PM -0600, tenspd137 . wrote:
> bummer....  Hmm - I wonder if an i686 cross compiler would work?

Yes, you can do that. It's just that gcc's multilib dir layout is not
compatible with musl -- it assumes library headers can be shared
between 32- and 64-bit versions of "the same" arch rather than
treating them as completely separate things.

Rich


> On Wed, Jun 5, 2019 at 5:34 PM Michael Everitt <m.j.everitt@iee.org> wrote:
> >
> > Musl doesn't support multilib ... :] fyi
> >
> > On 06/06/19 00:32, tenspd137 . wrote:
> > > Quick question - anyone know how to make a crossdev crosscompiler
> > > multilib so I can use -m32 when I compile?
> > >
> > > Thanks!
> > >
> > > On Wed, Jun 5, 2019 at 5:09 PM tenspd137 . <dcday137@gmail.com> wrote:
> > >> I probably don't fully understand how it works.  In
> > >> /etc/x86_64-pc-linux-musl/etc.portage/make.conf, march is not
> > >> specified.  It is specified in /etc/portage/make.conf.  When I removed
> > >> it from there, things worked.  Then I just put it back after using
> > >> crossdev to make x86_64-pc-linux-musl-*.
> > >>
> > >> Either way, loads of fun :)
> > >>
> > >> Thanks!
> > >>
> > >> -C
> > >>
> > >> On Wed, Jun 5, 2019 at 3:56 PM Michael Everitt <m.j.everitt@iee.org> wrote:
> > >>> In your /usr/${CTARGET}/etc/portage/make.conf you can set appropriate
> > >>> target flags there. But using 'march=native' is going to catch you out a
> > >>> lot cross-compiling anything ... :) At least if you've got it set to
> > >>> something, you're going to see errors that point immediately to your CFLAGS
> > >>> when/if it goes wrong!
> > >>>
> > >>> Michael.
> > >>>
> > >>> On 05/06/19 22:27, tenspd137 . wrote:
> > >>>> Thanks!  That was indeed the problem.  I had march=native for all
> > >>>> portage related stuff set, and my guess is that crossdev read that to
> > >>>> start.  I removed that, reran the crossdev tool to buiild the cross
> > >>>> toolchain, and can now build static binaries that run on different
> > >>>> systems.
> > >>>>
> > >>>> Much appreciated!
> > >>>>
> > >>>> -C
> > >>>>
> > >>>> On Wed, Jun 5, 2019 at 2:07 PM Rich Felker <dalias@libc.org> wrote:
> > >>>>> On Wed, Jun 05, 2019 at 01:53:58PM -0600, tenspd137 . wrote:
> > >>>>>> Sure -
> > >>>>>>
> > >>>>>> strace -d -v ./a.out:
> > >>>>>> strace: ptrace_setoptions = 0x51
> > >>>>>> strace: new tcb for pid 26302, active tcbs:1
> > >>>>>> strace: [wait(0x80137f) = 26302] WIFSTOPPED,sig=SIGSTOP,EVENT_STOP (128)
> > >>>>>> strace: pid 26302 has TCB_STARTUP, initializing it
> > >>>>>> strace: [wait(0x80057f) = 26302] WIFSTOPPED,sig=SIGTRAP,EVENT_STOP (128)
> > >>>>>> strace: [wait(0x00127f) = 26302] WIFSTOPPED,sig=SIGCONT
> > >>>>>> strace: [wait(0x00857f) = 26302] WIFSTOPPED,sig=133
> > >>>>>> execve("./a.out", ["./a.out"], ["SSH_CONNECTION=15.86.136.27 5196"...,
> > >>>>>> "LANG=en_US.UTF-8", "XDG_SESSION_ID=41", "USER=dayd",
> > >>>>>> "PWD=/home/dayd/projects/musl-tes"..., "HOME=/home/dayd",
> > >>>>>> "SSH_CLIENT=xx.xxx.xxx.xx 51960 22", "CCACHE_DIR=/ssd/dayd/.ccache",
> > >>>>>> "VMWARE_USE_SHIPPED_GTK=yes", "XDG_DATA_DIRS=/usr/local/share:/"...,
> > >>>>>> "USECCACHE=ON", "SSH_TTY=/dev/pts/2", "MAIL=/var/mail/dayd",
> > >>>>>> "TERM=rxvt-unicode-256color", "SHELL=/bin/bash", "SHLVL=1",
> > >>>>>> "PYTHONPATH=:/home/dayd/projects/"..., "LOGNAME=dayd",
> > >>>>>> "DBUS_SESSION_BUS_ADDRESS=unix:pa"...,
> > >>>>>> "XDG_RUNTIME_DIR=/run/user/6686",
> > >>>>>> "PATH=/usr/lib/ccache/bin/:/usr/l"..., "USEDISTCC=OFF",
> > >>>>>> "_=/usr/bin/strace", "OLDPWD=/home/dayd/projects"]strace:
> > >>>>>> [wait(0x04057f) = 26302] WIFSTOPPED,sig=SIGTRAP,EVENT_EXEC (4)
> > >>>>>> strace: [wait(0x00857f) = 26302] WIFSTOPPED,sig=133
> > >>>>>> ) = 0
> > >>>>>> strace: [wait(0x00047f) = 26302] WIFSTOPPED,sig=SIGILL
> > >>>>>> --- SIGILL {si_signo=SIGILL, si_code=ILL_ILLOPN, si_addr=0x40169e} ---
> > >>>>>> strace: [wait(0x06057f) = 26302] WIFSTOPPED,sig=SIGTRAP,EVENT_EXIT (6)
> > >>>>>> strace: [wait(0x000084) = 26302] WIFSIGNALED,core,sig=SIGILL
> > >>>>>> +++ killed by SIGILL (core dumped) +++
> > >>>>>> strace: dropped tcb for pid 26302, 0 remain
> > >>>>>> Illegal instruction (core dumped)
> > >>>>>> ******************************************************************************************
> > >>>>>> (gdb) bt
> > >>>>>> #0  0x00000000004016ae in __copy_tls ()
> > >>>>>> #1  0x0000000000000000 in ?? ()
> > >>>>>> *****************************************************************************************
> > >>>>>>
> > >>>>>> (gdb) disassemble
> > >>>>>> Dump of assembler code for function __copy_tls:
> > >>>>>>    0x0000000000401680 <+0>:    push   %r13
> > >>>>>>    0x0000000000401682 <+2>:    mov    %rdi,%r13
> > >>>>>>    0x0000000000401685 <+5>:    push   %r12
> > >>>>>>    0x0000000000401687 <+7>:    push   %rbp
> > >>>>>>    0x0000000000401688 <+8>:    push   %rbx
> > >>>>>>    0x0000000000401689 <+9>:    sub    $0x8,%rsp
> > >>>>>>    0x000000000040168d <+13>:    mov    0x410c(%rip),%rax        #
> > >>>>>> 0x4057a0 <__libc+32>
> > >>>>>>    0x0000000000401694 <+20>:    mov    0x410d(%rip),%rcx        #
> > >>>>>> 0x4057a8 <__libc+40>
> > >>>>>>    0x000000000040169b <+27>:    mov    0x40f6(%rip),%rbx        #
> > >>>>>> 0x405798 <__libc+24>
> > >>>>>>    0x00000000004016a2 <+34>:    lea    -0xe0(%rdi,%rax,1),%rax
> > >>>>>>    0x00000000004016aa <+42>:    lea    -0x1(%rcx),%r12
> > >>>>>> => 0x00000000004016ae <+46>:    andn   %rax,%r12,%r12
> > >>>>> This instruction, andn, is not in the base x86_64 ISA. It's part of
> > >>>>> the BMI1 extension:
> > >>>>>
> > >>>>> https://en.wikipedia.org/wiki/Bit_Manipulation_Instruction_Sets#BMI1_(Bit_Manipulation_Instruction_Set_1)
> > >>>>>
> > >>>>> Apparently Gentoo is providing cross compilers that default to
> > >>>>> producing "native ISA level" code for the host, rather than baseline
> > >>>>> ISA for the target. But:
> > >>>>>
> > >>>>>> as a bonus (I thought this might also help):
> > >>>>>> (%:~/projects/musl-test)┌- x86_64-pc-linux-musl-gcc -v -static -O0 -g
> > >>>>>> hello.c
> > >>>>>> Using built-in specs.
> > >>>>>> COLLECT_GCC=x86_64-pc-linux-musl-gcc
> > >>>>>> COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-pc-linux-musl/9.1.0/lto-wrapper
> > >>>>>> Target: x86_64-pc-linux-musl
> > >>>>>> Configured with:
> > >>>>>> /var/tmp/portage/cross-x86_64-pc-linux-musl/gcc-9.1.0/work/gcc-9.1..0/configure
> > >>>>>> --host=x86_64-pc-linux-gnu --target=x86_64-pc-linux-musl
> > >>>>>> --build=x86_64-pc-linux-gnu --prefix=/usr
> > >>>>>> --bindir=/usr/x86_64-pc-linux-gnu/x86_64-pc-linux-musl/gcc-bin/9..1.0
> > >>>>>> --includedir=/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/include
> > >>>>>> --datadir=/usr/share/gcc-data/x86_64-pc-linux-musl/9.1.0
> > >>>>>> --mandir=/usr/share/gcc-data/x86_64-pc-linux-musl/9.1.0/man
> > >>>>>> --infodir=/usr/share/gcc-data/x86_64-pc-linux-musl/9.1.0/info
> > >>>>>> --with-gxx-include-dir=/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/include/g++-v9
> > >>>>>> --with-python-dir=/share/gcc-data/x86_64-pc-linux-musl/9.1.0/python
> > >>>>>> --enable-languages=c,c++,fortran --enable-obsolete --enable-secureplt
> > >>>>>> --disable-werror --with-system-zlib --enable-nls
> > >>>>>> --without-included-gettext --enable-checking=release
> > >>>>>> --with-bugurl=https://bugs.gentoo.org/ --with-pkgversion='Gentoo 9.1.0
> > >>>>>> p1.0' --disable-esp --enable-libstdcxx-time
> > >>>>>> --enable-poison-system-directories
> > >>>>>> --with-sysroot=/usr/x86_64-pc-linux-musl --disable-bootstrap
> > >>>>>> --enable-__cxa_atexit --disable-multilib --with-multilib-list=m64
> > >>>>>> --disable-altivec --disable-fixed-point --enable-targets=all
> > >>>>>> --enable-libgomp --disable-libmudflap --disable-libssp
> > >>>>>> --disable-systemtap --disable-vtable-verify --disable-libvtv
> > >>>>>> --enable-lto --without-isl --disable-libsanitizer --enable-default-pie
> > >>>>>> --enable-default-ssp
> > >>>>>> Thread model: posix
> > >>>>>> gcc version 9.1.0 (Gentoo 9.1.0 p1.0)
> > >>>>>> COLLECT_GCC_OPTIONS='-v' '-static' '-O0' '-g' '-mtune=generic' '-march=x86-64'
> > >>>>>>  /usr/libexec/gcc/x86_64-pc-linux-musl/9.1.0/cc1 -quiet -v hello.c
> > >>>>>> -quiet -dumpbase hello.c -mtune=generic -march=x86-64 -auxbase hello
> > >>>>>> -g -O0 -version -o /tmp/ccoTkh38.s
> > >>>>>> GNU C17 (Gentoo 9.1.0 p1.0) version 9.1.0 (x86_64-pc-linux-musl)
> > >>>>>>     compiled by GNU C version 8.3.0, GMP version 6.1.2, MPFR version
> > >>>>>> 4.0.2, MPC version 1.1.0, isl version none
> > >>>>>> GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
> > >>>>>> ignoring nonexistent directory "/usr/x86_64-pc-linux-musl/usr/local/include"
> > >>>>>> ignoring nonexistent directory
> > >>>>>> "/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/../../../../x86_64-pc-linux-musl/include"
> > >>>>>> #include "..." search starts here:
> > >>>>>> #include <...> search starts here:
> > >>>>>>  /usr/x86_64-pc-linux-musl/usr/include
> > >>>>>>  /usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/include
> > >>>>>> End of search list.
> > >>>>>> GNU C17 (Gentoo 9.1.0 p1.0) version 9.1.0 (x86_64-pc-linux-musl)
> > >>>>>>     compiled by GNU C version 8.3.0, GMP version 6.1.2, MPFR version
> > >>>>>> 4.0.2, MPC version 1.1.0, isl version none
> > >>>>>> GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
> > >>>>>> Compiler executable checksum: a3183e5f435d1938198d432af6db159b
> > >>>>>> COLLECT_GCC_OPTIONS='-v' '-static' '-O0' '-g' '-mtune=generic' '-march=x86-64'
> > >>>>>>  /usr/libexec/gcc/x86_64-pc-linux-musl/as -v --64 -o /tmp/ccHq7CL6..o
> > >>>>>> /tmp/ccoTkh38.s
> > >>>>>> GNU assembler version 2.32.0 (x86_64-pc-linux-musl) using BFD version
> > >>>>>> (Gentoo 2.32 p2) 2.32.0
> > >>>>>> COMPILER_PATH=/usr/libexec/gcc/x86_64-pc-linux-musl/9.1.0/:/usr/libexec/gcc/x86_64-pc-linux-musl/9.1.0/:/usr/libexec/gcc/x86_64-pc-linux-musl/:/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/:/usr/lib/gcc/x86_64-pc-linux-musl/
> > >>>>>> LIBRARY_PATH=/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/:/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/../../../../x86_64-pc-linux-musl/lib/:/usr/x86_64-pc-linux-musl/lib/:/usr/x86_64-pc-linux-musl/usr/lib/
> > >>>>>> COLLECT_GCC_OPTIONS='-v' '-static' '-O0' '-g' '-mtune=generic' '-march=x86-64'
> > >>>>>>  /usr/libexec/gcc/x86_64-pc-linux-musl/9.1.0/collect2 -plugin
> > >>>>>> /usr/libexec/gcc/x86_64-pc-linux-musl/9.1.0/liblto_plugin.so
> > >>>>>> -plugin-opt=/usr/libexec/gcc/x86_64-pc-linux-musl/9.1.0/lto-wrapper
> > >>>>>> -plugin-opt=-fresolution=/tmp/ccWcifv4.res
> > >>>>>> -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_eh
> > >>>>>> -plugin-opt=-pass-through=-lc --sysroot=/usr/x86_64-pc-linux-musl -m
> > >>>>>> elf_x86_64 -static /usr/x86_64-pc-linux-musl/usr/lib/crt1.o
> > >>>>>> /usr/x86_64-pc-linux-musl/usr/lib/crti.o
> > >>>>>> /usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/crtbeginT.o
> > >>>>>> -L/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0
> > >>>>>> -L/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/../../../../x86_64-pc-linux-musl/lib
> > >>>>>> -L/usr/x86_64-pc-linux-musl/lib -L/usr/x86_64-pc-linux-musl/usr/lib
> > >>>>>> /tmp/ccHq7CL6.o --start-group -lgcc -lgcc_eh -lc --end-group
> > >>>>>> /usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/crtend.o
> > >>>>>> /usr/x86_64-pc-linux-musl/usr/lib/crtn.o
> > >>>>>> COLLECT_GCC_OPTIONS='-v' '-static' '-O0' '-g' '-mtune=generic' '-march=x86-64'
> > >>>>>>
> > >>>>>> mtune=generic and march=x86-64 suggests it isn't trying to do
> > >>>>>> something weird on the compile computer.
> > >>>>> Indeed, it looks like the default is right. So you probably need to
> > >>>>> check how musl was built. Is it also a package provided by Gentoo, and
> > >>>>> did they perhaps use -march=native even though it's being cross
> > >>>>> compiled?
> > >>>>>
> > >>>>> Rich
> > >>>
> >
> >


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

* Re: Illegal instruction in __copy_tls()
  2019-06-06  0:24                   ` Rich Felker
@ 2019-06-06  0:34                     ` tenspd137 .
  0 siblings, 0 replies; 13+ messages in thread
From: tenspd137 . @ 2019-06-06  0:34 UTC (permalink / raw)
  To: Rich Felker; +Cc: musl

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

Thanks everyone for all your help!  I think I have a way forward then.
Much appreciated!

C

On Wed, Jun 5, 2019, 6:24 PM Rich Felker <dalias@libc.org> wrote:

> On Wed, Jun 05, 2019 at 05:37:49PM -0600, tenspd137 . wrote:
> > bummer....  Hmm - I wonder if an i686 cross compiler would work?
>
> Yes, you can do that. It's just that gcc's multilib dir layout is not
> compatible with musl -- it assumes library headers can be shared
> between 32- and 64-bit versions of "the same" arch rather than
> treating them as completely separate things.
>
> Rich
>
>
> > On Wed, Jun 5, 2019 at 5:34 PM Michael Everitt <m.j.everitt@iee.org>
> wrote:
> > >
> > > Musl doesn't support multilib ... :] fyi
> > >
> > > On 06/06/19 00:32, tenspd137 . wrote:
> > > > Quick question - anyone know how to make a crossdev crosscompiler
> > > > multilib so I can use -m32 when I compile?
> > > >
> > > > Thanks!
> > > >
> > > > On Wed, Jun 5, 2019 at 5:09 PM tenspd137 . <dcday137@gmail.com>
> wrote:
> > > >> I probably don't fully understand how it works.  In
> > > >> /etc/x86_64-pc-linux-musl/etc.portage/make.conf, march is not
> > > >> specified.  It is specified in /etc/portage/make.conf.  When I
> removed
> > > >> it from there, things worked.  Then I just put it back after using
> > > >> crossdev to make x86_64-pc-linux-musl-*.
> > > >>
> > > >> Either way, loads of fun :)
> > > >>
> > > >> Thanks!
> > > >>
> > > >> -C
> > > >>
> > > >> On Wed, Jun 5, 2019 at 3:56 PM Michael Everitt <m.j.everitt@iee.org>
> wrote:
> > > >>> In your /usr/${CTARGET}/etc/portage/make.conf you can set
> appropriate
> > > >>> target flags there. But using 'march=native' is going to catch you
> out a
> > > >>> lot cross-compiling anything ... :) At least if you've got it set
> to
> > > >>> something, you're going to see errors that point immediately to
> your CFLAGS
> > > >>> when/if it goes wrong!
> > > >>>
> > > >>> Michael.
> > > >>>
> > > >>> On 05/06/19 22:27, tenspd137 . wrote:
> > > >>>> Thanks!  That was indeed the problem.  I had march=native for all
> > > >>>> portage related stuff set, and my guess is that crossdev read
> that to
> > > >>>> start.  I removed that, reran the crossdev tool to buiild the
> cross
> > > >>>> toolchain, and can now build static binaries that run on different
> > > >>>> systems.
> > > >>>>
> > > >>>> Much appreciated!
> > > >>>>
> > > >>>> -C
> > > >>>>
> > > >>>> On Wed, Jun 5, 2019 at 2:07 PM Rich Felker <dalias@libc.org>
> wrote:
> > > >>>>> On Wed, Jun 05, 2019 at 01:53:58PM -0600, tenspd137 . wrote:
> > > >>>>>> Sure -
> > > >>>>>>
> > > >>>>>> strace -d -v ./a.out:
> > > >>>>>> strace: ptrace_setoptions = 0x51
> > > >>>>>> strace: new tcb for pid 26302, active tcbs:1
> > > >>>>>> strace: [wait(0x80137f) = 26302]
> WIFSTOPPED,sig=SIGSTOP,EVENT_STOP (128)
> > > >>>>>> strace: pid 26302 has TCB_STARTUP, initializing it
> > > >>>>>> strace: [wait(0x80057f) = 26302]
> WIFSTOPPED,sig=SIGTRAP,EVENT_STOP (128)
> > > >>>>>> strace: [wait(0x00127f) = 26302] WIFSTOPPED,sig=SIGCONT
> > > >>>>>> strace: [wait(0x00857f) = 26302] WIFSTOPPED,sig=133
> > > >>>>>> execve("./a.out", ["./a.out"], ["SSH_CONNECTION=15.86.136.27
> 5196"...,
> > > >>>>>> "LANG=en_US.UTF-8", "XDG_SESSION_ID=41", "USER=dayd",
> > > >>>>>> "PWD=/home/dayd/projects/musl-tes"..., "HOME=/home/dayd",
> > > >>>>>> "SSH_CLIENT=xx.xxx.xxx.xx 51960 22",
> "CCACHE_DIR=/ssd/dayd/.ccache",
> > > >>>>>> "VMWARE_USE_SHIPPED_GTK=yes",
> "XDG_DATA_DIRS=/usr/local/share:/"...,
> > > >>>>>> "USECCACHE=ON", "SSH_TTY=/dev/pts/2", "MAIL=/var/mail/dayd",
> > > >>>>>> "TERM=rxvt-unicode-256color", "SHELL=/bin/bash", "SHLVL=1",
> > > >>>>>> "PYTHONPATH=:/home/dayd/projects/"..., "LOGNAME=dayd",
> > > >>>>>> "DBUS_SESSION_BUS_ADDRESS=unix:pa"...,
> > > >>>>>> "XDG_RUNTIME_DIR=/run/user/6686",
> > > >>>>>> "PATH=/usr/lib/ccache/bin/:/usr/l"..., "USEDISTCC=OFF",
> > > >>>>>> "_=/usr/bin/strace", "OLDPWD=/home/dayd/projects"]strace:
> > > >>>>>> [wait(0x04057f) = 26302] WIFSTOPPED,sig=SIGTRAP,EVENT_EXEC (4)
> > > >>>>>> strace: [wait(0x00857f) = 26302] WIFSTOPPED,sig=133
> > > >>>>>> ) = 0
> > > >>>>>> strace: [wait(0x00047f) = 26302] WIFSTOPPED,sig=SIGILL
> > > >>>>>> --- SIGILL {si_signo=SIGILL, si_code=ILL_ILLOPN,
> si_addr=0x40169e} ---
> > > >>>>>> strace: [wait(0x06057f) = 26302]
> WIFSTOPPED,sig=SIGTRAP,EVENT_EXIT (6)
> > > >>>>>> strace: [wait(0x000084) = 26302] WIFSIGNALED,core,sig=SIGILL
> > > >>>>>> +++ killed by SIGILL (core dumped) +++
> > > >>>>>> strace: dropped tcb for pid 26302, 0 remain
> > > >>>>>> Illegal instruction (core dumped)
> > > >>>>>>
> ******************************************************************************************
> > > >>>>>> (gdb) bt
> > > >>>>>> #0  0x00000000004016ae in __copy_tls ()
> > > >>>>>> #1  0x0000000000000000 in ?? ()
> > > >>>>>>
> *****************************************************************************************
> > > >>>>>>
> > > >>>>>> (gdb) disassemble
> > > >>>>>> Dump of assembler code for function __copy_tls:
> > > >>>>>>    0x0000000000401680 <+0>:    push   %r13
> > > >>>>>>    0x0000000000401682 <+2>:    mov    %rdi,%r13
> > > >>>>>>    0x0000000000401685 <+5>:    push   %r12
> > > >>>>>>    0x0000000000401687 <+7>:    push   %rbp
> > > >>>>>>    0x0000000000401688 <+8>:    push   %rbx
> > > >>>>>>    0x0000000000401689 <+9>:    sub    $0x8,%rsp
> > > >>>>>>    0x000000000040168d <+13>:    mov    0x410c(%rip),%rax
> #
> > > >>>>>> 0x4057a0 <__libc+32>
> > > >>>>>>    0x0000000000401694 <+20>:    mov    0x410d(%rip),%rcx
> #
> > > >>>>>> 0x4057a8 <__libc+40>
> > > >>>>>>    0x000000000040169b <+27>:    mov    0x40f6(%rip),%rbx
> #
> > > >>>>>> 0x405798 <__libc+24>
> > > >>>>>>    0x00000000004016a2 <+34>:    lea    -0xe0(%rdi,%rax,1),%rax
> > > >>>>>>    0x00000000004016aa <+42>:    lea    -0x1(%rcx),%r12
> > > >>>>>> => 0x00000000004016ae <+46>:    andn   %rax,%r12,%r12
> > > >>>>> This instruction, andn, is not in the base x86_64 ISA. It's part
> of
> > > >>>>> the BMI1 extension:
> > > >>>>>
> > > >>>>>
> https://en.wikipedia.org/wiki/Bit_Manipulation_Instruction_Sets#BMI1_(Bit_Manipulation_Instruction_Set_1)
> > > >>>>>
> > > >>>>> Apparently Gentoo is providing cross compilers that default to
> > > >>>>> producing "native ISA level" code for the host, rather than
> baseline
> > > >>>>> ISA for the target. But:
> > > >>>>>
> > > >>>>>> as a bonus (I thought this might also help):
> > > >>>>>> (%:~/projects/musl-test)┌- x86_64-pc-linux-musl-gcc -v -static
> -O0 -g
> > > >>>>>> hello.c
> > > >>>>>> Using built-in specs.
> > > >>>>>> COLLECT_GCC=x86_64-pc-linux-musl-gcc
> > > >>>>>>
> COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-pc-linux-musl/9.1.0/lto-wrapper
> > > >>>>>> Target: x86_64-pc-linux-musl
> > > >>>>>> Configured with:
> > > >>>>>>
> /var/tmp/portage/cross-x86_64-pc-linux-musl/gcc-9.1.0/work/gcc-9.1..0/configure
> > > >>>>>> --host=x86_64-pc-linux-gnu --target=x86_64-pc-linux-musl
> > > >>>>>> --build=x86_64-pc-linux-gnu --prefix=/usr
> > > >>>>>>
> --bindir=/usr/x86_64-pc-linux-gnu/x86_64-pc-linux-musl/gcc-bin/9..1.0
> > > >>>>>> --includedir=/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/include
> > > >>>>>> --datadir=/usr/share/gcc-data/x86_64-pc-linux-musl/9.1.0
> > > >>>>>> --mandir=/usr/share/gcc-data/x86_64-pc-linux-musl/9.1.0/man
> > > >>>>>> --infodir=/usr/share/gcc-data/x86_64-pc-linux-musl/9.1.0/info
> > > >>>>>>
> --with-gxx-include-dir=/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/include/g++-v9
> > > >>>>>>
> --with-python-dir=/share/gcc-data/x86_64-pc-linux-musl/9.1.0/python
> > > >>>>>> --enable-languages=c,c++,fortran --enable-obsolete
> --enable-secureplt
> > > >>>>>> --disable-werror --with-system-zlib --enable-nls
> > > >>>>>> --without-included-gettext --enable-checking=release
> > > >>>>>> --with-bugurl=https://bugs.gentoo.org/
> --with-pkgversion='Gentoo 9.1.0
> > > >>>>>> p1.0' --disable-esp --enable-libstdcxx-time
> > > >>>>>> --enable-poison-system-directories
> > > >>>>>> --with-sysroot=/usr/x86_64-pc-linux-musl --disable-bootstrap
> > > >>>>>> --enable-__cxa_atexit --disable-multilib
> --with-multilib-list=m64
> > > >>>>>> --disable-altivec --disable-fixed-point --enable-targets=all
> > > >>>>>> --enable-libgomp --disable-libmudflap --disable-libssp
> > > >>>>>> --disable-systemtap --disable-vtable-verify --disable-libvtv
> > > >>>>>> --enable-lto --without-isl --disable-libsanitizer
> --enable-default-pie
> > > >>>>>> --enable-default-ssp
> > > >>>>>> Thread model: posix
> > > >>>>>> gcc version 9.1.0 (Gentoo 9.1.0 p1.0)
> > > >>>>>> COLLECT_GCC_OPTIONS='-v' '-static' '-O0' '-g' '-mtune=generic'
> '-march=x86-64'
> > > >>>>>>  /usr/libexec/gcc/x86_64-pc-linux-musl/9.1.0/cc1 -quiet -v
> hello.c
> > > >>>>>> -quiet -dumpbase hello.c -mtune=generic -march=x86-64 -auxbase
> hello
> > > >>>>>> -g -O0 -version -o /tmp/ccoTkh38.s
> > > >>>>>> GNU C17 (Gentoo 9.1.0 p1.0) version 9.1.0 (x86_64-pc-linux-musl)
> > > >>>>>>     compiled by GNU C version 8.3.0, GMP version 6.1.2, MPFR
> version
> > > >>>>>> 4.0.2, MPC version 1.1.0, isl version none
> > > >>>>>> GGC heuristics: --param ggc-min-expand=100 --param
> ggc-min-heapsize=131072
> > > >>>>>> ignoring nonexistent directory
> "/usr/x86_64-pc-linux-musl/usr/local/include"
> > > >>>>>> ignoring nonexistent directory
> > > >>>>>>
> "/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/../../../../x86_64-pc-linux-musl/include"
> > > >>>>>> #include "..." search starts here:
> > > >>>>>> #include <...> search starts here:
> > > >>>>>>  /usr/x86_64-pc-linux-musl/usr/include
> > > >>>>>>  /usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/include
> > > >>>>>> End of search list.
> > > >>>>>> GNU C17 (Gentoo 9.1.0 p1.0) version 9.1.0 (x86_64-pc-linux-musl)
> > > >>>>>>     compiled by GNU C version 8.3.0, GMP version 6.1.2, MPFR
> version
> > > >>>>>> 4.0.2, MPC version 1.1.0, isl version none
> > > >>>>>> GGC heuristics: --param ggc-min-expand=100 --param
> ggc-min-heapsize=131072
> > > >>>>>> Compiler executable checksum: a3183e5f435d1938198d432af6db159b
> > > >>>>>> COLLECT_GCC_OPTIONS='-v' '-static' '-O0' '-g' '-mtune=generic'
> '-march=x86-64'
> > > >>>>>>  /usr/libexec/gcc/x86_64-pc-linux-musl/as -v --64 -o
> /tmp/ccHq7CL6..o
> > > >>>>>> /tmp/ccoTkh38.s
> > > >>>>>> GNU assembler version 2.32.0 (x86_64-pc-linux-musl) using BFD
> version
> > > >>>>>> (Gentoo 2.32 p2) 2.32.0
> > > >>>>>>
> COMPILER_PATH=/usr/libexec/gcc/x86_64-pc-linux-musl/9.1.0/:/usr/libexec/gcc/x86_64-pc-linux-musl/9.1.0/:/usr/libexec/gcc/x86_64-pc-linux-musl/:/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/:/usr/lib/gcc/x86_64-pc-linux-musl/
> > > >>>>>>
> LIBRARY_PATH=/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/:/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/../../../../x86_64-pc-linux-musl/lib/:/usr/x86_64-pc-linux-musl/lib/:/usr/x86_64-pc-linux-musl/usr/lib/
> > > >>>>>> COLLECT_GCC_OPTIONS='-v' '-static' '-O0' '-g' '-mtune=generic'
> '-march=x86-64'
> > > >>>>>>  /usr/libexec/gcc/x86_64-pc-linux-musl/9.1.0/collect2 -plugin
> > > >>>>>> /usr/libexec/gcc/x86_64-pc-linux-musl/9.1.0/liblto_plugin.so
> > > >>>>>>
> -plugin-opt=/usr/libexec/gcc/x86_64-pc-linux-musl/9.1.0/lto-wrapper
> > > >>>>>> -plugin-opt=-fresolution=/tmp/ccWcifv4.res
> > > >>>>>> -plugin-opt=-pass-through=-lgcc
> -plugin-opt=-pass-through=-lgcc_eh
> > > >>>>>> -plugin-opt=-pass-through=-lc
> --sysroot=/usr/x86_64-pc-linux-musl -m
> > > >>>>>> elf_x86_64 -static /usr/x86_64-pc-linux-musl/usr/lib/crt1.o
> > > >>>>>> /usr/x86_64-pc-linux-musl/usr/lib/crti.o
> > > >>>>>> /usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/crtbeginT.o
> > > >>>>>> -L/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0
> > > >>>>>>
> -L/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/../../../../x86_64-pc-linux-musl/lib
> > > >>>>>> -L/usr/x86_64-pc-linux-musl/lib
> -L/usr/x86_64-pc-linux-musl/usr/lib
> > > >>>>>> /tmp/ccHq7CL6.o --start-group -lgcc -lgcc_eh -lc --end-group
> > > >>>>>> /usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/crtend.o
> > > >>>>>> /usr/x86_64-pc-linux-musl/usr/lib/crtn.o
> > > >>>>>> COLLECT_GCC_OPTIONS='-v' '-static' '-O0' '-g' '-mtune=generic'
> '-march=x86-64'
> > > >>>>>>
> > > >>>>>> mtune=generic and march=x86-64 suggests it isn't trying to do
> > > >>>>>> something weird on the compile computer.
> > > >>>>> Indeed, it looks like the default is right. So you probably need
> to
> > > >>>>> check how musl was built. Is it also a package provided by
> Gentoo, and
> > > >>>>> did they perhaps use -march=native even though it's being cross
> > > >>>>> compiled?
> > > >>>>>
> > > >>>>> Rich
> > > >>>
> > >
> > >
>

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

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

end of thread, other threads:[~2019-06-06  0:34 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-05 18:16 Illegal instruction in __copy_tls() tenspd137 .
2019-06-05 18:37 ` Rich Felker
2019-06-05 19:53   ` tenspd137 .
2019-06-05 20:07     ` Rich Felker
2019-06-05 21:27       ` tenspd137 .
2019-06-05 21:56         ` Michael Everitt
2019-06-05 23:09           ` tenspd137 .
2019-06-05 23:32             ` tenspd137 .
2019-06-05 23:34               ` Michael Everitt
2019-06-05 23:37                 ` tenspd137 .
2019-06-05 23:41                   ` tenspd137 .
2019-06-06  0:24                   ` Rich Felker
2019-06-06  0:34                     ` tenspd137 .

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