Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 6 Nov 2018 04:51:59 +0200
From:      Konstantin Belousov <kostikbel@gmail.com>
To:        Charlie Li <ml@vishwin.info>
Cc:        Brooks Davis <brooks@freebsd.org>, svn-src-head@freebsd.org, toolchain@freebsd.org, current@freebsd.org
Subject:   Re: svn commit: r339898 - head/lib/libc/amd64/sys
Message-ID:  <20181106025159.GU5335@kib.kiev.ua>
In-Reply-To: <4907b3f9-d1c6-4368-5597-ce3d6be19461@vishwin.info>
References:  <201810300011.w9U0BUui038857@repo.freebsd.org> <a2d14762-d6f9-4c3e-b3d3-efb7dcb2640f@vishwin.info> <20181101160406.GA60233__23941.7825396687$1541088368$gmane$org@spindle.one-eyed-alien.net> <ae15161f-0728-d208-12a2-08a22fcbc50b@vishwin.info> <fdda06af-d189-b9b0-d2d5-26bcf2c6395a@vishwin.info> <20181103152936.GQ5335@kib.kiev.ua> <f8be07cd-f5eb-989c-44f1-ddcd60841411@vishwin.info> <20181103234551.GX5335@kib.kiev.ua> <4907b3f9-d1c6-4368-5597-ce3d6be19461@vishwin.info>

next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, Nov 05, 2018 at 09:10:13PM -0500, Charlie Li wrote:
> On 03/11/2018 19:45, Konstantin Belousov wrote:
> > Or rather, it is a middle of the valid instruction.
> > Next frame looks like it is process_irelocs(), if trusting the line
> > numbers.  So most likely it is something related to calling wrong
> > relocator function, if anything.
> > 
> > Perhaps you could try to trace the things manually, doing
> > single-stepping of the startup code in debugger. There should be very
> > modest amount of the irelocs, perhaps only one, and see where things go
> > off the way.
> > 
> After a few more complete buildworlds, including one with all
> bootstrapping enabled, this doesn't look compiler-specific. Static
> binaries built with the in-tree base LLVM (6.0.1) also crash.
For you, but not for me.

> 
> I stepped through bmake with base lldb, comparing the working copy in my
> system from circa r339990 with r340173 built with bootstrapped
> toolchain. Only the differing parts are shown for conciseness.
> 
> Circa r339990:
> Process 82271 stopped
> * thread #1, name = 'make', stop reason = step over
>     frame #0: 0x000000000024ab06 make`_init_tls at tls.c:471
>    468          }
>    469          tls = _rtld_allocate_tls(NULL, TLS_TCB_SIZE, TLS_TCB_ALIGN);
>    470
> -> 471          _set_tp(tls);
>    472  #endif
>    473  }
> (lldb) n
> Process 82271 stopped
> * thread #1, name = 'make', stop reason = step over
>     frame #0: 0x0000000000255e60 make`_set_tp(tp=0x00000008002f7830) at
> _set_tp.c:38
>    35
>    36   void
>    37   _set_tp(void *tp)
> -> 38   {
>    39
>    40           amd64_set_fsbase(tp);
>    41   }
> (lldb) s
> Process 82271 stopped
> * thread #1, name = 'make', stop reason = step in
>     frame #0: 0x0000000000255e64 make`_set_tp(tp=0x00000008002f7830) at
> _set_tp.c:40
>    37   _set_tp(void *tp)
>    38   {
>    39
> -> 40           amd64_set_fsbase(tp);
>    41   }
> (lldb) s
> Process 82271 stopped
> * thread #1, name = 'make', stop reason = step in
>     frame #0: 0x0000000000256580
> make`amd64_set_fsbase(addr=0x00000008002f7830) at amd64_set_fsbase.c:43
>    40   #include <machine/specialreg.h>
>    41   #include <machine/sysarch.h>
>    42   #include <x86/ifunc.h>
> -> 43   #include "libc_private.h"
>    44
>    45   static int
>    46   amd64_set_fsbase_cpu(void *addr)
> (lldb)
> 
> r340173:
> Process 22663 stopped
> * thread #1, name = 'make', stop reason = step over
>     frame #0: 0x0000000000247c96 make`_init_tls at tls.c:471
>    468          }
>    469          tls = _rtld_allocate_tls(NULL, TLS_TCB_SIZE, TLS_TCB_ALIGN);
>    470
> -> 471          _set_tp(tls);
>    472  #endif
>    473  }
> (lldb) n
> Process 22663 stopped
> * thread #1, name = 'make', stop reason = step over
>     frame #0: 0x0000000000252eb0 make`_set_tp(tp=0x00000008002ed830) at
> _set_tp.c:38
>    35
>    36   void
>    37   _set_tp(void *tp)
> -> 38   {
>    39
>    40           amd64_set_fsbase(tp);
>    41   }
> (lldb) s
> Process 22663 stopped
> * thread #1, name = 'make', stop reason = step in
>     frame #0: 0x0000000000252eb4 make`_set_tp(tp=0x00000008002ed830) at
> _set_tp.c:40
>    37   _set_tp(void *tp)
>    38   {
>    39
> -> 40           amd64_set_fsbase(tp);
>    41   }
> (lldb) s
> Process 22663 stopped
> * thread #1, name = 'make', stop reason = step in
>     frame #0: 0x0000000000252eb5 make`_set_tp(tp=0x00000008002ed830) at
> _set_tp.c:40
>    37   _set_tp(void *tp)
>    38   {
>    39
> -> 40           amd64_set_fsbase(tp);
>    41   }
> (lldb) s
> Process 22663 stopped
> * thread #1, name = 'make', stop reason = step in
>     frame #0: 0x00000000002ebdb0 make
> ->  0x2ebdb0: movq   0x3ce9(%rip), %r11
>     0x2ebdb7: callq  0x2ebda0                  ; _fini
>     0x2ebdbc: jmp    0x2ebd92                  ; _init + 6
>     0x2ebdc1: pushq  $0x0
> (lldb) n
> Process 22663 stopped
> * thread #1, name = 'make', stop reason = instruction step over
>     frame #0: 0x00000000002ebdb7 make
> ->  0x2ebdb7: callq  0x2ebda0                  ; _fini
I guess this is where things go off for you, but I may be wrong.
After ifuncification, 'amd64_set_fsbase()' line should be represented
by the asm as either
	call	<somewhere in plt>
and the place in plt is just
	jmp 	*(rip-based offset to GOT)(%rip)
In fact the call to amd64_set_fsbase() in the tail-call position, so
the first call is jmp.

For me, everything works.  If for you it does not you should look at the
instructions and see which values went off.  You completely omitted that
details from your trace, so I cannot even guess which part was corrupted.
Again, for me it works with the in-tree toolchain, so I am quite sure that
you have trouble with the toolchain.




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20181106025159.GU5335>