From 0fe51d2582de6ee7f7d76267e484c300505c93df Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Thu, 22 Feb 2024 15:09:50 -0700 Subject: [PATCH] add preview2_component_type.o to libc.a and libc.so (#472) This file adds a custom section to each core module linked with wasi-libc. That custom section contains component type information needed by e.g. `wasm-tools component new` to generate a component from the module. It will be required once we start using any part of WASI 0.2.0 directly (vs. via a Preview 1 adapter). In addition, it allows developers to `#include ` in their code and make use of those APIs directly even if wasi-libc is not using them yet. Signed-off-by: Joel Dice --- Makefile | 7 +++++++ expected/wasm32-wasi-preview2/defined-symbols.txt | 1 + expected/wasm32-wasi-preview2/undefined-symbols.txt | 1 - 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index f910d5e3..bb20e46a 100644 --- a/Makefile +++ b/Makefile @@ -380,6 +380,9 @@ DLMALLOC_OBJS = $(call objs,$(DLMALLOC_SOURCES)) EMMALLOC_OBJS = $(call objs,$(EMMALLOC_SOURCES)) LIBC_BOTTOM_HALF_ALL_OBJS = $(call objs,$(LIBC_BOTTOM_HALF_ALL_SOURCES)) LIBC_TOP_HALF_ALL_OBJS = $(call asmobjs,$(call objs,$(LIBC_TOP_HALF_ALL_SOURCES))) +ifeq ($(WASI_SNAPSHOT), preview2) +LIBC_OBJS += $(OBJDIR)/preview2_component_type.o +endif ifeq ($(MALLOC_IMPL),dlmalloc) LIBC_OBJS += $(DLMALLOC_OBJS) else ifeq ($(MALLOC_IMPL),emmalloc) @@ -601,6 +604,10 @@ $(OBJDIR)/%.long-double.pic.o: %.c include_dirs @mkdir -p "$(@D)" $(CC) $(CFLAGS) -MD -MP -o $@ -c $< +$(OBJDIR)/preview2_component_type.pic.o $(OBJDIR)/preview2_component_type.o: $(LIBC_BOTTOM_HALF_SOURCES)/preview2_component_type.o + @mkdir -p "$(@D)" + cp $< $@ + $(OBJDIR)/%.pic.o: %.c include_dirs @mkdir -p "$(@D)" $(CC) $(CFLAGS) -MD -MP -o $@ -c $< diff --git a/expected/wasm32-wasi-preview2/defined-symbols.txt b/expected/wasm32-wasi-preview2/defined-symbols.txt index 0fd9aa7a..da4d3910 100644 --- a/expected/wasm32-wasi-preview2/defined-symbols.txt +++ b/expected/wasm32-wasi-preview2/defined-symbols.txt @@ -19,6 +19,7 @@ __c_locale __clock __clock_gettime __clock_nanosleep +__component_type_object_force_link_preview2 __component_type_object_force_link_preview2_public_use_in_this_compilation_unit __cos __cosdf diff --git a/expected/wasm32-wasi-preview2/undefined-symbols.txt b/expected/wasm32-wasi-preview2/undefined-symbols.txt index 710e8116..4a72951d 100644 --- a/expected/wasm32-wasi-preview2/undefined-symbols.txt +++ b/expected/wasm32-wasi-preview2/undefined-symbols.txt @@ -1,5 +1,4 @@ __addtf3 -__component_type_object_force_link_preview2 __divtf3 __eqtf2 __extenddftf2