Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp3500879rdb; Wed, 13 Sep 2023 14:08:18 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFdgFOFjV/Jiqkb4Ok3j8iomr5gV73VdX8CnUc3/FRUIFcD4t92eMAXalrP7AG00gIchYrq X-Received: by 2002:a17:902:b943:b0:1bb:94ed:20a with SMTP id h3-20020a170902b94300b001bb94ed020amr4442294pls.24.1694639297867; Wed, 13 Sep 2023 14:08:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694639297; cv=none; d=google.com; s=arc-20160816; b=LA+z6zKkTBcwb3d3jUvM9d3VmLdHOfxCyPOG8QOd2vwC9SULBVje7v4ne1U1Cp8Gt1 wdMmKhrr+F8JNzjoDOsyvBe30WEfb7ZiPBuiLLWHG+AmXvaLCPbLkwh3SydHLGd1wGH4 8sirDTD9O80F/8aZytcV9yyTmiU/9g/8ITqZtHer0G4LhNB1v9ZVkvxwT75WeV3ztPc8 rguV82RdOBc8+KRAnlNfiyQEbCeVbI7oT7bBeNq9BWeO9l832cvwLMQwokKJUO0qtADX tiEg6h4GSm9wP9UlERePifZhs43TqmmiNntkfTlY3sslqo4r/lSpCjGU5vAE05bfR2Pa I8Aw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=mj0nOe1OLCBxvETfllnQA58So0/v94ZdcdHlmf/jp+s=; fh=lIMbEBm7YaiwnbKu1RGs7+Vhe0p+ebIp4Wg17G7gUT8=; b=v463dGPRwoy1cwSlZ3Ov3RvNq/tah+iIhNAVTExUPozk+QHcuDlgNcdy9+H+AZSx2a W5WaLQIOXxC7sNEbrcSfT8kvTD+bIVUFbW4YuPe18J1k7icTECcw4oxD23kPLlC1tO9p 9ona3mcvKjvQxJmxmZU/PTAItvknCSlAiFqdvsTb596Qm/nykhed5F8eEn5L+ImhSG9O 4lrV9XWX9PYTCmi1G/2uJT9JSUfWUQGsWuMpHyBwpqS5oOS6lXhEMFOjLwNstWySfA8s lgP7XNT9TWSui1hb1wZaBHoMyF2qH5E2Bc4J9HErreJ+TMuSCn2p4WjobhqYOz+lfy1a mHxA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id lg16-20020a170902fb9000b001b8946f3f95si128639plb.312.2023.09.13.14.08.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 14:08:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (Postfix) with ESMTP id E5BC38081BD5; Wed, 13 Sep 2023 14:01:02 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231866AbjIMVBA (ORCPT + 99 others); Wed, 13 Sep 2023 17:01:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45170 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231497AbjIMVA7 (ORCPT ); Wed, 13 Sep 2023 17:00:59 -0400 Received: from 1wt.eu (ded1.1wt.eu [163.172.96.212]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 6EA009B for ; Wed, 13 Sep 2023 14:00:39 -0700 (PDT) Received: (from willy@localhost) by pcw.home.local (8.15.2/8.15.2/Submit) id 38DKwclr021811; Wed, 13 Sep 2023 22:58:38 +0200 Date: Wed, 13 Sep 2023 22:58:38 +0200 From: Willy Tarreau To: Thomas =?iso-8859-1?Q?Wei=DFschuh?= Cc: Sebastian Ott , Mark Brown , linux-kernel@vger.kernel.org Subject: Re: aarch64 binaries using nolibc segfault before reaching the entry point Message-ID: <20230913205838.GA21038@1wt.eu> References: <5d49767a-fbdc-fbe7-5fb2-d99ece3168cb@redhat.com> <2da5ce29-e0de-4715-aa77-453ff3cc48aa@t-8ch.de> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <2da5ce29-e0de-4715-aa77-453ff3cc48aa@t-8ch.de> User-Agent: Mutt/1.10.1 (2018-07-13) 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 (lipwig.vger.email [0.0.0.0]); Wed, 13 Sep 2023 14:01:03 -0700 (PDT) X-Spam-Status: No, score=-0.8 required=5.0 tests=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 lipwig.vger.email 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. 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 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 Cheers, Willy