From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/14183 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: "tenspd137 ." Newsgroups: gmane.linux.lib.musl.general Subject: Re: Illegal instruction in __copy_tls() Date: Wed, 5 Jun 2019 17:09:36 -0600 Message-ID: References: <20190605183742.GK1506@brightrain.aerifal.cx> <20190605200747.GL1506@brightrain.aerifal.cx> <1ae0f7f0-ed7e-570b-5c65-5e6bc48b3306@iee.org> Reply-To: musl@lists.openwall.com Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="100178"; mail-complaints-to="usenet@blaine.gmane.org" To: musl@lists.openwall.com Original-X-From: musl-return-14199-gllmg-musl=m.gmane.org@lists.openwall.com Thu Jun 06 01:10:03 2019 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.89) (envelope-from ) id 1hYf2h-000PxA-4f for gllmg-musl@m.gmane.org; Thu, 06 Jun 2019 01:10:03 +0200 Original-Received: (qmail 1393 invoked by uid 550); 5 Jun 2019 23:10:00 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 1375 invoked from network); 5 Jun 2019 23:10:00 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :content-transfer-encoding; bh=kYeEZjERX97SLlT7nW/kTIAucOOIg41AxzW5irwLOGE=; b=Bh1is33ZuIHA3XG8NJa/9GPA0VK2OUhYcEmvwylDU5VcebQxE61a8/gWh+03YhoNEW XwmqcbmFfbVOdb1uVSi2Ajz9NjE+6dO95OfsOxHJ1nwwD2tBzIpYBMj7qU79m5ndIkqZ wgTAxkbhP3kV2rjp3xDNJdw/P2xus+I9ECHWixR2c4eEoePSQWUiumJZ+aF856f3kc7a zvSsxk99hpRJE4uoUUqhfo3Cx1jK7AFNIfHo1beVPYbjL/bTM1Xc3uY9TMHXwoVPJM4B /43/HGCdWiDA5uOCc291AwL23B6l9LHEpRWjnttVca/8pZ7hVRGNcBD8Yc73U7g5oKkJ j4Uw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:content-transfer-encoding; bh=kYeEZjERX97SLlT7nW/kTIAucOOIg41AxzW5irwLOGE=; b=nbSXCdmOHohOGfA8vl0wyfLXGfGmswE1mprbTmnHRbsLeltUHtgqdzDACiJhB7xucx Uqnji3D2XkeBLGTF/ndxg78+crCanRkw8wbiFHCENUIhw4HLV9vlJ5fVL0b9N27mZp/J WROd4MgW7HeTimXirn+TIBKCR1T06WLRFMrWCZdTdd+ugkIhrn71zwkpvG5VWOhaxjex UcXfn8uYSggqse9+9EMPgL21jQfEdNvFD1aTmZ6vfHga/qbNby23wUJZUsHw3IRegdyn RkY6S5o/oneYuR89ydy2KLWmOTxfXEAinseMJozJaLo3QQuUO+NUj3XBDVrKZXBQKKLa B+kw== X-Gm-Message-State: APjAAAU8pHWc8ExNccvJnPl0vLpfpIQUfNLWfxI3HsSSS7fjYdVNGRj5 7c3mAwDR3ILupXO0/i6K/mVZR+lxkSLZtrtr2BVioGdM X-Google-Smtp-Source: APXvYqzEnasytJYYWVn1H1tfij++DfhLMeeZS42W2K4U0/ugGslJmwzYVOX1dDGYk7VX5sgpE0qFqRJLC88iWEOegn8= X-Received: by 2002:a1c:be03:: with SMTP id o3mr23934528wmf.139.1559776188384; Wed, 05 Jun 2019 16:09:48 -0700 (PDT) In-Reply-To: <1ae0f7f0-ed7e-570b-5c65-5e6bc48b3306@iee.org> Xref: news.gmane.org gmane.linux.lib.musl.general:14183 Archived-At: 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 wrote: > > In your /usr/${CTARGET}/etc/portage/make.conf you can set appropriate > target flags there. But using 'march=3Dnative' 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 CFLA= GS > when/if it goes wrong! > > Michael. > > On 05/06/19 22:27, tenspd137 . wrote: > > Thanks! That was indeed the problem. I had march=3Dnative 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 wrote: > >> On Wed, Jun 05, 2019 at 01:53:58PM -0600, tenspd137 . wrote: > >>> Sure - > >>> > >>> strace -d -v ./a.out: > >>> strace: ptrace_setoptions =3D 0x51 > >>> strace: new tcb for pid 26302, active tcbs:1 > >>> strace: [wait(0x80137f) =3D 26302] WIFSTOPPED,sig=3DSIGSTOP,EVENT_STO= P (128) > >>> strace: pid 26302 has TCB_STARTUP, initializing it > >>> strace: [wait(0x80057f) =3D 26302] WIFSTOPPED,sig=3DSIGTRAP,EVENT_STO= P (128) > >>> strace: [wait(0x00127f) =3D 26302] WIFSTOPPED,sig=3DSIGCONT > >>> strace: [wait(0x00857f) =3D 26302] WIFSTOPPED,sig=3D133 > >>> execve("./a.out", ["./a.out"], ["SSH_CONNECTION=3D15.86.136.27 5196".= .., > >>> "LANG=3Den_US.UTF-8", "XDG_SESSION_ID=3D41", "USER=3Ddayd", > >>> "PWD=3D/home/dayd/projects/musl-tes"..., "HOME=3D/home/dayd", > >>> "SSH_CLIENT=3Dxx.xxx.xxx.xx 51960 22", "CCACHE_DIR=3D/ssd/dayd/.ccach= e", > >>> "VMWARE_USE_SHIPPED_GTK=3Dyes", "XDG_DATA_DIRS=3D/usr/local/share:/".= .., > >>> "USECCACHE=3DON", "SSH_TTY=3D/dev/pts/2", "MAIL=3D/var/mail/dayd", > >>> "TERM=3Drxvt-unicode-256color", "SHELL=3D/bin/bash", "SHLVL=3D1", > >>> "PYTHONPATH=3D:/home/dayd/projects/"..., "LOGNAME=3Ddayd", > >>> "DBUS_SESSION_BUS_ADDRESS=3Dunix:pa"..., > >>> "XDG_RUNTIME_DIR=3D/run/user/6686", > >>> "PATH=3D/usr/lib/ccache/bin/:/usr/l"..., "USEDISTCC=3DOFF", > >>> "_=3D/usr/bin/strace", "OLDPWD=3D/home/dayd/projects"]strace: > >>> [wait(0x04057f) =3D 26302] WIFSTOPPED,sig=3DSIGTRAP,EVENT_EXEC (4) > >>> strace: [wait(0x00857f) =3D 26302] WIFSTOPPED,sig=3D133 > >>> ) =3D 0 > >>> strace: [wait(0x00047f) =3D 26302] WIFSTOPPED,sig=3DSIGILL > >>> --- SIGILL {si_signo=3DSIGILL, si_code=3DILL_ILLOPN, si_addr=3D0x4016= 9e} --- > >>> strace: [wait(0x06057f) =3D 26302] WIFSTOPPED,sig=3DSIGTRAP,EVENT_EXI= T (6) > >>> strace: [wait(0x000084) =3D 26302] WIFSIGNALED,core,sig=3DSIGILL > >>> +++ 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 > >>> =3D> 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)=E2=94=8C- x86_64-pc-linux-musl-gcc -v -stati= c -O0 -g > >>> hello.c > >>> Using built-in specs. > >>> COLLECT_GCC=3Dx86_64-pc-linux-musl-gcc > >>> COLLECT_LTO_WRAPPER=3D/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=3Dx86_64-pc-linux-gnu --target=3Dx86_64-pc-linux-musl > >>> --build=3Dx86_64-pc-linux-gnu --prefix=3D/usr > >>> --bindir=3D/usr/x86_64-pc-linux-gnu/x86_64-pc-linux-musl/gcc-bin/9.1.= 0 > >>> --includedir=3D/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/include > >>> --datadir=3D/usr/share/gcc-data/x86_64-pc-linux-musl/9.1.0 > >>> --mandir=3D/usr/share/gcc-data/x86_64-pc-linux-musl/9.1.0/man > >>> --infodir=3D/usr/share/gcc-data/x86_64-pc-linux-musl/9.1.0/info > >>> --with-gxx-include-dir=3D/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/incl= ude/g++-v9 > >>> --with-python-dir=3D/share/gcc-data/x86_64-pc-linux-musl/9.1.0/python > >>> --enable-languages=3Dc,c++,fortran --enable-obsolete --enable-securep= lt > >>> --disable-werror --with-system-zlib --enable-nls > >>> --without-included-gettext --enable-checking=3Drelease > >>> --with-bugurl=3Dhttps://bugs.gentoo.org/ --with-pkgversion=3D'Gentoo = 9.1.0 > >>> p1.0' --disable-esp --enable-libstdcxx-time > >>> --enable-poison-system-directories > >>> --with-sysroot=3D/usr/x86_64-pc-linux-musl --disable-bootstrap > >>> --enable-__cxa_atexit --disable-multilib --with-multilib-list=3Dm64 > >>> --disable-altivec --disable-fixed-point --enable-targets=3Dall > >>> --enable-libgomp --disable-libmudflap --disable-libssp > >>> --disable-systemtap --disable-vtable-verify --disable-libvtv > >>> --enable-lto --without-isl --disable-libsanitizer --enable-default-pi= e > >>> --enable-default-ssp > >>> Thread model: posix > >>> gcc version 9.1.0 (Gentoo 9.1.0 p1.0) > >>> COLLECT_GCC_OPTIONS=3D'-v' '-static' '-O0' '-g' '-mtune=3Dgeneric' '-= march=3Dx86-64' > >>> /usr/libexec/gcc/x86_64-pc-linux-musl/9.1.0/cc1 -quiet -v hello.c > >>> -quiet -dumpbase hello.c -mtune=3Dgeneric -march=3Dx86-64 -auxbase he= llo > >>> -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=3D100 --param ggc-min-heapsize= =3D131072 > >>> ignoring nonexistent directory "/usr/x86_64-pc-linux-musl/usr/local/i= nclude" > >>> 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=3D100 --param ggc-min-heapsize= =3D131072 > >>> Compiler executable checksum: a3183e5f435d1938198d432af6db159b > >>> COLLECT_GCC_OPTIONS=3D'-v' '-static' '-O0' '-g' '-mtune=3Dgeneric' '-= march=3Dx86-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=3D/usr/libexec/gcc/x86_64-pc-linux-musl/9.1.0/:/usr/lib= exec/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=3D/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_6= 4-pc-linux-musl/lib/:/usr/x86_64-pc-linux-musl/usr/lib/ > >>> COLLECT_GCC_OPTIONS=3D'-v' '-static' '-O0' '-g' '-mtune=3Dgeneric' '-= march=3Dx86-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=3D/usr/libexec/gcc/x86_64-pc-linux-musl/9.1.0/lto-wrapper > >>> -plugin-opt=3D-fresolution=3D/tmp/ccWcifv4.res > >>> -plugin-opt=3D-pass-through=3D-lgcc -plugin-opt=3D-pass-through=3D-lg= cc_eh > >>> -plugin-opt=3D-pass-through=3D-lc --sysroot=3D/usr/x86_64-pc-linux-mu= sl -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=3D'-v' '-static' '-O0' '-g' '-mtune=3Dgeneric' '-= march=3Dx86-64' > >>> > >>> mtune=3Dgeneric and march=3Dx86-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=3Dnative even though it's being cross > >> compiled? > >> > >> Rich > >