mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-16 14:55:47 +00:00
Bug 1713735 - Add the bits necessary to build wasm sandbox libs with wasm2c. r=firefox-build-system-reviewers,mhentges
For the moment, it's opt-in via explicitly setting `LUCETC` to an empty string. Differential Revision: https://phabricator.services.mozilla.com/D119939
This commit is contained in:
parent
5bd8cbb171
commit
e2a1db5178
@ -214,6 +214,13 @@ netwerk/test/http3server/target: security/target
|
||||
endif
|
||||
endif
|
||||
|
||||
ifdef MOZ_USING_WASM_SANDBOXING
|
||||
ifndef LUCETC
|
||||
security/rlbox/target-objects: config/external/wasm2c_sandbox_compiler/host
|
||||
security/rlbox/target: security/rlbox/target-objects
|
||||
endif
|
||||
endif
|
||||
|
||||
# Most things are built during compile (target/host), but some things happen during export
|
||||
# Those need to depend on config/export for system wrappers.
|
||||
$(addprefix build/unix/stdc++compat/,target host) build/clang-plugin/host: config/export
|
||||
|
@ -214,6 +214,11 @@ WASM_LIBRARY :=
|
||||
endif
|
||||
|
||||
WASM_ARCHIVE = $(addsuffix .$(WASM_OBJ_SUFFIX),$(WASM_LIBRARY))
|
||||
ifndef LUCETC
|
||||
ifneq (,$(WASM_ARCHIVE))
|
||||
CSRCS += $(addsuffix .c,$(WASM_ARCHIVE))
|
||||
endif
|
||||
endif
|
||||
|
||||
ifdef MACH
|
||||
ifndef NO_BUILDSTATUS_MESSAGES
|
||||
@ -271,9 +276,9 @@ endif
|
||||
#
|
||||
|
||||
ifeq ($(OS_ARCH),Darwin)
|
||||
ifdef SHARED_LIBRARY
|
||||
ifneq (,$(SHARED_LIBRARY)$(WASM_LIBRARY))
|
||||
_LOADER_PATH := @executable_path
|
||||
EXTRA_DSO_LDOPTS += -dynamiclib -install_name $(_LOADER_PATH)/$(SHARED_LIBRARY) -compatibility_version 1 -current_version 1 -single_module
|
||||
EXTRA_DSO_LDOPTS += -dynamiclib -install_name $(_LOADER_PATH)/$@ -compatibility_version 1 -current_version 1 -single_module
|
||||
endif
|
||||
endif
|
||||
|
||||
@ -497,9 +502,10 @@ $(LIBRARY): $(OBJS) $(STATIC_LIBS) $(EXTRA_DEPS) $(GLOBAL_DEPS)
|
||||
|
||||
$(WASM_ARCHIVE): $(CWASMOBJS) $(CPPWASMOBJS) $(STATIC_LIBS) $(EXTRA_DEPS) $(GLOBAL_DEPS)
|
||||
$(REPORT_BUILD_VERBOSE)
|
||||
$(RM) $(WASM_LIBRARY).$(WASM_OBJ_SUFFIX)
|
||||
$(WASM_CXX) $(OUTOPTION)$@ -Wl,--export-all $(CWASMOBJS) $(CPPWASMOBJS)
|
||||
$(RM) $(WASM_ARCHIVE)
|
||||
$(WASM_CXX) $(OUTOPTION)$@ -Wl,--export-all $(if $(LUCETC),,-Wl,--no-entry -Wl,--growable-table) $(CWASMOBJS) $(CPPWASMOBJS)
|
||||
|
||||
ifdef LUCETC
|
||||
lucet_options := \
|
||||
--target $(LUCETC_TARGET) \
|
||||
--target-cpu baseline \
|
||||
@ -513,6 +519,17 @@ $(WASM_LIBRARY): $(WASM_LIBRARY).$(WASM_OBJ_SUFFIX)
|
||||
$(REPORT_BUILD)
|
||||
$(RM) $(WASM_LIBRARY)
|
||||
env LD="$(CC)" LDFLAGS="$(LUCETC_LDFLAGS)" $(LUCETC) $(lucet_options) $(WASM_LIBRARY).$(WASM_OBJ_SUFFIX) -o $(WASM_LIBRARY)
|
||||
else
|
||||
$(addsuffix .c,$(WASM_ARCHIVE)): $(WASM_ARCHIVE)
|
||||
$(DIST)/host/bin/wasm2c -o $@ $<
|
||||
|
||||
$(WASM_LIBRARY): DSO_SONAME=$@
|
||||
$(WASM_LIBRARY): $(filter %.$(OBJ_SUFFIX),$(OBJS))
|
||||
$(REPORT_BUILD)
|
||||
$(RM) $(WASM_LIBRARY)
|
||||
$(MKCSHLIB) $(filter %.$(OBJ_SUFFIX),$(OBJS)) $(LDFLAGS) $(STATIC_LIBS) $(SHARED_LIBS) $(EXTRA_DSO_LDOPTS) $(MOZ_GLUE_LDFLAGS) $(OS_LIBS)
|
||||
$(call py_action,check_binary,--target $@)
|
||||
endif
|
||||
|
||||
ifeq ($(OS_ARCH),WINNT)
|
||||
# Import libraries are created by the rules creating shared libraries.
|
||||
|
@ -85,6 +85,7 @@ OggDemuxer::nsAutoOggSyncState::~nsAutoOggSyncState() {
|
||||
rlbox_sandbox_ogg* OggDemuxer::CreateSandbox() {
|
||||
rlbox_sandbox_ogg* sandbox = new rlbox_sandbox_ogg();
|
||||
#ifdef MOZ_WASM_SANDBOXING_OGG
|
||||
# ifdef LUCETC_WASM_SANDBOXING
|
||||
// Firefox preloads the library externally to ensure we won't be stopped
|
||||
// by the content sandbox
|
||||
const bool external_loads_exist = true;
|
||||
@ -94,6 +95,9 @@ rlbox_sandbox_ogg* OggDemuxer::CreateSandbox() {
|
||||
const bool allow_stdio = false;
|
||||
sandbox->create_sandbox(mozilla::ipc::GetSandboxedRLBoxPath().get(),
|
||||
external_loads_exist, allow_stdio);
|
||||
# else
|
||||
sandbox->create_sandbox(mozilla::ipc::GetSandboxedRLBoxPath().get());
|
||||
# endif
|
||||
#else
|
||||
sandbox->create_sandbox();
|
||||
#endif
|
||||
|
@ -12,7 +12,11 @@
|
||||
#include "mozilla/rlbox/rlbox_config.h"
|
||||
|
||||
#ifdef MOZ_WASM_SANDBOXING_OGG
|
||||
# include "mozilla/rlbox/rlbox_lucet_sandbox.hpp"
|
||||
# ifdef LUCETC_WASM_SANDBOXING
|
||||
# include "mozilla/rlbox/rlbox_lucet_sandbox.hpp"
|
||||
# else
|
||||
# include "mozilla/rlbox/rlbox_wasm2c_sandbox.hpp"
|
||||
# endif
|
||||
#else
|
||||
// Extra configuration for no-op sandbox
|
||||
# define RLBOX_USE_STATIC_CALLS() rlbox_noop_sandbox_lookup_symbol
|
||||
|
@ -9,10 +9,17 @@
|
||||
#include "mozilla/rlbox/rlbox_types.hpp"
|
||||
|
||||
#ifdef MOZ_WASM_SANDBOXING_OGG
|
||||
# ifdef LUCETC_WASM_SANDBOXING
|
||||
namespace rlbox {
|
||||
class rlbox_lucet_sandbox;
|
||||
}
|
||||
using rlbox_ogg_sandbox_type = rlbox::rlbox_lucet_sandbox;
|
||||
# else
|
||||
namespace rlbox {
|
||||
class rlbox_wasm2c_sandbox;
|
||||
}
|
||||
using rlbox_ogg_sandbox_type = rlbox::rlbox_wasm2c_sandbox;
|
||||
# endif
|
||||
#else
|
||||
using rlbox_ogg_sandbox_type = rlbox::rlbox_noop_sandbox;
|
||||
#endif
|
||||
|
@ -38,6 +38,7 @@ RLBoxHunspell::RLBoxHunspell(const nsAutoCString& affpath,
|
||||
const nsAutoCString& dpath)
|
||||
: mHandle(nullptr) {
|
||||
#ifdef MOZ_WASM_SANDBOXING_HUNSPELL
|
||||
# ifdef LUCETC_WASM_SANDBOXING
|
||||
// Firefox preloads the library externally to ensure we won't be stopped by
|
||||
// the content sandbox
|
||||
const bool external_loads_exist = true;
|
||||
@ -47,6 +48,9 @@ RLBoxHunspell::RLBoxHunspell(const nsAutoCString& affpath,
|
||||
const bool allow_stdio = false;
|
||||
mSandbox.create_sandbox(mozilla::ipc::GetSandboxedRLBoxPath().get(),
|
||||
external_loads_exist, allow_stdio);
|
||||
# else
|
||||
mSandbox.create_sandbox(mozilla::ipc::GetSandboxedRLBoxPath().get());
|
||||
# endif
|
||||
#else
|
||||
mSandbox.create_sandbox();
|
||||
#endif
|
||||
|
@ -12,7 +12,11 @@
|
||||
#include "mozilla/rlbox/rlbox_config.h"
|
||||
|
||||
#ifdef MOZ_WASM_SANDBOXING_HUNSPELL
|
||||
# include "mozilla/rlbox/rlbox_lucet_sandbox.hpp"
|
||||
# ifdef LUCETC_WASM_SANDBOXING
|
||||
# include "mozilla/rlbox/rlbox_lucet_sandbox.hpp"
|
||||
# else
|
||||
# include "mozilla/rlbox/rlbox_wasm2c_sandbox.hpp"
|
||||
# endif
|
||||
#else
|
||||
// Extra configuration for no-op sandbox
|
||||
# define RLBOX_USE_STATIC_CALLS() rlbox_noop_sandbox_lookup_symbol
|
||||
|
@ -11,10 +11,17 @@
|
||||
#include "hunspell_csutil.hxx"
|
||||
|
||||
#ifdef MOZ_WASM_SANDBOXING_HUNSPELL
|
||||
# ifdef LUCETC_WASM_SANDBOXING
|
||||
namespace rlbox {
|
||||
class rlbox_lucet_sandbox;
|
||||
}
|
||||
using rlbox_hunspell_sandbox_type = rlbox::rlbox_lucet_sandbox;
|
||||
# else
|
||||
namespace rlbox {
|
||||
class rlbox_wasm2c_sandbox;
|
||||
}
|
||||
using rlbox_hunspell_sandbox_type = rlbox::rlbox_wasm2c_sandbox;
|
||||
# endif
|
||||
#else
|
||||
using rlbox_hunspell_sandbox_type = rlbox::rlbox_noop_sandbox;
|
||||
#endif
|
||||
|
@ -12,7 +12,11 @@
|
||||
#include "mozilla/rlbox/rlbox_config.h"
|
||||
|
||||
#ifdef MOZ_WASM_SANDBOXING_GRAPHITE
|
||||
# include "mozilla/rlbox/rlbox_lucet_sandbox.hpp"
|
||||
# ifdef LUCETC_WASM_SANDBOXING
|
||||
# include "mozilla/rlbox/rlbox_lucet_sandbox.hpp"
|
||||
# else
|
||||
# include "mozilla/rlbox/rlbox_wasm2c_sandbox.hpp"
|
||||
# endif
|
||||
#else
|
||||
// Extra configuration for no-op sandbox
|
||||
# define RLBOX_USE_STATIC_CALLS() rlbox_noop_sandbox_lookup_symbol
|
||||
|
@ -9,10 +9,17 @@
|
||||
#include "mozilla/rlbox/rlbox_types.hpp"
|
||||
|
||||
#ifdef MOZ_WASM_SANDBOXING_GRAPHITE
|
||||
# ifdef LUCETC_WASM_SANDBOXING
|
||||
namespace rlbox {
|
||||
class rlbox_lucet_sandbox;
|
||||
}
|
||||
using rlbox_gr_sandbox_type = rlbox::rlbox_lucet_sandbox;
|
||||
# else
|
||||
namespace rlbox {
|
||||
class rlbox_wasm2c_sandbox;
|
||||
}
|
||||
using rlbox_gr_sandbox_type = rlbox::rlbox_wasm2c_sandbox;
|
||||
# endif
|
||||
#else
|
||||
using rlbox_gr_sandbox_type = rlbox::rlbox_noop_sandbox;
|
||||
#endif
|
||||
|
@ -632,6 +632,7 @@ struct gfxFontEntry::GrSandboxData {
|
||||
|
||||
GrSandboxData() {
|
||||
#ifdef MOZ_WASM_SANDBOXING_GRAPHITE
|
||||
# ifdef LUCETC_WASM_SANDBOXING
|
||||
// Firefox preloads the library externally to ensure we won't be stopped by
|
||||
// the content sandbox
|
||||
const bool external_loads_exist = true;
|
||||
@ -641,6 +642,9 @@ struct gfxFontEntry::GrSandboxData {
|
||||
const bool allow_stdio = false;
|
||||
sandbox.create_sandbox(mozilla::ipc::GetSandboxedRLBoxPath().get(),
|
||||
external_loads_exist, allow_stdio);
|
||||
# else
|
||||
sandbox.create_sandbox(mozilla::ipc::GetSandboxedRLBoxPath().get());
|
||||
# endif
|
||||
#else
|
||||
sandbox.create_sandbox();
|
||||
#endif
|
||||
|
@ -9,6 +9,10 @@ if CONFIG["LUCETC"]:
|
||||
"/third_party/rust/rlbox_lucet_sandbox/c_src/lucet_sandbox_wrapper.c",
|
||||
]
|
||||
else:
|
||||
WASM_SOURCES += [
|
||||
"/third_party/rlbox_wasm2c_sandbox/c_src/wasm2c_sandbox_wrapper.c",
|
||||
]
|
||||
|
||||
LOCAL_INCLUDES += ["/third_party/wasm2c/wasm2c/"]
|
||||
|
||||
EXPORTS += ["/third_party/wasm2c/wasm2c/wasm-rt.h"]
|
||||
@ -20,6 +24,12 @@ else:
|
||||
"/third_party/wasm2c/wasm2c/wasm-rt-wasi.c",
|
||||
]
|
||||
|
||||
NoVisibilityFlags()
|
||||
|
||||
CFLAGS += [
|
||||
"-Wno-error=unused-function",
|
||||
]
|
||||
|
||||
WASM_DEFINES["MOZILLA_CLIENT"] = True
|
||||
|
||||
SANDBOXED_WASM_LIBRARY_NAME = "rlbox"
|
||||
|
@ -80,7 +80,7 @@ gkrust_features += ['glean_with_gecko']
|
||||
if not CONFIG['MOZILLA_OFFICIAL']:
|
||||
gkrust_features += ['glean_disable_upload']
|
||||
|
||||
if CONFIG['MOZ_USING_WASM_SANDBOXING']:
|
||||
if CONFIG['MOZ_USING_WASM_SANDBOXING'] and CONFIG['LUCETC']:
|
||||
gkrust_features += ['wasm_library_sandboxing']
|
||||
|
||||
if CONFIG['MOZ_ENABLE_DBUS']:
|
||||
|
@ -2077,7 +2077,24 @@ set_config("MOZ_USING_WASM_SANDBOXING", requires_wasm_sandboxing)
|
||||
set_define("MOZ_USING_WASM_SANDBOXING", requires_wasm_sandboxing)
|
||||
|
||||
with only_when(requires_wasm_sandboxing & compile_environment):
|
||||
lucetc = check_prog("LUCETC", ["lucetc"], bootstrap="lucetc")
|
||||
option(env="LUCETC", nargs=1, help="Location of the lucet compiler")
|
||||
|
||||
@depends("LUCETC")
|
||||
def lucetc(value):
|
||||
return value
|
||||
|
||||
# Allow setting LUCETC to an explicit empty value to force building
|
||||
# with wasm2c.
|
||||
@depends("LUCETC")
|
||||
def lucetc_not_empty(lucetc):
|
||||
if lucetc.origin != "default" and not lucetc:
|
||||
return False
|
||||
return True
|
||||
|
||||
lucetc = check_prog(
|
||||
"LUCETC", ["lucetc"], input=lucetc, bootstrap="lucetc", when=lucetc_not_empty
|
||||
)
|
||||
set_define("LUCETC_WASM_SANDBOXING", True, when=lucetc)
|
||||
|
||||
option(
|
||||
"--with-wasi-sysroot",
|
||||
|
Loading…
Reference in New Issue
Block a user