From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) (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 1DC80365A10 for ; Wed, 4 Feb 2026 12:46:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.175 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770209163; cv=none; b=cwaZwgTT8xN+ui5ph/MibABsWpYzMita5orrNSC6AYpV9jC8nBdkI+/uP1uiTEhS6bOfjAWyStLsbhPKJ5PCzD8pQyzsKo4XPst/m0VAHih3uz/PdaTW18i7WX4jq4CsOHUehHTmPerjUHnK81paWn7ElI7o92Zhf/w5yXXelfc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770209163; c=relaxed/simple; bh=r6Z/EgWN79NZ42CciI8U7d9ec/dyNTLi8m/YYGF/Nd8=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=msLr6addgC8ALTddWc4a/jTcb+Dk8c3afVmWgAf+PiR3Dp7q7aB09RmoU0hdtOXvlHnaO3O0MNBAX2jevZhIKLJY4hTMoI8MM68BBtgM1B7USyc/IUnQAVAKREaYGjehGi3Yy7kWk5kBBe4CqUi0v1qDeFEp34a9re/ssnHtAJA= 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=fgsWEMXz; arc=none smtp.client-ip=209.85.210.175 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="fgsWEMXz" Received: by mail-pf1-f175.google.com with SMTP id d2e1a72fcca58-81f4e36512aso6381379b3a.3 for ; Wed, 04 Feb 2026 04:46:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=thingy.jp; s=google; t=1770209161; x=1770813961; 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=y5RhdfUtia0mBgIB9fjkgypq15YB1Za+MjChvL9wBwU=; b=fgsWEMXzFKvTmPg/nQcf6GrxLMZ4ODEbgl2DvIY7AP/fyyldsVG6lneG+7SzXbIjcj p11WhNgiuVDNEFZwjnMoYoIWZ/gdoGqgF6ctpNbL/5L2JVCwXWQCJTQ4Nk/mHnC+MjIy qFbWRPwEkQhpjPU1V8yUL5fbWhH76pcR8s6gA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770209161; x=1770813961; 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=y5RhdfUtia0mBgIB9fjkgypq15YB1Za+MjChvL9wBwU=; b=NvK50Dy7BYgdtfxdNlWvR4plK4L1KRiQdXoRUOopyPw5bN/w6SeVvuXK3eQdHS3mgF TvhsUBQ0BLAVjkg1gg/08AOhmfMZh+VRN5d6ogJQF0TPp9we+XJ17efffCnd+GYB0kmc kdfBzlU4cMJqwNlSe6mjcClONgRp6cqfZir8pzfm752yozUgVCScxtUQWc83PMKNuSxl lQe5y6E5tP2Pta17jVy8FzbePPgswRB2BKEoaqsm7GJoqI1Dqyt6IXU39FAlb9QUlM9D Wy+0cWpaJtQzoLMBwJ6yKY9pTo3hlBakwbks/5TNCUZyWTXTM+tWKHhOa8ThFRT8T9Tq pqTQ== X-Gm-Message-State: AOJu0Yw5Hqi4D35ljBejyQ3bmzY/PPjOEZ5a+kIbW1/AASPZzguGhgx/ 0z+nzOmCdozs61D6AcquhkXLTMJl3G4WQrxIxBek53kV/nyNYAwQmym5gCjq/ILXRxY= X-Gm-Gg: AZuq6aIbENLOjGMVRERh18OC40UApOeqSDsJlWd4C5IuK1ewvhHydvn/wcRrZQc8dIQ zXyfjsBEJsSnOzSQwqcq2owh04+Qs+zFieFtUKh7bNpT+HplqIDUN4nGrDyUMIPAQS53xfjhlmN ktO8yqavXOSbmx/2Gsbo8Ci0potQ6zYz0xeeopg2inNs7A9qc4alGZ9vtaB/pXBGQWxxoh2mx7w hubh0GFxgRshC5U2rUvTAD3Oh8k4h6sQHOPSk1i9bP2gGNfi0/0roxcVnfHTK+xoVyJxdgL6U+h bIRM26c2EOqgSPe3C1eOAglG4pXBjdLEJ0Vg9Od/0vPbz/CYpo4POo8zvJJ84b0TDwB0TwnU2/7 c35w9PwM8wzLzeIKc88c++Z7XDZjeVs2YN3zs2v8q4Op0lqooYnpBNA2ki1jg7Od3yS9USlmDDx JkSNTJ4FzLBL/t1S24hqYzFdrfSOG/jGS3Wf2bW13hJPF1npwmSh+uPisnptF4fw2DPbGkkUFAl /Jb X-Received: by 2002:a05:6a21:880a:b0:393:73e5:7404 with SMTP id adf61e73a8af0-39373e57b0dmr2053683637.52.1770209161291; Wed, 04 Feb 2026 04:46:01 -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 98e67ed59e1d1-354862effa6sm2378920a91.9.2026.02.04.04.45.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Feb 2026 04:46:00 -0800 (PST) From: Daniel Palmer To: w@1wt.eu, linux@weissschuh.net Cc: linux-kernel@vger.kernel.org, Daniel Palmer Subject: [RFC PATCH v2 00/10] nolibc: Add static-pie support Date: Wed, 4 Feb 2026 21:45:32 +0900 Message-ID: <20260204124542.523567-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 v2: - This is still RFC quality - I have gotten a few more archs to work (not crash in nolibc-test) so I have added them to show the that the arch specific parts are pretty small. - This should now only add this extra code if NOLIBC_WANT_RELOC is defined, which happens automatically if you compile with -fpie. Should address Willy's concern with the size blowing up for even binaries that don't need this. Size difference on ppc64 is massive, I guess PIC code is big there. static: $ file nolibc-test nolibc-test: ELF 64-bit MSB executable, 64-bit PowerPC or cisco 7500, Power ELF V1 ABI, version 1 (SYSV), statically linked, not stripped $ size nolibc-test text data bss dec hex filename 59560 3240 104 62904 f5b8 nolibc-test static pie: $ file nolibc-test nolibc-test: ELF 64-bit MSB pie executable, 64-bit PowerPC or cisco 7500, Power ELF V1 ABI, version 1 (SYSV), static-pie linked, with debug_info, not stripped $ size nolibc-test text data bss dec hex filename 67801 3656 104 71561 11789 nolibc-test - Each of the archs checks that the relocations they need (just the one at the moment) is defined before defining the relocation defines. So this shouldn't break with older UAPI headers. - I think maybe you might want to set NOLIBC_WANT_RELOC even if __pie__ is not defined, maybe for testing? So I didn't make it _NOLIBC_WANT_RELOC. - I was worried some archs didn't work because calling the relocation functions was causing things like accessing the stack canary before it was accessible. So I added __inline__ to all of the relocation functions to force them to get inlined into _start_c(). This might be too much. checkpatch certainly hates it. - I think I addressed most of Thomas' code style comments, prefixing etc. Maybe added some new problems :) - I cleaned up the REL/RELA differences a bit more so the lines of code has dropped a bit in reloc.h. - I fixed working out where the dynamic section is, this fixed SuperH and PPC. I suspect I can get all of the others except maybe mips working now. - new elf UAPI header for the relocation types is still wrong, script to run the self-tests is still wonky. Thanks in advance, Daniel v1: https://lore.kernel.org/lkml/20260131074440.732588-1-daniel@thingy.jp/ v0: https://lore.kernel.org/lkml/20260116122812.2421621-1-daniel@thingy.jp/ Daniel Palmer (10): elf: Add relocation types used by nolibc tools/nolibc: crt: Split _start_c() into stack-only and normal parts tools/nolibc: Add basic ELF self-relocation support for static PIE tools/nolibc: m68k: Add relocation support tools/nolibc: x86: Add relocation support tools/nolibc: riscv: Add relocation support tools/nolibc: arm: Add relocation support tools/nolibc: sh: Add relocation support tools/nolibc: ppc: Add relocation support selftests/nolibc: Add option for building with -static-pie include/uapi/linux/elf-r.h | 27 +++ include/uapi/linux/elf.h | 1 + tools/include/nolibc/Makefile | 1 + tools/include/nolibc/arch-arm.h | 25 ++ tools/include/nolibc/arch-m68k.h | 27 ++- tools/include/nolibc/arch-powerpc.h | 24 ++ tools/include/nolibc/arch-riscv.h | 26 ++ tools/include/nolibc/arch-sh.h | 24 ++ tools/include/nolibc/arch-x86.h | 53 +++++ tools/include/nolibc/compiler.h | 6 + tools/include/nolibc/crt.h | 62 +++-- tools/include/nolibc/reloc.h | 224 ++++++++++++++++++ tools/testing/selftests/nolibc/Makefile | 2 +- .../testing/selftests/nolibc/Makefile.nolibc | 8 +- tools/testing/selftests/nolibc/run-tests.sh | 10 +- 15 files changed, 489 insertions(+), 31 deletions(-) create mode 100644 include/uapi/linux/elf-r.h create mode 100644 tools/include/nolibc/reloc.h -- 2.51.0