From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A10F2221264 for ; Sat, 31 Jan 2026 07:44:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.178 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769845488; cv=none; b=dPKhT/SjkfAbxAj5g/QeTGxcvhn6UoFv7RpLugwGLUVg4M5GwcQz6870R7+yoepmWFhNo5GlRmy5nDaV6bCpBIdQ3F9WwDrQsHEjEDU1vw7K+cAhCspjogC26Io+pcuFdT9hAXhJAtWU58EEyLE+sjP24Zn+wb7e8XnYekO5XeU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769845488; c=relaxed/simple; bh=VwQR5lJMRCvE2Lw8fLX5X0wiC7IcTGZhtXJBCWqiWjQ=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=N/Nz4trqknS9WVbJS7Ag5rt0dOctehdRQxG+q4Yh760lsyW9RMLb+/SoOGjmcovBthMBCTBXt9asNqGCmRRlJRETE79ZpfLzcjedfL0y4ChrkjeJ1yYTBv1mVfKb79Gy5LVOpYr2smMBAkXpikeslki0rn12BLM52Lq67TZXnxs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=thingy.jp; spf=pass smtp.mailfrom=0x0f.com; dkim=pass (1024-bit key) header.d=thingy.jp header.i=@thingy.jp header.b=M0p4caDR; arc=none smtp.client-ip=209.85.210.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=thingy.jp Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=0x0f.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=thingy.jp header.i=@thingy.jp header.b="M0p4caDR" Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-81f4dfa82edso1590626b3a.0 for ; Fri, 30 Jan 2026 23:44:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=thingy.jp; s=google; t=1769845485; x=1770450285; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=1FmTMSuHxeb2l8HCAC35omTe6dVeg/eZD8BadUXuqSI=; b=M0p4caDRUzIzPul/9Lf7aIQ6eRiDTkXuxcUKZZ8Vhtoy9Lsf3cGw5P018BdGY85Z/G lZ71wmfY/o5mP/+aj5idOEaIamQZIjqO1hPwNKy3wDG4+xXivE2UaEB4BLDjpdj4OB83 j57s2Khk5ioH/ZpqV5VRIt+VN21mCsM0GoBNo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769845485; x=1770450285; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=1FmTMSuHxeb2l8HCAC35omTe6dVeg/eZD8BadUXuqSI=; b=n7bT8ziYXE5rGzCvYhjR4msgf1RfPMF1pIqnTkrvaGiV/hN/DoYny96XTBnWA9pykW MAr+ucNfK/j8PpPkLPENMbynIcQH5Gcg9lKqIytJ9Cv3FdLXNfkgl/CHfu25I4nZ/Wmv dV7+/Jg/Q2XcPj9mThjTjP8DkNRh5v/pJ8ImEuQU/qzMP1mXNmKmhf4YlxbLHRBsaQk7 XriKMpBe6x29BbcWi99s+J5EkuM5Ub8iSdhhE4g1RnHTyi/6BID8texphtm4Gaza5ois aWxr9X+J5glJUJBJZWRMQQgoc3mSMWe4kJHjGLpUKslB1tRxAnQoHKINElM3LlsjcU9p 0+/A== X-Forwarded-Encrypted: i=1; AJvYcCX028VnCR/p0HMqwYVGShTA5mCMzKf+ScgwkMaLIkL8k+tc6vQzhmcGG/kn+j9+4eW+SumMhrFkN6mp3VI=@vger.kernel.org X-Gm-Message-State: AOJu0Yy5akk1rkknJXFQ4yewyxjbd0s3Mz52kBszNIJRzmSTbr7xH60h QQyBy9HRNbGZVfGZuY8lXb2mb6yfB5/rxvS9o46TBR6KWogld03b6pNdNY1fiBF8w4k7bpZ1z1e 0kw4i X-Gm-Gg: AZuq6aI06XoB29yjvvCmdpjBkhkGnFSLp98AQC51nxbI78n61ChGztmWdE5VCGK9ewS gsmZwkTuLWcPySpSHsde4lopO/j1Ag9OWPUot4kn66Eit48Mp7Xj6rhDrZYU1yJ4Ric253eA9/y UIQVVg1XUW1W3mJAga6OYPxdCQOiEINFgEYIdA9KPHprvea4j/vKbrn02Riw4Gkfpn6lXhIPiaV MJmlzEw3iikyl2752duzZpXb80tX6pR1fIs3G7Rw1OY4FPq+bG7XJ38l5RLlGbkjB1HUU9NS7hi ShLm95iLvhdM/M3JDLXq0GuT7JrCy1cIEB+290FM+KoeH0fzvcoxPpy7LKWVKSMTpSZyFhFxs/b J2a6o/ZP4Rxr3elXoFo31kSRBbncMuIfhqDbmBSspLziMIf8F5ZLLFuvyMJb4TeGXmskh3MC3HB GXSKFQMJ0OFcLvCiqV6tlr1gdjbSnGV53cF6WpByp8wMAiYMohqShLcxSDTvilr1w46rFi4+s1c 0Gw X-Received: by 2002:a05:6a21:6490:b0:2dc:40f5:3c6c with SMTP id adf61e73a8af0-392e0145956mr4764344637.54.1769845484869; Fri, 30 Jan 2026 23:44:44 -0800 (PST) Received: from kinako.work.home.arpa (p1490223-ipxg00b01sizuokaden.shizuoka.ocn.ne.jp. [153.223.134.223]) by smtp.googlemail.com with ESMTPSA id 41be03b00d2f7-c642a9f539dsm8866928a12.26.2026.01.30.23.44.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Jan 2026 23:44:44 -0800 (PST) From: Daniel Palmer To: linux@weissschuh.net, w@1wt.eu Cc: kees@kernel.org, linux-kernel@vger.kernel.org, Daniel Palmer Subject: [RFC PATCH 0/9] nolibc: Add static-pie support Date: Sat, 31 Jan 2026 16:44:31 +0900 Message-ID: <20260131074440.732588-1-daniel@thingy.jp> X-Mailer: git-send-email 2.51.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit For more background see: https://lore.kernel.org/lkml/20260116122812.2421621-1-daniel@thingy.jp/ Basically I am trying to run normal ELF binaries created with nolibc on nommu (m68k, 68000). To make this work without an external linker nolibc needs code to do the relocation. The following is my attempt at doing this by hacking just enough together that static-pie binaries work on a few archs. The ones that work have a patch in this series. Answers to questions you might have: Q: Don't we need to handle more relocation types? A: Maybe, everything exception sparc only had R_x_RELATIVE in the nolibc test binary. sparc emits R_SPARC_NONE as well. Q: Don't we need to make some sections writable for this to work. A: Maybe, I tried to get most of the supported archs working. The only one that had relocations on a non-writable section was arm64 and I think I can fix it so it doesn't need that. Q: Why can't you just pass -static-pie to gcc? A: Only x86 seemed to actually produce static PIE binaries doing that. Everything else produced normal static ones. Maybe this is a compiler version thing? There are probably things I'm missing, things I have done totally wrong. Please feel free to grill me. Daniel Palmer (9): elf: Add relocation types used by nolibc tools/nolibc: crt: Split _start_c() into stack-only and normal part tools/nolibc: Add basic ELF self-relocation support for static PIE tools/nolibc: m68k: Add relocation support tools/nolibc: x86: Add relocation support for x86_64 tools/nolibc: riscv: Add relocation support tools/nolibc: arm: Add relocation support selftests/nolibc: Add option for building with -static-pie fs/binfmt_elf_fdpic: Reflect that PIE binaries also work in KConfig help fs/Kconfig.binfmt | 10 + include/uapi/linux/elf-r.h | 27 ++ include/uapi/linux/elf.h | 1 + tools/include/nolibc/Makefile | 1 + tools/include/nolibc/arch-arm.h | 17 ++ tools/include/nolibc/arch-m68k.h | 20 +- tools/include/nolibc/arch-riscv.h | 18 ++ tools/include/nolibc/arch-x86.h | 35 +++ tools/include/nolibc/crt.h | 62 +++-- tools/include/nolibc/reloc.h | 240 ++++++++++++++++++ tools/testing/selftests/nolibc/Makefile | 2 +- .../testing/selftests/nolibc/Makefile.nolibc | 8 +- tools/testing/selftests/nolibc/run-tests.sh | 10 +- 13 files changed, 423 insertions(+), 28 deletions(-) create mode 100644 include/uapi/linux/elf-r.h create mode 100644 tools/include/nolibc/reloc.h -- 2.51.0