From nobody Mon Feb 9 17:10:03 2026 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2CD77156220 for ; Sat, 10 Aug 2024 10:54:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=159.69.126.157 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723287294; cv=none; b=M8+cWqxmWEE7yRxnbVcJL32gkDzsZyJn27tjQud08a61IPxLWxvijSIVaY4dDxdWqfQjaeVNzPB1f18mSvZlksQi9lB7/+yKBG9Yw38OnXoDsN6xD564+K9g14G1hNEf8+Out9n/BSge5xK70dMUXG7Tf2anvYDnJ+7a15mQ0Zg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723287294; c=relaxed/simple; bh=jzKF0yba0KcWR8N26vRI2/4+qJGExpvII+5NOGcuBUo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=N3CDwVR2tMNwq0EhFjrsaEDS+iXV+G20+m8USWq1iK2pj/oyYnxN0DIT2Mden0DYZvwgKavp1/M7TeWSEFYKQl84EOx4IUlPgdP4MwSx7ahCGKhDtYmsbyyCX0Lwm//GZZAq7ZIaCPR2HBpZaIqZca98W/r4dghIZk0p7cV/46A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net; spf=pass smtp.mailfrom=weissschuh.net; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b=htrzsqHU; arc=none smtp.client-ip=159.69.126.157 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b="htrzsqHU" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1723287289; bh=jzKF0yba0KcWR8N26vRI2/4+qJGExpvII+5NOGcuBUo=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=htrzsqHUYctVBc/taqurnaZ+idAnD1kfI1zP51jZDBPAmfe25pdIMqXu+b6ppJFpT gq/jh5rosWdc0Di98gTavhT3o84xKHqa5wYGWUe4FrdgEYWmG4d7rDojCr+WT9RwLn Xa238m8+w6Ms0qiVx1uPpjlFfYvneaR/W7LIWLZg= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Sat, 10 Aug 2024 12:54:44 +0200 Subject: [PATCH 1/3] tools/nolibc: crt: mark _start_c() as used Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240810-nolibc-lto-v1-1-a86e514c7fc1@weissschuh.net> References: <20240810-nolibc-lto-v1-0-a86e514c7fc1@weissschuh.net> In-Reply-To: <20240810-nolibc-lto-v1-0-a86e514c7fc1@weissschuh.net> To: Willy Tarreau Cc: Ammar Faizi , linux-kernel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1723287288; l=900; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=jzKF0yba0KcWR8N26vRI2/4+qJGExpvII+5NOGcuBUo=; b=/w4izn8BUZmm84A+drA29mNtfFmvzx5U8N1zxo05O2VXknB75ozIl6d3dD1yahifl45bJRo6y YyvHG2jmR3WBj+/BiuhPHfZsSYdwya0IQcEs1iwWYB9zSImpr0awhtG X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= During LTO the reference from the asm startup code to the _start_c() function is not visible and _start_c() is removed. This will then lead to errors during linking. As _start_c() is indeed always used, mark it as such. Signed-off-by: Thomas Wei=C3=9Fschuh --- tools/include/nolibc/crt.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/include/nolibc/crt.h b/tools/include/nolibc/crt.h index 43b551468c2a..161557e6650d 100644 --- a/tools/include/nolibc/crt.h +++ b/tools/include/nolibc/crt.h @@ -22,7 +22,7 @@ extern void (*const __init_array_end[])(void) __attribute= __((weak)); extern void (*const __fini_array_start[])(void) __attribute__((weak)); extern void (*const __fini_array_end[])(void) __attribute__((weak)); =20 -__attribute__((weak)) +__attribute__((weak,used)) void _start_c(long *sp) { long argc; --=20 2.46.0 From nobody Mon Feb 9 17:10:03 2026 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DD8A128DCB for ; Sat, 10 Aug 2024 10:54:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=159.69.126.157 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723287293; cv=none; b=olq57sRUL7Y/LYttKruw8e9Jtal8xycTNfCiosDp+otXiTIuQozuhnPTkTavw5qg6iEQMnKelJYh4lj8/66bOi0MLX1dKlMjKVelzpmyf6yqDi200ViUM9shFKxUXRs0gj8uWUtPztDCpuHLrGQKjSGCyIR3VreB3FzgXeS8K3k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723287293; c=relaxed/simple; bh=/6UR9g86XgMBxrxchwxIH+6QiNLYmtw9EUkdltAltxY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=FJvjCunzxxSGQjE43GAEwY3z7ueQ36dQayB85C5E7dMAjIpf1bU4PaioXu2MHLp25NKyqfYmyV44MISoxItZhwF5hnCVYy4CejJqVKNWNO/ZAMFcWjo2gCMvBN5H7nxnNbsDFgO70EYKiBF9V04K+2/guak3zBZ27uB+Mo+T9R0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net; spf=pass smtp.mailfrom=weissschuh.net; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b=mcsQlUod; arc=none smtp.client-ip=159.69.126.157 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b="mcsQlUod" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1723287289; bh=/6UR9g86XgMBxrxchwxIH+6QiNLYmtw9EUkdltAltxY=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=mcsQlUodksbtOpks/g2H3Q5g7chnrQ25wCxDado+C70n9LkFZMH51SnJnjYSQR0jI P7Uad2MSpaPXX2QM3++XZhu0E8ya9an2TicUNdqf4tZo4njYIz0ZNYP7NYWZAoSsw+ k0z8kNnfJWda31kW0I3h37KFMk/C8v0kMnLbwBvM= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Sat, 10 Aug 2024 12:54:45 +0200 Subject: [PATCH 2/3] tools/nolibc: stackprotector: mark implicitly used symbols as used Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240810-nolibc-lto-v1-2-a86e514c7fc1@weissschuh.net> References: <20240810-nolibc-lto-v1-0-a86e514c7fc1@weissschuh.net> In-Reply-To: <20240810-nolibc-lto-v1-0-a86e514c7fc1@weissschuh.net> To: Willy Tarreau Cc: Ammar Faizi , linux-kernel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1723287288; l=1268; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=/6UR9g86XgMBxrxchwxIH+6QiNLYmtw9EUkdltAltxY=; b=BD2VLzZM4cq9AS+CnW2Wa1elmV3h7CGqngIzFor2mev/TbPcJsIXTj0/of44hgd/G/0spUaoc 7q1uGxYRIolBzifdDRg/Ex2ywNfCXomoWc+QPnce9ClZYknlJhGCxvD X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= During LTO the references from the compiler-generated prologue and epilogues to the stack protector symbols are not visible and the symbols are removed. This will then lead to errors during linking. As those symbols are already #ifdeffed-out if unused mark them as "used" to prevent their removal. Signed-off-by: Thomas Wei=C3=9Fschuh --- tools/include/nolibc/stackprotector.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/include/nolibc/stackprotector.h b/tools/include/nolibc/s= tackprotector.h index 13f1d0e60387..1d0d5259ec41 100644 --- a/tools/include/nolibc/stackprotector.h +++ b/tools/include/nolibc/stackprotector.h @@ -18,7 +18,7 @@ * triggering stack protector errors themselves */ =20 -__attribute__((weak,noreturn,section(".text.nolibc_stack_chk"))) +__attribute__((weak,used,noreturn,section(".text.nolibc_stack_chk"))) void __stack_chk_fail(void) { pid_t pid; @@ -34,7 +34,7 @@ void __stack_chk_fail_local(void) __stack_chk_fail(); } =20 -__attribute__((weak,section(".data.nolibc_stack_chk"))) +__attribute__((weak,used,section(".data.nolibc_stack_chk"))) uintptr_t __stack_chk_guard; =20 static __no_stack_protector void __stack_chk_init(void) --=20 2.46.0 From nobody Mon Feb 9 17:10:03 2026 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2CD19150996 for ; Sat, 10 Aug 2024 10:54:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=159.69.126.157 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723287294; cv=none; b=ZxuGqSqv/XnZE4Sr53tf/o31hqf/XHMtlw4hszGJnaV1VajUrPZ1PpO0FIDZXNiCBhTeFXgPd+fjMP8JbBv4oq/VRhmimrVceIybumSHEARC1QAnPiSw9EOmeJzKDdSa+Bro6DGOXTAVw9QxnhOroDPvDjpkIfpk+bHmNhOOfBQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723287294; c=relaxed/simple; bh=cGwHAKfERKI5sQ+r87zSxLZ/oZCmGAEV09XlpQjon3g=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=RpMPwSehq3F6GQzdtjZZGmAotRzSkhaI5xXQ3Ua2qUYgV2RQ1w4uLrIEMk/1f4epJTf51MErLcmVVD34faVCe9aFG1b3Vjg4Od3rP+vINClinI5dAtWvnNboMOmNIl0K+MhN3S6fdj5TBO4hcLqrXg5TPQGSLkBQQwWm+AsBHXE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net; spf=pass smtp.mailfrom=weissschuh.net; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b=PEumRTuJ; arc=none smtp.client-ip=159.69.126.157 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b="PEumRTuJ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1723287289; bh=cGwHAKfERKI5sQ+r87zSxLZ/oZCmGAEV09XlpQjon3g=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=PEumRTuJSQaUebh63q09OBT7vMRphs3o9LjUZAZw2MMB/K0eNYHpdWRnKZ9f8VWlt ujsbPjKAl3Nkr0x0ChQfQKz+sN1E7vOC+WKingxsuxmlHN8aenDUb9xZOCIlet0HwB 81XtGJuDeRpY6aXCXfWnjJC2zUlqmWtFeBg0606I= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Sat, 10 Aug 2024 12:54:46 +0200 Subject: [PATCH 3/3] tools/nolibc: x86_64: wrap asm functions in functions Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240810-nolibc-lto-v1-3-a86e514c7fc1@weissschuh.net> References: <20240810-nolibc-lto-v1-0-a86e514c7fc1@weissschuh.net> In-Reply-To: <20240810-nolibc-lto-v1-0-a86e514c7fc1@weissschuh.net> To: Willy Tarreau Cc: Ammar Faizi , linux-kernel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1723287288; l=3197; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=cGwHAKfERKI5sQ+r87zSxLZ/oZCmGAEV09XlpQjon3g=; b=pxhMoc4sMKT6LD83WJ9WfI4uZpnrkecV6c3aWRQXSPEcjvRWGH/lrAYr3YEBlTKTyvvjU2sfR w8UqqOvB/uwCYktVMYaUZ59ucAEOB0rwjayQNpm5kkbCaueejuZA7d4 X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= The bare asm usage does not work well together with LTO. It leads to errors: /tmp/ccIHTYT6.s: Assembler messages: /tmp/ccIHTYT6.s:36: Error: symbol `memmove' is already defined /tmp/ccIHTYT6.s:37: Error: symbol `memcpy' is already defined /tmp/ccIHTYT6.s:46: Error: symbol `.Lbackward_copy' is already defined /tmp/ccIHTYT6.s:54: Error: symbol `memset' is already defined Wrap the asm in naked functions, which leads to the same object code but avoids the errors. Signed-off-by: Thomas Wei=C3=9Fschuh --- tools/include/nolibc/arch-x86_64.h | 80 +++++++++++++++++++++-------------= ---- 1 file changed, 44 insertions(+), 36 deletions(-) diff --git a/tools/include/nolibc/arch-x86_64.h b/tools/include/nolibc/arch= -x86_64.h index 3c3b703d9b0c..efbea173fb74 100644 --- a/tools/include/nolibc/arch-x86_64.h +++ b/tools/include/nolibc/arch-x86_64.h @@ -174,45 +174,53 @@ void __attribute__((weak, noreturn)) __nolibc_naked _= _no_stack_protector _start( } =20 #define NOLIBC_ARCH_HAS_MEMMOVE -void *memmove(void *dst, const void *src, size_t len); +__attribute__((weak,unused,section(".text.nolibc_memmove"))) +__nolibc_naked __no_stack_protector +void *memmove(void *dst __attribute__((unused)), + const void *src __attribute__((unused)), + size_t len __attribute__((unused))) +{ + __asm__ volatile ( + "movq %rdx, %rcx\n\t" + "movq %rdi, %rax\n\t" + "movq %rdi, %rdx\n\t" + "subq %rsi, %rdx\n\t" + "cmpq %rcx, %rdx\n\t" + "jb .Lbackward_copy\n\t" + "rep movsb\n\t" + "retq\n" + ".Lbackward_copy:" + "leaq -1(%rdi, %rcx, 1), %rdi\n\t" + "leaq -1(%rsi, %rcx, 1), %rsi\n\t" + "std\n\t" + "rep movsb\n\t" + "cld\n\t" + "retq\n" + ); + __nolibc_naked_epilogue(); +} =20 #define NOLIBC_ARCH_HAS_MEMCPY -void *memcpy(void *dst, const void *src, size_t len); +static __inline__ void *memcpy(void *dst, const void *src, size_t len) +{ + return memmove(dst, src, len); +} =20 #define NOLIBC_ARCH_HAS_MEMSET -void *memset(void *dst, int c, size_t len); - -__asm__ ( -".section .text.nolibc_memmove_memcpy\n" -".weak memmove\n" -".weak memcpy\n" -"memmove:\n" -"memcpy:\n" - "movq %rdx, %rcx\n\t" - "movq %rdi, %rax\n\t" - "movq %rdi, %rdx\n\t" - "subq %rsi, %rdx\n\t" - "cmpq %rcx, %rdx\n\t" - "jb .Lbackward_copy\n\t" - "rep movsb\n\t" - "retq\n" -".Lbackward_copy:" - "leaq -1(%rdi, %rcx, 1), %rdi\n\t" - "leaq -1(%rsi, %rcx, 1), %rsi\n\t" - "std\n\t" - "rep movsb\n\t" - "cld\n\t" - "retq\n" - -".section .text.nolibc_memset\n" -".weak memset\n" -"memset:\n" - "xchgl %eax, %esi\n\t" - "movq %rdx, %rcx\n\t" - "pushq %rdi\n\t" - "rep stosb\n\t" - "popq %rax\n\t" - "retq\n" -); +__attribute__((weak,unused,section(".text.nolibc_memset"))) +__nolibc_naked __no_stack_protector +void *memset(void *dst __attribute__((unused)), int c __attribute__((unuse= d)), + size_t len __attribute__((unused))) +{ + __asm__ volatile ( + "xchgl %eax, %esi\n\t" + "movq %rdx, %rcx\n\t" + "pushq %rdi\n\t" + "rep stosb\n\t" + "popq %rax\n\t" + "retq\n" + ); + __nolibc_naked_epilogue(); +} =20 #endif /* _NOLIBC_ARCH_X86_64_H */ --=20 2.46.0