Skip to content

Commit

Permalink
fix shared library build with llvm-19
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
yamt committed Aug 13, 2024
1 parent d14295a commit 09fe387
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
12 changes: 10 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
3 changes: 3 additions & 0 deletions linker-provided-symbols.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
__heap_base
__heap_end
__c_longjmp

0 comments on commit 09fe387

Please sign in to comment.