From d14295ade98507668278a5449411fc266f6ccd23 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Tue, 13 Aug 2024 15:49:21 +0900 Subject: [PATCH 1/7] libc-top-half/musl/src/signal/psignal.c: avoid libc internal symbol --- libc-top-half/musl/src/signal/psignal.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libc-top-half/musl/src/signal/psignal.c b/libc-top-half/musl/src/signal/psignal.c index 138dbe00f..aa49ae069 100644 --- a/libc-top-half/musl/src/signal/psignal.c +++ b/libc-top-half/musl/src/signal/psignal.c @@ -3,6 +3,11 @@ #include #include +/* undef the macro to use the standard stderr instead of __stderr_FILE + * (the libc internal symbol) as this lives in a separate library, + * libwasi-emulated-signal.so. */ +#undef stderr + void psignal(int sig, const char *msg) { FILE *f = stderr; From 09fe38708ddeb09afa21cb2a45527e77c1880cf7 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Tue, 13 Aug 2024 15:49:49 +0900 Subject: [PATCH 2/7] fix shared library build with llvm-19 * for non libc.so libraries, don't forget to link libc.so * avoid link errors on linker-provided symbols. i feel this is a workaround for a wasm-ld bug. --- Makefile | 12 ++++++++++-- linker-provided-symbols.txt | 3 +++ 2 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 linker-provided-symbols.txt diff --git a/Makefile b/Makefile index 39a16b141..ea61be8cb 100644 --- a/Makefile +++ b/Makefile @@ -616,9 +616,17 @@ PIC_OBJS = \ # link that using `--whole-archive` rather than pass the object files directly # to CC. This is a workaround for a Windows command line size limitation. See # the `%.a` rule below for details. -$(SYSROOT_LIB)/%.so: $(OBJDIR)/%.so.a $(BUILTINS_LIB) + +# Note: libc.so is special because it shouldn't link to libc.so. +$(SYSROOT_LIB)/libc.so: $(OBJDIR)/libc.so.a $(BUILTINS_LIB) $(CC) --target=$(TARGET_TRIPLE) -nodefaultlibs -shared --sysroot=$(SYSROOT) \ - -o $@ -Wl,--whole-archive $< -Wl,--no-whole-archive $(BUILTINS_LIB) + -o $@ -Wl,--whole-archive $< -Wl,--no-whole-archive $(BUILTINS_LIB) \ + -Wl,--allow-undefined-file=linker-provided-symbols.txt + +$(SYSROOT_LIB)/%.so: $(OBJDIR)/%.so.a $(SYSROOT_LIB)/libc.so + $(CC) -v --target=$(TARGET_TRIPLE) -shared --sysroot=$(SYSROOT) \ + -o $@ -Wl,--whole-archive $< -Wl,--no-whole-archive \ + -Wl,--allow-undefined-file=linker-provided-symbols.txt $(OBJDIR)/libc.so.a: $(LIBC_SO_OBJS) $(MUSL_PRINTSCAN_LONG_DOUBLE_SO_OBJS) diff --git a/linker-provided-symbols.txt b/linker-provided-symbols.txt new file mode 100644 index 000000000..8508f8d50 --- /dev/null +++ b/linker-provided-symbols.txt @@ -0,0 +1,3 @@ +__heap_base +__heap_end +__c_longjmp From cd882ed566a1e4b1c3d4b7f531b22d5dea5831f5 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Tue, 13 Aug 2024 21:14:04 +0900 Subject: [PATCH 3/7] remove -v flag slipped in with an unrelated change --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index ea61be8cb..8c4ee9d39 100644 --- a/Makefile +++ b/Makefile @@ -624,7 +624,7 @@ $(SYSROOT_LIB)/libc.so: $(OBJDIR)/libc.so.a $(BUILTINS_LIB) -Wl,--allow-undefined-file=linker-provided-symbols.txt $(SYSROOT_LIB)/%.so: $(OBJDIR)/%.so.a $(SYSROOT_LIB)/libc.so - $(CC) -v --target=$(TARGET_TRIPLE) -shared --sysroot=$(SYSROOT) \ + $(CC) --target=$(TARGET_TRIPLE) -shared --sysroot=$(SYSROOT) \ -o $@ -Wl,--whole-archive $< -Wl,--no-whole-archive \ -Wl,--allow-undefined-file=linker-provided-symbols.txt From fab3862bfcc0641265aa6a53098c231ecc1f038d Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Tue, 13 Aug 2024 21:15:30 +0900 Subject: [PATCH 4/7] fix compiler-rt for shared libraries when building a shared library, specify all CFLAGS because it can contain options like -resource-dir. --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 8c4ee9d39..b96f45bbe 100644 --- a/Makefile +++ b/Makefile @@ -619,12 +619,12 @@ PIC_OBJS = \ # Note: libc.so is special because it shouldn't link to libc.so. $(SYSROOT_LIB)/libc.so: $(OBJDIR)/libc.so.a $(BUILTINS_LIB) - $(CC) --target=$(TARGET_TRIPLE) -nodefaultlibs -shared --sysroot=$(SYSROOT) \ + $(CC) $(CFLAGS) -nodefaultlibs -shared --sysroot=$(SYSROOT) \ -o $@ -Wl,--whole-archive $< -Wl,--no-whole-archive $(BUILTINS_LIB) \ -Wl,--allow-undefined-file=linker-provided-symbols.txt $(SYSROOT_LIB)/%.so: $(OBJDIR)/%.so.a $(SYSROOT_LIB)/libc.so - $(CC) --target=$(TARGET_TRIPLE) -shared --sysroot=$(SYSROOT) \ + $(CC) $(CFLAGS) -shared --sysroot=$(SYSROOT) \ -o $@ -Wl,--whole-archive $< -Wl,--no-whole-archive \ -Wl,--allow-undefined-file=linker-provided-symbols.txt From 8513933cd3b195207a16d7bdcec54bc9d31428c9 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Wed, 14 Aug 2024 13:38:22 +0900 Subject: [PATCH 5/7] mention https://github.com/llvm/llvm-project/issues/103592 --- Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Makefile b/Makefile index b96f45bbe..63134117b 100644 --- a/Makefile +++ b/Makefile @@ -618,6 +618,8 @@ PIC_OBJS = \ # the `%.a` rule below for details. # Note: libc.so is special because it shouldn't link to libc.so. +# Note: --allow-undefined-file=linker-provided-symbols.txt is +# a workaround for https://github.com/llvm/llvm-project/issues/103592 $(SYSROOT_LIB)/libc.so: $(OBJDIR)/libc.so.a $(BUILTINS_LIB) $(CC) $(CFLAGS) -nodefaultlibs -shared --sysroot=$(SYSROOT) \ -o $@ -Wl,--whole-archive $< -Wl,--no-whole-archive $(BUILTINS_LIB) \ From b11539046b1865f40561b9d9b3f734e2201f18e3 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Thu, 15 Aug 2024 00:52:37 +0900 Subject: [PATCH 6/7] wrap a local modification with __wasilibc_unmodified_upstream --- libc-top-half/musl/src/signal/psignal.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libc-top-half/musl/src/signal/psignal.c b/libc-top-half/musl/src/signal/psignal.c index aa49ae069..5b9dc38fa 100644 --- a/libc-top-half/musl/src/signal/psignal.c +++ b/libc-top-half/musl/src/signal/psignal.c @@ -3,10 +3,12 @@ #include #include +#ifndef __wasilibc_unmodified_upstream /* undef the macro to use the standard stderr instead of __stderr_FILE * (the libc internal symbol) as this lives in a separate library, * libwasi-emulated-signal.so. */ #undef stderr +#endif void psignal(int sig, const char *msg) { From 10d410c205cccb4b51f0ea8625c8c01ae82b8d89 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Sat, 24 Aug 2024 18:03:28 +0900 Subject: [PATCH 7/7] Fix wasi-sdk windows job In the wasi-sdk windows job, when building libc.so, for some reasons, the -isystem option in CFLAGS here seems to prevent the linker from finding compiler-rt. I don't understand how it happens because: * Afaik, -isystem should not affect how the linker search objects * The compiler-rt path is explicitly given as BUILTINS_LIB Anyway, this commit tries to work it around by passing only a subset of the options. --- Makefile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 63134117b..952c267ad 100644 --- a/Makefile +++ b/Makefile @@ -621,12 +621,14 @@ PIC_OBJS = \ # Note: --allow-undefined-file=linker-provided-symbols.txt is # a workaround for https://github.com/llvm/llvm-project/issues/103592 $(SYSROOT_LIB)/libc.so: $(OBJDIR)/libc.so.a $(BUILTINS_LIB) - $(CC) $(CFLAGS) -nodefaultlibs -shared --sysroot=$(SYSROOT) \ + $(CC) $(EXTRA_CFLAGS) --target=${TARGET_TRIPLE} -nodefaultlibs \ + -shared --sysroot=$(SYSROOT) \ -o $@ -Wl,--whole-archive $< -Wl,--no-whole-archive $(BUILTINS_LIB) \ -Wl,--allow-undefined-file=linker-provided-symbols.txt $(SYSROOT_LIB)/%.so: $(OBJDIR)/%.so.a $(SYSROOT_LIB)/libc.so - $(CC) $(CFLAGS) -shared --sysroot=$(SYSROOT) \ + $(CC) $(EXTRA_CFLAGS) --target=${TARGET_TRIPLE} \ + -shared --sysroot=$(SYSROOT) \ -o $@ -Wl,--whole-archive $< -Wl,--no-whole-archive \ -Wl,--allow-undefined-file=linker-provided-symbols.txt