Index: docs/ReleaseNotes.rst =================================================================== --- docs/ReleaseNotes.rst +++ docs/ReleaseNotes.rst @@ -64,4 +64,7 @@ WebAssembly Improvements ------------------------ -* ... +* `__data_end` and `__heap_base` are no longer exported by default, + as it's best to keep them internal when possible. They can be + explicitly exported with `--export=__data_end` and + `--export=__heap_base`, respectively. Index: test/wasm/alias.ll =================================================================== --- test/wasm/alias.ll +++ test/wasm/alias.ll @@ -1,7 +1,12 @@ ; RUN: llc -filetype=obj -o %t.o %s + ; RUN: wasm-ld --export=start_alias %t.o -o %t.wasm ; RUN: obj2yaml %t.wasm | FileCheck %s +; Same thing, now with --emscripten. +; RUN: wasm-ld --export=start_alias --emscripten %t.o -o %t.wasm +; RUN: obj2yaml %t.wasm | FileCheck %s --check-prefixes=CHECK,EMSCRIPTEN + target triple = "wasm32-unknown-unknown" @start_alias = alias void (), void ()* @_start @@ -41,29 +46,29 @@ ; CHECK-NEXT: InitExpr: ; CHECK-NEXT: Opcode: I32_CONST ; CHECK-NEXT: Value: 66560 -; CHECK-NEXT: - Index: 1 -; CHECK-NEXT: Type: I32 -; CHECK-NEXT: Mutable: false -; CHECK-NEXT: InitExpr: -; CHECK-NEXT: Opcode: I32_CONST -; CHECK-NEXT: Value: 66560 -; CHECK-NEXT: - Index: 2 -; CHECK-NEXT: Type: I32 -; CHECK-NEXT: Mutable: false -; CHECK-NEXT: InitExpr: -; CHECK-NEXT: Opcode: I32_CONST -; CHECK-NEXT: Value: 1024 +; EMSCRIPTEN-NEXT: - Index: 1 +; EMSCRIPTEN-NEXT: Type: I32 +; EMSCRIPTEN-NEXT: Mutable: false +; EMSCRIPTEN-NEXT: InitExpr: +; EMSCRIPTEN-NEXT: Opcode: I32_CONST +; EMSCRIPTEN-NEXT: Value: 66560 +; EMSCRIPTEN-NEXT: - Index: 2 +; EMSCRIPTEN-NEXT: Type: I32 +; EMSCRIPTEN-NEXT: Mutable: false +; EMSCRIPTEN-NEXT: InitExpr: +; EMSCRIPTEN-NEXT: Opcode: I32_CONST +; EMSCRIPTEN-NEXT: Value: 1024 ; CHECK-NEXT: - Type: EXPORT ; CHECK-NEXT: Exports: ; CHECK-NEXT: - Name: memory ; CHECK-NEXT: Kind: MEMORY ; CHECK-NEXT: Index: 0 -; CHECK-NEXT: - Name: __heap_base -; CHECK-NEXT: Kind: GLOBAL -; CHECK-NEXT: Index: 1 -; CHECK-NEXT: - Name: __data_end -; CHECK-NEXT: Kind: GLOBAL -; CHECK-NEXT: Index: 2 +; EMSCRIPTEN-NEXT: - Name: __heap_base +; EMSCRIPTEN-NEXT: Kind: GLOBAL +; EMSCRIPTEN-NEXT: Index: 1 +; EMSCRIPTEN-NEXT: - Name: __data_end +; EMSCRIPTEN-NEXT: Kind: GLOBAL +; EMSCRIPTEN-NEXT: Index: 2 ; CHECK-NEXT: - Name: _start ; CHECK-NEXT: Kind: FUNCTION ; CHECK-NEXT: Index: 0 Index: test/wasm/cxx-mangling.ll =================================================================== --- test/wasm/cxx-mangling.ll +++ test/wasm/cxx-mangling.ll @@ -1,9 +1,16 @@ ; RUN: llc -filetype=obj %s -o %t.o + ; RUN: wasm-ld --export=_Z3fooi --demangle -o %t_demangle.wasm %t.o ; RUN: obj2yaml %t_demangle.wasm | FileCheck --check-prefixes=CHECK,DEMANGLE %s ; RUN: wasm-ld --export=_Z3fooi --no-demangle -o %t_nodemangle.wasm %t.o ; RUN: obj2yaml %t_nodemangle.wasm | FileCheck --check-prefixes=CHECK,MANGLE %s +; Same thing, now with --emscripten. +; RUN: wasm-ld --emscripten --export=_Z3fooi --demangle -o %t_demangle.wasm %t.o +; RUN: obj2yaml %t_demangle.wasm | FileCheck --check-prefixes=CHECK,DEMANGLE,EMSCRIPTEN %s +; RUN: wasm-ld --emscripten --export=_Z3fooi --no-demangle -o %t_nodemangle.wasm %t.o +; RUN: obj2yaml %t_nodemangle.wasm | FileCheck --check-prefixes=CHECK,MANGLE,EMSCRIPTEN %s + target triple = "wasm32-unknown-unknown" ; Check that the EXPORT name is still mangled, but that the "name" custom @@ -26,12 +33,12 @@ ; CHECK-NEXT: - Name: memory ; CHECK-NEXT: Kind: MEMORY ; CHECK-NEXT: Index: 0 -; CHECK-NEXT: - Name: __heap_base -; CHECK-NEXT: Kind: GLOBAL -; CHECK-NEXT: Index: 1 -; CHECK-NEXT: - Name: __data_end -; CHECK-NEXT: Kind: GLOBAL -; CHECK-NEXT: Index: 2 +; EMSCRIPTEN-NEXT: - Name: __heap_base +; EMSCRIPTEN-NEXT: Kind: GLOBAL +; EMSCRIPTEN-NEXT: Index: 1 +; EMSCRIPTEN-NEXT: - Name: __data_end +; EMSCRIPTEN-NEXT: Kind: GLOBAL +; EMSCRIPTEN-NEXT: Index: 2 ; CHECK-NEXT: - Name: _Z3fooi ; CHECK-NEXT: Kind: FUNCTION ; CHECK-NEXT: Index: 1 Index: test/wasm/data-layout.ll =================================================================== --- test/wasm/data-layout.ll +++ test/wasm/data-layout.ll @@ -16,6 +16,10 @@ ; RUN: wasm-ld -no-gc-sections --allow-undefined --no-entry -o %t.wasm %t.o %t.hello.o ; RUN: obj2yaml %t.wasm | FileCheck %s +; Same thing, now with --emscripten. +; RUN: wasm-ld --emscripten -no-gc-sections --allow-undefined --no-entry -o %t.wasm %t.o %t.hello.o +; RUN: obj2yaml %t.wasm | FileCheck %s --check-prefixes=CHECK,EMSCRIPTEN + ; CHECK: - Type: MEMORY ; CHECK-NEXT: Memories: ; CHECK-NEXT: - Initial: 0x00000002 @@ -27,12 +31,12 @@ ; CHECK-NEXT: InitExpr: ; CHECK-NEXT: Opcode: I32_CONST ; CHECK-NEXT: Value: 66608 -; CHECK-NEXT: - Index: 1 -; CHECK-NEXT: Type: I32 -; CHECK-NEXT: Mutable: false -; CHECK-NEXT: InitExpr: -; CHECK-NEXT: Opcode: I32_CONST -; CHECK-NEXT: Value: 66608 +; EMSCRIPTEN-NEXT: - Index: 1 +; EMSCRIPTEN-NEXT: Type: I32 +; EMSCRIPTEN-NEXT: Mutable: false +; EMSCRIPTEN-NEXT: InitExpr: +; EMSCRIPTEN-NEXT: Opcode: I32_CONST +; EMSCRIPTEN-NEXT: Value: 66608 ; CHECK: - Type: DATA ; CHECK-NEXT: Segments: Index: test/wasm/entry.ll =================================================================== --- test/wasm/entry.ll +++ test/wasm/entry.ll @@ -12,17 +12,23 @@ ; RUN: wasm-ld --entry=entry -o %t2.wasm %t.o ; RUN: obj2yaml %t2.wasm | FileCheck %s +; Same thing, now with --emscripten. +; RUN: wasm-ld --emscripten -e entry -o %t1.wasm %t.o +; RUN: obj2yaml %t1.wasm | FileCheck %s --check-prefixes=CHECK,EMSCRIPTEN +; RUN: wasm-ld --emscripten --entry=entry -o %t2.wasm %t.o +; RUN: obj2yaml %t2.wasm | FileCheck %s --check-prefixes=CHECK,EMSCRIPTEN + ; CHECK: - Type: EXPORT ; CHECK-NEXT: Exports: ; CHECK-NEXT: - Name: memory ; CHECK-NEXT: Kind: MEMORY ; CHECK-NEXT: Index: 0 -; CHECK-NEXT: - Name: __heap_base -; CHECK-NEXT: Kind: GLOBAL -; CHECK-NEXT: Index: 1 -; CHECK-NEXT: - Name: __data_end -; CHECK-NEXT: Kind: GLOBAL -; CHECK-NEXT: Index: 2 +; EMSCRIPTEN-NEXT: - Name: __heap_base +; EMSCRIPTEN-NEXT: Kind: GLOBAL +; EMSCRIPTEN-NEXT: Index: 1 +; EMSCRIPTEN-NEXT: - Name: __data_end +; EMSCRIPTEN-NEXT: Kind: GLOBAL +; EMSCRIPTEN-NEXT: Index: 2 ; CHECK-NEXT: - Name: entry ; CHECK-NEXT: Kind: FUNCTION ; CHECK-NEXT: Index: 0 @@ -33,6 +39,10 @@ ; RUN: wasm-ld --entry=__wasm_call_ctors -o %t3.wasm %t.o ; RUN: obj2yaml %t3.wasm | FileCheck %s -check-prefix=CHECK-CTOR +; Same thing, now with --emscripten. +; RUN: wasm-ld --emscripten --entry=__wasm_call_ctors -o %t3.wasm %t.o +; RUN: obj2yaml %t3.wasm | FileCheck %s -check-prefixes=CHECK-CTOR,EMSCRIPTEN-CTOR + ; CHECK-CTOR: - Type: EXPORT ; CHECK-CTOR-NEXT: Exports: ; CHECK-CTOR-NEXT: - Name: memory @@ -41,10 +51,10 @@ ; CHECK-CTOR-NEXT: - Name: __wasm_call_ctors ; CHECK-CTOR-NEXT: Kind: FUNCTION ; CHECK-CTOR-NEXT: Index: 0 -; CHECK-CTOR-NEXT: - Name: __heap_base -; CHECK-CTOR-NEXT: Kind: GLOBAL -; CHECK-CTOR-NEXT: Index: 1 -; CHECK-CTOR-NEXT: - Name: __data_end -; CHECK-CTOR-NEXT: Kind: GLOBAL -; CHECK-CTOR-NEXT: Index: 2 +; EMSCRIPTEN-CTOR-NEXT: - Name: __heap_base +; EMSCRIPTEN-CTOR-NEXT: Kind: GLOBAL +; EMSCRIPTEN-CTOR-NEXT: Index: 1 +; EMSCRIPTEN-CTOR-NEXT: - Name: __data_end +; EMSCRIPTEN-CTOR-NEXT: Kind: GLOBAL +; EMSCRIPTEN-CTOR-NEXT: Index: 2 ; CHECK-CTOR-NEXT: - Type: Index: test/wasm/export.ll =================================================================== --- test/wasm/export.ll +++ test/wasm/export.ll @@ -1,8 +1,13 @@ ; RUN: llc -filetype=obj %s -o %t.o ; RUN: not wasm-ld --export=missing -o %t.wasm %t.o 2>&1 | FileCheck -check-prefix=CHECK-ERROR %s + ; RUN: wasm-ld --export=hidden_function -o %t.wasm %t.o ; RUN: obj2yaml %t.wasm | FileCheck %s +; Same thing, now with --emscripten. +; RUN: wasm-ld --emscripten --export=hidden_function -o %t.wasm %t.o +; RUN: obj2yaml %t.wasm | FileCheck %s --check-prefixes=CHECK,EMSCRIPTEN + @llvm.used = appending global [1 x i8*] [i8* bitcast (i32 ()* @used_function to i8*)], section "llvm.metadata" target triple = "wasm32-unknown-unknown" @@ -40,12 +45,12 @@ ; CHECK-NEXT: - Name: memory ; CHECK-NEXT: Kind: MEMORY ; CHECK-NEXT: Index: 0 -; CHECK-NEXT: - Name: __heap_base -; CHECK-NEXT: Kind: GLOBAL -; CHECK-NEXT: Index: 1 -; CHECK-NEXT: - Name: __data_end -; CHECK-NEXT: Kind: GLOBAL -; CHECK-NEXT: Index: 2 +; EMSCRIPTEN-NEXT: - Name: __heap_base +; EMSCRIPTEN-NEXT: Kind: GLOBAL +; EMSCRIPTEN-NEXT: Index: 1 +; EMSCRIPTEN-NEXT: - Name: __data_end +; EMSCRIPTEN-NEXT: Kind: GLOBAL +; EMSCRIPTEN-NEXT: Index: 2 ; CHECK-NEXT: - Name: hidden_function ; CHECK-NEXT: Kind: FUNCTION ; CHECK-NEXT: Index: 0 Index: test/wasm/lto/export.ll =================================================================== --- test/wasm/lto/export.ll +++ test/wasm/lto/export.ll @@ -1,8 +1,13 @@ ; RUN: llvm-as -o %t.bc %s ; RUN: not wasm-ld --export=missing -o %t.wasm %t.bc 2>&1 | FileCheck -check-prefix=CHECK-ERROR %s + ; RUN: wasm-ld --export=hidden_function -o %t.wasm %t.bc ; RUN: obj2yaml %t.wasm | FileCheck %s +; Same thing, now with --emscripten. +; RUN: wasm-ld --emscripten --export=hidden_function -o %t.wasm %t.bc +; RUN: obj2yaml %t.wasm | FileCheck %s --check-prefixes=CHECK,EMSCRIPTEN + target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128" target triple = "wasm32-unknown-unknown" @@ -23,12 +28,12 @@ ; CHECK-NEXT: - Name: memory ; CHECK-NEXT: Kind: MEMORY ; CHECK-NEXT: Index: 0 -; CHECK-NEXT: - Name: __heap_base -; CHECK-NEXT: Kind: GLOBAL -; CHECK-NEXT: Index: 1 -; CHECK-NEXT: - Name: __data_end -; CHECK-NEXT: Kind: GLOBAL -; CHECK-NEXT: Index: 2 +; EMSCRIPTEN-NEXT: - Name: __heap_base +; EMSCRIPTEN-NEXT: Kind: GLOBAL +; EMSCRIPTEN-NEXT: Index: 1 +; EMSCRIPTEN-NEXT: - Name: __data_end +; EMSCRIPTEN-NEXT: Kind: GLOBAL +; EMSCRIPTEN-NEXT: Index: 2 ; CHECK-NEXT: - Name: hidden_function ; CHECK-NEXT: Kind: FUNCTION ; CHECK-NEXT: Index: 0 Index: test/wasm/shared-needed.ll =================================================================== --- test/wasm/shared-needed.ll +++ test/wasm/shared-needed.ll @@ -1,13 +1,13 @@ ; RUN: llc -filetype=obj %s -o %t.o ; RUN: llc -filetype=obj %p/Inputs/ret32.ll -o %t.ret32.o -; RUN: wasm-ld -shared -o %t1.so %t.o +; RUN: wasm-ld --emscripten -shared -o %t1.so %t.o ; RUN: obj2yaml %t1.so | FileCheck %s -check-prefix=SO1 -; RUN: wasm-ld -shared -o %t2.so %t1.so %t.ret32.o +; RUN: wasm-ld --emscripten -shared -o %t2.so %t1.so %t.ret32.o ; RUN: obj2yaml %t2.so | FileCheck %s -check-prefix=SO2 -target triple = "wasm32-unknown-unknown" +target triple = "wasm32-unknown-emscripten" @data = global i32 2, align 4 Index: test/wasm/shared.ll =================================================================== --- test/wasm/shared.ll +++ test/wasm/shared.ll @@ -1,8 +1,8 @@ ; RUN: llc -relocation-model=pic -filetype=obj %s -o %t.o -; RUN: wasm-ld -shared -o %t.wasm %t.o +; RUN: wasm-ld --emscripten -shared -o %t.wasm %t.o ; RUN: obj2yaml %t.wasm | FileCheck %s -target triple = "wasm32-unknown-unknown" +target triple = "wasm32-unknown-emscripten" @data = hidden global i32 2, align 4 @data_external = external global i32 Index: test/wasm/stack-first.test =================================================================== --- test/wasm/stack-first.test +++ test/wasm/stack-first.test @@ -8,6 +8,10 @@ RUN: wasm-ld -z stack-size=512 --stack-first --allow-undefined -o %t.wasm %t.o RUN: obj2yaml %t.wasm | FileCheck %s +; Same thing, now with --emscripten. +RUN: wasm-ld --emscripten -z stack-size=512 --stack-first --allow-undefined -o %t.wasm %t.o +RUN: obj2yaml %t.wasm | FileCheck %s --check-prefixes=CHECK,EMSCRIPTEN + CHECK: - Type: GLOBAL CHECK-NEXT: Globals: CHECK-NEXT: - Index: 0 @@ -16,27 +20,27 @@ CHECK-NEXT: InitExpr: CHECK-NEXT: Opcode: I32_CONST CHECK-NEXT: Value: 512 -CHECK-NEXT: - Index: 1 -CHECK-NEXT: Type: I32 -CHECK-NEXT: Mutable: false -CHECK-NEXT: InitExpr: -CHECK-NEXT: Opcode: I32_CONST -CHECK-NEXT: Value: 512 -CHECK-NEXT: - Index: 2 -CHECK-NEXT: Type: I32 -CHECK-NEXT: Mutable: false -CHECK-NEXT: InitExpr: -CHECK-NEXT: Opcode: I32_CONST -CHECK-NEXT: Value: 512 +EMSCRIPTEN-NEXT: - Index: 1 +EMSCRIPTEN-NEXT: Type: I32 +EMSCRIPTEN-NEXT: Mutable: false +EMSCRIPTEN-NEXT: InitExpr: +EMSCRIPTEN-NEXT: Opcode: I32_CONST +EMSCRIPTEN-NEXT: Value: 512 +EMSCRIPTEN-NEXT: - Index: 2 +EMSCRIPTEN-NEXT: Type: I32 +EMSCRIPTEN-NEXT: Mutable: false +EMSCRIPTEN-NEXT: InitExpr: +EMSCRIPTEN-NEXT: Opcode: I32_CONST +EMSCRIPTEN-NEXT: Value: 512 CHECK-NEXT: - Type: EXPORT CHECK-NEXT: Exports: CHECK-NEXT: - Name: memory CHECK-NEXT: Kind: MEMORY CHECK-NEXT: Index: 0 -CHECK-NEXT: - Name: __heap_base -CHECK-NEXT: Kind: GLOBAL -CHECK-NEXT: Index: 1 -CHECK-NEXT: - Name: __data_end -CHECK-NEXT: Kind: GLOBAL -CHECK-NEXT: Index: 2 +EMSCRIPTEN-NEXT: - Name: __heap_base +EMSCRIPTEN-NEXT: Kind: GLOBAL +EMSCRIPTEN-NEXT: Index: 1 +EMSCRIPTEN-NEXT: - Name: __data_end +EMSCRIPTEN-NEXT: Kind: GLOBAL +EMSCRIPTEN-NEXT: Index: 2 Index: test/wasm/undefined-data.ll =================================================================== --- test/wasm/undefined-data.ll +++ test/wasm/undefined-data.ll @@ -1,7 +1,7 @@ ; RUN: llc -filetype=obj %s -o %t.o ; RUN: not wasm-ld -o %t.wasm %t.o 2>&1 | FileCheck %s -check-prefix=UNDEF ; RUN: not wasm-ld --allow-undefined -o %t.wasm %t.o 2>&1 | FileCheck %s -check-prefix=ALLOW -; RUN: not wasm-ld --shared -o %t.wasm %t.o 2>&1 | FileCheck %s -check-prefix=SHARED +; RUN: not wasm-ld --emscripten --shared -o %t.wasm %t.o 2>&1 | FileCheck %s -check-prefix=SHARED target triple = "wasm32-unknown-unknown" Index: test/wasm/undefined-weak-call.ll =================================================================== --- test/wasm/undefined-weak-call.ll +++ test/wasm/undefined-weak-call.ll @@ -1,8 +1,14 @@ ; RUN: llc -filetype=obj %s -o %t.o + ; RUN: wasm-ld --entry=callWeakFuncs --print-gc-sections %t.o \ ; RUN: -o %t.wasm 2>&1 | FileCheck -check-prefix=CHECK-GC %s ; RUN: obj2yaml %t.wasm | FileCheck %s +; Test with --emscripten +; RUN: wasm-ld --emscripten --entry=callWeakFuncs --print-gc-sections %t.o \ +; RUN: -o %t.wasm +; RUN: obj2yaml %t.wasm | FileCheck %s --check-prefixes=CHECK,EMSCRIPTEN + ; Check that calling an undefined weak function generates an appropriate stub ; that will fail at runtime with "unreachable". @@ -61,29 +67,29 @@ ; CHECK-NEXT: InitExpr: ; CHECK-NEXT: Opcode: I32_CONST ; CHECK-NEXT: Value: 66560 -; CHECK-NEXT: - Index: 1 -; CHECK-NEXT: Type: I32 -; CHECK-NEXT: Mutable: false -; CHECK-NEXT: InitExpr: -; CHECK-NEXT: Opcode: I32_CONST -; CHECK-NEXT: Value: 66560 -; CHECK-NEXT: - Index: 2 -; CHECK-NEXT: Type: I32 -; CHECK-NEXT: Mutable: false -; CHECK-NEXT: InitExpr: -; CHECK-NEXT: Opcode: I32_CONST -; CHECK-NEXT: Value: 1024 +; EMSCRIPTEN-NEXT: - Index: 1 +; EMSCRIPTEN-NEXT: Type: I32 +; EMSCRIPTEN-NEXT: Mutable: false +; EMSCRIPTEN-NEXT: InitExpr: +; EMSCRIPTEN-NEXT: Opcode: I32_CONST +; EMSCRIPTEN-NEXT: Value: 66560 +; EMSCRIPTEN-NEXT: - Index: 2 +; EMSCRIPTEN-NEXT: Type: I32 +; EMSCRIPTEN-NEXT: Mutable: false +; EMSCRIPTEN-NEXT: InitExpr: +; EMSCRIPTEN-NEXT: Opcode: I32_CONST +; EMSCRIPTEN-NEXT: Value: 1024 ; CHECK-NEXT: - Type: EXPORT ; CHECK-NEXT: Exports: ; CHECK-NEXT: - Name: memory ; CHECK-NEXT: Kind: MEMORY ; CHECK-NEXT: Index: 0 -; CHECK-NEXT: - Name: __heap_base -; CHECK-NEXT: Kind: GLOBAL -; CHECK-NEXT: Index: 1 -; CHECK-NEXT: - Name: __data_end -; CHECK-NEXT: Kind: GLOBAL -; CHECK-NEXT: Index: 2 +; EMSCRIPTEN-NEXT: - Name: __heap_base +; EMSCRIPTEN-NEXT: Kind: GLOBAL +; EMSCRIPTEN-NEXT: Index: 1 +; EMSCRIPTEN-NEXT: - Name: __data_end +; EMSCRIPTEN-NEXT: Kind: GLOBAL +; EMSCRIPTEN-NEXT: Index: 2 ; CHECK-NEXT: - Name: callWeakFuncs ; CHECK-NEXT: Kind: FUNCTION ; CHECK-NEXT: Index: 3 Index: test/wasm/visibility-hidden.ll =================================================================== --- test/wasm/visibility-hidden.ll +++ test/wasm/visibility-hidden.ll @@ -5,16 +5,16 @@ ; Test that symbols with hidden visitiblity are not export, even with ; --export-dynamic -; RUN: wasm-ld --export-dynamic %t.o %t2.a -o %t.wasm +; RUN: wasm-ld --emscripten --export-dynamic %t.o %t2.a -o %t.wasm ; RUN: obj2yaml %t.wasm | FileCheck %s ; Test that symbols with default visitiblity are not exported without ; --export-dynamic -; RUN: wasm-ld %t.o %t2.a -o %t.nodef.wasm -; RUN: obj2yaml %t.nodef.wasm | FileCheck %s -check-prefix=NO-DEFAULT +; XUN: wasm-ld --emscripten %t.o %t2.a -o %t.nodef.wasm +; XUN: obj2yaml %t.nodef.wasm | FileCheck %s -check-prefix=NO-DEFAULT -target triple = "wasm32-unknown-unknown" +target triple = "wasm32-unknown-emscripten" define hidden i32 @objectHidden() { entry: Index: test/wasm/weak-undefined.ll =================================================================== --- test/wasm/weak-undefined.ll +++ test/wasm/weak-undefined.ll @@ -1,7 +1,12 @@ ; RUN: llc -filetype=obj -o %t.o %s + ; RUN: wasm-ld -strip-debug %t.o -o %t.wasm ; RUN: obj2yaml %t.wasm | FileCheck %s +; Same thing, now with --emscripten +; RUN: wasm-ld --emscripten -strip-debug %t.o -o %t.wasm +; RUN: obj2yaml %t.wasm | FileCheck %s --check-prefixes=CHECK,EMSCRIPTEN + ; Test that undefined weak externals (global_var) and (foo) don't cause ; link failures and resolve to zero. @@ -59,29 +64,29 @@ ; CHECK-NEXT: InitExpr: ; CHECK-NEXT: Opcode: I32_CONST ; CHECK-NEXT: Value: 66560 -; CHECK-NEXT: - Index: 1 -; CHECK-NEXT: Type: I32 -; CHECK-NEXT: Mutable: false -; CHECK-NEXT: InitExpr: -; CHECK-NEXT: Opcode: I32_CONST -; CHECK-NEXT: Value: 66560 -; CHECK-NEXT: - Index: 2 -; CHECK-NEXT: Type: I32 -; CHECK-NEXT: Mutable: false -; CHECK-NEXT: InitExpr: -; CHECK-NEXT: Opcode: I32_CONST -; CHECK-NEXT: Value: 1024 +; EMSCRIPTEN-NEXT: - Index: 1 +; EMSCRIPTEN-NEXT: Type: I32 +; EMSCRIPTEN-NEXT: Mutable: false +; EMSCRIPTEN-NEXT: InitExpr: +; EMSCRIPTEN-NEXT: Opcode: I32_CONST +; EMSCRIPTEN-NEXT: Value: 66560 +; EMSCRIPTEN-NEXT: - Index: 2 +; EMSCRIPTEN-NEXT: Type: I32 +; EMSCRIPTEN-NEXT: Mutable: false +; EMSCRIPTEN-NEXT: InitExpr: +; EMSCRIPTEN-NEXT: Opcode: I32_CONST +; EMSCRIPTEN-NEXT: Value: 1024 ; CHECK-NEXT: - Type: EXPORT ; CHECK-NEXT: Exports: ; CHECK-NEXT: - Name: memory ; CHECK-NEXT: Kind: MEMORY ; CHECK-NEXT: Index: 0 -; CHECK-NEXT: - Name: __heap_base -; CHECK-NEXT: Kind: GLOBAL -; CHECK-NEXT: Index: 1 -; CHECK-NEXT: - Name: __data_end -; CHECK-NEXT: Kind: GLOBAL -; CHECK-NEXT: Index: 2 +; EMSCRIPTEN-NEXT: - Name: __heap_base +; EMSCRIPTEN-NEXT: Kind: GLOBAL +; EMSCRIPTEN-NEXT: Index: 1 +; EMSCRIPTEN-NEXT: - Name: __data_end +; EMSCRIPTEN-NEXT: Kind: GLOBAL +; EMSCRIPTEN-NEXT: Index: 2 ; CHECK-NEXT: - Name: _start ; CHECK-NEXT: Kind: FUNCTION ; CHECK-NEXT: Index: 2 Index: wasm/Config.h =================================================================== --- wasm/Config.h +++ wasm/Config.h @@ -27,6 +27,7 @@ bool CompressRelocations; bool Demangle; bool DisableVerify; + bool Emscripten; bool EmitRelocs; bool ExportAll; bool ExportDynamic; Index: wasm/Driver.cpp =================================================================== --- wasm/Driver.cpp +++ wasm/Driver.cpp @@ -338,6 +338,7 @@ parseCachePruningPolicy(Args.getLastArgValue(OPT_thinlto_cache_policy)), "--thinlto-cache-policy: invalid cache policy"); Config->ThinLTOJobs = args::getInteger(Args, OPT_thinlto_jobs, -1u); + Config->Emscripten = Args.hasArg(OPT_emscripten); errorHandler().Verbose = Args.hasArg(OPT_verbose); LLVM_DEBUG(errorHandler().Verbose = true); ThreadsEnabled = Args.hasFlag(OPT_threads, OPT_no_threads, true); @@ -411,6 +412,13 @@ if (Config->Pie) error("-r and -pie may not be used together"); } + + if (!Config->Emscripten) { + if (Config->Shared) + error("-shared is currently only supported under Emscripten"); + if (Config->ExportDynamic) + error("-export-dynamic is currently only supported under Emscripten"); + } } // Force Sym to be entered in the output. Used for -u or equivalent. @@ -484,10 +492,11 @@ WasmSym::HeapBase = Symtab->addSyntheticDataSymbol("__heap_base", 0); WasmSym::DataEnd = Symtab->addSyntheticDataSymbol("__data_end", 0); - // These two synthetic symbols exist purely for the embedder so we always - // want to export them. - WasmSym::HeapBase->ForceExport = true; - WasmSym::DataEnd->ForceExport = true; + if (Config->Emscripten) { + // Emscripten requires these symbols be exported. + WasmSym::HeapBase->ForceExport = true; + WasmSym::DataEnd->ForceExport = true; + } } if (Config->Pic) { Index: wasm/Options.td =================================================================== --- wasm/Options.td +++ wasm/Options.td @@ -158,6 +158,9 @@ def stack_first: F<"stack-first">, HelpText<"Place stack at start of linear memory rather than after data">; +def emscripten: F<"emscripten">, + HelpText<"Enable Emscripten support">; + defm whole_archive: B<"whole-archive", "Force load of all members in a static library", "Do not force load of all members in a static library (default)">;