From 09fe38708ddeb09afa21cb2a45527e77c1880cf7 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Tue, 13 Aug 2024 15:49:49 +0900 Subject: [PATCH] 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 39a16b14..ea61be8c 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 00000000..8508f8d5 --- /dev/null +++ b/linker-provided-symbols.txt @@ -0,0 +1,3 @@ +__heap_base +__heap_end +__c_longjmp