From owner-freebsd-hackers@freebsd.org Thu Dec 20 08:59:41 2018 Return-Path: Delivered-To: freebsd-hackers@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 437B9133CEAE for ; Thu, 20 Dec 2018 08:59:41 +0000 (UTC) (envelope-from 6yearold@gmail.com) Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id E02826E53A for ; Thu, 20 Dec 2018 08:59:39 +0000 (UTC) (envelope-from 6yearold@gmail.com) Received: by mail-pf1-f169.google.com with SMTP id y126so604138pfb.4 for ; Thu, 20 Dec 2018 00:59:39 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=NoWd0sDcwERDZ27Ztmh9tvTK8dfSLRNsafUSFlz0dp4=; b=aCfuSxuWV7TBQZHNbVPrzuDREXUflP/SjluKLG7kIrf4ZMJB7z9+0OE7LteM/oofA8 buEjvu4WbhsE4e+ekLz7bYK0Ug3ZGYhaDeLsK5hfZc8NSqVlvIzK0vkEvTDSaykbyTFo S4ZLhc0LGLQSIRXojTcVODL4QQ3i4i0gxTQ8TLywHgwC0fic6tvM2JjZ0eiOwXHbRSdU we0nec3de4S0V9MUImhKZHiLxLqMv1p6I+KZmyKNVuhZOPHV5ebMfzckSTlTbU6lE9CN fmpDIgQBtrYMyNSOB+Bdv4cbNN1sHj8UlzP4QUDF39igbd5sOig2hyzVxBtR4zKt6FWW Anmw== X-Gm-Message-State: AA+aEWZtGG94OylJz46NhiohoUG8AVgWhK0Ybr0MnaHT8HQhJ0HT7i1L Jm7nkyqHA419LILw844Alu+4h0/cEyk= X-Google-Smtp-Source: AFSGD/XI+vBScDY3xhPluImbqrbVQTQkCsxNAA8XzncaS4TffWc/mwDmFG6eXqAtESqXpBZ8N19c4Q== X-Received: by 2002:a63:193:: with SMTP id 141mr22371128pgb.136.1545296373489; Thu, 20 Dec 2018 00:59:33 -0800 (PST) Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com. [209.85.214.173]) by smtp.gmail.com with ESMTPSA id w136sm29522549pfd.169.2018.12.20.00.59.33 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Dec 2018 00:59:33 -0800 (PST) Received: by mail-pl1-f173.google.com with SMTP id t13so557308ply.13 for ; Thu, 20 Dec 2018 00:59:33 -0800 (PST) X-Received: by 2002:a17:902:d891:: with SMTP id b17mr23793941plz.80.1545296372985; Thu, 20 Dec 2018 00:59:32 -0800 (PST) MIME-Version: 1.0 From: Gleb Popov Date: Thu, 20 Dec 2018 12:59:06 +0400 X-Gmail-Original-Message-ID: Message-ID: Subject: Calling a function from a SO breaks in libc To: freebsd-hackers X-Rspamd-Queue-Id: E02826E53A X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org; spf=pass (mx1.freebsd.org: domain of 6yearold@gmail.com designates 209.85.210.169 as permitted sender) smtp.mailfrom=6yearold@gmail.com X-Spamd-Result: default: False [-2.92 / 15.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; R_SPF_ALLOW(-0.20)[+ip4:209.85.128.0/17]; URI_COUNT_ODD(1.00)[1]; RCVD_COUNT_THREE(0.00)[4]; TO_DN_ALL(0.00)[]; MX_GOOD(-0.01)[cached: alt3.gmail-smtp-in.l.google.com]; NEURAL_HAM_SHORT(-0.89)[-0.887,0]; FORGED_SENDER(0.30)[arrowd@freebsd.org,6yearold@gmail.com]; MIME_TRACE(0.00)[0:+,1:+]; R_DKIM_NA(0.00)[]; FREEMAIL_ENVFROM(0.00)[gmail.com]; ASN(0.00)[asn:15169, ipnet:209.85.128.0/17, country:US]; FROM_NEQ_ENVFROM(0.00)[arrowd@freebsd.org,6yearold@gmail.com]; TO_DOM_EQ_FROM_DOM(0.00)[]; ARC_NA(0.00)[]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; NEURAL_HAM_LONG(-1.00)[-0.998,0]; MIME_GOOD(-0.10)[multipart/alternative,text/plain]; PREVIOUSLY_DELIVERED(0.00)[freebsd-hackers@freebsd.org]; DMARC_NA(0.00)[freebsd.org]; RCPT_COUNT_ONE(0.00)[1]; IP_SCORE(-1.02)[ipnet: 209.85.128.0/17(-3.62), asn: 15169(-1.40), country: US(-0.08)]; RCVD_IN_DNSWL_NONE(0.00)[169.210.85.209.list.dnswl.org : 127.0.5.0]; RCVD_TLS_LAST(0.00)[] Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 20 Dec 2018 08:59:41 -0000 When debugging software with GDB on FreeBSD 12+ I often get into following situation: (gdb) next (anonymous namespace)::D13AsmPrinter::EmitInstruction (this=0x8056b4b80, MI=0x805765690) at /home/arr/projects/d13/lib/Target/D13/D13AsmPrinter.cpp:152 152 EmitToStreamer(*OutStreamer, TmpInst); (gdb) step Now instead of entering into EmitStreamer(), I see: _thr_rtld_set_flag (mask=1) at /usr/src/lib/libthr/thread/thr_rtld.c:171 171 { Trying to get out of there: (gdb) finish Run till exit from #0 _thr_rtld_set_flag (mask=1) at /usr/src/lib/libthr/thread/thr_rtld.c:171 0x000000080027669b in thread_mask_set (mask=) at /usr/src/libexec/rtld-elf/rtld_lock.c:177 177 return lockinfo.thread_set_flag(mask); Value returned is $3 = 0 (gdb) finish Run till exit from #0 0x000000080027669b in thread_mask_set (mask=) at /usr/src/libexec/rtld-elf/rtld_lock.c:177 rlock_acquire (lock=0x800287ba0 , lockstate=0x7fffffff9608) at /usr/src/libexec/rtld-elf/rtld_lock.c:203 203 if (thread_mask_set(lock->mask) & lock->mask) { (gdb) finish Run till exit from #0 rlock_acquire (lock=0x800287ba0 , lockstate=0x7fffffff9608) at /usr/src/libexec/rtld-elf/rtld_lock.c:203 _rtld_bind (obj=0x80028b400, reloff=625152) at /usr/src/libexec/rtld-elf/rtld.c:808 808 if (sigsetjmp(lockstate.env, 0) != 0) (gdb) finish Run till exit from #0 _rtld_bind (obj=0x80028b400, reloff=625152) at /usr/src/libexec/rtld-elf/rtld.c:808 _rtld_bind_start () at /usr/src/libexec/rtld-elf/amd64/rtld_start.S:124 124 movq %rax,0x60(%rsp) # Store target over reloff argument Value returned is $4 = 34402603952 (gdb) finish Run till exit from #0 _rtld_bind_start () at /usr/src/libexec/rtld-elf/amd64/rtld_start.S:124 Program received signal SIGTRAP, Trace/breakpoint trap. _rtld_bind_start () at /usr/src/libexec/rtld-elf/amd64/rtld_start.S:155 155 ret # "Return" to target address (gdb) finish Run till exit from #0 _rtld_bind_start () at /usr/src/libexec/rtld-elf/amd64/rtld_start.S:155 Program received signal SIGTRAP, Trace/breakpoint trap. 0x00000008028e13b4 in llvm::AsmPrinter::EmitToStreamer (this=0x80028b400, S=..., Inst=...) at /home/arr/projects/d13/lib/CodeGen/AsmPrinter/AsmPrinter.cpp:228 After this. the debugging is impossible, because every "cont/step/next" command yields "Program received signal SIGTRAP, Trace/breakpoint trap". Trying to "print" anything causes GDB to crash. It should be noted, that I'm linking to LLVM-7.so library. Using static linkage for the executable I'm debugging makes this bug go away. Anyone have an idea what's going on and how to fix that?