Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp3606832rdb; Wed, 13 Sep 2023 18:20:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE/x2IEO6Sqr/0hNGOAu3er7Vm4Rw+G04iey1JWjEdaPmpKB06YjYXDvOQ6P6q6Alepb0Qf X-Received: by 2002:a05:6358:2512:b0:142:efb8:5295 with SMTP id m18-20020a056358251200b00142efb85295mr827900rwb.19.1694654452392; Wed, 13 Sep 2023 18:20:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694654452; cv=none; d=google.com; s=arc-20160816; b=MH4+G2jnToX/SiPblPRg2D9vpkgnMx83pi5ifpGD5FLhh89iiI2oChUV1+52BSks+e ouqPFouMrl1CmsW0VPt/XWHr4GluMFNFProULMZhFUaSwfP5G+dswxDgn0MGw4/dUkHP 7R7RDROnjmGy2/fSOUoRYYRiVyoQ2gZhPFsOJgVkC75c0+apCvRprHDu8piGD/7BczdQ TnS/HVx+wdQQvizbrsHvi6BhQcTbcmrFs1wYQcgbXzncYJgP78OYnYJRVkkmvTS2N/hu wnh8DsZ/Xhy8EpuxqbHyccTqVlg72fyGvoVwUGJzAD7KwuGyow1Hjd8mqbyyf9iJjG5L T66Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=j8pPzyJ9y4XAjrqnk6Rslpw/Ybq9yqQ/jxmUXNZWGj4=; fh=VZCxdrrm2Be0BgZHaqFrlRW4B4MYLvGqTGzmlqPB8g8=; b=Avls4Bk4XwzK+dv0fx5OGdixLLr1UwidMOyJu/EJN9ffH05mZQmaLP5jtmLJz9dod1 y0SQKn/D+/4Kh7du2zcSjfYauo2qXbx8YuqlkAt1nWVrIP8nnD1eLsgCyiebrAAM3v93 qiuVFS5n+LWTYwC8gdbu8AM7Tqs6yX8bDo2Qes7SiVgtUnI/PTMBn6TfUz4Tz45uIYje ZRcFKWC/ph34HAMujDZk34C/VVSAboiQDjw5yk/H3m9eipmn4DKHHn6ZjC5ifBTiuznj WiDagROuxCIfFYJtvQKaBd27noZzB22TXhCGM2xuAXZalaBf+cywELZPabuM45/VZHzA Oh4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@weissschuh.net header.s=mail header.b=LD4NZh66; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id bt8-20020a632908000000b00565f0e91894si350065pgb.394.2023.09.13.18.20.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 18:20:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@weissschuh.net header.s=mail header.b=LD4NZh66; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 22E1A81EE2C4; Wed, 13 Sep 2023 14:23:51 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229918AbjIMVXr (ORCPT + 99 others); Wed, 13 Sep 2023 17:23:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36220 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229572AbjIMVXq (ORCPT ); Wed, 13 Sep 2023 17:23:46 -0400 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 707A41739 for ; Wed, 13 Sep 2023 14:23:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1694640220; bh=7UMXyUu1H7AInb4Jf1UkOFSbvi8aI+lZ+c555okXulk=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=LD4NZh66O4MJk7Y9JGURpc7BrqLSXa+ZkQkaeR0V2UdefICVXhMUpkBFN3sGQRg56 82zT9QNobZLmMPa0TOyFybnriF7s2lDZFWLjsfuCwc2pR5XROAzPAI7Gj6wmccXXJO F8vms5XZ4j7Zh0mDK3bJdwsEm32Fvaa9ILjIkgWA= Date: Wed, 13 Sep 2023 23:23:40 +0200 From: Thomas =?utf-8?Q?Wei=C3=9Fschuh?= To: Willy Tarreau Cc: Sebastian Ott , Mark Brown , linux-kernel@vger.kernel.org Subject: Re: aarch64 binaries using nolibc segfault before reaching the entry point Message-ID: References: <5d49767a-fbdc-fbe7-5fb2-d99ece3168cb@redhat.com> <2da5ce29-e0de-4715-aa77-453ff3cc48aa@t-8ch.de> <20230913205838.GA21038@1wt.eu> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20230913205838.GA21038@1wt.eu> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Wed, 13 Sep 2023 14:23:51 -0700 (PDT) X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email On 2023-09-13 22:58:38+0200, Willy Tarreau wrote: > On Wed, Sep 13, 2023 at 10:19:00PM +0200, Thomas Weißschuh wrote: > > > All on aarch64 running fedora37 + upstream kernel. Any hints on what could > > > be borken here or how to actually fix it? > > > > I reduced it to the following reproducer: > > > > $ cat test.c > > int foo; /* It works when deleting this variable */ > > > > void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) _start(void) > > { > > __asm__ volatile ( > > "mov x8, 93\n" /* NR_exit == 93 */ > > "svc #0\n" > > ); > > __builtin_unreachable(); > > } > > > > $ aarch64-linux-gnu-gcc -Os -static -fno-stack-protector -Wall -nostdlib test.c > > $ ./a.out > > Segmentation fault > > > > Also when running under gdb the error message is: > > > > During startup program terminated with signal SIGSEGV, Segmentation fault. > > > > So it seems the error already happens during loading. > > > > Could be a compiler or kernel bug? > > I tried here with gcc-11.4.0 native on an ubuntu-22.04 and using a > cross gcc-9.5 executed on another box and couldn't reproduce the issue > at all. It could be that the compiler inserts whatever, did someone > try to disassemble de resulting program to see what it looks like ? > Maybe we're even dealing with issues related to random stack alignment > that causes issues past a function call due to some garbage being placed > at the wrong place in the stack. Also, dmesg should generally report > what (and where) the segv happened. Similarly, gdb with "info reg" > and "disassemble $pc" should report some info. Im using: aarch64-linux-gnu-gcc (GCC) 13.2.0 It's reproducible reliably. No output in dmesg, binary works in qemu-user. There should be no function calls at all, or? GDB also doesn't show any registers, it seems to fail before anything is executed. > > In my case, I just have this: > > $ objdump -d a.out > > a.out: file format elf64-littleaarch64 > > > Disassembly of section .text: > > 0000000000400144 <_start>: > 400144: d2800ba8 mov x8, #0x5d // #93 > 400148: d4000001 svc #0x0 Looks absolutely identical for me. > > The kernel is a 6.2: > > $ uname -a > Linux ampere 6.2.0-26-generic #26~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Thu Jul 13 20:49:15 UTC 2 aarch64 aarch64 aarch64 GNU/Linux Linux fedora-4gb-fsn1-1 6.4.11-200.fc38.aarch64 #1 SMP PREEMPT_DYNAMIC Wed Aug 16 18:01:59 UTC 2023 aarch64 GNU/Linux (Just a default ARM VM on Hetzner with Fedora 38)