Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp5371782rdb; Sat, 16 Sep 2023 14:10:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGZms58KUwoW9K/7s0puC0BEVhsyI9BxuQ1iuFNPgaeg/nWvl7zLeGH2X4swt6u/mxL7ve3 X-Received: by 2002:a05:6808:206:b0:3a7:2621:2daf with SMTP id l6-20020a056808020600b003a726212dafmr5568744oie.42.1694898652548; Sat, 16 Sep 2023 14:10:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694898652; cv=none; d=google.com; s=arc-20160816; b=qudhh+WcnM4JhGbr5WuMrPbLfGpaNjJNqENZBK2bOAnesv1dsQFdgFuIuB3N7NimUi oxOzFkwN/jrwVL0gapY6g9yhopoulyQ7sHPljjTtDeJs8SpVNRMqysvhFSGcGn36UUR3 bFDDxSoT8IEUOPulX0+te5vXJc+XEDuvHkY9Okl/JaHdUURHYCRSs9RJKS14JJqBSqRc IAKV1nHSMMIY/CDWD0fAt0sqHUTYNUX72fSipsxLkuVITF90nH4GD4rv08ypEQ6MtDJf BszRvhwc47mmC7wnICp/nkkbdJ6vxRo7rdG0K9RYHk7EeCmzrl0kCOAZ7Um8up+0X9YO 7Hig== 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-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=S6/+QB9UjxYkKT9TlIDNcThfplRrWeKHMEGEGX/Nxmk=; fh=kkErRrUiwv/2mCQIf8VZbJU4agBSpowlFWdTkqfmH+k=; b=pe3fr/BTaSnYWkDCYTJM3BPLW7oYZ4NbD2wFc/5r/XU1kEVornMnebYEBJCS7fBmtS i3MnedtMHQuFelA5GyJ0GOmsbV9oHI40PzM+Y9UnqArTGerJxDb8q52pzKEHj4RRS9GZ E63y0O3tOr7bNN7GszXfRinqCT5WQ3NtNTqTqGqiYid6nQk5wL8q3bcV9dEVcpA6MIt2 Swsd1unZTMr2GQo8L/SAj1s0gTGGgMMeejTzVoRlsr/Dc4QZ5+VIUCNwfJmJ2bElUATi +Ts9+7M9wWPx7bMe3WR34wdTlOVpvr3BqUXcvSrB6YiNLGB0M52kaKxf/YUhsA2SJRcQ /m9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@weissschuh.net header.s=mail header.b=TQuqqvFo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id t21-20020a639555000000b00578005041b7si4636040pgn.294.2023.09.16.14.10.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Sep 2023 14:10:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@weissschuh.net header.s=mail header.b=TQuqqvFo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (Postfix) with ESMTP id BB19D827B4A6; Wed, 13 Sep 2023 13:19:05 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232173AbjIMUTI (ORCPT + 99 others); Wed, 13 Sep 2023 16:19:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34118 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229527AbjIMUTH (ORCPT ); Wed, 13 Sep 2023 16:19:07 -0400 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 46E381BC8 for ; Wed, 13 Sep 2023 13:19:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1694636341; bh=lBmo7mf5P9G8d/uhsBJm9ostdhSi5Tl1kSOEEW/9bZo=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=TQuqqvFovP6Vtg8eNFMRMJsOQ4NB/qQs7AL5bh29YdddvyzJz+2oGAw+UHLoq6Ox2 QMYnIee+hf7jqi5ueaaQfAI/tvjrUQdZdcc8Hdnqt4oQMMEIqlOvj49e/D9tNsSKTX ol/QAg852j709vwUgN9F8qIVOKXjRRG04oL3uK/c= Date: Wed, 13 Sep 2023 22:19:00 +0200 From: Thomas =?utf-8?Q?Wei=C3=9Fschuh?= To: Sebastian Ott Cc: Mark Brown , Willy Tarreau , linux-kernel@vger.kernel.org Subject: Re: aarch64 binaries using nolibc segfault before reaching the entry point Message-ID: <2da5ce29-e0de-4715-aa77-453ff3cc48aa@t-8ch.de> References: <5d49767a-fbdc-fbe7-5fb2-d99ece3168cb@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5d49767a-fbdc-fbe7-5fb2-d99ece3168cb@redhat.com> 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 (snail.vger.email [0.0.0.0]); Wed, 13 Sep 2023 13:19:05 -0700 (PDT) On 2023-09-13 20:44:59+0200, Sebastian Ott wrote: > Hi, > > the tpidr2 selftest on an arm box segfaults before reaching the entry point. > I have no clue what is to blame for this or how to debug it but for a > statically linked binary there shouldn't be much stuff going on besides the > elf loader? > > I can reproduce this with a program using an empty main function. Also checked > for other nolibc users - same result for init.c from rcutorture. > > tools/testing/selftests/arm64/fp/za-fork is working though - the only > difference I could spot here is that it is linked together with another object > file. I also looked at the elf headers but didn't find anything obvious (but > I'm a bit out of my comfort zone here..) > > After playing around with linker options I found that using -static-pie > lets the binaries run successful. > > [root@arm abi]# cat test.c > int main(void) > { > return 1; > } > [root@arm abi]# gcc -Os -static -Wall -lgcc -nostdlib -ffreestanding -include ../../../../include/nolibc/nolibc.h test.c > [root@arm abi]# ./a.out Segmentation fault > [root@arm abi]# gcc -Os -static -Wall -lgcc -nostdlib -ffreestanding -static-pie -include ../../../../include/nolibc/nolibc.h test.c > [root@arm abi]# ./a.out [root@arm abi]# > > 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? Thomas