[llvm-branch-commits] [lld] release/18.x: [lld][WebAssembly] Fix test on Windows, use llvm-ar instead of ar (PR #91967)
https://github.com/sbc100 approved this pull request. https://github.com/llvm/llvm-project/pull/91967 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [lld] release/18.x: [lld][WebAssembly] Fix test on Windows, use llvm-ar instead of ar (PR #91967)
sbc100 wrote: Since this is just a test fix I don't think it needs to be in the release notes (but I could be wrong). https://github.com/llvm/llvm-project/pull/91967 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [lld] 299b0e5 - [lld] Consistent help text for `--save-temps`
Author: Sam Clegg Date: 2021-01-25T10:27:18-08:00 New Revision: 299b0e5ee9ee30093ccc9fe78b7797c16887150d URL: https://github.com/llvm/llvm-project/commit/299b0e5ee9ee30093ccc9fe78b7797c16887150d DIFF: https://github.com/llvm/llvm-project/commit/299b0e5ee9ee30093ccc9fe78b7797c16887150d.diff LOG: [lld] Consistent help text for `--save-temps` I noticed that this option was not appearing at all in the `--help` messages for `wasm-ld` or `ld.lld`. Add help text and make it consistent across all ports. Differential Revision: https://reviews.llvm.org/D94925 Added: Modified: lld/COFF/Options.td lld/ELF/Options.td lld/MachO/Options.td lld/wasm/Options.td Removed: diff --git a/lld/COFF/Options.td b/lld/COFF/Options.td index 5447c8312128..73c3380df17c 100644 --- a/lld/COFF/Options.td +++ b/lld/COFF/Options.td @@ -68,7 +68,7 @@ def lldltocache : P<"lldltocache", def lldltocachepolicy : P<"lldltocachepolicy", "Pruning policy for the ThinLTO cache">; def lldsavetemps : F<"lldsavetemps">, -HelpText<"Save temporary files instead of deleting them">; +HelpText<"Save intermediate LTO compilation results">; def machine : P<"machine", "Specify target platform">; def merge : P<"merge", "Combine sections">; def mllvm : P<"mllvm", "Options to pass to LLVM">; diff --git a/lld/ELF/Options.td b/lld/ELF/Options.td index 0ca283cdfe08..65ef3e824f50 100644 --- a/lld/ELF/Options.td +++ b/lld/ELF/Options.td @@ -566,7 +566,7 @@ def opt_remarks_with_hotness: FF<"opt-remarks-with-hotness">, HelpText<"Include hotness information in the optimization remarks file">; def opt_remarks_format: Separate<["--"], "opt-remarks-format">, HelpText<"The format used for serializing remarks (default: YAML)">; -def save_temps: F<"save-temps">; +def save_temps: F<"save-temps">, HelpText<"Save intermediate LTO compilation results">; def lto_basic_block_sections: JJ<"lto-basic-block-sections=">, HelpText<"Enable basic block sections for LTO">; defm lto_unique_basic_block_section_names: BB<"lto-unique-basic-block-section-names", diff --git a/lld/MachO/Options.td b/lld/MachO/Options.td index 3410f50fa317..51c834c57238 100644 --- a/lld/MachO/Options.td +++ b/lld/MachO/Options.td @@ -477,7 +477,7 @@ def dependency_info : Separate<["-"], "dependency_info">, Flags<[HelpHidden]>, Group; def save_temps : Flag<["-"], "save-temps">, - HelpText<"Save temporary files instead of deleting them">, + HelpText<"Save intermediate LTO compilation results">, Group; def grp_symtab : OptionGroup<"symtab">, HelpText<"SYMBOL TABLE OPTIMIZATIONS">; diff --git a/lld/wasm/Options.td b/lld/wasm/Options.td index ae5ec20d07e8..8e9ebeb168d6 100644 --- a/lld/wasm/Options.td +++ b/lld/wasm/Options.td @@ -214,7 +214,7 @@ def lto_O: J<"lto-O">, MetaVarName<"">, def lto_partitions: J<"lto-partitions=">, HelpText<"Number of LTO codegen partitions">; def disable_verify: F<"disable-verify">; -def save_temps: F<"save-temps">; +def save_temps: F<"save-temps">, HelpText<"Save intermediate LTO compilation results">; def thinlto_cache_dir: J<"thinlto-cache-dir=">, HelpText<"Path to ThinLTO cached object file directory">; defm thinlto_cache_policy: Eq<"thinlto-cache-policy", "Pruning policy for the ThinLTO cache">; ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [compiler-rt] 60e78c0 - Update library changes from upstream llvmorg-12.0.0
Author: Sam Clegg Date: 2021-05-24T20:49:18-07:00 New Revision: 60e78c0fb0a394b17d61e9be2a43ed1e34b31852 URL: https://github.com/llvm/llvm-project/commit/60e78c0fb0a394b17d61e9be2a43ed1e34b31852 DIFF: https://github.com/llvm/llvm-project/commit/60e78c0fb0a394b17d61e9be2a43ed1e34b31852.diff LOG: Update library changes from upstream llvmorg-12.0.0 These changes are from emscripten as of 3ad991a6cc3c085ac325be. Added: Modified: compiler-rt/include/sanitizer/tsan_interface_atomic.h compiler-rt/lib/asan/asan_errors.cpp compiler-rt/lib/asan/asan_flags.cpp compiler-rt/lib/asan/asan_interceptors.cpp compiler-rt/lib/asan/asan_interceptors_memintrinsics.cpp compiler-rt/lib/asan/asan_malloc_linux.cpp compiler-rt/lib/asan/asan_mapping.h compiler-rt/lib/asan/asan_poisoning.cpp compiler-rt/lib/asan/asan_poisoning.h compiler-rt/lib/asan/asan_posix.cpp compiler-rt/lib/asan/asan_rtl.cpp compiler-rt/lib/asan/asan_shadow_setup.cpp compiler-rt/lib/asan/asan_thread.cpp compiler-rt/lib/interception/interception.h compiler-rt/lib/interception/interception_linux.h compiler-rt/lib/lsan/lsan.cpp compiler-rt/lib/lsan/lsan_allocator.cpp compiler-rt/lib/lsan/lsan_allocator.h compiler-rt/lib/lsan/lsan_common.cpp compiler-rt/lib/lsan/lsan_common.h compiler-rt/lib/lsan/lsan_common_linux.cpp compiler-rt/lib/lsan/lsan_interceptors.cpp compiler-rt/lib/lsan/lsan_linux.cpp compiler-rt/lib/sanitizer_common/sanitizer_errno_codes.h compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp compiler-rt/lib/sanitizer_common/sanitizer_linux.h compiler-rt/lib/sanitizer_common/sanitizer_platform.h compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h compiler-rt/lib/sanitizer_common/sanitizer_posix.cpp compiler-rt/lib/sanitizer_common/sanitizer_posix_libcdep.cpp compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.cpp compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.h compiler-rt/lib/sanitizer_common/sanitizer_stacktrace_libcdep.cpp compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cpp compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_report.cpp compiler-rt/lib/sanitizer_common/sanitizer_syscall_generic.inc compiler-rt/lib/ubsan/ubsan_checks.inc compiler-rt/lib/ubsan/ubsan_diag.cpp compiler-rt/lib/ubsan/ubsan_flags.cpp compiler-rt/lib/ubsan/ubsan_handlers.cpp compiler-rt/lib/ubsan/ubsan_platform.h compiler-rt/lib/ubsan/ubsan_signals_standalone.cpp libcxx/include/__config libcxx/include/typeinfo libcxx/src/include/config_elast.h libcxx/src/new.cpp libcxx/src/support/runtime/exception_fallback.ipp libcxxabi/include/cxxabi.h libcxxabi/src/abort_message.cpp libcxxabi/src/cxa_exception.cpp libcxxabi/src/cxa_exception.h libcxxabi/src/cxa_handlers.cpp libcxxabi/src/cxa_personality.cpp libcxxabi/src/private_typeinfo.cpp libcxxabi/src/stdlib_new_delete.cpp Removed: diff --git a/compiler-rt/include/sanitizer/tsan_interface_atomic.h b/compiler-rt/include/sanitizer/tsan_interface_atomic.h index 8052bc1d56b38..5e41e2256c300 100644 --- a/compiler-rt/include/sanitizer/tsan_interface_atomic.h +++ b/compiler-rt/include/sanitizer/tsan_interface_atomic.h @@ -30,7 +30,7 @@ __extension__ typedef __int128 __tsan_atomic128; #endif // Part of ABI, do not change. -// https://github.com/llvm/llvm-project/blob/master/libcxx/include/atomic +// https://github.com/llvm/llvm-project/blob/main/libcxx/include/atomic typedef enum { __tsan_memory_order_relaxed, __tsan_memory_order_consume, diff --git a/compiler-rt/lib/asan/asan_errors.cpp b/compiler-rt/lib/asan/asan_errors.cpp index 541c6e0353b57..e1c953b141643 100644 --- a/compiler-rt/lib/asan/asan_errors.cpp +++ b/compiler-rt/lib/asan/asan_errors.cpp @@ -480,6 +480,17 @@ ErrorGeneric::ErrorGeneric(u32 tid, uptr pc_, uptr bp_, uptr sp_, uptr addr, scariness.Scare(bug_type_score + read_after_free_bonus, bug_descr); if (far_from_bounds) scariness.Scare(10, "far-from-bounds"); } +#if SANITIZER_EMSCRIPTEN +// If address is in the first page (64 KB), then it is likely that the +// access is a result of a null pointer dereference. +else if (addr < 65536) { + bug_descr = "null-pointer-dereference"; + scariness.Scare(25, bug_descr); +} else if (AddrIsInShadow(addr)) { + bug_descr = "shadow-access"; + scariness.Scare(25, bug_descr); +} +#endif } } diff --git a/compiler-rt/lib/asan/asan_flags.cpp b/compiler-rt/lib/asan/asan_flags.cpp index cb6a89fe32ce7..197dfb23661af 100644 --- a/compiler-rt/lib/asan/as
[llvm-branch-commits] [libcxxabi] 29521dc - Patches from emscripten 2.0.33
Author: Sam Clegg Date: 2021-11-04T09:02:39-07:00 New Revision: 29521dc528ba3714fe315fbf9a4ca7154368869d URL: https://github.com/llvm/llvm-project/commit/29521dc528ba3714fe315fbf9a4ca7154368869d DIFF: https://github.com/llvm/llvm-project/commit/29521dc528ba3714fe315fbf9a4ca7154368869d.diff LOG: Patches from emscripten 2.0.33 Added: Modified: compiler-rt/lib/asan/asan_flags.cpp compiler-rt/lib/asan/asan_posix.cpp compiler-rt/lib/lsan/lsan_allocator.cpp compiler-rt/lib/lsan/lsan_allocator.h compiler-rt/lib/lsan/lsan_interceptors.cpp compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h compiler-rt/lib/ubsan/ubsan_flags.cpp libcxxabi/src/cxa_exception.h libcxxabi/src/cxa_handlers.cpp libcxxabi/src/cxa_thread_atexit.cpp Removed: diff --git a/compiler-rt/lib/asan/asan_flags.cpp b/compiler-rt/lib/asan/asan_flags.cpp index 197dfb23661af..5c47926c07e42 100644 --- a/compiler-rt/lib/asan/asan_flags.cpp +++ b/compiler-rt/lib/asan/asan_flags.cpp @@ -128,8 +128,9 @@ void InitializeFlags() { #if SANITIZER_EMSCRIPTEN char *options; // Override from Emscripten Module. + // TODO: add EM_ASM_I64 and avoid using a double for a 64-bit pointer. #define MAKE_OPTION_LOAD(parser, name) \ -options = (char*) EM_ASM_INT({ \ +options = (char*)(long)EM_ASM_DOUBLE({ \ return withBuiltinMalloc(function () { \ return allocateUTF8(Module[name] || 0); \ }); \ diff --git a/compiler-rt/lib/asan/asan_posix.cpp b/compiler-rt/lib/asan/asan_posix.cpp index 6e49520498158..b19f28a2484db 100644 --- a/compiler-rt/lib/asan/asan_posix.cpp +++ b/compiler-rt/lib/asan/asan_posix.cpp @@ -115,7 +115,7 @@ void PlatformTSDDtor(void *tsd) { atomic_signal_fence(memory_order_seq_cst); AsanThread::TSDDtor(tsd); } -#elif !SANITIZER_EMSCRIPTEN +#else static pthread_key_t tsd_key; static bool tsd_key_inited = false; void AsanTSDInit(void (*destructor)(void *tsd)) { diff --git a/compiler-rt/lib/lsan/lsan_allocator.cpp b/compiler-rt/lib/lsan/lsan_allocator.cpp index 5dff571e4a059..a682cc1fa8caf 100644 --- a/compiler-rt/lib/lsan/lsan_allocator.cpp +++ b/compiler-rt/lib/lsan/lsan_allocator.cpp @@ -28,7 +28,7 @@ extern "C" void *memset(void *ptr, int value, uptr num); namespace __lsan { #if defined(__i386__) || defined(__arm__) || defined(__wasm32__) static const uptr kMaxAllowedMallocSize = 1UL << 30; -#elif defined(__mips64) || defined(__aarch64__) +#elif defined(__mips64) || defined(__aarch64__) || defined(__wasm64__) static const uptr kMaxAllowedMallocSize = 4UL << 30; #else static const uptr kMaxAllowedMallocSize = 8UL << 30; diff --git a/compiler-rt/lib/lsan/lsan_allocator.h b/compiler-rt/lib/lsan/lsan_allocator.h index 050a9143bc014..a15fb0434e255 100644 --- a/compiler-rt/lib/lsan/lsan_allocator.h +++ b/compiler-rt/lib/lsan/lsan_allocator.h @@ -50,7 +50,7 @@ struct ChunkMetadata { }; #if defined(__mips64) || defined(__aarch64__) || defined(__i386__) || \ -defined(__arm__) || defined(__wasm32__) +defined(__arm__) || defined(__wasm__) static const uptr kRegionSizeLog = 20; static const uptr kNumRegions = SANITIZER_MMAP_RANGE_SIZE >> kRegionSizeLog; template diff --git a/compiler-rt/lib/lsan/lsan_interceptors.cpp b/compiler-rt/lib/lsan/lsan_interceptors.cpp index e90bcb50d0f3a..e4e1d75b84ba5 100644 --- a/compiler-rt/lib/lsan/lsan_interceptors.cpp +++ b/compiler-rt/lib/lsan/lsan_interceptors.cpp @@ -532,7 +532,8 @@ namespace __lsan { void InitializeInterceptors() { // Fuchsia doesn't use interceptors that require any setup. -#if !SANITIZER_FUCHSIA && !SANITIZER_EMSCRIPTEN +#if !SANITIZER_FUCHSIA +#if !SANITIZER_EMSCRIPTEN InitializeSignalInterceptors(); INTERCEPT_FUNCTION(malloc); @@ -562,6 +563,7 @@ void InitializeInterceptors() { LSAN_MAYBE_INTERCEPT_PTHREAD_ATFORK; LSAN_MAYBE_INTERCEPT_STRERROR; +#endif // !SANITIZER_EMSCRIPTEN #if !SANITIZER_NETBSD && !SANITIZER_FREEBSD if (pthread_key_create(&g_thread_finalize_key, &thread_finalize)) { diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp index d1738e0c2aecf..4b16ca8930b35 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp +++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp @@ -261,8 +261,11 @@ uptr internal_write(fd_t fd, const void *buf, uptr count) { uptr internal_ftruncate(fd_t fd, uptr size) { sptr res; #if SANITIZER_EMSCRIPTEN + // The __SYSCALL_LL_O macros that musl uses to split 64-bit arguments + // doesn't work in C++ code so we have to do it manually. + union { long long ll; long l[2]; } split{ .ll = size }; HANDLE_EINTR(res, (sptr)internal_syscall(SYSCALL(ftruncate), fd, - 0, size, 0)); +
[llvm-branch-commits] [libcxxabi] 542cc25 - Update library changes from upstream llvmorg-12.0.0
Author: Sam Clegg Date: 2021-05-25T08:32:22-07:00 New Revision: 542cc257de9ef0378a33cd5c5354d63941361d2d URL: https://github.com/llvm/llvm-project/commit/542cc257de9ef0378a33cd5c5354d63941361d2d DIFF: https://github.com/llvm/llvm-project/commit/542cc257de9ef0378a33cd5c5354d63941361d2d.diff LOG: Update library changes from upstream llvmorg-12.0.0 These changes are from emscripten as of 3ad991a6cc3c085ac325be. Added: Modified: compiler-rt/include/sanitizer/tsan_interface_atomic.h compiler-rt/lib/asan/asan_errors.cpp compiler-rt/lib/asan/asan_flags.cpp compiler-rt/lib/asan/asan_interceptors.cpp compiler-rt/lib/asan/asan_interceptors_memintrinsics.cpp compiler-rt/lib/asan/asan_malloc_linux.cpp compiler-rt/lib/asan/asan_mapping.h compiler-rt/lib/asan/asan_poisoning.cpp compiler-rt/lib/asan/asan_poisoning.h compiler-rt/lib/asan/asan_posix.cpp compiler-rt/lib/asan/asan_rtl.cpp compiler-rt/lib/asan/asan_shadow_setup.cpp compiler-rt/lib/asan/asan_thread.cpp compiler-rt/lib/interception/interception.h compiler-rt/lib/interception/interception_linux.h compiler-rt/lib/lsan/lsan.cpp compiler-rt/lib/lsan/lsan_allocator.cpp compiler-rt/lib/lsan/lsan_allocator.h compiler-rt/lib/lsan/lsan_common.cpp compiler-rt/lib/lsan/lsan_common.h compiler-rt/lib/lsan/lsan_common_linux.cpp compiler-rt/lib/lsan/lsan_interceptors.cpp compiler-rt/lib/lsan/lsan_linux.cpp compiler-rt/lib/sanitizer_common/sanitizer_errno_codes.h compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp compiler-rt/lib/sanitizer_common/sanitizer_linux.h compiler-rt/lib/sanitizer_common/sanitizer_platform.h compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h compiler-rt/lib/sanitizer_common/sanitizer_posix.cpp compiler-rt/lib/sanitizer_common/sanitizer_posix_libcdep.cpp compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.cpp compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.h compiler-rt/lib/sanitizer_common/sanitizer_stacktrace_libcdep.cpp compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cpp compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_report.cpp compiler-rt/lib/sanitizer_common/sanitizer_syscall_generic.inc compiler-rt/lib/ubsan/ubsan_checks.inc compiler-rt/lib/ubsan/ubsan_diag.cpp compiler-rt/lib/ubsan/ubsan_flags.cpp compiler-rt/lib/ubsan/ubsan_handlers.cpp compiler-rt/lib/ubsan/ubsan_platform.h compiler-rt/lib/ubsan/ubsan_signals_standalone.cpp libcxx/include/__config libcxx/include/typeinfo libcxx/src/include/config_elast.h libcxx/src/new.cpp libcxx/src/support/runtime/exception_fallback.ipp libcxxabi/include/cxxabi.h libcxxabi/src/abort_message.cpp libcxxabi/src/cxa_exception.cpp libcxxabi/src/cxa_exception.h libcxxabi/src/cxa_handlers.cpp libcxxabi/src/cxa_personality.cpp libcxxabi/src/private_typeinfo.cpp libcxxabi/src/stdlib_new_delete.cpp Removed: diff --git a/compiler-rt/include/sanitizer/tsan_interface_atomic.h b/compiler-rt/include/sanitizer/tsan_interface_atomic.h index 8052bc1d56b38..5e41e2256c300 100644 --- a/compiler-rt/include/sanitizer/tsan_interface_atomic.h +++ b/compiler-rt/include/sanitizer/tsan_interface_atomic.h @@ -30,7 +30,7 @@ __extension__ typedef __int128 __tsan_atomic128; #endif // Part of ABI, do not change. -// https://github.com/llvm/llvm-project/blob/master/libcxx/include/atomic +// https://github.com/llvm/llvm-project/blob/main/libcxx/include/atomic typedef enum { __tsan_memory_order_relaxed, __tsan_memory_order_consume, diff --git a/compiler-rt/lib/asan/asan_errors.cpp b/compiler-rt/lib/asan/asan_errors.cpp index 541c6e0353b57..e1c953b141643 100644 --- a/compiler-rt/lib/asan/asan_errors.cpp +++ b/compiler-rt/lib/asan/asan_errors.cpp @@ -480,6 +480,17 @@ ErrorGeneric::ErrorGeneric(u32 tid, uptr pc_, uptr bp_, uptr sp_, uptr addr, scariness.Scare(bug_type_score + read_after_free_bonus, bug_descr); if (far_from_bounds) scariness.Scare(10, "far-from-bounds"); } +#if SANITIZER_EMSCRIPTEN +// If address is in the first page (64 KB), then it is likely that the +// access is a result of a null pointer dereference. +else if (addr < 65536) { + bug_descr = "null-pointer-dereference"; + scariness.Scare(25, bug_descr); +} else if (AddrIsInShadow(addr)) { + bug_descr = "shadow-access"; + scariness.Scare(25, bug_descr); +} +#endif } } diff --git a/compiler-rt/lib/asan/asan_flags.cpp b/compiler-rt/lib/asan/asan_flags.cpp index cb6a89fe32ce7..197dfb23661af 100644 --- a/compiler-rt/lib/asan/as
[llvm-branch-commits] [lld] 07b6aeb - [lld][WebAssembly] Fix for TLS + --relocatable
Author: Sam Clegg Date: 2021-01-13T07:49:39-08:00 New Revision: 07b6aeb5685fa6474cbeae797ebc5ea1f17da0f7 URL: https://github.com/llvm/llvm-project/commit/07b6aeb5685fa6474cbeae797ebc5ea1f17da0f7 DIFF: https://github.com/llvm/llvm-project/commit/07b6aeb5685fa6474cbeae797ebc5ea1f17da0f7.diff LOG: [lld][WebAssembly] Fix for TLS + --relocatable When running in `-r/--relocatable` we output relocations but the new TLS relocations type was missing from `ObjFile::calcNewAddend` causing this combination of inputs/flags to crash the linker. Also avoid creating tls variables in relocatable mode. These variables are only needed when linking final executables. Fixes: https://github.com/emscripten-core/emscripten/issues/12934 Fixes: PR48506 Differential Revision: https://reviews.llvm.org/D93554 Added: Modified: lld/test/wasm/tls-no-shared.s lld/test/wasm/tls.s lld/wasm/Driver.cpp lld/wasm/InputFiles.cpp lld/wasm/Writer.cpp Removed: diff --git a/lld/test/wasm/tls-no-shared.s b/lld/test/wasm/tls-no-shared.s index 3fdc7057ad07..6c17489b7d42 100644 --- a/lld/test/wasm/tls-no-shared.s +++ b/lld/test/wasm/tls-no-shared.s @@ -1,5 +1,5 @@ # Test that linking without shared memory causes __tls_base to be -# interlized +# internalized # RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown -o %t.o %s diff --git a/lld/test/wasm/tls.s b/lld/test/wasm/tls.s index f5072dc13afa..878498bc2e48 100644 --- a/lld/test/wasm/tls.s +++ b/lld/test/wasm/tls.s @@ -73,8 +73,8 @@ tls3: # RUN: wasm-ld -no-gc-sections --shared-memory --max-memory=131072 --no-entry -o %t.wasm %t.o # RUN: obj2yaml %t.wasm | FileCheck %s -# RUN: wasm-ld -no-gc-sections --shared-memory --max-memory=131072 --no-merge-data-segments --no-entry -o %t.wasm %t.o -# RUN: obj2yaml %t.wasm | FileCheck %s +# RUN: wasm-ld -no-gc-sections --shared-memory --max-memory=131072 --no-merge-data-segments --no-entry -o %t2.wasm %t.o +# RUN: obj2yaml %t2.wasm | FileCheck %s # CHECK: - Type:GLOBAL # CHECK-NEXT: Globals: @@ -163,3 +163,32 @@ tls3: # Expected body of tls_align: # global.get 3 # end + + +# Also verify TLS usage with --relocatable +# RUN: wasm-ld --relocatable -o %t3.wasm %t.o +# RUN: obj2yaml %t3.wasm | FileCheck %s --check-prefix=RELOC + +# RELOC: - Type:IMPORT +# RELOC-NEXT:Imports: +# RELOC-NEXT: - Module: env +# RELOC-NEXT:Field: __tls_base +# RELOC-NEXT:Kind:GLOBAL +# RELOC-NEXT:GlobalType: I32 +# RELOC-NEXT:GlobalMutable: true +# RELOC-NEXT: - Module: env +# RELOC-NEXT:Field: __tls_align +# RELOC-NEXT:Kind:GLOBAL +# RELOC-NEXT:GlobalType: I32 +# RELOC-NEXT:GlobalMutable: false + +# RELOC: GlobalNames: +# RELOC-NEXT: - Index: 0 +# RELOC-NEXT:Name:__tls_base +# RELOC-NEXT: - Index: 1 +# RELOC-NEXT:Name:__tls_align +# RELOC-NEXT:DataSegmentNames: +# RELOC-NEXT: - Index: 0 +# RELOC-NEXT:Name:.tdata +# RELOC-NEXT: - Index: 1 +# RELOC-NEXT:Name:.bss.no_tls diff --git a/lld/wasm/Driver.cpp b/lld/wasm/Driver.cpp index fb699c55fc8c..84fdb77aea2c 100644 --- a/lld/wasm/Driver.cpp +++ b/lld/wasm/Driver.cpp @@ -639,7 +639,7 @@ static void createSyntheticSymbols() { WasmSym::stackPointer->markLive(); } - if (config->sharedMemory) { + if (config->sharedMemory && !config->relocatable) { WasmSym::tlsBase = createGlobalVariable("__tls_base", true); WasmSym::tlsSize = createGlobalVariable("__tls_size", false); WasmSym::tlsAlign = createGlobalVariable("__tls_align", false); diff --git a/lld/wasm/InputFiles.cpp b/lld/wasm/InputFiles.cpp index 68a9472819e4..eb37ae548b80 100644 --- a/lld/wasm/InputFiles.cpp +++ b/lld/wasm/InputFiles.cpp @@ -123,6 +123,7 @@ uint64_t ObjFile::calcNewAddend(const WasmRelocation &reloc) const { case R_WASM_MEMORY_ADDR_REL_SLEB64: case R_WASM_MEMORY_ADDR_I32: case R_WASM_MEMORY_ADDR_I64: + case R_WASM_MEMORY_ADDR_TLS_SLEB: case R_WASM_FUNCTION_OFFSET_I32: case R_WASM_FUNCTION_OFFSET_I64: return reloc.Addend; diff --git a/lld/wasm/Writer.cpp b/lld/wasm/Writer.cpp index c95b92504634..710404943df2 100644 --- a/lld/wasm/Writer.cpp +++ b/lld/wasm/Writer.cpp @@ -284,7 +284,7 @@ void Writer::layoutMemory() { log(formatv("mem: {0,-15} offset={1,-8} size={2,-8} align={3}", seg->name, memoryPtr, seg->size, seg->alignment)); -if (seg->name == ".tdata") { +if (!config->relocatable && seg->name == ".tdata") { if (config->sharedMemory) { auto *tlsSize = cast(WasmSym::tlsSize); setGlobalPtr(tlsSize, seg->size); ___ llvm-br
[llvm-branch-commits] [lld] b99147b - [lld][WebAssembly] Don't defined indirect function table in relocatable output
Author: Sam Clegg Date: 2021-01-19T12:59:20-08:00 New Revision: b99147b4fa7b361fba4eeefdb443dca72b8ee87f URL: https://github.com/llvm/llvm-project/commit/b99147b4fa7b361fba4eeefdb443dca72b8ee87f DIFF: https://github.com/llvm/llvm-project/commit/b99147b4fa7b361fba4eeefdb443dca72b8ee87f.diff LOG: [lld][WebAssembly] Don't defined indirect function table in relocatable output Object files (and the output --relocatable) should never define __indirect_function_table. It should always be linker synthesized with the final output executable. Differential Revision: https://reviews.llvm.org/D94993 Added: Modified: lld/test/wasm/locals-duplicate.test lld/test/wasm/relocatable.ll lld/test/wasm/signature-mismatch.ll lld/test/wasm/weak-alias.ll lld/wasm/Driver.cpp Removed: diff --git a/lld/test/wasm/locals-duplicate.test b/lld/test/wasm/locals-duplicate.test index cf9a148d4ab7..1d704ec2dff1 100644 --- a/lld/test/wasm/locals-duplicate.test +++ b/lld/test/wasm/locals-duplicate.test @@ -231,17 +231,19 @@ ; RELOC-NEXT: ParamTypes: [] ; RELOC-NEXT: ReturnTypes: ; RELOC-NEXT: - I32 +; RELOC-NEXT: - Type:IMPORT +; RELOC-NEXT:Imports: +; RELOC-NEXT: - Module: env +; RELOC-NEXT:Field: __indirect_function_table +; RELOC-NEXT:Kind:TABLE +; RELOC-NEXT:Table: +; RELOC-NEXT: Index: 0 +; RELOC-NEXT: ElemType:FUNCREF +; RELOC-NEXT: Limits: +; RELOC-NEXT:Initial: 0x3 ; RELOC-NEXT: - Type:FUNCTION ; RELOC-NEXT: FunctionTypes: [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ; RELOC-NEXT:0, 0 ] -; RELOC-NEXT: - Type:TABLE -; RELOC-NEXT: Tables: -; RELOC-NEXT: - Index: 0 -; RELOC-NEXT: ElemType:FUNCREF -; RELOC-NEXT: Limits: -; RELOC-NEXT: Flags: [ HAS_MAX ] -; RELOC-NEXT: Initial: 0x7 -; RELOC-NEXT: Maximum: 0x7 ; RELOC-NEXT: - Type:MEMORY ; RELOC-NEXT: Memories: ; RELOC-NEXT: - Initial: 0x1 @@ -412,7 +414,7 @@ ; RELOC-NEXT: - Index: 8 ; RELOC-NEXT: Kind:TABLE ; RELOC-NEXT: Name:__indirect_function_table -; RELOC-NEXT: Flags: [ VISIBILITY_HIDDEN ] +; RELOC-NEXT: Flags: [ UNDEFINED, NO_STRIP ] ; RELOC-NEXT: Table: 0 ; RELOC-NEXT: - Index: 9 ; RELOC-NEXT: Kind:FUNCTION diff --git a/lld/test/wasm/relocatable.ll b/lld/test/wasm/relocatable.ll index e8129da9ad3d..7de51a38f5c9 100644 --- a/lld/test/wasm/relocatable.ll +++ b/lld/test/wasm/relocatable.ll @@ -1,7 +1,10 @@ ; RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown %p/Inputs/hello.s -o %t.hello.o ; RUN: llc -filetype=obj %s -o %t.o -; RUN: wasm-ld -r -o %t.wasm %t.hello.o %t.o -; RUN: obj2yaml %t.wasm | FileCheck %s +; RUN: wasm-ld -r -o %t2.o %t.hello.o %t.o +; RUN: obj2yaml %t2.o | FileCheck %s + +; Verify the resulting object can be used as linker input +; RUN: wasm-ld --allow-undefined -o %t.wasm %t2.o --export-table target triple = "wasm32-unknown-unknown" @@ -32,6 +35,11 @@ entry: ; Test that __attribute__(used) (i.e NO_STRIP) is preserved in the relocated symbol table @llvm.used = appending global [1 x i8*] [i8* bitcast (i32 ()* @my_func to i8*)], section "llvm.metadata" +define void @_start() { + ret void +} + + ; CHECK: --- !WASM ; CHECK-NEXT: FileHeader: ; CHECK-NEXT: Version: 0x1 @@ -63,16 +71,16 @@ entry: ; CHECK-NEXT: Field: bar_import ; CHECK-NEXT: Kind:FUNCTION ; CHECK-NEXT: SigIndex:1 +; CHECK-NEXT: - Module: env +; CHECK-NEXT: Field: __indirect_function_table +; CHECK-NEXT: Kind:TABLE +; CHECK-NEXT: Table: +; CHECK-NEXT: Index: 0 +; CHECK-NEXT: ElemType:FUNCREF +; CHECK-NEXT: Limits: +; CHECK-NEXT: Initial: 0x3 ; CHECK-NEXT: - Type:FUNCTION -; CHECK-NEXT: FunctionTypes: [ 2, 1, 1 ] -; CHECK-NEXT: - Type:TABLE -; CHECK-NEXT: Tables: -; CHECK-NEXT: - Index: 0 -; CHECK-NEXT: ElemType:FUNCREF -; CHECK-NEXT: Limits: -; CHECK-NEXT: Flags: [ HAS_MAX ] -; CHECK-NEXT: Initial: 0x4 -; CHECK-NEXT: Maximum: 0x4 +; CHECK-NEXT: FunctionTypes: [ 2, 1, 1, 2 ] ; CHECK-NEXT: - Type:MEMORY ; CHECK-NEXT: Memories: ; CHECK-NEXT: - Initial: 0x1 diff --git a/lld/test/wasm/signature-mismatch.ll b/lld/test/wasm/signature-mismatch.ll index 65ce73910ffa..931
[llvm-branch-commits] [lld] 96ef4f3 - Revert "[WebAssembly] call_indirect issues table number relocs"
Author: Sam Clegg Date: 2021-01-19T15:06:07-08:00 New Revision: 96ef4f307df27f4e0946eb344bac2703017ad073 URL: https://github.com/llvm/llvm-project/commit/96ef4f307df27f4e0946eb344bac2703017ad073 DIFF: https://github.com/llvm/llvm-project/commit/96ef4f307df27f4e0946eb344bac2703017ad073.diff LOG: Revert "[WebAssembly] call_indirect issues table number relocs" This reverts commit 418df4a6ab35d343cc0f2608c90a73dd9b8d0ab1. This change broke emscripten tests, I believe because it started generating 5-byte a wide table index in the call_indirect instruction. Neither v8 nor wabt seem to be able to handle that. The spec currently says that this is single 0x0 byte and: "In future versions of WebAssembly, the zero byte occurring in the encoding of the call_indirectcall_indirect instruction may be used to index additional tables." So we need to revisit this change. For backwards compat I guess we need to guarantee that __indirect_function_table is always at address zero. We could also consider making this a single-byte relocation with and assert if have more than 127 tables (for now). Differential Revision: https://reviews.llvm.org/D95005 Added: Modified: lld/test/wasm/call-indirect.ll lld/test/wasm/compress-relocs.ll lld/test/wasm/shared.ll llvm/lib/MC/WasmObjectWriter.cpp llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyInstPrinter.cpp llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.h llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp llvm/lib/Target/WebAssembly/WebAssemblyInstrCall.td llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp llvm/test/CodeGen/WebAssembly/function-pointer64.ll llvm/test/CodeGen/WebAssembly/multivalue.ll llvm/test/MC/WebAssembly/basic-assembly.s llvm/test/MC/WebAssembly/reloc-code.ll llvm/test/MC/WebAssembly/tail-call-encodings.s llvm/test/MC/WebAssembly/type-index.s llvm/test/MC/WebAssembly/weak-alias.s Removed: llvm/test/MC/WebAssembly/call-indirect-relocs.s diff --git a/lld/test/wasm/call-indirect.ll b/lld/test/wasm/call-indirect.ll index 08b4336c481d..f6d3df4914bf 100644 --- a/lld/test/wasm/call-indirect.ll +++ b/lld/test/wasm/call-indirect.ll @@ -122,16 +122,16 @@ define void @call_ptr(i64 (i64)* %arg) { ; CHECK-NEXT: Body:42010B ; CHECK-NEXT: - Index: 1 ; CHECK-NEXT: Locals: -; CHECK-NEXT: Body: 41002802808880800011808080800080808080001A41002802848880800011818080800080808080001A0B +; CHECK-NEXT: Body: 41002802808880800011808080801A41002802848880800011818080801A0B ; CHECK-NEXT: - Index: 2 ; CHECK-NEXT: Locals: ; CHECK-NEXT: Body:41020B ; CHECK-NEXT: - Index: 3 ; CHECK-NEXT: Locals: -; CHECK-NEXT: Body: 4100280280800011818080800080808080001A0B +; CHECK-NEXT: Body:4100280280800011818080801A0B ; CHECK-NEXT: - Index: 4 ; CHECK-NEXT: Locals: -; CHECK-NEXT: Body:4201200011828080800080808080001A0B +; CHECK-NEXT: Body:4201200011828080801A0B ; CHECK-NEXT: - Type:DATA ; CHECK-NEXT: Segments: ; CHECK-NEXT: - SectionOffset:7 diff --git a/lld/test/wasm/compress-relocs.ll b/lld/test/wasm/compress-relocs.ll index 9285b080a3b5..4d4ac4b705ee 100644 --- a/lld/test/wasm/compress-relocs.ll +++ b/lld/test/wasm/compress-relocs.ll @@ -22,5 +22,5 @@ entry: ; ERROR: wasm-ld: error: --compress-relocations is incompatible with output debug information. Please pass --strip-debug or --strip-all -; CHECK:Body: 41002802808880800011808080800080808080001A41002802848880800011818080800080808080001A0B +; CHECK:Body: 41002802808880800011808080801A41002802848880800011818080801A0B ; COMPRESS: Body:410028028008111A4100280284081101001A0B diff --git a/lld/test/wasm/shared.ll b/lld/test/wasm/shared.ll index aca517ea7443..61337fcc6a3a 100644 --- a/lld/test/wasm/shared.ll +++ b/lld/test/wasm/shared.ll @@ -84,6 +84,10 @@ declare void @func_external() ; CHECK-NEXT: GlobalType: I32 ; CHECK-NEXT: GlobalMutable: false ; CHECK-NEXT: - Module: env +; CHECK-NEXT: Field: func_external +; CHECK-NEXT: Kind:FUNCTION +; CHECK-NEXT: SigIndex:1 +; CHECK-NEXT: - Module: env ; CHECK-NEXT: Field: __indirect_function_table ; CHECK-NEXT: Kind:TABLE ; CHECK-NEXT: Table: @@ -91,10 +95,6 @@ declare void @func_external() ; CHECK-NEXT: ElemType:FUNCREF ; CHECK-NEXT:
[llvm-branch-commits] [llvm] d75b371 - [WebAssembly] Test that invalid symbol/relocation types generate errors
Author: Sam Clegg Date: 2021-01-21T13:58:28-08:00 New Revision: d75b3719828f3e0c9736476e50a08e5083f90c0b URL: https://github.com/llvm/llvm-project/commit/d75b3719828f3e0c9736476e50a08e5083f90c0b DIFF: https://github.com/llvm/llvm-project/commit/d75b3719828f3e0c9736476e50a08e5083f90c0b.diff LOG: [WebAssembly] Test that invalid symbol/relocation types generate errors See https://bugs.llvm.org/show_bug.cgi?id=48827 Differential Revision: https://reviews.llvm.org/D95163 Added: llvm/test/Object/Inputs/WASM/bad-reloc-type.wasm llvm/test/Object/Inputs/WASM/bad-symbol-type.wasm llvm/test/Object/wasm-bad-reloc-type.test llvm/test/Object/wasm-bad-symbol-type.test Modified: llvm/lib/Object/WasmObjectFile.cpp Removed: diff --git a/llvm/lib/Object/WasmObjectFile.cpp b/llvm/lib/Object/WasmObjectFile.cpp index a349dde303e5..65adec341ebe 100644 --- a/llvm/lib/Object/WasmObjectFile.cpp +++ b/llvm/lib/Object/WasmObjectFile.cpp @@ -693,7 +693,8 @@ Error WasmObjectFile::parseLinkingSectionSymtab(ReadContext &Ctx) { } default: - return make_error("Invalid symbol type", + return make_error("Invalid symbol type: " + +Twine(unsigned(Info.Kind)), object_error::parse_failed); } @@ -850,14 +851,15 @@ Error WasmObjectFile::parseRelocSection(StringRef Name, ReadContext &Ctx) { uint32_t PreviousOffset = 0; while (RelocCount--) { wasm::WasmRelocation Reloc = {}; -Reloc.Type = readVaruint32(Ctx); +uint32_t type = readVaruint32(Ctx); +Reloc.Type = type; Reloc.Offset = readVaruint32(Ctx); if (Reloc.Offset < PreviousOffset) return make_error("Relocations not in offset order", object_error::parse_failed); PreviousOffset = Reloc.Offset; Reloc.Index = readVaruint32(Ctx); -switch (Reloc.Type) { +switch (type) { case wasm::R_WASM_FUNCTION_INDEX_LEB: case wasm::R_WASM_TABLE_INDEX_SLEB: case wasm::R_WASM_TABLE_INDEX_SLEB64: @@ -935,9 +937,8 @@ Error WasmObjectFile::parseRelocSection(StringRef Name, ReadContext &Ctx) { Reloc.Addend = readVarint32(Ctx); break; default: - return make_error("Bad relocation type: " + -Twine(Reloc.Type), -object_error::parse_failed); + return make_error( + "Bad relocation type: " + Twine(type), object_error::parse_failed); } // Relocations must fit inside the section, and must appear in order. They diff --git a/llvm/test/Object/Inputs/WASM/bad-reloc-type.wasm b/llvm/test/Object/Inputs/WASM/bad-reloc-type.wasm new file mode 100644 index ..0f6de0ef6778 Binary files /dev/null and b/llvm/test/Object/Inputs/WASM/bad-reloc-type.wasm diff er diff --git a/llvm/test/Object/Inputs/WASM/bad-symbol-type.wasm b/llvm/test/Object/Inputs/WASM/bad-symbol-type.wasm new file mode 100644 index ..8c7135f89f3b Binary files /dev/null and b/llvm/test/Object/Inputs/WASM/bad-symbol-type.wasm diff er diff --git a/llvm/test/Object/wasm-bad-reloc-type.test b/llvm/test/Object/wasm-bad-reloc-type.test new file mode 100644 index ..786532aa12b2 --- /dev/null +++ b/llvm/test/Object/wasm-bad-reloc-type.test @@ -0,0 +1,3 @@ +RUN: not llvm-objdump -s %p/Inputs/WASM/bad-reloc-type.wasm 2>&1 | FileCheck %s + +CHECK: Bad relocation type: 63 diff --git a/llvm/test/Object/wasm-bad-symbol-type.test b/llvm/test/Object/wasm-bad-symbol-type.test new file mode 100644 index ..06846a18f8f5 --- /dev/null +++ b/llvm/test/Object/wasm-bad-symbol-type.test @@ -0,0 +1,3 @@ +RUN: not llvm-objdump -s %p/Inputs/WASM/bad-symbol-type.wasm 2>&1 | FileCheck %s + +CHECK: Invalid symbol type: 63 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] 30d314a - [MC][WebAssembly] Avoid recalculating indexes in -gsplit-dwarf mode
Author: Sam Clegg Date: 2021-01-06T01:35:06-08:00 New Revision: 30d314aae10eee1e66aff6515a764ee696a03e8d URL: https://github.com/llvm/llvm-project/commit/30d314aae10eee1e66aff6515a764ee696a03e8d DIFF: https://github.com/llvm/llvm-project/commit/30d314aae10eee1e66aff6515a764ee696a03e8d.diff LOG: [MC][WebAssembly] Avoid recalculating indexes in -gsplit-dwarf mode Be consistent about asserting before setting WasmIndices. Adding these assertions revealed that we were duplicating a lot of work and setting these indexed twice when running in DWO mode. Differential Revision: https://reviews.llvm.org/D93650 Added: Modified: llvm/lib/MC/WasmObjectWriter.cpp Removed: diff --git a/llvm/lib/MC/WasmObjectWriter.cpp b/llvm/lib/MC/WasmObjectWriter.cpp index 683678b70ebc..112c5b3f120b 100644 --- a/llvm/lib/MC/WasmObjectWriter.cpp +++ b/llvm/lib/MC/WasmObjectWriter.cpp @@ -1212,6 +1212,7 @@ static bool isInSymtab(const MCSymbolWasm &Sym) { return true; } + void WasmObjectWriter::prepareImports( SmallVectorImpl &Imports, MCAssembler &Asm, const MCAsmLayout &Layout) { @@ -1363,6 +1364,7 @@ uint64_t WasmObjectWriter::writeOneObject(MCAssembler &Asm, if (Mode != DwoMode::DwoOnly) { prepareImports(Imports, Asm, Layout); } + // Populate DataSegments and CustomSections, which must be done before // populating DataLocations. for (MCSection &Sec : Asm) { @@ -1417,6 +1419,7 @@ uint64_t WasmObjectWriter::writeOneObject(MCAssembler &Asm, MCSymbol *Begin = Sec.getBeginSymbol(); if (Begin) { +assert(WasmIndices.count(cast(Begin)) == 0); WasmIndices[cast(Begin)] = CustomSections.size(); } @@ -1445,214 +1448,218 @@ uint64_t WasmObjectWriter::writeOneObject(MCAssembler &Asm, } } - // Populate WasmIndices and DataLocations for defined symbols. - for (const MCSymbol &S : Asm.symbols()) { -// Ignore unnamed temporary symbols, which aren't ever exported, imported, -// or used in relocations. -if (S.isTemporary() && S.getName().empty()) - continue; + if (Mode != DwoMode::DwoOnly) { +// Populate WasmIndices and DataLocations for defined symbols. +for (const MCSymbol &S : Asm.symbols()) { + // Ignore unnamed temporary symbols, which aren't ever exported, imported, + // or used in relocations. + if (S.isTemporary() && S.getName().empty()) +continue; -const auto &WS = static_cast(S); -LLVM_DEBUG( -dbgs() << "MCSymbol: " << toString(WS.getType()) << " '" << S << "'" - << " isDefined=" << S.isDefined() << " isExternal=" - << S.isExternal() << " isTemporary=" << S.isTemporary() - << " isWeak=" << WS.isWeak() << " isHidden=" << WS.isHidden() - << " isVariable=" << WS.isVariable() << "\n"); - -if (WS.isVariable()) - continue; -if (WS.isComdat() && !WS.isDefined()) - continue; + const auto &WS = static_cast(S); + LLVM_DEBUG( + dbgs() << "MCSymbol: " << toString(WS.getType()) << " '" << S << "'" + << " isDefined=" << S.isDefined() << " isExternal=" + << S.isExternal() << " isTemporary=" << S.isTemporary() + << " isWeak=" << WS.isWeak() << " isHidden=" << WS.isHidden() + << " isVariable=" << WS.isVariable() << "\n"); -if (WS.isFunction()) { - unsigned Index; - if (WS.isDefined()) { -if (WS.getOffset() != 0) - report_fatal_error( - "function sections must contain one function each"); - -if (WS.getSize() == nullptr) - report_fatal_error( - "function symbols must have a size set with .size"); - -// A definition. Write out the function body. -Index = NumFunctionImports + Functions.size(); -WasmFunction Func; -Func.SigIndex = getFunctionType(WS); -Func.Sym = &WS; -WasmIndices[&WS] = Index; -Functions.push_back(Func); - -auto &Section = static_cast(WS.getSection()); -if (const MCSymbolWasm *C = Section.getGroup()) { - Comdats[C->getName()].emplace_back( - WasmComdatEntry{wasm::WASM_COMDAT_FUNCTION, Index}); + if (WS.isVariable()) +continue; + if (WS.isComdat() && !WS.isDefined()) +continue; + + if (WS.isFunction()) { +unsigned Index; +if (WS.isDefined()) { + if (WS.getOffset() != 0) +report_fatal_error( +"function sections must contain one function each"); + + if (WS.getSize() == nullptr) +report_fatal_error( +"function symbols must have a size set with .size"); + + // A definition. Write out the function body. + Index = NumFunctionImports + Functions.size(); + WasmFunction Func; + Func.SigIndex = getFunctionType(WS);
[llvm-branch-commits] [clang] c832edf - [WebAssembly] Add new target feature in support of 'extended-const' proposal
Author: Sam Clegg Date: 2022-03-07T16:45:42-08:00 New Revision: c832edfd3fbccfac6d5212d6495f0dde851dbdde URL: https://github.com/llvm/llvm-project/commit/c832edfd3fbccfac6d5212d6495f0dde851dbdde DIFF: https://github.com/llvm/llvm-project/commit/c832edfd3fbccfac6d5212d6495f0dde851dbdde.diff LOG: [WebAssembly] Add new target feature in support of 'extended-const' proposal We don't yet do anything when this feature is enabled, this change just lays the ground work by accepting that there is such a feature. See https://github.com/WebAssembly/extended-const Differential Revision: https://reviews.llvm.org/D121151 Added: Modified: clang/docs/ClangCommandLineReference.rst clang/include/clang/Driver/Options.td clang/lib/Basic/Targets/WebAssembly.cpp clang/lib/Basic/Targets/WebAssembly.h clang/test/Preprocessor/wasm-target-features.c llvm/lib/Target/WebAssembly/WebAssembly.td llvm/lib/Target/WebAssembly/WebAssemblyInstrInfo.td llvm/lib/Target/WebAssembly/WebAssemblySubtarget.h Removed: diff --git a/clang/docs/ClangCommandLineReference.rst b/clang/docs/ClangCommandLineReference.rst index 77c20d3646500..6815dca1f1529 100644 --- a/clang/docs/ClangCommandLineReference.rst +++ b/clang/docs/ClangCommandLineReference.rst @@ -3629,6 +3629,8 @@ WebAssembly .. option:: -mtail-call, -mno-tail-call +.. option:: -mextended-const, -mno-extended-const + WebAssembly Driver -- .. option:: -mexec-model= diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 24e2069711be5..06802ae424f7a 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -3468,6 +3468,8 @@ def mtail_call : Flag<["-"], "mtail-call">, Group; def mno_tail_call : Flag<["-"], "mno-tail-call">, Group; def mreference_types : Flag<["-"], "mreference-types">, Group; def mno_reference_types : Flag<["-"], "mno-reference-types">, Group; +def mextended_const : Flag<["-"], "mextended-const">, Group; +def mno_extended_const : Flag<["-"], "mno-extended-const">, Group; def mexec_model_EQ : Joined<["-"], "mexec-model=">, Group, Values<"command,reactor">, HelpText<"Execution model (WebAssembly only)">; diff --git a/clang/lib/Basic/Targets/WebAssembly.cpp b/clang/lib/Basic/Targets/WebAssembly.cpp index 18ff109bf2d39..b3b6c2be5c134 100644 --- a/clang/lib/Basic/Targets/WebAssembly.cpp +++ b/clang/lib/Basic/Targets/WebAssembly.cpp @@ -56,6 +56,7 @@ bool WebAssemblyTargetInfo::hasFeature(StringRef Feature) const { .Case("multivalue", HasMultivalue) .Case("tail-call", HasTailCall) .Case("reference-types", HasReferenceTypes) + .Case("extended-const", HasExtendedConst) .Default(false); } @@ -93,6 +94,8 @@ void WebAssemblyTargetInfo::getTargetDefines(const LangOptions &Opts, Builder.defineMacro("__wasm_tail_call__"); if (HasReferenceTypes) Builder.defineMacro("__wasm_reference_types__"); + if (HasExtendedConst) +Builder.defineMacro("__wasm_extended_const__"); } void WebAssemblyTargetInfo::setSIMDLevel(llvm::StringMap &Features, @@ -240,6 +243,14 @@ bool WebAssemblyTargetInfo::handleTargetFeatures( HasReferenceTypes = false; continue; } +if (Feature == "+extended-const") { + HasExtendedConst = true; + continue; +} +if (Feature == "-extended-const") { + HasExtendedConst = false; + continue; +} Diags.Report(diag::err_opt_not_valid_with_opt) << Feature << "-target-feature"; diff --git a/clang/lib/Basic/Targets/WebAssembly.h b/clang/lib/Basic/Targets/WebAssembly.h index 075486990558b..63418869d10ac 100644 --- a/clang/lib/Basic/Targets/WebAssembly.h +++ b/clang/lib/Basic/Targets/WebAssembly.h @@ -39,6 +39,7 @@ class LLVM_LIBRARY_VISIBILITY WebAssemblyTargetInfo : public TargetInfo { bool HasMultivalue = false; bool HasTailCall = false; bool HasReferenceTypes = false; + bool HasExtendedConst = false; std::string ABI; diff --git a/clang/test/Preprocessor/wasm-target-features.c b/clang/test/Preprocessor/wasm-target-features.c index 3c743142a3e38..c05b26a0c2278 100644 --- a/clang/test/Preprocessor/wasm-target-features.c +++ b/clang/test/Preprocessor/wasm-target-features.c @@ -105,6 +105,15 @@ // RUN: | FileCheck %s -check-prefix=REFERENCE-TYPES // // REFERENCE-TYPES:#define __wasm_reference_types__ 1{{$}} +// +// RUN: %clang -E -dM %s -o - 2>&1 \ +// RUN: -target wasm32-unknown-unknown -mextended-const \ +// RUN: | FileCheck %s -check-prefix=EXTENDED-CONST +// RUN: %clang -E -dM %s -o - 2>&1 \ +// RUN: -target wasm64-unknown-unknown -mextended-const \ +// RUN: | FileCheck %s -check-prefix=EXTENDED-CONST +// +// EXTENDED-CONST:#define __wasm_extended_const__ 1{{$}} // RUN: %clang -E -dM %s -o - 2>&1 \ // RUN: -target wasm
[llvm-branch-commits] [compiler-rt] 57626a5 - Rebase of changed from emscripten-libs-13.0.0 onto llvmorg-14.0.0
Author: Sam Clegg Date: 2022-05-22T19:08:19-07:00 New Revision: 57626a57ad4bb35367f0b361bd80ceb3266a URL: https://github.com/llvm/llvm-project/commit/57626a57ad4bb35367f0b361bd80ceb3266a DIFF: https://github.com/llvm/llvm-project/commit/57626a57ad4bb35367f0b361bd80ceb3266a.diff LOG: Rebase of changed from emscripten-libs-13.0.0 onto llvmorg-14.0.0 Added: Modified: compiler-rt/lib/asan/asan_errors.cpp compiler-rt/lib/asan/asan_flags.cpp compiler-rt/lib/asan/asan_interceptors.cpp compiler-rt/lib/asan/asan_interceptors_memintrinsics.cpp compiler-rt/lib/asan/asan_malloc_linux.cpp compiler-rt/lib/asan/asan_mapping.h compiler-rt/lib/asan/asan_poisoning.cpp compiler-rt/lib/asan/asan_poisoning.h compiler-rt/lib/asan/asan_posix.cpp compiler-rt/lib/asan/asan_rtl.cpp compiler-rt/lib/asan/asan_shadow_setup.cpp compiler-rt/lib/asan/asan_thread.cpp compiler-rt/lib/builtins/fp_compare_impl.inc compiler-rt/lib/interception/interception.h compiler-rt/lib/interception/interception_linux.h compiler-rt/lib/lsan/lsan.cpp compiler-rt/lib/lsan/lsan_allocator.cpp compiler-rt/lib/lsan/lsan_allocator.h compiler-rt/lib/lsan/lsan_common.cpp compiler-rt/lib/lsan/lsan_common.h compiler-rt/lib/lsan/lsan_common_linux.cpp compiler-rt/lib/lsan/lsan_interceptors.cpp compiler-rt/lib/lsan/lsan_linux.cpp compiler-rt/lib/sanitizer_common/sanitizer_errno_codes.h compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp compiler-rt/lib/sanitizer_common/sanitizer_linux.h compiler-rt/lib/sanitizer_common/sanitizer_platform.h compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h compiler-rt/lib/sanitizer_common/sanitizer_posix.cpp compiler-rt/lib/sanitizer_common/sanitizer_posix_libcdep.cpp compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.cpp compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.h compiler-rt/lib/sanitizer_common/sanitizer_stacktrace_libcdep.cpp compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cpp compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_report.cpp compiler-rt/lib/sanitizer_common/sanitizer_syscall_generic.inc compiler-rt/lib/ubsan/ubsan_checks.inc compiler-rt/lib/ubsan/ubsan_diag.cpp compiler-rt/lib/ubsan/ubsan_flags.cpp compiler-rt/lib/ubsan/ubsan_handlers.cpp compiler-rt/lib/ubsan/ubsan_platform.h compiler-rt/lib/ubsan/ubsan_signals_standalone.cpp libcxx/include/__config libcxx/include/locale libcxx/include/typeinfo libcxx/src/include/config_elast.h libcxx/src/new.cpp libcxx/src/support/runtime/exception_fallback.ipp libcxxabi/include/cxxabi.h libcxxabi/src/abort_message.cpp libcxxabi/src/cxa_exception.cpp libcxxabi/src/cxa_exception.h libcxxabi/src/cxa_handlers.cpp libcxxabi/src/cxa_personality.cpp libcxxabi/src/cxa_thread_atexit.cpp libcxxabi/src/private_typeinfo.cpp libcxxabi/src/stdlib_new_delete.cpp Removed: diff --git a/compiler-rt/lib/asan/asan_errors.cpp b/compiler-rt/lib/asan/asan_errors.cpp index a22bf130d8233..f1ccbb8f50f82 100644 --- a/compiler-rt/lib/asan/asan_errors.cpp +++ b/compiler-rt/lib/asan/asan_errors.cpp @@ -482,6 +482,17 @@ ErrorGeneric::ErrorGeneric(u32 tid, uptr pc_, uptr bp_, uptr sp_, uptr addr, scariness.Scare(bug_type_score + read_after_free_bonus, bug_descr); if (far_from_bounds) scariness.Scare(10, "far-from-bounds"); } +#if SANITIZER_EMSCRIPTEN +// If address is in the first page (64 KB), then it is likely that the +// access is a result of a null pointer dereference. +else if (addr < 65536) { + bug_descr = "null-pointer-dereference"; + scariness.Scare(25, bug_descr); +} else if (AddrIsInShadow(addr)) { + bug_descr = "shadow-access"; + scariness.Scare(25, bug_descr); +} +#endif } } diff --git a/compiler-rt/lib/asan/asan_flags.cpp b/compiler-rt/lib/asan/asan_flags.cpp index 9ea899f84b4b7..d7ef1a109f2ee 100644 --- a/compiler-rt/lib/asan/asan_flags.cpp +++ b/compiler-rt/lib/asan/asan_flags.cpp @@ -22,6 +22,12 @@ #include "ubsan/ubsan_flags.h" #include "ubsan/ubsan_platform.h" +#if SANITIZER_EMSCRIPTEN +extern "C" void emscripten_builtin_free(void *); +#include +#endif + + namespace __asan { Flags asan_flags_dont_use_directly; // use via flags(). @@ -54,7 +60,11 @@ void InitializeFlags() { CommonFlags cf; cf.CopyFrom(*common_flags()); cf.detect_leaks = cf.detect_leaks && CAN_SANITIZE_LEAKS; +#if !SANITIZER_EMSCRIPTEN +// getenv on emscripten uses malloc, which we can't when using LSan. +// You can't run external sym
[llvm-branch-commits] [compiler-rt] bce25ef - Patches from emscripten 3.1.11
Author: Sam Clegg Date: 2022-05-22T19:15:19-07:00 New Revision: bce25ef66596b013cd61c322c0098f89e43e92f6 URL: https://github.com/llvm/llvm-project/commit/bce25ef66596b013cd61c322c0098f89e43e92f6 DIFF: https://github.com/llvm/llvm-project/commit/bce25ef66596b013cd61c322c0098f89e43e92f6.diff LOG: Patches from emscripten 3.1.11 Added: Modified: compiler-rt/lib/lsan/lsan_common.cpp compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h compiler-rt/lib/sanitizer_common/sanitizer_posix.cpp libcxx/include/__config Removed: diff --git a/compiler-rt/lib/lsan/lsan_common.cpp b/compiler-rt/lib/lsan/lsan_common.cpp index b52106537a677..1a7a3d4203d4e 100644 --- a/compiler-rt/lib/lsan/lsan_common.cpp +++ b/compiler-rt/lib/lsan/lsan_common.cpp @@ -185,6 +185,14 @@ static uptr GetCallerPC(const StackTrace &stack) { // valid before reporting chunks as leaked. bool LeakSuppressionContext::SuppressInvalid(const StackTrace &stack) { uptr caller_pc = GetCallerPC(stack); +#if SANITIZER_EMSCRIPTEN + // caller_pr will always be 0 if we use malloc_context_size=0 (or 1) which + // we recommend under emscripten to save memory. It seems that this setting + // now (inadvertently?) suppreses all leaks. + // See https://reviews.llvm.org/D115319#3526676. + if (!caller_pc) +return false; +#endif // If caller_pc is unknown, this chunk may be allocated in a coroutine. Mark // it as reachable, as we can't properly report its allocation stack anyway. return !caller_pc || @@ -313,7 +321,7 @@ void ScanRangeForPointers(uptr begin, uptr end, Frontier *frontier, #if SANITIZER_EMSCRIPTEN && !defined(__EMSCRIPTEN_PTHREADS__) if (cache_begin <= pp && pp < cache_end) { LOG_POINTERS("%p: skipping because it overlaps the cache %p-%p.\n", - pp, cache_begin, cache_end); + (void*)pp, (void*)cache_begin, (void*)cache_end); continue; } #endif @@ -804,53 +812,6 @@ static int DoRecoverableLeakCheck() { void DoRecoverableLeakCheckVoid() { DoRecoverableLeakCheck(); } -<<< HEAD -=== -Suppression *LeakSuppressionContext::GetSuppressionForAddr(uptr addr) { - Suppression *s = nullptr; - - // Suppress by module name. - if (const char *module_name = - Symbolizer::GetOrInit()->GetModuleNameForPc(addr)) -if (context.Match(module_name, kSuppressionLeak, &s)) - return s; - - // Suppress by file or function name. - SymbolizedStack *frames = Symbolizer::GetOrInit()->SymbolizePC(addr); - for (SymbolizedStack *cur = frames; cur; cur = cur->next) { -if (context.Match(cur->info.function, kSuppressionLeak, &s) || -context.Match(cur->info.file, kSuppressionLeak, &s)) { - break; -} - } - frames->ClearAll(); - return s; -} - -Suppression *LeakSuppressionContext::GetSuppressionForStack( -u32 stack_trace_id) { - LazyInit(); - StackTrace stack = StackDepotGet(stack_trace_id); - for (uptr i = 0; i < stack.size; i++) { -#if SANITIZER_EMSCRIPTEN -// On Emscripten, the stack trace is the actual call site, not -// the code that would be executed after the return. -// Therefore, StackTrace::GetPreviousInstructionPc is not needed. -Suppression *s = GetSuppressionForAddr(stack.trace[i]); -#else -Suppression *s = GetSuppressionForAddr( -StackTrace::GetPreviousInstructionPc(stack.trace[i])); -#endif -if (s) { - suppressed_stacks_sorted = false; - suppressed_stacks.push_back(stack_trace_id); - return s; -} - } - return nullptr; -} - ->>> 2bbe2c4b7413 (Rebase of changed from emscripten-libs-12.0.0 onto llvmorg-13.0.0) / LeakReport implementation. / // A hard limit on the number of distinct leaks, to avoid quadratic complexity diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h b/compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h index 7fa8008589b63..fee0ba277 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h @@ -139,7 +139,7 @@ namespace __sanitizer { typedef unsigned long long uptr; typedef signed long long sptr; #else -# if (SANITIZER_WORDSIZE == 64) || SANITIZER_MAC || SANITIZER_WINDOWS +# if (SANITIZER_WORDSIZE == 64) || SANITIZER_MAC || SANITIZER_WINDOWS || SANITIZER_EMSCRIPTEN typedef unsigned long uptr; typedef signed long sptr; # else diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_posix.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_posix.cpp index 4269fed630051..32b96dbdf96f7 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_posix.cpp +++ b/compiler-rt/lib/sanitizer_common/sanitizer_posix.cpp @@ -145,11 +145,19 @@ void *MmapFixedOrDieOnFatalError(uptr fixed_addr, uptr size, const char *name) { } bool MprotectNoAccess(uptr addr, uptr size) { +#if SANITIZER_EMSCRIPTEN + return true; +#else return 0 == int
[llvm-branch-commits] [libcxx] bfd609f - Patches from emscripten 3.1.12
Author: Sam Clegg Date: 2022-05-27T19:01:47-07:00 New Revision: bfd609f67960b463229f0167b5ca720f70319797 URL: https://github.com/llvm/llvm-project/commit/bfd609f67960b463229f0167b5ca720f70319797 DIFF: https://github.com/llvm/llvm-project/commit/bfd609f67960b463229f0167b5ca720f70319797.diff LOG: Patches from emscripten 3.1.12 Added: Modified: libcxx/include/__locale libcxx/src/include/config_elast.h Removed: diff --git a/libcxx/include/__locale b/libcxx/include/__locale index 51f35eece7121..08db4bcbe01e8 100644 --- a/libcxx/include/__locale +++ b/libcxx/include/__locale @@ -34,8 +34,7 @@ # include <__support/newlib/xlocale.h> #elif defined(__OpenBSD__) # include <__support/openbsd/xlocale.h> -#elif (defined(__APPLE__) || defined(__FreeBSD__) \ -|| defined(__EMSCRIPTEN__) || defined(__IBMCPP__)) +#elif (defined(__APPLE__) || defined(__FreeBSD__) || defined(__IBMCPP__)) # include #elif defined(__Fuchsia__) # include <__support/fuchsia/xlocale.h> diff --git a/libcxx/src/include/config_elast.h b/libcxx/src/include/config_elast.h index 13e1624a97ee3..bef26ec5019ec 100644 --- a/libcxx/src/include/config_elast.h +++ b/libcxx/src/include/config_elast.h @@ -29,12 +29,12 @@ // No _LIBCPP_ELAST needed on Fuchsia #elif defined(__wasi__) // No _LIBCPP_ELAST needed on WASI +#elif defined(__EMSCRIPTEN__) +// No _LIBCPP_ELAST needed on Emscripten #elif defined(__linux__) || defined(_LIBCPP_HAS_MUSL_LIBC) #define _LIBCPP_ELAST 4095 #elif defined(__APPLE__) // No _LIBCPP_ELAST needed on Apple -#elif defined(__EMSCRIPTEN__) // XXX EMSCRIPTEN added ELAST value -#define _LIBCPP_ELAST 256 #elif defined(__sun__) #define _LIBCPP_ELAST ESTALE #elif defined(__MVS__) ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [compiler-rt] 5fd26fb - Patches from emscripten 3.1.20
Author: Sam Clegg Date: 2022-09-06T02:21:33-07:00 New Revision: 5fd26fb4fcb1657bff8fc489cf6cd8628993f71c URL: https://github.com/llvm/llvm-project/commit/5fd26fb4fcb1657bff8fc489cf6cd8628993f71c DIFF: https://github.com/llvm/llvm-project/commit/5fd26fb4fcb1657bff8fc489cf6cd8628993f71c.diff LOG: Patches from emscripten 3.1.20 Added: Modified: compiler-rt/lib/asan/asan_globals.cpp compiler-rt/lib/lsan/lsan_interceptors.cpp compiler-rt/lib/sanitizer_common/sanitizer_common_libcdep.cpp compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp compiler-rt/lib/sanitizer_common/sanitizer_posix_libcdep.cpp compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_internal.h compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_libcdep.cpp compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cpp Removed: diff --git a/compiler-rt/lib/asan/asan_globals.cpp b/compiler-rt/lib/asan/asan_globals.cpp index ecc2600f039a1..fa050988e5351 100644 --- a/compiler-rt/lib/asan/asan_globals.cpp +++ b/compiler-rt/lib/asan/asan_globals.cpp @@ -315,6 +315,7 @@ void PrintGlobalLocation(InternalScopedString *str, const __asan_global &g) { // -- Interface {{{1 using namespace __asan; +#if !SANITIZER_EMSCRIPTEN // Apply __asan_register_globals to all globals found in the same loaded // executable or shared library as `flag'. The flag tracks whether globals have // already been registered or not for this image. @@ -352,6 +353,7 @@ void __asan_unregister_elf_globals(uptr *flag, void *start, void *stop) { __asan_unregister_globals(globals_start, globals_stop - globals_start); *flag = 0; } +#endif // Register an array of globals. void __asan_register_globals(__asan_global *globals, uptr n) { diff --git a/compiler-rt/lib/lsan/lsan_interceptors.cpp b/compiler-rt/lib/lsan/lsan_interceptors.cpp index c7032032ff9a7..00c0428f4a8bb 100644 --- a/compiler-rt/lib/lsan/lsan_interceptors.cpp +++ b/compiler-rt/lib/lsan/lsan_interceptors.cpp @@ -32,6 +32,17 @@ #include "lsan_common.h" #include "lsan_thread.h" +#if SANITIZER_EMSCRIPTEN +#define __ATTRP_C11_THREAD ((void*)(uptr)-1) +#include +extern "C" { +int emscripten_builtin_pthread_create(void *thread, void *attr, + void *(*callback)(void *), void *arg); +int emscripten_builtin_pthread_join(void *th, void **ret); +int emscripten_builtin_pthread_detach(void *th); +} +#endif + #include using namespace __lsan; @@ -403,18 +414,6 @@ INTERCEPTOR(int, pthread_atfork, void (*prepare)(), void (*parent)(), #define LSAN_MAYBE_INTERCEPT_PTHREAD_ATFORK #endif -#if SANITIZER_EMSCRIPTEN -#define __ATTRP_C11_THREAD ((void*)(uptr)-1) -extern "C" { - int emscripten_builtin_pthread_create(void *thread, void *attr, -void *(*callback)(void *), void *arg); - int emscripten_builtin_pthread_join(void *th, void **ret); - int emscripten_builtin_pthread_detach(void *th); - void *emscripten_builtin_malloc(size_t size); - void emscripten_builtin_free(void *); -} -#endif - #if SANITIZER_INTERCEPT_STRERROR INTERCEPTOR(char *, strerror, int errnum) { __lsan::ScopedInterceptorDisabler disabler; diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_libcdep.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_common_libcdep.cpp index c4cc0e45193ea..c64b0955b78c5 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_common_libcdep.cpp +++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_libcdep.cpp @@ -78,6 +78,7 @@ void *BackgroundThread(void *arg) { } } +#if !SANITIZER_EMSCRIPTEN void MaybeStartBackgroudThread() { // Need to implement/test on other platforms. // Start the background thread if one of the rss limits is given. @@ -110,6 +111,7 @@ static struct BackgroudThreadStarted { #else void MaybeStartBackgroudThread() {} #endif +#endif void WriteToSyslog(const char *msg) { InternalScopedString msg_copy; diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp index ef0b0167fb3a6..33e7f017aac83 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp +++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp @@ -59,7 +59,7 @@ #include #include #include -#if !SANITIZER_SOLARIS +#if !SANITIZER_SOLARIS && !SANITIZER_EMSCRIPTEN #include #endif #include @@ -596,7 +596,9 @@ u64 NanoTime() { #endif #if SANITIZER_EMSCRIPTEN +extern "C" { int __clock_gettime(__sanitizer_clockid_t clk_id, void *tp); +} uptr internal_clock_gettime(__sanitizer_clockid_t clk_id, void *tp) { return __clock_gettime(clk_id, tp); @@ -1850,7 +1852,7 @@ HandleSignalMode GetHandleSignalMode(int signum) { return result; } -#if !SANITIZER_GO +#if !SANITIZER_GO && !SANITIZER
[llvm-branch-commits] [compiler-rt] 57626a5 - Rebase of changed from emscripten-libs-13.0.0 onto llvmorg-14.0.0
Author: Sam Clegg Date: 2022-05-22T19:08:19-07:00 New Revision: 57626a57ad4bb35367f0b361bd80ceb3266a URL: https://github.com/llvm/llvm-project/commit/57626a57ad4bb35367f0b361bd80ceb3266a DIFF: https://github.com/llvm/llvm-project/commit/57626a57ad4bb35367f0b361bd80ceb3266a.diff LOG: Rebase of changed from emscripten-libs-13.0.0 onto llvmorg-14.0.0 Added: Modified: compiler-rt/lib/asan/asan_errors.cpp compiler-rt/lib/asan/asan_flags.cpp compiler-rt/lib/asan/asan_interceptors.cpp compiler-rt/lib/asan/asan_interceptors_memintrinsics.cpp compiler-rt/lib/asan/asan_malloc_linux.cpp compiler-rt/lib/asan/asan_mapping.h compiler-rt/lib/asan/asan_poisoning.cpp compiler-rt/lib/asan/asan_poisoning.h compiler-rt/lib/asan/asan_posix.cpp compiler-rt/lib/asan/asan_rtl.cpp compiler-rt/lib/asan/asan_shadow_setup.cpp compiler-rt/lib/asan/asan_thread.cpp compiler-rt/lib/builtins/fp_compare_impl.inc compiler-rt/lib/interception/interception.h compiler-rt/lib/interception/interception_linux.h compiler-rt/lib/lsan/lsan.cpp compiler-rt/lib/lsan/lsan_allocator.cpp compiler-rt/lib/lsan/lsan_allocator.h compiler-rt/lib/lsan/lsan_common.cpp compiler-rt/lib/lsan/lsan_common.h compiler-rt/lib/lsan/lsan_common_linux.cpp compiler-rt/lib/lsan/lsan_interceptors.cpp compiler-rt/lib/lsan/lsan_linux.cpp compiler-rt/lib/sanitizer_common/sanitizer_errno_codes.h compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp compiler-rt/lib/sanitizer_common/sanitizer_linux.h compiler-rt/lib/sanitizer_common/sanitizer_platform.h compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h compiler-rt/lib/sanitizer_common/sanitizer_posix.cpp compiler-rt/lib/sanitizer_common/sanitizer_posix_libcdep.cpp compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.cpp compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.h compiler-rt/lib/sanitizer_common/sanitizer_stacktrace_libcdep.cpp compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cpp compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_report.cpp compiler-rt/lib/sanitizer_common/sanitizer_syscall_generic.inc compiler-rt/lib/ubsan/ubsan_checks.inc compiler-rt/lib/ubsan/ubsan_diag.cpp compiler-rt/lib/ubsan/ubsan_flags.cpp compiler-rt/lib/ubsan/ubsan_handlers.cpp compiler-rt/lib/ubsan/ubsan_platform.h compiler-rt/lib/ubsan/ubsan_signals_standalone.cpp libcxx/include/__config libcxx/include/locale libcxx/include/typeinfo libcxx/src/include/config_elast.h libcxx/src/new.cpp libcxx/src/support/runtime/exception_fallback.ipp libcxxabi/include/cxxabi.h libcxxabi/src/abort_message.cpp libcxxabi/src/cxa_exception.cpp libcxxabi/src/cxa_exception.h libcxxabi/src/cxa_handlers.cpp libcxxabi/src/cxa_personality.cpp libcxxabi/src/cxa_thread_atexit.cpp libcxxabi/src/private_typeinfo.cpp libcxxabi/src/stdlib_new_delete.cpp Removed: diff --git a/compiler-rt/lib/asan/asan_errors.cpp b/compiler-rt/lib/asan/asan_errors.cpp index a22bf130d8233..f1ccbb8f50f82 100644 --- a/compiler-rt/lib/asan/asan_errors.cpp +++ b/compiler-rt/lib/asan/asan_errors.cpp @@ -482,6 +482,17 @@ ErrorGeneric::ErrorGeneric(u32 tid, uptr pc_, uptr bp_, uptr sp_, uptr addr, scariness.Scare(bug_type_score + read_after_free_bonus, bug_descr); if (far_from_bounds) scariness.Scare(10, "far-from-bounds"); } +#if SANITIZER_EMSCRIPTEN +// If address is in the first page (64 KB), then it is likely that the +// access is a result of a null pointer dereference. +else if (addr < 65536) { + bug_descr = "null-pointer-dereference"; + scariness.Scare(25, bug_descr); +} else if (AddrIsInShadow(addr)) { + bug_descr = "shadow-access"; + scariness.Scare(25, bug_descr); +} +#endif } } diff --git a/compiler-rt/lib/asan/asan_flags.cpp b/compiler-rt/lib/asan/asan_flags.cpp index 9ea899f84b4b7..d7ef1a109f2ee 100644 --- a/compiler-rt/lib/asan/asan_flags.cpp +++ b/compiler-rt/lib/asan/asan_flags.cpp @@ -22,6 +22,12 @@ #include "ubsan/ubsan_flags.h" #include "ubsan/ubsan_platform.h" +#if SANITIZER_EMSCRIPTEN +extern "C" void emscripten_builtin_free(void *); +#include +#endif + + namespace __asan { Flags asan_flags_dont_use_directly; // use via flags(). @@ -54,7 +60,11 @@ void InitializeFlags() { CommonFlags cf; cf.CopyFrom(*common_flags()); cf.detect_leaks = cf.detect_leaks && CAN_SANITIZE_LEAKS; +#if !SANITIZER_EMSCRIPTEN +// getenv on emscripten uses malloc, which we can't when using LSan. +// You can't run external sym
[llvm-branch-commits] [compiler-rt] 908f8e1 - Rebase of changed from emscripten-libs-13.0.0 onto llvmorg-14.0.0
Author: Sam Clegg Date: 2022-09-06T02:22:35-07:00 New Revision: 908f8e197b3162cc9cae9d9e9b35bb366e7e99e1 URL: https://github.com/llvm/llvm-project/commit/908f8e197b3162cc9cae9d9e9b35bb366e7e99e1 DIFF: https://github.com/llvm/llvm-project/commit/908f8e197b3162cc9cae9d9e9b35bb366e7e99e1.diff LOG: Rebase of changed from emscripten-libs-13.0.0 onto llvmorg-14.0.0 Added: Modified: compiler-rt/lib/asan/asan_errors.cpp compiler-rt/lib/asan/asan_flags.cpp compiler-rt/lib/asan/asan_globals.cpp compiler-rt/lib/asan/asan_interceptors.cpp compiler-rt/lib/asan/asan_interceptors_memintrinsics.cpp compiler-rt/lib/asan/asan_malloc_linux.cpp compiler-rt/lib/asan/asan_mapping.h compiler-rt/lib/asan/asan_poisoning.cpp compiler-rt/lib/asan/asan_poisoning.h compiler-rt/lib/asan/asan_posix.cpp compiler-rt/lib/asan/asan_rtl.cpp compiler-rt/lib/asan/asan_shadow_setup.cpp compiler-rt/lib/asan/asan_thread.cpp compiler-rt/lib/builtins/fp_compare_impl.inc compiler-rt/lib/interception/interception.h compiler-rt/lib/interception/interception_linux.h compiler-rt/lib/lsan/lsan.cpp compiler-rt/lib/lsan/lsan_allocator.cpp compiler-rt/lib/lsan/lsan_common.cpp compiler-rt/lib/lsan/lsan_common.h compiler-rt/lib/lsan/lsan_common_linux.cpp compiler-rt/lib/lsan/lsan_interceptors.cpp compiler-rt/lib/lsan/lsan_linux.cpp compiler-rt/lib/sanitizer_common/sanitizer_common_libcdep.cpp compiler-rt/lib/sanitizer_common/sanitizer_errno_codes.h compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp compiler-rt/lib/sanitizer_common/sanitizer_linux.h compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp compiler-rt/lib/sanitizer_common/sanitizer_platform.h compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h compiler-rt/lib/sanitizer_common/sanitizer_posix.cpp compiler-rt/lib/sanitizer_common/sanitizer_posix_libcdep.cpp compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.cpp compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.h compiler-rt/lib/sanitizer_common/sanitizer_stacktrace_libcdep.cpp compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_internal.h compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_libcdep.cpp compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cpp compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_report.cpp compiler-rt/lib/sanitizer_common/sanitizer_syscall_generic.inc compiler-rt/lib/ubsan/ubsan_checks.inc compiler-rt/lib/ubsan/ubsan_diag.cpp compiler-rt/lib/ubsan/ubsan_flags.cpp compiler-rt/lib/ubsan/ubsan_handlers.cpp compiler-rt/lib/ubsan/ubsan_platform.h compiler-rt/lib/ubsan/ubsan_signals_standalone.cpp libcxx/include/__config libcxx/include/typeinfo libcxx/src/new.cpp libcxx/src/support/runtime/exception_fallback.ipp libcxxabi/include/cxxabi.h libcxxabi/src/abort_message.cpp libcxxabi/src/cxa_exception.cpp libcxxabi/src/cxa_exception.h libcxxabi/src/cxa_handlers.cpp libcxxabi/src/cxa_personality.cpp libcxxabi/src/cxa_thread_atexit.cpp libcxxabi/src/private_typeinfo.cpp libcxxabi/src/stdlib_new_delete.cpp Removed: diff --git a/compiler-rt/lib/asan/asan_errors.cpp b/compiler-rt/lib/asan/asan_errors.cpp index 10f7c17991d72..c5f958a453197 100644 --- a/compiler-rt/lib/asan/asan_errors.cpp +++ b/compiler-rt/lib/asan/asan_errors.cpp @@ -480,6 +480,17 @@ ErrorGeneric::ErrorGeneric(u32 tid, uptr pc_, uptr bp_, uptr sp_, uptr addr, scariness.Scare(bug_type_score + read_after_free_bonus, bug_descr); if (far_from_bounds) scariness.Scare(10, "far-from-bounds"); } +#if SANITIZER_EMSCRIPTEN +// If address is in the first page (64 KB), then it is likely that the +// access is a result of a null pointer dereference. +else if (addr < 65536) { + bug_descr = "null-pointer-dereference"; + scariness.Scare(25, bug_descr); +} else if (AddrIsInShadow(addr)) { + bug_descr = "shadow-access"; + scariness.Scare(25, bug_descr); +} +#endif } } diff --git a/compiler-rt/lib/asan/asan_flags.cpp b/compiler-rt/lib/asan/asan_flags.cpp index 2398984332321..b1feaf903e206 100644 --- a/compiler-rt/lib/asan/asan_flags.cpp +++ b/compiler-rt/lib/asan/asan_flags.cpp @@ -22,6 +22,12 @@ #include "ubsan/ubsan_flags.h" #include "ubsan/ubsan_platform.h" +#if SANITIZER_EMSCRIPTEN +extern "C" void emscripten_builtin_free(void *); +#include +#endif + + namespace __asan { Flags asan_flags_dont_use_directly; // use via flags(). @@ -54,7 +60,11 @@ void InitializeFlags() { CommonFlags cf; cf.CopyFrom(*common_f
[llvm-branch-commits] [libcxxabi] b88f4ab - Rebase of changed from emscripten-libs-13.0.0 onto llvmorg-14.0.0
Author: Sam Clegg Date: 2022-09-06T02:34:14-07:00 New Revision: b88f4ab4994e008b539522fb27bfd46fd8de9639 URL: https://github.com/llvm/llvm-project/commit/b88f4ab4994e008b539522fb27bfd46fd8de9639 DIFF: https://github.com/llvm/llvm-project/commit/b88f4ab4994e008b539522fb27bfd46fd8de9639.diff LOG: Rebase of changed from emscripten-libs-13.0.0 onto llvmorg-14.0.0 Added: Modified: compiler-rt/lib/asan/asan_errors.cpp compiler-rt/lib/asan/asan_flags.cpp compiler-rt/lib/asan/asan_globals.cpp compiler-rt/lib/asan/asan_interceptors.cpp compiler-rt/lib/asan/asan_interceptors_memintrinsics.cpp compiler-rt/lib/asan/asan_malloc_linux.cpp compiler-rt/lib/asan/asan_mapping.h compiler-rt/lib/asan/asan_poisoning.cpp compiler-rt/lib/asan/asan_poisoning.h compiler-rt/lib/asan/asan_posix.cpp compiler-rt/lib/asan/asan_rtl.cpp compiler-rt/lib/asan/asan_shadow_setup.cpp compiler-rt/lib/asan/asan_thread.cpp compiler-rt/lib/builtins/fp_compare_impl.inc compiler-rt/lib/interception/interception.h compiler-rt/lib/interception/interception_linux.h compiler-rt/lib/lsan/lsan.cpp compiler-rt/lib/lsan/lsan_allocator.cpp compiler-rt/lib/lsan/lsan_common.cpp compiler-rt/lib/lsan/lsan_common.h compiler-rt/lib/lsan/lsan_common_linux.cpp compiler-rt/lib/lsan/lsan_interceptors.cpp compiler-rt/lib/lsan/lsan_linux.cpp compiler-rt/lib/sanitizer_common/sanitizer_common_libcdep.cpp compiler-rt/lib/sanitizer_common/sanitizer_errno_codes.h compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp compiler-rt/lib/sanitizer_common/sanitizer_linux.h compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp compiler-rt/lib/sanitizer_common/sanitizer_platform.h compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h compiler-rt/lib/sanitizer_common/sanitizer_posix.cpp compiler-rt/lib/sanitizer_common/sanitizer_posix_libcdep.cpp compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.cpp compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.h compiler-rt/lib/sanitizer_common/sanitizer_stacktrace_libcdep.cpp compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_internal.h compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_libcdep.cpp compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cpp compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_report.cpp compiler-rt/lib/sanitizer_common/sanitizer_syscall_generic.inc compiler-rt/lib/ubsan/ubsan_checks.inc compiler-rt/lib/ubsan/ubsan_diag.cpp compiler-rt/lib/ubsan/ubsan_flags.cpp compiler-rt/lib/ubsan/ubsan_handlers.cpp compiler-rt/lib/ubsan/ubsan_platform.h compiler-rt/lib/ubsan/ubsan_signals_standalone.cpp libcxx/include/__config libcxx/include/typeinfo libcxx/src/new.cpp libcxx/src/support/runtime/exception_fallback.ipp libcxxabi/include/cxxabi.h libcxxabi/src/abort_message.cpp libcxxabi/src/cxa_exception.cpp libcxxabi/src/cxa_exception.h libcxxabi/src/cxa_handlers.cpp libcxxabi/src/cxa_personality.cpp libcxxabi/src/cxa_thread_atexit.cpp libcxxabi/src/private_typeinfo.cpp libcxxabi/src/stdlib_new_delete.cpp Removed: diff --git a/compiler-rt/lib/asan/asan_errors.cpp b/compiler-rt/lib/asan/asan_errors.cpp index 10f7c17991d72..c5f958a453197 100644 --- a/compiler-rt/lib/asan/asan_errors.cpp +++ b/compiler-rt/lib/asan/asan_errors.cpp @@ -480,6 +480,17 @@ ErrorGeneric::ErrorGeneric(u32 tid, uptr pc_, uptr bp_, uptr sp_, uptr addr, scariness.Scare(bug_type_score + read_after_free_bonus, bug_descr); if (far_from_bounds) scariness.Scare(10, "far-from-bounds"); } +#if SANITIZER_EMSCRIPTEN +// If address is in the first page (64 KB), then it is likely that the +// access is a result of a null pointer dereference. +else if (addr < 65536) { + bug_descr = "null-pointer-dereference"; + scariness.Scare(25, bug_descr); +} else if (AddrIsInShadow(addr)) { + bug_descr = "shadow-access"; + scariness.Scare(25, bug_descr); +} +#endif } } diff --git a/compiler-rt/lib/asan/asan_flags.cpp b/compiler-rt/lib/asan/asan_flags.cpp index 2398984332321..b1feaf903e206 100644 --- a/compiler-rt/lib/asan/asan_flags.cpp +++ b/compiler-rt/lib/asan/asan_flags.cpp @@ -22,6 +22,12 @@ #include "ubsan/ubsan_flags.h" #include "ubsan/ubsan_platform.h" +#if SANITIZER_EMSCRIPTEN +extern "C" void emscripten_builtin_free(void *); +#include +#endif + + namespace __asan { Flags asan_flags_dont_use_directly; // use via flags(). @@ -54,7 +60,11 @@ void InitializeFlags() { CommonFlags cf; cf.CopyFrom(*common_f
[llvm-branch-commits] [lld] 465e0bf - [lld][WebAssebmly] Ensure stub symbols always get address 0
Author: Sam Clegg Date: 2020-11-24T08:13:04-08:00 New Revision: 465e0bf415e1449919ec2f62027dc5df0ebc338d URL: https://github.com/llvm/llvm-project/commit/465e0bf415e1449919ec2f62027dc5df0ebc338d DIFF: https://github.com/llvm/llvm-project/commit/465e0bf415e1449919ec2f62027dc5df0ebc338d.diff LOG: [lld][WebAssebmly] Ensure stub symbols always get address 0 Without this extra flag we can't distingish between stub functions and functions that happen to have address 0 (relative to __table_base). Adding this flag bit the base symbol class actually avoids growing the SymbolUnion struct which would not be true if we added it to the FunctionSymbol subclass (due to bitbacking). The previous approach of setting it's table index to zero worked for normal static relocations but not for `-fPIC` code. See https://github.com/emscripten-core/emscripten/issues/12819 Added: lld/test/wasm/weak-undefined-pic.s Modified: lld/wasm/MarkLive.cpp lld/wasm/Relocations.cpp lld/wasm/SymbolTable.cpp lld/wasm/Symbols.h lld/wasm/SyntheticSections.cpp Removed: diff --git a/lld/test/wasm/weak-undefined-pic.s b/lld/test/wasm/weak-undefined-pic.s new file mode 100644 index ..f0c85268fe79 --- /dev/null +++ b/lld/test/wasm/weak-undefined-pic.s @@ -0,0 +1,36 @@ +# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown -o %t.o %s +# RUN: wasm-ld %t.o -o %t.wasm +# RUN: obj2yaml %t.wasm | FileCheck %s + +# Test that undefined weak external functions get resolved to address zero +# under static linking, and also with `-pie --unresolved-symbols=ignore` + +.globl get_foo_addr +get_foo_addr: + .functype get_foo_addr () -> (i32) + global.get foo@GOT + end_function + +.globl _start +_start: + .functype _start () -> () + call get_foo_addr + end_function + +.weak foo +.functype foo () -> (i32) + +# CHECK: - Type:CUSTOM +# CHECK-NEXT:Name:name +# CHECK-NEXT:FunctionNames: +# CHECK-NEXT: - Index: 0 +# CHECK-NEXT:Name:'undefined_weak:foo' +# CHECK-NEXT: - Index: 1 +# CHECK-NEXT:Name:get_foo_addr +# CHECK-NEXT: - Index: 2 +# CHECK-NEXT:Name:_start +# CHECK-NEXT:GlobalNames: +# CHECK-NEXT: - Index: 0 +# CHECK-NEXT:Name:__stack_pointer +# CHECK-NEXT: - Index: 1 +# CHECK-NEXT:Name:'undefined_weak:foo' diff --git a/lld/wasm/MarkLive.cpp b/lld/wasm/MarkLive.cpp index 4bce68877040..235936e4ef3e 100644 --- a/lld/wasm/MarkLive.cpp +++ b/lld/wasm/MarkLive.cpp @@ -142,7 +142,7 @@ void MarkLive::mark() { reloc.Type == R_WASM_TABLE_INDEX_I32 || reloc.Type == R_WASM_TABLE_INDEX_I64) { auto *funcSym = cast(sym); -if (funcSym->hasTableIndex() && funcSym->getTableIndex() == 0) +if (funcSym->isStub) continue; } diff --git a/lld/wasm/Relocations.cpp b/lld/wasm/Relocations.cpp index 5b131d4f23f4..bd07c0410dc5 100644 --- a/lld/wasm/Relocations.cpp +++ b/lld/wasm/Relocations.cpp @@ -62,7 +62,9 @@ static void reportUndefined(Symbol *sym) { << "ignoring undefined symbol: " + toString(*sym) + "\n"); f->stubFunction = symtab->createUndefinedStub(*f->getSignature()); f->stubFunction->markLive(); - f->setTableIndex(0); + // Mark the function itself as a stub which prevents it from being + // assigned a table entry. + f->isStub = true; } } break; diff --git a/lld/wasm/SymbolTable.cpp b/lld/wasm/SymbolTable.cpp index fc92020d07dd..e469aca89ad7 100644 --- a/lld/wasm/SymbolTable.cpp +++ b/lld/wasm/SymbolTable.cpp @@ -673,9 +673,7 @@ InputFunction *SymbolTable::replaceWithUnreachable(Symbol *sym, // to be exported outside the object file. replaceSymbol(sym, debugName, WASM_SYMBOL_BINDING_LOCAL, nullptr, func); - // Ensure it compares equal to the null pointer, and so that table relocs - // don't pull in the stub body (only call-operand relocs should do that). - func->setTableIndex(0); + sym->isStub = true; return func; } diff --git a/lld/wasm/Symbols.h b/lld/wasm/Symbols.h index 865a9e7fee99..90fb5194edcd 100644 --- a/lld/wasm/Symbols.h +++ b/lld/wasm/Symbols.h @@ -124,7 +124,7 @@ class Symbol { Symbol(StringRef name, Kind k, uint32_t flags, InputFile *f) : name(name), file(f), symbolKind(k), referenced(!config->gcSections), requiresGOT(false), isUsedInRegularObj(false), forceExport(false), -canInline(false), traced(false), flags(flags) {} +canInline(false), traced(false), isStub(false), flags(flags) {} StringRef name; InputFile *file; @@ -157,6 +157,11 @@ class Symbol { // True if this symbol is specified by --trace-symbol option. bool traced : 1; + // T
[llvm-branch-commits] [lld] 1933c9d - [WebAssembly] Factor out WasmTableType in binary format
Author: Andy Wingo Date: 2020-11-25T08:00:08-08:00 New Revision: 1933c9d41a08cfc4c5c0ae80eedf466b5ae7ef01 URL: https://github.com/llvm/llvm-project/commit/1933c9d41a08cfc4c5c0ae80eedf466b5ae7ef01 DIFF: https://github.com/llvm/llvm-project/commit/1933c9d41a08cfc4c5c0ae80eedf466b5ae7ef01.diff LOG: [WebAssembly] Factor out WasmTableType in binary format This commit factors out a WasmTableType definition from WasmTable, as is the case for WasmGlobal and other data types. Also add support for extracting the SymbolName for a table from the linking section's symbol table. Differential Revision: https://reviews.llvm.org/D91849 Added: Modified: lld/wasm/SyntheticSections.cpp lld/wasm/WriterUtils.cpp lld/wasm/WriterUtils.h llvm/include/llvm/BinaryFormat/Wasm.h llvm/lib/MC/WasmObjectWriter.cpp llvm/lib/Object/WasmObjectFile.cpp llvm/tools/obj2yaml/wasm2yaml.cpp Removed: diff --git a/lld/wasm/SyntheticSections.cpp b/lld/wasm/SyntheticSections.cpp index 407eb8084d0e..3e0581cbcfc4 100644 --- a/lld/wasm/SyntheticSections.cpp +++ b/lld/wasm/SyntheticSections.cpp @@ -223,7 +223,7 @@ void TableSection::writeBody() { limits = {0, tableSize, 0}; else limits = {WASM_LIMITS_FLAG_HAS_MAX, tableSize, tableSize}; - writeTableType(os, WasmTable{0, WASM_TYPE_FUNCREF, limits}); + writeTableType(os, WasmTableType{WASM_TYPE_FUNCREF, limits}); } void MemorySection::writeBody() { diff --git a/lld/wasm/WriterUtils.cpp b/lld/wasm/WriterUtils.cpp index cd221855a12b..81fcee4e68fe 100644 --- a/lld/wasm/WriterUtils.cpp +++ b/lld/wasm/WriterUtils.cpp @@ -195,7 +195,7 @@ void writeEvent(raw_ostream &os, const WasmEvent &event) { writeEventType(os, event.Type); } -void writeTableType(raw_ostream &os, const llvm::wasm::WasmTable &type) { +void writeTableType(raw_ostream &os, const WasmTableType &type) { writeU8(os, WASM_TYPE_FUNCREF, "table type"); writeLimits(os, type.Limits); } diff --git a/lld/wasm/WriterUtils.h b/lld/wasm/WriterUtils.h index 86df768af5c6..98f5ab1fbf3b 100644 --- a/lld/wasm/WriterUtils.h +++ b/lld/wasm/WriterUtils.h @@ -54,7 +54,7 @@ void writeEventType(raw_ostream &os, const llvm::wasm::WasmEventType &type); void writeEvent(raw_ostream &os, const llvm::wasm::WasmEvent &event); -void writeTableType(raw_ostream &os, const llvm::wasm::WasmTable &type); +void writeTableType(raw_ostream &os, const llvm::wasm::WasmTableType &type); void writeImport(raw_ostream &os, const llvm::wasm::WasmImport &import); diff --git a/llvm/include/llvm/BinaryFormat/Wasm.h b/llvm/include/llvm/BinaryFormat/Wasm.h index f1441c7e0794..adcd9d364431 100644 --- a/llvm/include/llvm/BinaryFormat/Wasm.h +++ b/llvm/include/llvm/BinaryFormat/Wasm.h @@ -67,12 +67,17 @@ struct WasmLimits { uint64_t Maximum; }; -struct WasmTable { - uint32_t Index; +struct WasmTableType { uint8_t ElemType; WasmLimits Limits; }; +struct WasmTable { + uint32_t Index; + WasmTableType Type; + StringRef SymbolName; // from the "linking" section +}; + struct WasmInitExpr { uint8_t Opcode; union { @@ -115,7 +120,7 @@ struct WasmImport { union { uint32_t SigIndex; WasmGlobalType Global; -WasmTable Table; +WasmTableType Table; WasmLimits Memory; WasmEventType Event; }; diff --git a/llvm/lib/MC/WasmObjectWriter.cpp b/llvm/lib/MC/WasmObjectWriter.cpp index 0cf6e310ae32..029b776fd774 100644 --- a/llvm/lib/MC/WasmObjectWriter.cpp +++ b/llvm/lib/MC/WasmObjectWriter.cpp @@ -848,11 +848,11 @@ void WasmObjectWriter::writeTableSection(ArrayRef Tables) { encodeULEB128(Tables.size(), W->OS); for (const wasm::WasmTable &Table : Tables) { -encodeULEB128(Table.ElemType, W->OS); -encodeULEB128(Table.Limits.Flags, W->OS); -encodeULEB128(Table.Limits.Initial, W->OS); -if (Table.Limits.Flags & wasm::WASM_LIMITS_FLAG_HAS_MAX) - encodeULEB128(Table.Limits.Maximum, W->OS); +encodeULEB128(Table.Type.ElemType, W->OS); +encodeULEB128(Table.Type.Limits.Flags, W->OS); +encodeULEB128(Table.Type.Limits.Initial, W->OS); +if (Table.Type.Limits.Flags & wasm::WASM_LIMITS_FLAG_HAS_MAX) + encodeULEB128(Table.Type.Limits.Maximum, W->OS); } endSection(Section); } @@ -1527,10 +1527,10 @@ uint64_t WasmObjectWriter::writeOneObject(MCAssembler &Asm, if (WS.isDefined()) { assert(WasmIndices.count(&WS) == 0); wasm::WasmTable Table; -Table.ElemType = static_cast(WS.getTableType()); Table.Index = NumTableImports + Tables.size(); +Table.Type.ElemType = static_cast(WS.getTableType()); // FIXME: Work on custom limits is ongoing -Table.Limits = {wasm::WASM_LIMITS_FLAG_NONE, 0, 0}; +Table.Type.Limits = {wasm::WASM_LIMITS_FLAG_NONE, 0, 0}; WasmIndices[&WS] = Table.Index; Tables.push_back(Table); diff --git a/llvm/lib/Object/WasmObjectFile.cpp
[llvm-branch-commits] [llvm] feac819 - [MC][WebAssembly] Only emit indirect function table import if needed
Author: Andy Wingo Date: 2020-11-25T08:38:43-08:00 New Revision: feac819e50b2b62eeafdf1a7e6ecaa725d7bf08d URL: https://github.com/llvm/llvm-project/commit/feac819e50b2b62eeafdf1a7e6ecaa725d7bf08d DIFF: https://github.com/llvm/llvm-project/commit/feac819e50b2b62eeafdf1a7e6ecaa725d7bf08d.diff LOG: [MC][WebAssembly] Only emit indirect function table import if needed The indirect function table, synthesized by the linker, is needed if and only if there are TABLE_INDEX relocs. Differential Revision: https://reviews.llvm.org/D91637 Added: Modified: llvm/include/llvm/MC/MCSymbolWasm.h llvm/include/llvm/Object/Wasm.h llvm/lib/MC/WasmObjectWriter.cpp llvm/lib/Object/WasmObjectFile.cpp llvm/test/MC/WebAssembly/assembler-binary.ll llvm/test/MC/WebAssembly/comdat.ll llvm/test/MC/WebAssembly/custom-sections.ll llvm/test/MC/WebAssembly/data-section.s llvm/test/MC/WebAssembly/event-section.ll llvm/test/MC/WebAssembly/external-func-address.ll llvm/test/MC/WebAssembly/global-ctor-dtor.ll llvm/test/MC/WebAssembly/reloc-pic.s llvm/test/MC/WebAssembly/tables.s llvm/test/MC/WebAssembly/type-index.s llvm/test/MC/WebAssembly/wasm64.s Removed: diff --git a/llvm/include/llvm/MC/MCSymbolWasm.h b/llvm/include/llvm/MC/MCSymbolWasm.h index 52ff9f933f92..ae512fd27be2 100644 --- a/llvm/include/llvm/MC/MCSymbolWasm.h +++ b/llvm/include/llvm/MC/MCSymbolWasm.h @@ -96,6 +96,15 @@ class MCSymbolWasm : public MCSymbol { StringRef getExportName() const { return ExportName.getValue(); } void setExportName(StringRef Name) { ExportName = Name; } + bool isFunctionTable() const { +return isTable() && hasTableType() && + getTableType() == wasm::ValType::FUNCREF; + } + void setFunctionTable() { +setType(wasm::WASM_SYMBOL_TYPE_TABLE); +setTableType(wasm::ValType::FUNCREF); + } + void setUsedInGOT() const { IsUsedInGOT = true; } bool isUsedInGOT() const { return IsUsedInGOT; } @@ -111,8 +120,9 @@ class MCSymbolWasm : public MCSymbol { } void setGlobalType(wasm::WasmGlobalType GT) { GlobalType = GT; } - const wasm::ValType &getTableType() const { -assert(TableType.hasValue()); + bool hasTableType() const { return TableType.hasValue(); } + wasm::ValType getTableType() const { +assert(hasTableType()); return TableType.getValue(); } void setTableType(wasm::ValType TT) { TableType = TT; } diff --git a/llvm/include/llvm/Object/Wasm.h b/llvm/include/llvm/Object/Wasm.h index 72e4403a45cb..e5091f5a8552 100644 --- a/llvm/include/llvm/Object/Wasm.h +++ b/llvm/include/llvm/Object/Wasm.h @@ -299,6 +299,7 @@ class WasmObjectFile : public ObjectFile { uint32_t DataSection = 0; uint32_t EventSection = 0; uint32_t GlobalSection = 0; + uint32_t TableSection = 0; }; class WasmSectionOrderChecker { diff --git a/llvm/lib/MC/WasmObjectWriter.cpp b/llvm/lib/MC/WasmObjectWriter.cpp index 029b776fd774..a05d4c993089 100644 --- a/llvm/lib/MC/WasmObjectWriter.cpp +++ b/llvm/lib/MC/WasmObjectWriter.cpp @@ -40,8 +40,8 @@ using namespace llvm; namespace { -// Went we ceate the indirect function table we start at 1, so that there is -// and emtpy slot at 0 and therefore calling a null function pointer will trap. +// When we create the indirect function table we start at 1, so that there is +// and empty slot at 0 and therefore calling a null function pointer will trap. static const uint32_t InitialTableOffset = 1; // For patching purposes, we need to remember where each section starts, both @@ -218,9 +218,7 @@ class WasmObjectWriter : public MCObjectWriter { SmallVector DataSegments; unsigned NumFunctionImports = 0; unsigned NumGlobalImports = 0; - // NumTableImports is initialized to 1 to account for the hardcoded import of - // __indirect_function_table - unsigned NumTableImports = 1; + unsigned NumTableImports = 0; unsigned NumEventImports = 0; uint32_t SectionCount = 0; @@ -270,7 +268,7 @@ class WasmObjectWriter : public MCObjectWriter { SectionFunctions.clear(); NumFunctionImports = 0; NumGlobalImports = 0; -NumTableImports = 1; +NumTableImports = 0; MCObjectWriter::reset(); } @@ -497,6 +495,29 @@ void WasmObjectWriter::recordRelocation(MCAssembler &Asm, SymA = cast(SectionSymbol); } + if (Type == wasm::R_WASM_TABLE_INDEX_REL_SLEB || + Type == wasm::R_WASM_TABLE_INDEX_SLEB || + Type == wasm::R_WASM_TABLE_INDEX_SLEB64 || + Type == wasm::R_WASM_TABLE_INDEX_I32 || + Type == wasm::R_WASM_TABLE_INDEX_I64) { +// TABLE_INDEX relocs implicitly use the default indirect function table. +auto TableName = "__indirect_function_table"; +MCSymbolWasm *Sym = cast_or_null(Ctx.lookupSymbol(TableName)); +if (Sym) { + if (!Sym->isFunctionTable()) +Ctx.reportError( +Fixup.getLoc(), +"symbol '__indire
[llvm-branch-commits] [lld] 48ddf5e - [lld][WebAssembly] Ensure stub symbols always get address 0
Author: Sam Clegg Date: 2020-11-25T18:26:34-08:00 New Revision: 48ddf5e182c61cb93d66325f5690312d9e9226eb URL: https://github.com/llvm/llvm-project/commit/48ddf5e182c61cb93d66325f5690312d9e9226eb DIFF: https://github.com/llvm/llvm-project/commit/48ddf5e182c61cb93d66325f5690312d9e9226eb.diff LOG: [lld][WebAssembly] Ensure stub symbols always get address 0 Without this extra flag we can't distingish between stub functions and functions that happen to have address 0 (relative to __table_base). Adding this flag bit the base symbol class actually avoids growing the SymbolUnion struct which would not be true if we added it to the FunctionSymbol subclass (due to bitbacking). The previous approach of setting it's table index to zero worked for normal static relocations but not for `-fPIC` code. See https://github.com/emscripten-core/emscripten/issues/12819 Differential Revision: https://reviews.llvm.org/D92038 Added: lld/test/wasm/weak-undefined-pic.s Modified: lld/wasm/Driver.cpp lld/wasm/MarkLive.cpp lld/wasm/Relocations.cpp lld/wasm/SymbolTable.cpp lld/wasm/Symbols.h lld/wasm/SyntheticSections.cpp Removed: diff --git a/lld/test/wasm/weak-undefined-pic.s b/lld/test/wasm/weak-undefined-pic.s new file mode 100644 index ..c12ef235d85f --- /dev/null +++ b/lld/test/wasm/weak-undefined-pic.s @@ -0,0 +1,90 @@ +# Checks handling of undefined weak external functions. When the +# static linker decides they are undefined, check GOT relocations +# resolve to zero (i.e. a global that contains zero.). +# +# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown -o %t.o %s +# RUN: wasm-ld %t.o -o %t1.wasm +# RUN: obj2yaml %t1.wasm | FileCheck %s +# +# With `--unresolved-symbols=ignore-all` the behaviour should be the same +# as the default.> +# +# RUN: wasm-ld --unresolved-symbols=ignore-all %t.o -o %t2.wasm +# RUN: obj2yaml %t2.wasm | FileCheck %s + +.globl get_foo_addr +get_foo_addr: + .functype get_foo_addr () -> (i32) + global.get foo@GOT + end_function + +.globl _start +_start: + .functype _start () -> () + call get_foo_addr + end_function + +.weak foo +.functype foo () -> (i32) + +# Verify that we do not generate dynamnic relocations for the GOT entry. + +# CHECK-NOT: __wasm_apply_relocs + +# Verify that we do not generate an import for foo + +# CHECK-NOT: - Type:IMPORT + +# CHECK: - Type:GLOBAL +# CHECK-NEXT: Globals: +# CHECK-NEXT: - Index: 0 +# CHECK-NEXT: Type:I32 +# CHECK-NEXT: Mutable: true +# CHECK-NEXT: InitExpr: +# CHECK-NEXT: Opcode: I32_CONST +# CHECK-NEXT: Value: 66560 +# Global 'undefined_weak:foo' representing the GOT entry for foo +# Unlike other internal GOT entries that need to be mutable this one +# is immutable and not updated by `__wasm_apply_relocs` +# CHECK-NEXT: - Index: 1 +# CHECK-NEXT: Type:I32 +# CHECK-NEXT: Mutable: false +# CHECK-NEXT: InitExpr: +# CHECK-NEXT: Opcode: I32_CONST +# CHECK-NEXT: Value: 0 + +# CHECK: - Type:CUSTOM +# CHECK-NEXT:Name:name +# CHECK-NEXT:FunctionNames: +# CHECK-NEXT: - Index: 0 +# CHECK-NEXT:Name:'undefined_weak:foo' +# CHECK-NEXT: - Index: 1 +# CHECK-NEXT:Name:get_foo_addr +# CHECK-NEXT: - Index: 2 +# CHECK-NEXT:Name:_start +# CHECK-NEXT:GlobalNames: +# CHECK-NEXT: - Index: 0 +# CHECK-NEXT:Name:__stack_pointer +# CHECK-NEXT: - Index: 1 +# CHECK-NEXT:Name:'undefined_weak:foo' + +# With `-pie` or `-shared` the resolution should is defered to the dynamic +# linker and the function address should be imported as GOT.func.foo. +# +# RUN: wasm-ld --experimental-pic -pie %t.o -o %t3.wasm +# RUN: obj2yaml %t3.wasm | FileCheck %s --check-prefix=IMPORT + +# IMPORT: - Type:IMPORT +# IMPORT: - Module: GOT.func +# IMPORT-NEXT:Field: foo +# IMPORT-NEXT:Kind:GLOBAL +# IMPORT-NEXT:GlobalType: I32 +# IMPORT-NEXT:GlobalMutable: true + +# IMPORT: GlobalNames: +# IMPORT-NEXT: - Index: 0 +# IMPORT-NEXT: Name:__memory_base +# IMPORT-NEXT: - Index: 1 +# IMPORT-NEXT: Name:__table_base +# IMPORT-NEXT: - Index: 2 +# IMPORT-NEXT: Name:foo diff --git a/lld/wasm/Driver.cpp b/lld/wasm/Driver.cpp index 8aa124795f6f..f26b190b6058 100644 --- a/lld/wasm/Driver.cpp +++ b/lld/wasm/Driver.cpp @@ -973,7 +973,7 @@ void LinkerDriver::link(ArrayRef argsArr) { warn(Twine("symbol exported via --
[llvm-branch-commits] [lld] a38ed62 - [lld][WebAssembly] Feedback from D92038. NFC
Author: Sam Clegg Date: 2020-12-01T14:53:59-08:00 New Revision: a38ed62ea803a41c2e1f3fa12edbc176e474056f URL: https://github.com/llvm/llvm-project/commit/a38ed62ea803a41c2e1f3fa12edbc176e474056f DIFF: https://github.com/llvm/llvm-project/commit/a38ed62ea803a41c2e1f3fa12edbc176e474056f.diff LOG: [lld][WebAssembly] Feedback from D92038. NFC Differential Revision: https://reviews.llvm.org/D92429 Added: Modified: lld/test/wasm/weak-undefined-pic.s lld/wasm/Symbols.h Removed: diff --git a/lld/test/wasm/weak-undefined-pic.s b/lld/test/wasm/weak-undefined-pic.s index c12ef235d85f..a169fd315f08 100644 --- a/lld/test/wasm/weak-undefined-pic.s +++ b/lld/test/wasm/weak-undefined-pic.s @@ -27,7 +27,7 @@ _start: .weak foo .functype foo () -> (i32) -# Verify that we do not generate dynamnic relocations for the GOT entry. +# Verify that we do not generate dynamic relocations for the GOT entry. # CHECK-NOT: __wasm_apply_relocs @@ -68,7 +68,7 @@ _start: # CHECK-NEXT: - Index: 1 # CHECK-NEXT:Name:'undefined_weak:foo' -# With `-pie` or `-shared` the resolution should is defered to the dynamic +# With `-pie` or `-shared` the resolution should be deferred to the dynamic # linker and the function address should be imported as GOT.func.foo. # # RUN: wasm-ld --experimental-pic -pie %t.o -o %t3.wasm diff --git a/lld/wasm/Symbols.h b/lld/wasm/Symbols.h index 90fb5194edcd..cfa686998de4 100644 --- a/lld/wasm/Symbols.h +++ b/lld/wasm/Symbols.h @@ -160,6 +160,9 @@ class Symbol { // True if this symbol is a linker-synthesized stub function (traps when // called) and should otherwise be treated as missing/undefined. See // SymbolTable::replaceWithUndefined. + // These stubs never appear in the table and any table index relocations + // against them will produce address 0 (The table index representing + // the null function pointer). bool isStub : 1; uint32_t flags; ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [lld] 701fa0b - [lld][WebAssembly] Fix malformed output with -pie + --shared-memory
Author: Sam Clegg Date: 2020-12-03T11:06:07-08:00 New Revision: 701fa0b5ab04e9aa309cbc30599e9d6ee879e61a URL: https://github.com/llvm/llvm-project/commit/701fa0b5ab04e9aa309cbc30599e9d6ee879e61a DIFF: https://github.com/llvm/llvm-project/commit/701fa0b5ab04e9aa309cbc30599e9d6ee879e61a.diff LOG: [lld][WebAssembly] Fix malformed output with -pie + --shared-memory The conditional guarding createInitMemoryFunction was incorrect and didn't match that guarding the creation of the associated symbol. Rather that reproduce the same conditions in multiple places we can simply use the presence of the associated symbol. Also, add an assertion that would have caught this bug. Also, add a new test for this flag combination. This is part of an ongoing effort to enable dynamic linking with threads in emscripten. See https://github.com/emscripten-core/emscripten/issues/3494 Differential Revision: https://reviews.llvm.org/D92520 Added: Modified: lld/test/wasm/data-segments.ll lld/wasm/MarkLive.cpp lld/wasm/OutputSections.cpp lld/wasm/Writer.cpp Removed: diff --git a/lld/test/wasm/data-segments.ll b/lld/test/wasm/data-segments.ll index eb419ba07f30..835aa31b7ab1 100644 --- a/lld/test/wasm/data-segments.ll +++ b/lld/test/wasm/data-segments.ll @@ -13,6 +13,10 @@ ; RUN: wasm-ld -no-gc-sections --no-entry --shared-memory --max-memory=131072 %t.atomics.bulk-mem.o -o %t.atomics.bulk-mem.wasm ; RUN: obj2yaml %t.atomics.bulk-mem.wasm | FileCheck %s --check-prefixes PASSIVE +; Also test in combination with PIC/pie +; RUN: llc -filetype=obj -relocation-model=pic %s -o %t.atomics.bulk-mem.pic.o -mattr=+atomics,+bulk-memory,+mutable-globals +; RUN: wasm-ld --experimental-pic -pie -no-gc-sections --no-entry --shared-memory --max-memory=131072 %t.atomics.bulk-mem.pic.o -o %t.pic.wasm + target triple = "wasm32-unknown-unknown" @a = hidden global [6 x i8] c"hello\00", align 1 diff --git a/lld/wasm/MarkLive.cpp b/lld/wasm/MarkLive.cpp index 235936e4ef3e..046041bab472 100644 --- a/lld/wasm/MarkLive.cpp +++ b/lld/wasm/MarkLive.cpp @@ -96,15 +96,13 @@ void MarkLive::run() { if (sym->isNoStrip() || sym->isExported()) enqueue(sym); - // If we'll be calling the user's `__wasm_call_dtors` function, mark it live. - if (Symbol *callDtors = WasmSym::callDtors) -enqueue(callDtors); + if (WasmSym::callDtors) +enqueue(WasmSym::callDtors); - // In Emscripten-style PIC, `__wasm_call_ctors` calls `__wasm_apply_relocs`. - if (config->isPic) + if (WasmSym::applyRelocs) enqueue(WasmSym::applyRelocs); - if (config->sharedMemory && !config->shared) + if (WasmSym::initMemory) enqueue(WasmSym::initMemory); // Enqueue constructors in objects explicitly live from the command-line. diff --git a/lld/wasm/OutputSections.cpp b/lld/wasm/OutputSections.cpp index fca9bd79296c..89f51ec467b1 100644 --- a/lld/wasm/OutputSections.cpp +++ b/lld/wasm/OutputSections.cpp @@ -90,6 +90,8 @@ void CodeSection::finalizeContents() { func->outputSec = this; func->outputOffset = bodySize; func->calculateSize(); +// All functions should have a non-empty body at this point +assert(func->getSize()); bodySize += func->getSize(); } diff --git a/lld/wasm/Writer.cpp b/lld/wasm/Writer.cpp index 0be9a044763b..e818bc5db60a 100644 --- a/lld/wasm/Writer.cpp +++ b/lld/wasm/Writer.cpp @@ -1214,11 +1214,12 @@ void Writer::run() { calculateInitFunctions(); if (!config->relocatable) { -// Create linker synthesized functions -if (config->isPic) +if (WasmSym::applyRelocs) createApplyRelocationsFunction(); -else if (config->sharedMemory) +if (WasmSym::initMemory) createInitMemoryFunction(); + +// Create linker synthesized functions createCallCtorsFunction(); // Create export wrappers for commands if needed. ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [lld] 1bb7987 - [lld][WebAssembly] Set memory limits correctly for PIC + shared memory
Author: Sam Clegg Date: 2020-12-03T18:14:28-08:00 New Revision: 1bb79875e4b8f9018142a5155ca3f7df37778419 URL: https://github.com/llvm/llvm-project/commit/1bb79875e4b8f9018142a5155ca3f7df37778419 DIFF: https://github.com/llvm/llvm-project/commit/1bb79875e4b8f9018142a5155ca3f7df37778419.diff LOG: [lld][WebAssembly] Set memory limits correctly for PIC + shared memory Don't early return from layoutMemory in PIC mode before we have set the memory limits. This matters in particular with shared-memory + PIC because shared memories require maximum size. Secondly, when we need a maximum, but the user does not supply one, default to MAX_INT rather than 0 (defaulting to zero is completely useless and means that building with -shared didn't previously work at all without --maximum-memory, because zero is never big enough). This is part of an ongoing effort to enable dynamic linking with threads in emscripten. See https://github.com/emscripten-core/emscripten/issues/3494 Differential Revision: https://reviews.llvm.org/D92528 Added: Modified: lld/test/wasm/shared-memory.yaml lld/test/wasm/shared.ll lld/wasm/Writer.cpp Removed: diff --git a/lld/test/wasm/shared-memory.yaml b/lld/test/wasm/shared-memory.yaml index 11dd6b166fbf..8710a06db3f7 100644 --- a/lld/test/wasm/shared-memory.yaml +++ b/lld/test/wasm/shared-memory.yaml @@ -1,6 +1,6 @@ # RUN: yaml2obj %s -o %t1.o -# RUN: not wasm-ld --no-entry --shared-memory %t1.o -o - 2>&1 | FileCheck %s --check-prefix SHARED-NO-MAX +# RUN: wasm-ld --no-entry --shared-memory --features=atomics,bulk-memory %t1.o -o - | obj2yaml | FileCheck %s --check-prefix SHARED # RUN: not wasm-ld --no-entry --shared-memory --max-memory=10 %t1.o -o - 2>&1 | FileCheck %s --check-prefix SHARED-UNALIGNED @@ -56,8 +56,6 @@ Sections: Flags: [ ] ... -# SHARED-NO-MAX: maximum memory too small, 66576 bytes needed{{$}} - # SHARED-UNALIGNED: maximum memory must be 65536-byte aligned{{$}} # SHARED-NO-ATOMICS: 'atomics' feature must be used in order to use shared memory diff --git a/lld/test/wasm/shared.ll b/lld/test/wasm/shared.ll index 3740ea336b73..98751adda489 100644 --- a/lld/test/wasm/shared.ll +++ b/lld/test/wasm/shared.ll @@ -1,5 +1,5 @@ ; RUN: llc -relocation-model=pic -mattr=+mutable-globals -filetype=obj %s -o %t.o -; RUN: wasm-ld -shared -o %t.wasm %t.o +; RUN: wasm-ld --experimental-pic -shared -o %t.wasm %t.o ; RUN: obj2yaml %t.wasm | FileCheck %s target triple = "wasm32-unknown-emscripten" @@ -67,7 +67,7 @@ declare void @func_external() ; CHECK-NEXT: Field: memory ; CHECK-NEXT: Kind:MEMORY ; CHECK-NEXT: Memory: -; CHECK-NEXT: Initial: 0x0 +; CHECK-NEXT: Initial: 0x1 ; CHECK-NEXT: - Module: env ; CHECK-NEXT: Field: __indirect_function_table ; CHECK-NEXT: Kind:TABLE diff --git a/lld/wasm/Writer.cpp b/lld/wasm/Writer.cpp index 89f79aea8bd0..d927b71e1d97 100644 --- a/lld/wasm/Writer.cpp +++ b/lld/wasm/Writer.cpp @@ -308,20 +308,19 @@ void Writer::layoutMemory() { uint64_t staticDataSize = memoryPtr - dataStart; log("mem: static data = " + Twine(staticDataSize)); - if (config->isPic) { + if (config->isPic) out.dylinkSec->memSize = staticDataSize; -return; - } if (!config->stackFirst) placeStack(); - // Set `__heap_base` to directly follow the end of the stack or global data. - // The fact that this comes last means that a malloc/brk implementation - // can grow the heap at runtime. - log("mem: heap base = " + Twine(memoryPtr)); - if (WasmSym::heapBase) + if (WasmSym::heapBase) { +// Set `__heap_base` to directly follow the end of the stack or global data. +// The fact that this comes last means that a malloc/brk implementation +// can grow the heap at runtime. +log("mem: heap base = " + Twine(memoryPtr)); WasmSym::heapBase->setVirtualAddress(memoryPtr); + } uint64_t maxMemorySetting = 1ULL << (config->is64.getValueOr(false) ? 48 : 32); @@ -340,8 +339,7 @@ void Writer::layoutMemory() { alignTo(memoryPtr, WasmPageSize) / WasmPageSize; log("mem: total pages = " + Twine(out.memorySec->numMemoryPages)); - // Check max if explicitly supplied or required by shared memory - if (config->maxMemory != 0 || config->sharedMemory) { + if (config->maxMemory != 0) { if (config->maxMemory != alignTo(config->maxMemory, WasmPageSize)) error("maximum memory must be " + Twine(WasmPageSize) + "-byte aligned"); if (memoryPtr > config->maxMemory) @@ -349,7 +347,20 @@ void Writer::layoutMemory() { if (config->maxMemory > maxMemorySetting) error("maximum memory too large, cannot be greater than " + Twine(maxMemorySetting)); -out.memorySec->maxMemoryPages = co
[llvm-branch-commits] [lld] ab58e4c - [lld][WebAssembly] Add suppport for PIC + passive data initialization
Author: Sam Clegg Date: 2020-12-04T17:28:23-08:00 New Revision: ab58e4cb5185cc2042f3e1c077c85430b83c28b5 URL: https://github.com/llvm/llvm-project/commit/ab58e4cb5185cc2042f3e1c077c85430b83c28b5 DIFF: https://github.com/llvm/llvm-project/commit/ab58e4cb5185cc2042f3e1c077c85430b83c28b5.diff LOG: [lld][WebAssembly] Add suppport for PIC + passive data initialization This change improves our support for shared memory to include PIC executables (and shared libraries). To handle this case the linker-generated `__wasm_init_memory` function (that only exists in shared memory builds) must be capable of loading memory segements at non-const offsets based on the runtime value of `__memory_base`. Differential Revision: https://reviews.llvm.org/D92620 Added: Modified: lld/test/lit.cfg.py lld/test/wasm/data-segments.ll lld/wasm/Driver.cpp lld/wasm/SyntheticSections.cpp lld/wasm/Writer.cpp llvm/include/llvm/BinaryFormat/Wasm.h Removed: diff --git a/lld/test/lit.cfg.py b/lld/test/lit.cfg.py index c031505e5c3e..8e31fd3977f9 100644 --- a/lld/test/lit.cfg.py +++ b/lld/test/lit.cfg.py @@ -18,8 +18,7 @@ # testFormat: The test format to use to interpret tests. # -# For now we require '&&' between commands, until they get globally killed and -# the test runner updated. +# For now we require '&&' between commands, until they get globally killed and the test runner updated. config.test_format = lit.formats.ShTest(not llvm_config.use_lit_shell) # suffixes: A list of file extensions to treat as test files. diff --git a/lld/test/wasm/data-segments.ll b/lld/test/wasm/data-segments.ll index a31fe467e942..ecd18190b9c3 100644 --- a/lld/test/wasm/data-segments.ll +++ b/lld/test/wasm/data-segments.ll @@ -2,6 +2,8 @@ ; RUN: llc --mtriple=wasm32-unknown-unknown -filetype=obj %s -o %t.bulk-mem.o -mattr=+bulk-memory ; RUN: llc --mtriple=wasm32-unknown-unknown -filetype=obj %s -o %t.atomics.bulk-mem.o -mattr=+atomics,+bulk-memory ; RUN: llc --mtriple=wasm64-unknown-unknown -filetype=obj %s -o %t.atomics.bulk-mem64.o -mattr=+atomics,+bulk-memory +; RUN: llc --mtriple=wasm32-unknown-unknown -filetype=obj %s -o %t.atomics.bulk-mem.pic.o -relocation-model=pic -mattr=+atomics,+bulk-memory,+mutable-globals +; RUN: llc --mtriple=wasm64-unknown-unknown -filetype=obj %s -o %t.atomics.bulk-mem.pic-mem64.o -relocation-model=pic -mattr=+atomics,+bulk-memory,+mutable-globals ; atomics, shared memory => error ; RUN: not wasm-ld -no-gc-sections --no-entry --shared-memory --max-memory=131072 %t.atomics.o -o %t.atomics.wasm 2>&1 | FileCheck %s --check-prefix ERROR @@ -19,8 +21,12 @@ ; RUN: obj2yaml %t.atomics.bulk-mem64.wasm | FileCheck %s --check-prefixes PASSIVE,PASSIVE64 ; Also test in combination with PIC/pie -; RUN: llc --mtriple=wasm32-unknown-unknown -filetype=obj -relocation-model=pic %s -o %t.atomics.bulk-mem.pic.o -mattr=+atomics,+bulk-memory,+mutable-globals ; RUN: wasm-ld --experimental-pic -pie -no-gc-sections --no-entry --shared-memory --max-memory=131072 %t.atomics.bulk-mem.pic.o -o %t.pic.wasm +; RUN: obj2yaml %t.pic.wasm | FileCheck %s --check-prefixes PASSIVE-PIC,PASSIVE32-PIC + +; Also test in combination with PIC/pie + wasm64 +; RUN: wasm-ld -mwasm64 --experimental-pic -pie -no-gc-sections --no-entry --shared-memory --max-memory=131072 %t.atomics.bulk-mem.pic-mem64.o -o %t.pic-mem64.wasm +; RUN: obj2yaml %t.pic-mem64.wasm | FileCheck %s --check-prefixes PASSIVE-PIC,PASSIVE64-PIC @a = hidden global [6 x i8] c"hello\00", align 1 @b = hidden global [8 x i8] c"goodbye\00", align 1 @@ -91,3 +97,42 @@ ; PASSIVE-NEXT:Name:__wasm_init_memory ; PASSIVE-NEXT: - Index: 2 ; PASSIVE-NEXT:Name:__wasm_init_tls + +; PASSIVE-PIC: - Type:START +; PASSIVE-PIC-NEXT:StartFunction: 2 +; PASSIVE-PIC-NEXT: - Type:DATACOUNT +; PASSIVE-PIC-NEXT:Count: 1 +; PASSIVE-PIC-NEXT: - Type:CODE +; PASSIVE-PIC-NEXT:Functions: +; PASSIVE-PIC-NEXT: - Index: 0 +; PASSIVE-PIC-NEXT:Locals: [] +; PASSIVE-PIC-NEXT:Body:10010B +; PASSIVE-PIC-NEXT: - Index: 1 +; PASSIVE-PIC-NEXT:Locals: [] +; PASSIVE-PIC-NEXT:Body:0B +; PASSIVE-PIC-NEXT: - Index: 2 +; PASSIVE-PIC-NEXT:Locals: +; PASSIVE32-PIC-NEXT: - Type:I32 +; PASSIVE64-PIC-NEXT: - Type:I64 +; PASSIVE-PIC-NEXT:Count: 1 +; PASSIVE32-PIC-NEXT:Body: 230141B4CE006A2100200041004101FE480200044020004101427FFE0102001A05410023016A410041B1CE00FC0820004102FE1702002000417FFE0002001A0BFC09000B +; PASSIVE64-PIC-NEXT:Body: 230142B4CE006A2100200041004101FE480200044020004101427FFE0102001A05420023016A410041B1CE00FC082000
[llvm-branch-commits] [llvm] 1b6d879 - [WebAssembly] Fix code generated for atomic operations in PIC mode
Author: Sam Clegg Date: 2020-12-08T18:41:32-08:00 New Revision: 1b6d879ec1fc4e883d0f1f580bbe9230215d9e80 URL: https://github.com/llvm/llvm-project/commit/1b6d879ec1fc4e883d0f1f580bbe9230215d9e80 DIFF: https://github.com/llvm/llvm-project/commit/1b6d879ec1fc4e883d0f1f580bbe9230215d9e80.diff LOG: [WebAssembly] Fix code generated for atomic operations in PIC mode The main this this test does is to add the `IsNotPIC` predicate to the all the atomic instructions pattern that directly refer to `tglobaladdr`. This is because in PIC mode we need to generate separate instruction sequence (either a direct global.get, or __memory_base + offset) for accessing global addresses. As part of this change I noticed that many of the `Requires` attributes added to the instruction in `WebAssemblyInstrAtomics.td` were being honored. This is because the wrapped in a `let Predicates = [HasAtomics]` block and it seems that that outer wrapping overrides any `Requires` on defs within it. As a workaround I removed the outer `let` and added `HasAtomics` to all the inner `Requires`. I believe that all the instrucitons that don't have `Requires` explicit bottom out in `ATOMIC_I` and `ATOMIC_NRI` which have `HasAtomics` so this should not remove this predicate from any patterns (at least that is the idea). The alternative to this approach looks like implementing something like `PredicateControl` in `Mips.td` where we can split the predicates into groups so they don't clobber each other. Differential Revision: https://reviews.llvm.org/D92744 Added: llvm/test/CodeGen/WebAssembly/atomic-pic.ll Modified: llvm/lib/Target/WebAssembly/WebAssemblyInstrAtomics.td llvm/test/CodeGen/WebAssembly/offset-atomics.ll Removed: diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyInstrAtomics.td b/llvm/lib/Target/WebAssembly/WebAssemblyInstrAtomics.td index 316568595784..22103b0bfb38 100644 --- a/llvm/lib/Target/WebAssembly/WebAssemblyInstrAtomics.td +++ b/llvm/lib/Target/WebAssembly/WebAssemblyInstrAtomics.td @@ -77,16 +77,15 @@ defm MEMORY_ATOMIC_WAIT64_A64 : } // mayLoad = 1 } // hasSideEffects = 1 -let Predicates = [HasAtomics] in { // Select notifys with no constant offset. def NotifyPatNoOffset_A32 : Pat<(i32 (int_wasm_memory_atomic_notify I32:$addr, I32:$count)), (MEMORY_ATOMIC_NOTIFY_A32 0, 0, I32:$addr, I32:$count)>, - Requires<[HasAddr32]>; + Requires<[HasAddr32, HasAtomics]>; def NotifyPatNoOffset_A64 : Pat<(i32 (int_wasm_memory_atomic_notify I64:$addr, I32:$count)), (MEMORY_ATOMIC_NOTIFY_A64 0, 0, I64:$addr, I32:$count)>, - Requires<[HasAddr64]>; + Requires<[HasAddr64, HasAtomics]>; // Select notifys with a constant offset. @@ -95,11 +94,11 @@ multiclass NotifyPatImmOff { def : Pat<(i32 (int_wasm_memory_atomic_notify (operand I32:$addr, imm:$off), I32:$count)), (!cast(inst#_A32) 0, imm:$off, I32:$addr, I32:$count)>, -Requires<[HasAddr32]>; +Requires<[HasAddr32, HasAtomics]>; def : Pat<(i32 (int_wasm_memory_atomic_notify (operand I64:$addr, imm:$off), I32:$count)), (!cast(inst#_A64) 0, imm:$off, I64:$addr, I32:$count)>, -Requires<[HasAddr64]>; +Requires<[HasAddr64, HasAtomics]>; } defm : NotifyPatImmOff; defm : NotifyPatImmOff; @@ -108,34 +107,34 @@ defm : NotifyPatImmOff; def NotifyPatOffsetOnly_A32 : Pat<(i32 (int_wasm_memory_atomic_notify imm:$off, I32:$count)), (MEMORY_ATOMIC_NOTIFY_A32 0, imm:$off, (CONST_I32 0), I32:$count)>, - Requires<[HasAddr32]>; + Requires<[HasAddr32, HasAtomics]>; def NotifyPatOffsetOnly_A64 : Pat<(i32 (int_wasm_memory_atomic_notify imm:$off, I32:$count)), (MEMORY_ATOMIC_NOTIFY_A64 0, imm:$off, (CONST_I64 0), I32:$count)>, - Requires<[HasAddr64]>; + Requires<[HasAddr64, HasAtomics]>; def NotifyPatGlobalAddrOffOnly_A32 : Pat<(i32 (int_wasm_memory_atomic_notify (WebAssemblywrapper tglobaladdr:$off), I32:$count)), (MEMORY_ATOMIC_NOTIFY_A32 0, tglobaladdr:$off, (CONST_I32 0), I32:$count) >, - Requires<[HasAddr32]>; + Requires<[HasAddr32, HasAtomics, IsNotPIC]>; def NotifyPatGlobalAddrOffOnly_A64 : Pat<(i32 (int_wasm_memory_atomic_notify (WebAssemblywrapper tglobaladdr:$off), I32:$count)), (MEMORY_ATOMIC_NOTIFY_A64 0, tglobaladdr:$off, (CONST_I64 0), I32:$count) >, - Requires<[HasAddr64]>; + Requires<[HasAddr64, HasAtomics, IsNotPIC]>; // Select waits with no constant offset. multiclass WaitPatNoOffset { def : Pat<(i32 (kind I32:$addr, ty:$exp, I64:$timeout)), (!cast(inst#_A32) 0, 0, I32:$addr, ty:$exp, I64:$timeout)>, -Requires<[HasAddr32]>; +Requires<[HasAddr32, HasAtomics]>; def : Pat<(i32 (kind I64:$addr, ty:$exp, I64:$timeout)), (!cast(inst#_A64) 0, 0, I64:
[llvm-branch-commits] [llvm] 9a72d3e - [WebAssembly] Add support for named data sections in wasm binaries
Author: Sam Clegg Date: 2020-12-09T12:57:07-08:00 New Revision: 9a72d3e3e456ffa9cfb4e0b2c2e81da78bb15dd3 URL: https://github.com/llvm/llvm-project/commit/9a72d3e3e456ffa9cfb4e0b2c2e81da78bb15dd3 DIFF: https://github.com/llvm/llvm-project/commit/9a72d3e3e456ffa9cfb4e0b2c2e81da78bb15dd3.diff LOG: [WebAssembly] Add support for named data sections in wasm binaries Followup to https://reviews.llvm.org/D91769 which added support for names globals. Differential Revision: https://reviews.llvm.org/D92909 Added: Modified: lld/test/wasm/call-indirect.ll lld/test/wasm/data-segment-merging.ll lld/test/wasm/gc-sections.ll lld/test/wasm/local-symbols.ll lld/test/wasm/locals-duplicate.test lld/test/wasm/map-file.s lld/test/wasm/signature-mismatch.ll lld/test/wasm/weak-symbols.s lld/wasm/SyntheticSections.cpp lld/wasm/SyntheticSections.h lld/wasm/Writer.cpp llvm/include/llvm/BinaryFormat/Wasm.h llvm/include/llvm/ObjectYAML/WasmYAML.h llvm/lib/Object/WasmObjectFile.cpp llvm/lib/ObjectYAML/WasmEmitter.cpp llvm/lib/ObjectYAML/WasmYAML.cpp llvm/tools/obj2yaml/wasm2yaml.cpp Removed: diff --git a/lld/test/wasm/call-indirect.ll b/lld/test/wasm/call-indirect.ll index 84a84710f2ba..4acc1edae4f2 100644 --- a/lld/test/wasm/call-indirect.ll +++ b/lld/test/wasm/call-indirect.ll @@ -156,4 +156,7 @@ define void @call_ptr(i64 (i64)* %arg) { ; CHECK-NEXT: GlobalNames: ; CHECK-NEXT: - Index: 0 ; CHECK-NEXT: Name:__stack_pointer +; CHECK-NEXT: DataSegmentNames: +; CHECK-NEXT: - Index: 0 +; CHECK-NEXT: Name:.data ; CHECK-NEXT: ... diff --git a/lld/test/wasm/data-segment-merging.ll b/lld/test/wasm/data-segment-merging.ll index bc347d193574..1dee1ccbda29 100644 --- a/lld/test/wasm/data-segment-merging.ll +++ b/lld/test/wasm/data-segment-merging.ll @@ -31,7 +31,9 @@ ; MERGE-NEXT:GlobalNames: ; MERGE-NEXT: - Index: 0 ; MERGE-NEXT:Name:__stack_pointer -; MERGE-NOT: - Index: +; MERGE-NEXT:DataSegmentNames: +; MERGE-NEXT: - Index: 0 +; MERGE-NEXT:Name:.rodata ; RUN: wasm-ld -no-gc-sections --no-entry --no-merge-data-segments -o %t.separate.wasm %t.o ; RUN: obj2yaml %t.separate.wasm | FileCheck %s --check-prefix=SEPARATE @@ -71,7 +73,9 @@ ; SEPARATE-NEXT:GlobalNames: ; SEPARATE-NEXT: - Index: 0 ; SEPARATE-NEXT:Name:__stack_pointer -; SEPARATE-NOT: - Index: +; SEPARATE-NEXT:DataSegmentNames: +; SEPARATE-NEXT: - Index: 0 +; SEPARATE-NEXT:Name:.rodata ; RUN: wasm-ld -no-gc-sections --no-entry --shared-memory --max-memory=131072 -o %t.merged.passive.wasm %t.passive.o ; RUN: obj2yaml %t.merged.passive.wasm | FileCheck %s --check-prefix=PASSIVE-MERGE diff --git a/lld/test/wasm/gc-sections.ll b/lld/test/wasm/gc-sections.ll index 8bac2fd07827..de8298697bf1 100644 --- a/lld/test/wasm/gc-sections.ll +++ b/lld/test/wasm/gc-sections.ll @@ -87,6 +87,9 @@ entry: ; CHECK-NEXT: Name:__stack_pointer ; CHECK-NEXT: - Index: 1 ; CHECK-NEXT: Name:used_global +; CHECK-NEXT: DataSegmentNames: +; CHECK-NEXT: - Index: 0 +; CHECK-NEXT: Name:.data ; CHECK-NEXT: ... ; RUN: wasm-ld -print-gc-sections --no-gc-sections -o %t1.no-gc.wasm \ @@ -162,6 +165,9 @@ entry: ; NO-GC-NEXT: Name:unused_global ; NO-GC-NEXT: - Index: 2 ; NO-GC-NEXT: Name:used_global +; NO-GC-NEXT: DataSegmentNames: +; NO-GC-NEXT: - Index: 0 +; NO-GC-NEXT: Name:.data ; NO-GC-NEXT: ... ; RUN: not wasm-ld --gc-sections --relocatable -o %t1.no-gc.wasm %t.o 2>&1 | FileCheck %s -check-prefix=CHECK-ERROR diff --git a/lld/test/wasm/local-symbols.ll b/lld/test/wasm/local-symbols.ll index d0a520a950a2..13c200d648e9 100644 --- a/lld/test/wasm/local-symbols.ll +++ b/lld/test/wasm/local-symbols.ll @@ -97,4 +97,7 @@ entry: ; CHECK-NEXT: GlobalNames: ; CHECK-NEXT: - Index: 0 ; CHECK-NEXT: Name:__stack_pointer +; CHECK-NEXT: DataSegmentNames: +; CHECK-NEXT: - Index: 0 +; CHECK-NEXT: Name:.data ; CHECK-NEXT: ... diff --git a/lld/test/wasm/locals-duplicate.test b/lld/test/wasm/locals-duplicate.test index dc6b9c88be29..07abb7485381 100644 --- a/lld/test/wasm/locals-duplicate.test +++ b/lld/test/wasm/locals-duplicate.test @@ -212,6 +212,9 @@ ; CHECK-NEXT: GlobalNames: ; CHECK-NEXT: - Index: 0 ; CHECK-NEXT: Name:__stack_pointer +; CHECK-NEXT: DataSegmentNames: +; CHECK-NEXT: - Index: 0 +; CHECK-NEXT: Name:.data ; CHECK
[llvm-branch-commits] [lld] d8ed639 - [lld][WebAssembly] Don't emit names for data segments that we omit
Author: Sam Clegg Date: 2020-12-09T20:59:26-08:00 New Revision: d8ed639a6a3b210d7df9a3f77d5a7546fad15f49 URL: https://github.com/llvm/llvm-project/commit/d8ed639a6a3b210d7df9a3f77d5a7546fad15f49 DIFF: https://github.com/llvm/llvm-project/commit/d8ed639a6a3b210d7df9a3f77d5a7546fad15f49.diff LOG: [lld][WebAssembly] Don't emit names for data segments that we omit Followup to https://reviews.llvm.org/D92909 Differential Revision: https://reviews.llvm.org/D92997 Added: Modified: lld/test/wasm/bss-only.s lld/wasm/SyntheticSections.cpp Removed: diff --git a/lld/test/wasm/bss-only.s b/lld/test/wasm/bss-only.s index 56963530a0b0..1c0500f172ca 100644 --- a/lld/test/wasm/bss-only.s +++ b/lld/test/wasm/bss-only.s @@ -41,3 +41,5 @@ b: # CHECK-NEXT: - Name:__data_end # CHECK-NEXT: Kind:GLOBAL # CHECK-NEXT: Index: 1 + +# CHECK-NOT: DataSegmentNames: diff --git a/lld/wasm/SyntheticSections.cpp b/lld/wasm/SyntheticSections.cpp index 95a48528db9e..8e2c7c631f95 100644 --- a/lld/wasm/SyntheticSections.cpp +++ b/lld/wasm/SyntheticSections.cpp @@ -566,7 +566,7 @@ unsigned NameSection::numNamedDataSegments() const { unsigned numNames = 0; for (const OutputSegment *s : segments) -if (!s->name.empty()) +if (!s->name.empty() && !s->isBss) ++numNames; return numNames; @@ -636,8 +636,10 @@ void NameSection::writeBody() { writeUleb128(sub.os, count, "name count"); for (OutputSegment *s : segments) { - writeUleb128(sub.os, s->index, "global index"); - writeStr(sub.os, s->name, "segment name"); + if (!s->name.empty() && !s->isBss) { +writeUleb128(sub.os, s->index, "global index"); +writeStr(sub.os, s->name, "segment name"); + } } sub.writeTo(bodyOutputStream); ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [lld] 1994970 - [lld][WebAssembly] Delay creation of internal __wasm_memory_init function
Author: Sam Clegg Date: 2020-12-10T10:47:18-08:00 New Revision: 199497086e46804084e4b8841b39e3604c678f34 URL: https://github.com/llvm/llvm-project/commit/199497086e46804084e4b8841b39e3604c678f34 DIFF: https://github.com/llvm/llvm-project/commit/199497086e46804084e4b8841b39e3604c678f34.diff LOG: [lld][WebAssembly] Delay creation of internal __wasm_memory_init function This also allows for its creation to be conditional so it is completely elided when not needed. Differential Revision: https://reviews.llvm.org/D93035 Added: Modified: lld/test/wasm/data-segment-merging.ll lld/test/wasm/data-segments.ll lld/test/wasm/no-tls.s lld/test/wasm/tls.s lld/wasm/Driver.cpp lld/wasm/MarkLive.cpp lld/wasm/SyntheticSections.h lld/wasm/Writer.cpp Removed: diff --git a/lld/test/wasm/data-segment-merging.ll b/lld/test/wasm/data-segment-merging.ll index 1dee1ccbda29..99f1a95c5854 100644 --- a/lld/test/wasm/data-segment-merging.ll +++ b/lld/test/wasm/data-segment-merging.ll @@ -98,9 +98,9 @@ ; PASSIVE-MERGE-NEXT: - Index: 0 ; PASSIVE-MERGE-NEXT:Name:__wasm_call_ctors ; PASSIVE-MERGE-NEXT: - Index: 1 -; PASSIVE-MERGE-NEXT:Name:__wasm_init_memory -; PASSIVE-MERGE-NEXT: - Index: 2 ; PASSIVE-MERGE-NEXT:Name:__wasm_init_tls +; PASSIVE-MERGE-NEXT: - Index: 2 +; PASSIVE-MERGE-NEXT:Name:__wasm_init_memory ; RUN: wasm-ld -no-gc-sections --no-entry --shared-memory --max-memory=131072 -no-merge-data-segments -o %t.separate.passive.wasm %t.passive.o ; RUN: obj2yaml %t.separate.passive.wasm | FileCheck %s --check-prefix=PASSIVE-SEPARATE @@ -135,6 +135,6 @@ ; PASSIVE-SEPARATE-NEXT:- Index: 0 ; PASSIVE-SEPARATE-NEXT: Name:__wasm_call_ctors ; PASSIVE-SEPARATE-NEXT:- Index: 1 -; PASSIVE-SEPARATE-NEXT: Name:__wasm_init_memory -; PASSIVE-SEPARATE-NEXT:- Index: 2 ; PASSIVE-SEPARATE-NEXT: Name:__wasm_init_tls +; PASSIVE-SEPARATE-NEXT:- Index: 2 +; PASSIVE-SEPARATE-NEXT: Name:__wasm_init_memory diff --git a/lld/test/wasm/data-segments.ll b/lld/test/wasm/data-segments.ll index ecd18190b9c3..6f6d96a30fa5 100644 --- a/lld/test/wasm/data-segments.ll +++ b/lld/test/wasm/data-segments.ll @@ -64,7 +64,7 @@ ; ACTIVE-NEXT:Name:__wasm_call_ctors ; PASSIVE-LABEL: - Type:START -; PASSIVE-NEXT:StartFunction: 1 +; PASSIVE-NEXT:StartFunction: 2 ; PASSIVE-LABEL: - Type:DATACOUNT ; PASSIVE-NEXT:Count: 2 ; PASSIVE-LABEL: - Type:CODE @@ -74,12 +74,11 @@ ; PASSIVE-NEXT:Body:0B ; PASSIVE-NEXT: - Index: 1 ; PASSIVE-NEXT:Locals: [] +; PASSIVE-NEXT:Body:0B +; PASSIVE-NEXT: - Index: 2 +; PASSIVE-NEXT:Locals: [] ; PASSIVE32-NEXT:Body: 41B4D60041004101FE480200044041B4D6004101427FFE0102001A054180084100410DFC0841900841004114FC08010041B4D6004102FE17020041B4D600417FFE0002001A0BFC0900FC09010B ; PASSIVE64-NEXT:Body: 42B4D60041004101FE480200044042B4D6004101427FFE0102001A054280084100410DFC0842900841004114FC08010042B4D6004102FE17020042B4D600417FFE0002001A0BFC0900FC09010B - -; PASSIVE-NEXT: - Index: 2 -; PASSIVE-NEXT:Locals: [] -; PASSIVE-NEXT:Body:0B ; PASSIVE-NEXT: - Type:DATA ; PASSIVE-NEXT:Segments: ; PASSIVE-NEXT: - SectionOffset: 3 @@ -94,12 +93,12 @@ ; PASSIVE-NEXT: - Index: 0 ; PASSIVE-NEXT:Name:__wasm_call_ctors ; PASSIVE-NEXT: - Index: 1 -; PASSIVE-NEXT:Name:__wasm_init_memory -; PASSIVE-NEXT: - Index: 2 ; PASSIVE-NEXT:Name:__wasm_init_tls +; PASSIVE-NEXT: - Index: 2 +; PASSIVE-NEXT:Name:__wasm_init_memory ; PASSIVE-PIC: - Type:START -; PASSIVE-PIC-NEXT:StartFunction: 2 +; PASSIVE-PIC-NEXT:StartFunction: 3 ; PASSIVE-PIC-NEXT: - Type:DATACOUNT ; PASSIVE-PIC-NEXT:Count: 1 ; PASSIVE-PIC-NEXT: - Type:CODE @@ -111,15 +110,15 @@ ; PASSIVE-PIC-NEXT:Locals: [] ; PASSIVE-PIC-NEXT:Body:0B ; PASSIVE-PIC-NEXT: - Index: 2 +; PASSIVE-PIC-NEXT:Locals: [] +; PASSIVE-PIC-NEXT:Body:0B +; PASSIVE-PIC-NEXT: - Index: 3 ; PASSIVE-PIC-NEXT:Locals: ; PASSIVE32-PIC-NEXT: - Type:I32 ; PASSIVE64-PIC-NEXT: - Type:I64 ; PASSIVE-PIC-NEXT:Count: 1 ; PASSIVE3
[llvm-branch-commits] [lld] e52881a - [lld][WebAssembly] Split __wasm_apply_relocs function in two
Author: Sam Clegg Date: 2020-12-10T17:07:39-08:00 New Revision: e52881a2870234f0dad6e338a0f084eddeaa9356 URL: https://github.com/llvm/llvm-project/commit/e52881a2870234f0dad6e338a0f084eddeaa9356 DIFF: https://github.com/llvm/llvm-project/commit/e52881a2870234f0dad6e338a0f084eddeaa9356.diff LOG: [lld][WebAssembly] Split __wasm_apply_relocs function in two We have two types of relocations that we apply on startup: 1. Relocations that apply to wasm globals 2. Relocations that apply to wasm memory The first set of relocations use only the `__memory_base` import to update a set of internal globals. Because wasm globals are thread local these need to run on each thread. Memory relocations, like static constructors, must only be run once. To ensure global relocations run on all threads and because the only depend on the immutable `__memory_base` import we can run them during the WebAssembly start functions, instead of waiting until the post-instantiation __wasm_call_ctors. Differential Revision: https://reviews.llvm.org/D93066 Added: Modified: lld/test/wasm/bsymbolic.s lld/test/wasm/data-segments.ll lld/test/wasm/pie.ll lld/test/wasm/weak-undefined-pic.s lld/wasm/Driver.cpp lld/wasm/MarkLive.cpp lld/wasm/Symbols.cpp lld/wasm/Symbols.h lld/wasm/SyntheticSections.cpp lld/wasm/SyntheticSections.h lld/wasm/Writer.cpp Removed: diff --git a/lld/test/wasm/bsymbolic.s b/lld/test/wasm/bsymbolic.s index dc0e0ddcc773..07989fc5f437 100644 --- a/lld/test/wasm/bsymbolic.s +++ b/lld/test/wasm/bsymbolic.s @@ -1,5 +1,5 @@ // RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown %s -o %t.o -// RUN: wasm-ld --no-entry -Bsymbolic %t.o -o %t2.so 2>&1 | FileCheck -check-prefix=WARNING %s +// RUN: wasm-ld --no-entry -Bsymbolic %t.o -o %t.wasm 2>&1 | FileCheck -check-prefix=WARNING %s // WARNING: warning: -Bsymbolic is only meaningful when combined with -shared // RUN: wasm-ld --experimental-pic -shared %t.o -o %t0.so diff --git a/lld/test/wasm/data-segments.ll b/lld/test/wasm/data-segments.ll index 6f6d96a30fa5..8c4c4ca79672 100644 --- a/lld/test/wasm/data-segments.ll +++ b/lld/test/wasm/data-segments.ll @@ -98,27 +98,27 @@ ; PASSIVE-NEXT:Name:__wasm_init_memory ; PASSIVE-PIC: - Type:START -; PASSIVE-PIC-NEXT:StartFunction: 3 +; PASSIVE-PIC-NEXT:StartFunction: 2 ; PASSIVE-PIC-NEXT: - Type:DATACOUNT ; PASSIVE-PIC-NEXT:Count: 1 ; PASSIVE-PIC-NEXT: - Type:CODE ; PASSIVE-PIC-NEXT:Functions: ; PASSIVE-PIC-NEXT: - Index: 0 ; PASSIVE-PIC-NEXT:Locals: [] -; PASSIVE-PIC-NEXT:Body:10010B +; PASSIVE-PIC-NEXT:Body:10030B ; PASSIVE-PIC-NEXT: - Index: 1 ; PASSIVE-PIC-NEXT:Locals: [] ; PASSIVE-PIC-NEXT:Body:0B ; PASSIVE-PIC-NEXT: - Index: 2 -; PASSIVE-PIC-NEXT:Locals: [] -; PASSIVE-PIC-NEXT:Body:0B -; PASSIVE-PIC-NEXT: - Index: 3 ; PASSIVE-PIC-NEXT:Locals: ; PASSIVE32-PIC-NEXT: - Type:I32 ; PASSIVE64-PIC-NEXT: - Type:I64 ; PASSIVE-PIC-NEXT:Count: 1 ; PASSIVE32-PIC-NEXT:Body: 230141B4CE006A2100200041004101FE480200044020004101427FFE0102001A05410023016A410041B1CE00FC0820004102FE1702002000417FFE0002001A0BFC09000B ; PASSIVE64-PIC-NEXT:Body: 230142B4CE006A2100200041004101FE480200044020004101427FFE0102001A05420023016A410041B1CE00FC0820004102FE1702002000417FFE0002001A0BFC09000B +; PASSIVE-PIC-NEXT: - Index: 3 +; PASSIVE-PIC-NEXT:Locals: [] +; PASSIVE-PIC-NEXT:Body:0B ; PASSIVE-PIC-NEXT: - Type:DATA ; PASSIVE-PIC-NEXT:Segments: ; PASSIVE-PIC-NEXT: - SectionOffset: 4 @@ -130,8 +130,8 @@ ; PASSIVE-PIC-NEXT: - Index: 0 ; PASSIVE-PIC-NEXT:Name:__wasm_call_ctors ; PASSIVE-PIC-NEXT: - Index: 1 -; PASSIVE-PIC-NEXT:Name:__wasm_apply_relocs -; PASSIVE-PIC-NEXT: - Index: 2 ; PASSIVE-PIC-NEXT:Name:__wasm_init_tls -; PASSIVE-PIC-NEXT: - Index: 3 +; PASSIVE-PIC-NEXT: - Index: 2 ; PASSIVE-PIC-NEXT:Name:__wasm_init_memory +; PASSIVE-PIC-NEXT: - Index: 3 +; PASSIVE-PIC-NEXT:Name:__wasm_apply_data_relocs diff --git a/lld/test/wasm/pie.ll b/lld/test/wasm/pie.ll index 20a6c928b6ee..84555a08f19d 100644 --- a/lld/test/wasm/pie.ll +++ b/lld/test/wasm/pie.ll @@ -1,6 +1,5 @@ ; RUN: llc -relocation-model=pic -mattr=+mutable-globals -filetype=obj %s -o %t.o ; RUN: wasm-ld --no-gc-sections --allow-undefined --experimental-pic -pie
[llvm-branch-commits] [compiler-rt] d3592fe - feedback
Author: Sam Clegg Date: 2020-02-10T19:33:02-08:00 New Revision: d3592fec22a6769ab29656a490d1f3e1725add2c URL: https://github.com/llvm/llvm-project/commit/d3592fec22a6769ab29656a490d1f3e1725add2c DIFF: https://github.com/llvm/llvm-project/commit/d3592fec22a6769ab29656a490d1f3e1725add2c.diff LOG: feedback Added: Modified: compiler-rt/lib/builtins/powitf2.c compiler-rt/test/builtins/Unit/powitf2_test.c Removed: diff --git a/compiler-rt/lib/builtins/powitf2.c b/compiler-rt/lib/builtins/powitf2.c index 22617401270b..141a3a0ea727 100644 --- a/compiler-rt/lib/builtins/powitf2.c +++ b/compiler-rt/lib/builtins/powitf2.c @@ -10,9 +10,10 @@ // //===--===// -#include "int_lib.h" +#define QUAD_PRECISION +#include "fp_lib.h" -#if defined(_ARCH_PPC) || defined(__wasm__) +#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT) // Returns: a ^ b diff --git a/compiler-rt/test/builtins/Unit/powitf2_test.c b/compiler-rt/test/builtins/Unit/powitf2_test.c index 2e679e30a9dc..fd25f38d5177 100644 --- a/compiler-rt/test/builtins/Unit/powitf2_test.c +++ b/compiler-rt/test/builtins/Unit/powitf2_test.c @@ -14,7 +14,7 @@ #include -#if defined (_ARCH_PPC) || defined (__wasm__) +#if __LDBL_MANT_DIG__ == 113 #include "int_lib.h" #include @@ -37,7 +37,7 @@ int test__powitf2(long double a, si_int b, long double expected) int main() { -#if defined(_ARCH_PPC) || defined (__wasm__) +#if __LDBL_MANT_DIG__ == 113 if (test__powitf2(0, 0, 1)) return 1; if (test__powitf2(1, 0, 1)) ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [compiler-rt] 83b1073 - revert cmake
Author: Sam Clegg Date: 2020-02-10T19:23:12-08:00 New Revision: 83b1073e82c32f0976b69095e88fb840976e15e6 URL: https://github.com/llvm/llvm-project/commit/83b1073e82c32f0976b69095e88fb840976e15e6 DIFF: https://github.com/llvm/llvm-project/commit/83b1073e82c32f0976b69095e88fb840976e15e6.diff LOG: revert cmake Added: Modified: compiler-rt/lib/builtins/CMakeLists.txt Removed: diff --git a/compiler-rt/lib/builtins/CMakeLists.txt b/compiler-rt/lib/builtins/CMakeLists.txt index 7b05c9e0c847..125a3a1b1476 100644 --- a/compiler-rt/lib/builtins/CMakeLists.txt +++ b/compiler-rt/lib/builtins/CMakeLists.txt @@ -144,7 +144,6 @@ set(GENERIC_SOURCES powidf2.c powisf2.c powitf2.c - powixf2.c subdf3.c subsf3.c subvdi3.c @@ -249,6 +248,7 @@ set(x86_ARCH_SOURCES floatundixf.c floatuntixf.c mulxc3.c + powixf2.c ) if (NOT MSVC) ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [compiler-rt] 9102812 - [compiler-rt] Compile __powitf2 under wasm
Author: Sam Clegg Date: 2020-02-07T20:39:26-08:00 New Revision: 910281203eaaac1998def7f98d563e0c8a2c9683 URL: https://github.com/llvm/llvm-project/commit/910281203eaaac1998def7f98d563e0c8a2c9683 DIFF: https://github.com/llvm/llvm-project/commit/910281203eaaac1998def7f98d563e0c8a2c9683.diff LOG: [compiler-rt] Compile __powitf2 under wasm Summary: Also move this file to GENRIC_SOURCES. See https://github.com/emscripten-core/emscripten/issues/10374 See https://reviews.llvm.org/D74274 Subscribers: dberris, mgorny, aheejin, sunfish, #sanitizers, llvm-commits Tags: #sanitizers, #llvm Differential Revision: https://reviews.llvm.org/D74275 Added: Modified: compiler-rt/lib/builtins/CMakeLists.txt compiler-rt/lib/builtins/powitf2.c compiler-rt/test/builtins/Unit/powitf2_test.c Removed: diff --git a/compiler-rt/lib/builtins/CMakeLists.txt b/compiler-rt/lib/builtins/CMakeLists.txt index 125a3a1b1476..7b05c9e0c847 100644 --- a/compiler-rt/lib/builtins/CMakeLists.txt +++ b/compiler-rt/lib/builtins/CMakeLists.txt @@ -144,6 +144,7 @@ set(GENERIC_SOURCES powidf2.c powisf2.c powitf2.c + powixf2.c subdf3.c subsf3.c subvdi3.c @@ -248,7 +249,6 @@ set(x86_ARCH_SOURCES floatundixf.c floatuntixf.c mulxc3.c - powixf2.c ) if (NOT MSVC) diff --git a/compiler-rt/lib/builtins/powitf2.c b/compiler-rt/lib/builtins/powitf2.c index fcbdb4c2ee2a..22617401270b 100644 --- a/compiler-rt/lib/builtins/powitf2.c +++ b/compiler-rt/lib/builtins/powitf2.c @@ -12,7 +12,7 @@ #include "int_lib.h" -#if _ARCH_PPC +#if defined(_ARCH_PPC) || defined(__wasm__) // Returns: a ^ b diff --git a/compiler-rt/test/builtins/Unit/powitf2_test.c b/compiler-rt/test/builtins/Unit/powitf2_test.c index 70bc6dae0d2d..2e679e30a9dc 100644 --- a/compiler-rt/test/builtins/Unit/powitf2_test.c +++ b/compiler-rt/test/builtins/Unit/powitf2_test.c @@ -14,7 +14,7 @@ #include -#if _ARCH_PPC +#if defined (_ARCH_PPC) || defined (__wasm__) #include "int_lib.h" #include @@ -37,7 +37,7 @@ int test__powitf2(long double a, si_int b, long double expected) int main() { -#if _ARCH_PPC +#if defined(_ARCH_PPC) || defined (__wasm__) if (test__powitf2(0, 0, 1)) return 1; if (test__powitf2(1, 0, 1)) ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [lld] 704e0ba - [lld][WebAssembly] Honor --allow-undefined for data symbols too
Author: Sam Clegg Date: 2020-05-01T10:08:58-07:00 New Revision: 704e0ba53cb2d849fef08d1850175de8efd814c7 URL: https://github.com/llvm/llvm-project/commit/704e0ba53cb2d849fef08d1850175de8efd814c7 DIFF: https://github.com/llvm/llvm-project/commit/704e0ba53cb2d849fef08d1850175de8efd814c7.diff LOG: [lld][WebAssembly] Honor --allow-undefined for data symbols too This was originally the way this worked before before https://reviews.llvm.org/D60882. In retrospect it seems inconsistent that `--allow-undefined` doesn't work for all symbols. See: https://groups.google.com/g/emscripten-discuss/c/HSRgQiIq1gI/m/Kt9oFWHiAwAJ I'm also planning a followup change which implement the full `--unresolved-symbols=..` flags supported by ELF linkers (both ld and ld.lld) since it seems more standard. Added: Modified: lld/test/wasm/undefined-data.ll lld/wasm/Relocations.cpp Removed: diff --git a/lld/test/wasm/undefined-data.ll b/lld/test/wasm/undefined-data.ll index e19086c2e0e0..59f7407bd610 100644 --- a/lld/test/wasm/undefined-data.ll +++ b/lld/test/wasm/undefined-data.ll @@ -1,6 +1,6 @@ ; 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=UNDEF +; RUN: wasm-ld --allow-undefined -o %t.wasm %t.o ; RUN: not wasm-ld --shared -o %t.wasm %t.o 2>&1 | FileCheck %s -check-prefix=SHARED target triple = "wasm32-unknown-unknown" diff --git a/lld/wasm/Relocations.cpp b/lld/wasm/Relocations.cpp index 9475ff1c312e..e49acec244c1 100644 --- a/lld/wasm/Relocations.cpp +++ b/lld/wasm/Relocations.cpp @@ -21,13 +21,6 @@ static bool requiresGOTAccess(const Symbol *sym) { } static bool allowUndefined(const Symbol* sym) { - // Historically --allow-undefined doesn't work for data symbols since we don't - // have any way to represent these as imports in the final binary. The idea - // behind allowing undefined symbols is to allow importing these symbols from - // the embedder and we can't do this for data symbols (at least not without - // compiling with -fPIC) - if (isa(sym)) -return false; // Undefined functions with explicit import name are allowed to be undefined // at link time. if (auto *F = dyn_cast(sym)) ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [lld] fd1c894 - [lld][WebAssembly] Convert some lld tests to assembly
Author: Sam Clegg Date: 2020-05-28T16:52:01-07:00 New Revision: fd1c894a4a3690b2e500bfdf71194e9cc3f1b399 URL: https://github.com/llvm/llvm-project/commit/fd1c894a4a3690b2e500bfdf71194e9cc3f1b399 DIFF: https://github.com/llvm/llvm-project/commit/fd1c894a4a3690b2e500bfdf71194e9cc3f1b399.diff LOG: [lld][WebAssembly] Convert some lld tests to assembly When we originally wrote these tests we didn't have a stable and fleshed out assembly format. Now we do so we should prefer that over llvm ir for lld tests to avoid including more part of llvm than necessary in order to run the test. This change converts just 30 out of about 130 test files. More to come when I have some more time. Differential Revision: https://reviews.llvm.org/D80361 Added: lld/test/wasm/Inputs/call-indirect.s lld/test/wasm/Inputs/call-ret32.s lld/test/wasm/Inputs/hello.s lld/test/wasm/Inputs/hidden.s lld/test/wasm/Inputs/import-attributes.s lld/test/wasm/Inputs/optional-symbol.s lld/test/wasm/Inputs/ret32.s lld/test/wasm/Inputs/ret64.s lld/test/wasm/Inputs/start.s lld/test/wasm/Inputs/strong-symbol.s lld/test/wasm/Inputs/weak-symbol1.s lld/test/wasm/Inputs/weak-symbol2.s lld/test/wasm/alias.s lld/test/wasm/archive-no-index.s lld/test/wasm/bss-only.s lld/test/wasm/demangle.s lld/test/wasm/entry-signature.s lld/test/wasm/export-optional-lazy.test lld/test/wasm/import-attribute-mismatch.s lld/test/wasm/no-tls.ll lld/test/wasm/optional-symbol.s lld/test/wasm/symbol-type-mismatch.s lld/test/wasm/version.s Modified: lld/test/wasm/archive-export.ll lld/test/wasm/archive-weak-undefined.ll lld/test/wasm/archive.ll lld/test/wasm/call-indirect.ll lld/test/wasm/compress-relocs.ll lld/test/wasm/conflict.test lld/test/wasm/data-layout.ll lld/test/wasm/emit-relocs-fpic.s lld/test/wasm/emit-relocs.ll lld/test/wasm/export-empty.test lld/test/wasm/export-table.test lld/test/wasm/fatal-warnings.ll lld/test/wasm/function-imports-first.ll lld/test/wasm/function-imports.ll lld/test/wasm/function-index.test lld/test/wasm/global-base.test lld/test/wasm/growable-table.test lld/test/wasm/import-memory.test lld/test/wasm/import-table.test lld/test/wasm/invalid-stack-size.test lld/test/wasm/large-memory.test lld/test/wasm/load-undefined.test lld/test/wasm/pic-static.ll lld/test/wasm/relocatable.ll lld/test/wasm/responsefile.test lld/test/wasm/shared-needed.ll lld/test/wasm/signature-mismatch-export.ll lld/test/wasm/signature-mismatch-unknown.ll lld/test/wasm/signature-mismatch-weak.ll lld/test/wasm/signature-mismatch.ll lld/test/wasm/stack-first.test lld/test/wasm/strip-all.test lld/test/wasm/strip-debug.test lld/test/wasm/trace-symbol.ll lld/test/wasm/trace.test lld/test/wasm/undefined-entry.test lld/test/wasm/visibility-hidden.ll lld/test/wasm/weak-symbols.ll lld/test/wasm/whole-archive.test Removed: lld/test/wasm/Inputs/call-indirect.ll lld/test/wasm/Inputs/call-ret32.ll lld/test/wasm/Inputs/hello.ll lld/test/wasm/Inputs/hidden.ll lld/test/wasm/Inputs/import-attributes.ll lld/test/wasm/Inputs/optional-symbol.ll lld/test/wasm/Inputs/ret32.ll lld/test/wasm/Inputs/ret64.ll lld/test/wasm/Inputs/start.ll lld/test/wasm/Inputs/strong-symbol.ll lld/test/wasm/Inputs/weak-symbol1.ll lld/test/wasm/Inputs/weak-symbol2.ll lld/test/wasm/alias.ll lld/test/wasm/archive-no-index.ll lld/test/wasm/bss-only.ll lld/test/wasm/demangle.ll lld/test/wasm/entry-signature.ll lld/test/wasm/export-optional-lazy.ll lld/test/wasm/import-attribute-mismatch.ll lld/test/wasm/no-tls.test lld/test/wasm/optional-symbol.ll lld/test/wasm/symbol-type-mismatch.ll lld/test/wasm/version.ll diff --git a/lld/test/wasm/Inputs/call-indirect.ll b/lld/test/wasm/Inputs/call-indirect.ll deleted file mode 100644 index 6afcf30c2515.. --- a/lld/test/wasm/Inputs/call-indirect.ll +++ /dev/null @@ -1,20 +0,0 @@ -target triple = "wasm32-unknown-unknown" - -@indirect_bar = internal local_unnamed_addr global i64 ()* @bar, align 4 -@indirect_foo = internal local_unnamed_addr global i32 ()* @foo, align 4 - -declare i32 @foo() local_unnamed_addr - -define i64 @bar() { -entry: - ret i64 1 -} - -define void @call_bar_indirect() local_unnamed_addr #1 { -entry: - %0 = load i64 ()*, i64 ()** @indirect_bar, align 4 - %1 = load i32 ()*, i32 ()** @indirect_foo, align 4 - %call0 = tail call i64 %0() #2 - %call1 = tail call i32 %1() #2 - ret void -} diff --git a/lld/test/wasm/Inputs/call-indirect.s b/lld/test/wasm/Inputs/call-indirect.s new file mode 100644 index ..c181aa19ad6b --- /dev/null +++ b/lld/test/wasm/Inputs/call-indirect.s @@ -0,0 +1,28 @@ + .globl bar +bar: + .f
[llvm-branch-commits] [lld][WebAssembly] Replace config-> with ctx.arg. (PR #119835)
@@ -48,7 +48,7 @@ ConfigWrapper config; Ctx ctx; sbc100 wrote: Can we remove the global `config` on line 47, or is that for a followup? https://github.com/llvm/llvm-project/pull/119835 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [lld][WebAssembly] Replace config-> with ctx.arg. (PR #119835)
https://github.com/sbc100 commented: lgtm % comment https://github.com/llvm/llvm-project/pull/119835 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] release/19.x: [WebAssembly] Handle symbols in `.init_array` sections (#119127) (PR #119533)
https://github.com/sbc100 approved this pull request. LGTM if tests pass https://github.com/llvm/llvm-project/pull/119533 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [lld, wasm] Replace config-> with ctx.arg. (PR #119835)
https://github.com/sbc100 commented: Could you add a little context to the PR description? i.e. Why is this better? Does this change also remove the old `config` global or just stop using it? Objectively this still like a regression in readability since it adds more visual noise and indirection.However, I get that we are trying to make lld more library-friendly. I'm just a little sad that it comes are this readability cost :( https://github.com/llvm/llvm-project/pull/119835 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [lld][WebAssembly] Replace config-> with ctx.arg. (PR #119835)
https://github.com/sbc100 approved this pull request. https://github.com/llvm/llvm-project/pull/119835 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [lld] release/20.x: [wasm-ld] Refactor WasmSym from static globals to per-link context (#134970) (PR #137620)
sbc100 wrote: > cc @tstellar > > Not sure you saw my tag above but as I mentioned here [#137620 > (comment)](https://github.com/llvm/llvm-project/pull/137620#issuecomment-2834979164) > I had to manually backport this due to some merge conflicts. This was > critical for downstream projects and I was hoping it would be picked up in > the 20.1.4 release 😬 > > EDIT: I relized 20.1.4 is out, so probably you could help me move this a part > of 20.1.5 ? To be fair we actually track the release/20.x branch, so as soon > as this PR goes in, we can put it to use. Thanks ! Do you not build llvm from source in your project? Can't you therefore build from tip-of-tree? https://github.com/llvm/llvm-project/pull/137620 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [lld] release/20.x: [wasm-ld] Refactor WasmSym from static globals to per-link context (#134970) (PR #137620)
sbc100 wrote: > > > Do you not build llvm from source in your project? Can't you therefore > > > build from tip-of-tree? > > > > > > Hi, yes I think the latest changes on the release/latest_version.x branch > > is being used for https://github.com/compiler-research/CppInterOp > > (@vgvassilev or @mcbarton can confirm) > > So probably we don't exactly need a release everytime I think but yeah need > > these changes to go into the release branch > > CppInterOp is capable of building against the head of the release branches, > and this is what we do in our ci. Without this patch we are unable to run our > Emscripten tests in our PR to upgrade to llvm 20 here > [compiler-research/CppInterOp#491] If this patch is needed to run your emscripten tests, how did the pass prior to the llvm 20 upgrade? https://github.com/llvm/llvm-project/pull/137620 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits