* [PATCH v2 0/3] tools/nolibc: clang LTO compatibility
@ 2024-08-12 20:50 Thomas Weißschuh
2024-08-12 20:50 ` [PATCH v2 1/3] tools/nolibc: crt: mark _start_c() as used Thomas Weißschuh
` (3 more replies)
0 siblings, 4 replies; 6+ messages in thread
From: Thomas Weißschuh @ 2024-08-12 20:50 UTC (permalink / raw)
To: Willy Tarreau; +Cc: Ammar Faizi, linux-kernel, Thomas Weißschuh
A few tiny bugfixes and refactoring to provide compatibility with
clangs -flto.
$ CFLAGS_EXTRA=-flto ./run-tests.sh -m user -l
i386: 195 test(s): 193 passed, 2 skipped, 0 failed => status: warning
x86_64: 195 test(s): 193 passed, 2 skipped, 0 failed => status: warning
arm64: 195 test(s): 193 passed, 2 skipped, 0 failed => status: warning
arm: 195 test(s): 193 passed, 2 skipped, 0 failed => status: warning
mips32le: 195 test(s): 192 passed, 3 skipped, 0 failed => status: warning
mips32be: 195 test(s): 192 passed, 3 skipped, 0 failed => status: warning
ppc: 195 test(s): 192 passed, 3 skipped, 0 failed => status: warning
ppc64: 195 test(s): 192 passed, 3 skipped, 0 failed => status: warning
ppc64le: 195 test(s): 192 passed, 3 skipped, 0 failed => status: warning
riscv: 195 test(s): 192 passed, 3 skipped, 0 failed => status: warning
s390: 195 test(s): 192 passed, 3 skipped, 0 failed => status: warning
loongarch: 195 test(s): 192 passed, 3 skipped, 0 failed => status: warning
GCC is not supported, for details read the discussion in v1 of the
series.
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
Changes in v2:
- Drop GCC support
- arch-x86_64.h: Don't try to wrap the asm functions in C functions,
Instead just replace the local symbol with a local label.
- Link to v1: https://lore.kernel.org/r/20240810-nolibc-lto-v1-0-a86e514c7fc1@weissschuh.net
---
Thomas Weißschuh (3):
tools/nolibc: crt: mark _start_c() as used
tools/nolibc: stackprotector: mark implicitly used symbols as used
tools/nolibc: x86_64: use local label in memcpy/memmove
tools/include/nolibc/arch-x86_64.h | 4 ++--
tools/include/nolibc/crt.h | 2 +-
tools/include/nolibc/stackprotector.h | 4 ++--
3 files changed, 5 insertions(+), 5 deletions(-)
---
base-commit: 22ba81c50a49468d80055674d8d6f78afb1c92c4
change-id: 20240728-nolibc-lto-331813b72a0b
Best regards,
--
Thomas Weißschuh <linux@weissschuh.net>
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2 1/3] tools/nolibc: crt: mark _start_c() as used
2024-08-12 20:50 [PATCH v2 0/3] tools/nolibc: clang LTO compatibility Thomas Weißschuh
@ 2024-08-12 20:50 ` Thomas Weißschuh
2024-08-12 20:50 ` [PATCH v2 2/3] tools/nolibc: stackprotector: mark implicitly used symbols " Thomas Weißschuh
` (2 subsequent siblings)
3 siblings, 0 replies; 6+ messages in thread
From: Thomas Weißschuh @ 2024-08-12 20:50 UTC (permalink / raw)
To: Willy Tarreau; +Cc: Ammar Faizi, linux-kernel, Thomas Weißschuh
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ßschuh <linux@weissschuh.net>
---
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 ac291574f6c0..bbcd5fd09806 100644
--- a/tools/include/nolibc/crt.h
+++ b/tools/include/nolibc/crt.h
@@ -22,7 +22,7 @@ extern void (*const __init_array_end[])(int, char **, char**) __attribute__((wea
extern void (*const __fini_array_start[])(void) __attribute__((weak));
extern void (*const __fini_array_end[])(void) __attribute__((weak));
-__attribute__((weak))
+__attribute__((weak,used))
void _start_c(long *sp)
{
long argc;
--
2.46.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2 2/3] tools/nolibc: stackprotector: mark implicitly used symbols as used
2024-08-12 20:50 [PATCH v2 0/3] tools/nolibc: clang LTO compatibility Thomas Weißschuh
2024-08-12 20:50 ` [PATCH v2 1/3] tools/nolibc: crt: mark _start_c() as used Thomas Weißschuh
@ 2024-08-12 20:50 ` Thomas Weißschuh
2024-08-12 20:50 ` [PATCH v2 3/3] tools/nolibc: x86_64: use local label in memcpy/memmove Thomas Weißschuh
2024-08-12 21:00 ` [PATCH v2 0/3] tools/nolibc: clang LTO compatibility Willy Tarreau
3 siblings, 0 replies; 6+ messages in thread
From: Thomas Weißschuh @ 2024-08-12 20:50 UTC (permalink / raw)
To: Willy Tarreau; +Cc: Ammar Faizi, linux-kernel, Thomas Weißschuh
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ßschuh <linux@weissschuh.net>
---
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/stackprotector.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
*/
-__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();
}
-__attribute__((weak,section(".data.nolibc_stack_chk")))
+__attribute__((weak,used,section(".data.nolibc_stack_chk")))
uintptr_t __stack_chk_guard;
static __no_stack_protector void __stack_chk_init(void)
--
2.46.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2 3/3] tools/nolibc: x86_64: use local label in memcpy/memmove
2024-08-12 20:50 [PATCH v2 0/3] tools/nolibc: clang LTO compatibility Thomas Weißschuh
2024-08-12 20:50 ` [PATCH v2 1/3] tools/nolibc: crt: mark _start_c() as used Thomas Weißschuh
2024-08-12 20:50 ` [PATCH v2 2/3] tools/nolibc: stackprotector: mark implicitly used symbols " Thomas Weißschuh
@ 2024-08-12 20:50 ` Thomas Weißschuh
2024-08-13 0:15 ` Ammar Faizi
2024-08-12 21:00 ` [PATCH v2 0/3] tools/nolibc: clang LTO compatibility Willy Tarreau
3 siblings, 1 reply; 6+ messages in thread
From: Thomas Weißschuh @ 2024-08-12 20:50 UTC (permalink / raw)
To: Willy Tarreau; +Cc: Ammar Faizi, linux-kernel, Thomas Weißschuh
Compiling arch-x86_64.h with clang and binutils LD yields
duplicate label errors:
.../gcc-13.2.0-nolibc/x86_64-linux/bin/x86_64-linux-ld: error: LLVM gold plugin: <inline asm>:44:1: symbol '.Lbackward_copy' is already defined
.Lbackward_copy:leaq -1(%rdi, %rcx, 1), %rdi
Instead of a local symbol use a local label which can be defined
multiple times and therefore avoids the error.
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
tools/include/nolibc/arch-x86_64.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tools/include/nolibc/arch-x86_64.h b/tools/include/nolibc/arch-x86_64.h
index 65252c005a30..1e40620a2b33 100644
--- a/tools/include/nolibc/arch-x86_64.h
+++ b/tools/include/nolibc/arch-x86_64.h
@@ -193,10 +193,10 @@ __asm__ (
"movq %rdi, %rdx\n\t"
"subq %rsi, %rdx\n\t"
"cmpq %rcx, %rdx\n\t"
- "jb .Lbackward_copy\n\t"
+ "jb 1f\n\t"
"rep movsb\n\t"
"retq\n"
-".Lbackward_copy:"
+"1:" /* backward copy */
"leaq -1(%rdi, %rcx, 1), %rdi\n\t"
"leaq -1(%rsi, %rcx, 1), %rsi\n\t"
"std\n\t"
--
2.46.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 0/3] tools/nolibc: clang LTO compatibility
2024-08-12 20:50 [PATCH v2 0/3] tools/nolibc: clang LTO compatibility Thomas Weißschuh
` (2 preceding siblings ...)
2024-08-12 20:50 ` [PATCH v2 3/3] tools/nolibc: x86_64: use local label in memcpy/memmove Thomas Weißschuh
@ 2024-08-12 21:00 ` Willy Tarreau
3 siblings, 0 replies; 6+ messages in thread
From: Willy Tarreau @ 2024-08-12 21:00 UTC (permalink / raw)
To: Thomas Weißschuh; +Cc: Ammar Faizi, linux-kernel
On Mon, Aug 12, 2024 at 10:50:16PM +0200, Thomas Weißschuh wrote:
> A few tiny bugfixes and refactoring to provide compatibility with
> clangs -flto.
>
> $ CFLAGS_EXTRA=-flto ./run-tests.sh -m user -l
> i386: 195 test(s): 193 passed, 2 skipped, 0 failed => status: warning
> x86_64: 195 test(s): 193 passed, 2 skipped, 0 failed => status: warning
> arm64: 195 test(s): 193 passed, 2 skipped, 0 failed => status: warning
> arm: 195 test(s): 193 passed, 2 skipped, 0 failed => status: warning
> mips32le: 195 test(s): 192 passed, 3 skipped, 0 failed => status: warning
> mips32be: 195 test(s): 192 passed, 3 skipped, 0 failed => status: warning
> ppc: 195 test(s): 192 passed, 3 skipped, 0 failed => status: warning
> ppc64: 195 test(s): 192 passed, 3 skipped, 0 failed => status: warning
> ppc64le: 195 test(s): 192 passed, 3 skipped, 0 failed => status: warning
> riscv: 195 test(s): 192 passed, 3 skipped, 0 failed => status: warning
> s390: 195 test(s): 192 passed, 3 skipped, 0 failed => status: warning
> loongarch: 195 test(s): 192 passed, 3 skipped, 0 failed => status: warning
>
> GCC is not supported, for details read the discussion in v1 of the
> series.
>
> Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
> ---
> Changes in v2:
> - Drop GCC support
> - arch-x86_64.h: Don't try to wrap the asm functions in C functions,
> Instead just replace the local symbol with a local label.
> - Link to v1: https://lore.kernel.org/r/20240810-nolibc-lto-v1-0-a86e514c7fc1@weissschuh.net
For the whole series:
Acked-by: Willy Tarreau <w@1wt.eu>
Thanks Thoams!
Willy
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 3/3] tools/nolibc: x86_64: use local label in memcpy/memmove
2024-08-12 20:50 ` [PATCH v2 3/3] tools/nolibc: x86_64: use local label in memcpy/memmove Thomas Weißschuh
@ 2024-08-13 0:15 ` Ammar Faizi
0 siblings, 0 replies; 6+ messages in thread
From: Ammar Faizi @ 2024-08-13 0:15 UTC (permalink / raw)
To: Thomas Weißschuh; +Cc: Willy Tarreau, linux-kernel
On Mon, Aug 12, 2024 at 10:50:19PM +0200, Thomas Weißschuh wrote:
> Compiling arch-x86_64.h with clang and binutils LD yields
> duplicate label errors:
>
> .../gcc-13.2.0-nolibc/x86_64-linux/bin/x86_64-linux-ld: error: LLVM gold plugin: <inline asm>:44:1: symbol '.Lbackward_copy' is already defined
> .Lbackward_copy:leaq -1(%rdi, %rcx, 1), %rdi
>
> Instead of a local symbol use a local label which can be defined
> multiple times and therefore avoids the error.
>
> Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
> ---
Reviewed-by: Ammar Faizi <ammarfaizi2@gnuweeb.org>
--
Ammar Faizi
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2024-08-13 0:15 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-08-12 20:50 [PATCH v2 0/3] tools/nolibc: clang LTO compatibility Thomas Weißschuh
2024-08-12 20:50 ` [PATCH v2 1/3] tools/nolibc: crt: mark _start_c() as used Thomas Weißschuh
2024-08-12 20:50 ` [PATCH v2 2/3] tools/nolibc: stackprotector: mark implicitly used symbols " Thomas Weißschuh
2024-08-12 20:50 ` [PATCH v2 3/3] tools/nolibc: x86_64: use local label in memcpy/memmove Thomas Weißschuh
2024-08-13 0:15 ` Ammar Faizi
2024-08-12 21:00 ` [PATCH v2 0/3] tools/nolibc: clang LTO compatibility Willy Tarreau
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®