rt.sections_elf_shared.d: Populate _tlsRanges in every thread#2558
rt.sections_elf_shared.d: Populate _tlsRanges in every thread#2558thewilsonator merged 1 commit intodlang:masterfrom ibuclaw:empty-tls-range
Conversation
|
Thanks for your pull request, @ibuclaw! Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub fetch digger
dub run digger -- build "master + druntime#2558" |
|
Mhm, this appears to be similar to a draft @dnadlinger came up with in https://forum.dlang.org/post/mailman.6193.1546546742.29801.digitalmars-d-ldc@puremagic.com. He mentioned that this shouldn't be necessary for glibc. This gist from @s-ludwig might serve as test; seems like we desperately need one for this serious issue. |
Ah, ok. I've only observed the segfault on FreeBSD libc so far, however I observed the same null tlsRange on glibc too but by then I ran out of time to look further as to why it doesn't crash. I'm not sure about this comment by @dnadlinger
Unless there's a peculiar internals detail I'm missing, glibc can't possibly preempt how many threads you may have open after entering main(). Though it will certainly go unnoticed if glibc preallocates more than we ever test. |
|
The test I'm running is shared/linkD.exe, however linking against libphobos statically. |
|
@kinke - Confirmed that small program also segfaults on FreeBSD/x86_64, so have added it to the testsuite. |
Yes, it can't – hence it just puts the TLS area for each new thread at the beginning of the newly created stack. Due to the way we detect the stack bottom, we hoover up the TLS data along with what we think the stack is on Linux/Glibc. This is of course a dirty implementation detail, but explains why things don't crash on GNU/Linux the way they are. |
|
I don't currently have the time to properly review this – would be good to test that we now have all the TLS ranges, but without duplicates |
The already existing DSO check should be good enough to cover that. I just switched to just adding a populate-if-empty in initTLSRange(), so any subsequent calls to _d_dso_registry() in a given thread still gets the array appended to. |
|
GCC release is imminent, so I'll apply it locally to gdc for now... |
Crashes on the auto-tester, though?
What I meant is to check that we don't end up scanning the same memory region multiple times (at least beyond scanning the non-main-thread TLS regions on glibc as they are included with the stack too). I'd be quite happy to accept a slight pessimisation for the time being, though, if you can make the PR pass the auto-tester and just put up an issue to revisit this in the future. (We could e.g. simply check for overlapping ranges when we initialise the list.) |
dnadlinger
left a comment
There was a problem hiding this comment.
(Didn't review the whole mechanism in detail, but as discussed above, there is definitely a real problem here on non-Glibc platforms.)
Looks like the test takes too long for the timelimit given, maybe we don't need to loop and allocate so much. |
|
Reduced memory allocation from |
|
How about making the extra thread sleep for a bit, sleeping for a shorter while in the main thread too (waiting for the other thread to be fully initialized), then invoking |
|
Going to need some decisive action here (fixed my end by forking rt.sections). |
|
I've rewritten the test to not rely on automatic collections or timing - it became a bit longer, but it works: |
|
Thanks @s-ludwig, I've now updated the test and rebased on master... |
|
Ping @thewilsonator |
|
Sorry, this had already slipped from view when the test was fixed – I really wasn't expecting this still to be unmerged. |
|
@dnadlinger - I've had interruptions in work, but there was nothing stopping others pushing the updated test to branch in my absence... :-) |
|
… or to merge this in mine. ;) |
|
Can you give this another push ? There was a network issue. |
|
I think it's safe to just merge. The socket timeout is currently ignored by our PR manager. |
Fangrui Song (7):
CMake: Fix LLVM_INTRINSIC_TD_PATH and LDC_INSTALL_PREFIX expansion (#3223)
Fix -Wunused-variable (#3224)
irstate.h: fix -Wdeprecated-copy
Use function attribute "frame-pointer" instead of "no-frame-pointer-elim"/"no-frame-pointer-elim-non-leaf"
Add assembly tests for "frame-pointer"
dibuilder: fix createGlobalVariableExpression call for LLVM 10 (#3266)
Fix StringRef conversion for LLVM 11 (777180a32b61070a10dd330b4f038bf24e916af1) (#3305)
Gianfranco Costamagna (1):
Update FindLLVM.cmake to cope with new llvm-config names
Guillaume Piolat (1):
Disambiguate that -link-defaultlib-shared can take a parameter (#3169)
Hiroki Noda (2):
Fix #3250: use `originalLType->isAggregateType()` in assertion (#3251)
Remove _d_execBss{Beg,End}Addr, used for copy-relocation check (#3247)
Ivan Butygin (4):
Travis lit tests use wrong jit lib (from host compiler) (#3152)
Make LDC custom passes available to jit, add API for jit compiler options (#2758)
jit compiler context (#3154)
jit bind: fix bool handling (#3174)
Jacob Carlborg (5):
Add predefined version identifiers for Apple platforms
Fix wrong size and emulated `real` for Apple ARM
Fix undefined symbol `__Dmodule_ref` for Apple ARM
Fix warning about critical section size for Apple ARM
Fix missing symbol `__va_list` on Apple ARM
Johan Engelen (14):
Align with Clang what -fsanitize=fuzzer implies
Fix fuzzing: inline-8bit-counters should also imply edge tracing
Fix CMake configuring with LLVM 10 (current trunk)
LLVM 10 fix: prevent linking in LLVM's TargetOptionsCommandFlags.o
LLVM 10 fix: add llvm::make_unique and LLMaybeAlign "aliases". (an explicit cast from integer to llvm::MaybeAlign is needed now to setAlignment)
Sort includes and fix SanitizerCoverage pass call
lld >= 10 must also be linked with LLVMSymbolize.
Add LLVM bin dir to search path for Lit tests (for FileCheck and not)
Update druntime with LLVM 10 support.
LLVM bin dir is already part of the path, doesn't need extra adding anymore for sanitizer tests.
Fix asan_fiber_main tests. Sometimes debug line info was missing in ASan output report due to test execution order bug.
Link with LLVMSymbolize _after_ linking with the LLD libraries.
Add explicit casts to llvm::MaybeAlign for setAlignment to use the new LLVM trunk API (silences deprecation messages of old API)
[Travis] Enable runtime sanitizer testing for Linux LLVM 9 and macOS LLVM 8 CI testers. (#3199)
Martin Kinkelin (187):
Upgrade front-end & libs to v2.088.0-beta.1
druntime: Port core.atomic additions to LDC
Adapt lit-test to druntime changes
Adapt dcompute lit-test to new front-end lowering
druntime: Adapt expected profiling test output for LDC
dmd-testsuite: Adapt a few tests for LDC
Improve emission of vector literals (#3139)
Fix front-end patch version
dmd-testsuite: Adapt runnable/testpic.d to unsupported -fPIE
druntime: Slightly optimize CAS implementation of atomicOp
Phobos: Merge upstream stable for Win32 unittest fix
dmd-testsuite: Disable a new dshell test
Merge v2.088.0
Upgrade bundled dub to v1.17.0+ (with cross-compilation support) (#3157)
Make all DtoGEP helpers use implicit `inbounds`
Don't emit init symbol for zero-initialized structs (#3131)
druntime: Add {load,store}Unaligned and prefetch to core.simd (#3160)
Merge upstream stable (32de317145) (#3161)
Azure & Shippable: Upgrade LDC-LLVM to v9.0.0
Add support for LLVM 9.0.0
Adapt jit-rt to LLVM 9
Adapt lit-tests to LLVM 9
Adapt PGO lit-tests to LLVM 9 on Windows
Windows: Adapt to LLVM 9 apparently supporting naked DMD-style asm with LTO
Adapt fsanitize_fuzzer lit test
Travis: Add Linux LLVM 9.0.0 job
Adapt sanitizers/link_fuzzer test to LLVM 9
CMake: Enable manual D_LINKER_ARGS input (for cross-compilation) (#3163)
druntime: Fix regression for POSIX systems without backtrace[_symbols]
Merge upstream stable (61020a6d1d)
CMake: Fix linker cmdline order for Phobos testrunners
druntime: Disable new forkgc test on Windows
CMake: Remove apparently obsolete MSVC workaround when linking testrunners
druntime: Fix exception chaining for latest MSVC runtime v14.23
CMake: Use add_executable() for LDC_LINK_MANUALLY
CMake: Fix position of LLVMSPIRVLib in linker cmdline
CMake: Don't build gccbuiltins utility when cross-compiling
Azure CI: Add Android cross-compilation job (incl. prebuilt release package)
Don't link ldc-build-runtime and ldc-prune-cache against LLVM libs
Keep lvalue-ness when casting AA to another AA (#3179)
Merge v2.088.1 (#3190)
CMake: Fix regression for make (#3191)
Update CHANGELOG.md
Upgrade front-end & libs to v2.089.0-beta.1
Front-end: Re-expose a few functions to C++ interface
Fix front-end C++ headers
Azure CI: Bump host LDC version to 1.18 + bash nanofix
druntime: Make core.sys.windows.odbcinst compilable without deprecations
CMake: Compile default libs with `-de -dip1000`
druntime: Fix core.atomic.atomicStore() regression
druntime: Make type repainting in core.atomic.atomicLoad() cheaper
New DIP1021 implies DIP1000
dmd-testsuite: Fixup _Dmain signature in minimal object.d
druntime: Don't instrument C main function
dmd-testsuite: Fixup C main signature in minimal object.d
dmd-testsuite: Slighlty adapt dshell/test6952.d and runnable/testpdb.d
Make ClassReferenceExp → IR global association more robust
Resync LDMD2 help output
Restore compilability with ltsmaster
druntime: Fix version(SupportSanitizers) regression
Phobos: Disable std.math.signbit() tests with negated NaNs on AArch64
Shippable CI: Adapt to core.thread refactoring
CMake: Fix hacky way of determining LLVM libs for jit-rt
CircleCI: Bump LIBCLANG_COMMON_VERSION for latest ubuntu:rolling
Make gccbuiltins_*.di files available to non-installed compiler
Travis: Bump LLVM version for macOS jobs (#3200)
dmd-testsuite: Make compilable/json2.d less brittle wrt. -I switches
Azure: Upgrade to new pipeline artifacts syntax (#3203)
CircleCI: Bump the macOS image as well as host LDC & LLVM versions
Azure CI: Extend Android ldc2.conf by required default switches (#3206)
druntime: Adapt test shared/finalize to recent macOS not unloading .dylibs with TLS
Azure CI: Bump macOS image to v10.14
Posix x86_64: Pass non-POD arguments indirectly by value, not just for extern(C++)
Try to in-place-construct temporary structs and static arrays
Posix x86: Pass non-POD arguments indirectly by value, not just for extern(C++)
POSIX: Default to cc for linking, not gcc (or clang for FreeBSD 10+)
CLI: Unhide -gcc, list under linking options, and revise description
Hide command-line options leaking from LLVM 9
Make sure a replaced temporary's lvalue is an alloca
Merge v2.089.0-rc.1 (#3210)
Fix equality/identity comparisons of vectors with length >= 32 (#3209)
Shippable: Switch linker from gold to bfd
dmd-testsuite: Disable/adapt a few tests for non-x86 architectures
Shippable: Don't default to bfd linker in package's ldc2.conf
Merge v2.089.0
Upgrade bundled dub to v1.18.0
CircleCI: Work around ldc-developers/ldc#3127
Fix issue #3221 (@assumeUsed on global union) (#3222)
druntime: Add llvm_sideeffect intrinsic
Azure CI Windows: Build LDC itself with ThinLTO
Azure CI Windows: Switch to FullLTO
Azure CI Windows: Use ThinLTO for 32-bit job
Reduce code duplication in DtoLowerMagicIntrinsic() wrt. atomic intrinsics
Make llvm_atomic_cmp_xchg signature match LLVM's
Extend llvm_atomic_cmp_xchg by isWeak and separate failure ordering
Fix issue #3228 (#3230)
Merge upstream stable (47874e5b37)
Minimally revise -gcc cmdline help
Fix regression #3234 (#3235)
druntime: Add @Cold function UDA to ldc.attributes
Fix DMD issue 20401 (#3233)
Windows: Upgrade bundled MinGW-based libs to v7.0.0 RC1 (#3241)
Merge upstream stable (da6fc42436) (#3242)
Merge upstream stable (a5d1cae776)
druntime: Cherry-pick dlang/druntime#2558 (populate _tlsRanges in every thread)
Fix wrong output file collision errors for .di files (#3258)
Upgrade LLVM to v9.0.1 and add Android/AArch64 CI job/package
Azure CI Android: Cross-compile i686/x86_64 libs too and include in armv7a/aarch64 packages
Azure CI: Deploy text file with listing of SHA256 hashes
Merge upstream stable (cf3e6398ea) (#3261)
Update CHANGELOG.md
Refactoring: Modernize some legacy asmstmt code (#3225)
Upgrade frontend & libs to v2.090.0-beta.1
Adapt to frontend refactorings
Merge v2.090.0
dmd-testsuite: Update $(YEAR) ddoc test to 2020
Revise recent adaptations to frontend refactorings
Adapt tests/baremetal/wasm2.d to Phobos changes
dmd-testsuite: Adapt compilable/cppmangle.d some more
Restore compilability with ltsmaster host compiler
druntime: Fix regression for GNU backtraces
Declare ModuleInfo.importedModules pointers as weak symbols, like DMD
Fix issue #3272 (debuginfo for enum of function pointers)
Fix debuginfo for enum of delegates
Merge upstream stable
Revert "CircleCI: Disable parallel GC marking for 64-bit unittest runners on Linux"
Revert to strong ModuleInfo.importedModules for MSVC targets
Support 2 leading dashes in manual CLI pre-parsing (#3275)
Config file: Use a separate section for multilib targets (#3276)
CMake: Sync D compiler flags for druntime/Phobos with upstream
Bump bundled dub version to 1.19.0
Merge upstream stable
Revert "Adapt tests/baremetal/wasm2.d to Phobos changes"
Embed linker directives in ELF and Mach-O object files (#3259)
Azure CI: Build LDC itself with full LTO, on Linux and Mac too (#3236)
Refactoring: Replace Expression::op check followed by static cast to Expression::is<ExpressionType> (#3141)
Slightly revise ldc-build-runtime & make --dFlags extend the default D flags (#3278)
Fix default cross-linker for MSVC targets on non-Windows hosts (#3282)
CircleCI: Use gdmd as host compiler for ubuntu:rolling job
Bypass the GC (without -lowmem) with gdmd host compilers too
dmd-testsuite: Tweak d_do_test runner to skip some uninteresting permutations
dmd-testsuite: Restrict non-debug dmd-testsuite to runnable tests only
CI: Adapt Travis and Shippable to reduced non-debug dmd-testsuite
dmd-testsuite: Prepare for switch from Makefile to run.d
Azure CI: Fix regression with new Windows image
Fix minor potential issues wrt. CLI parsing of -m32/-m64
Enable core.math.yl2x[p1] CTFE support with GDC host compilers and on non-x86 hosts
CI: Upgrade Mac images for Travis and CircleCI
dmd-testsuite: Switch from Makefile to run.d
dmd-testsuite: Remove -fPIC permute arg and disable runnable/test17338.d
dmd-testsuite: Tweak runnable test order in run.d
dmd-testsuite: Don't test with -m<model> for C(++) compiler for non-x86 targets
Shippable CI: Disable gdb tests in dmd-testsuite
Azure CI: Use 7zip for .tar.xz archiving on Linux hosts
Experiment with Cirrus CI
Cirrus CI: Split up into multiple script blocks
Cirrus CI: Add macOS
Cirrus CI: Experiment with FreeBSD
Cirrus CI: Add Ubuntu rolling shared-libs-only job
Cirrus CI: Sync yaml with current Circle CI script
Cirrus CI: Try unifying pip + lit installation
Cirrus CI: Add shared-libs-only macOS job
DMD-style asm: Support data directives (integral ones)
Remove Semaphore CI
DMD-style asm: Support floating-point data directives too
Merge upstream stable (890f7eb2e9) (#3296)
Slightly revise iOS additions
Merge v2.090.1-beta.1
Azure CI: Prepare for upcoming breaking change
Try to improve dmd-testsuite stability by prebuilding run.d tool
Enable other compilers to build dmd-testsuite's run.d tool tweaked for LDC
Build dmd-testsuite's run.d tool with built LDC compiler
Build dmd-testsuite's run.d tool lazily
Don't allocate front-end Strings on C++ heap
Properly disable GC without -lowmem
Phobos: Cherry-pick soft-float improvements (#3303)
Windows: Bump bundled MinGW-based libs to v7.0.0 final (#3311)
Add predefined versions WASI and CRuntime_WASI for triples like wasm32-unknown-wasi
WebAssembly: Emit all TLS globals as regular __gshared globals
Add little WASI test
Merge v2.090.1 (#3317)
Update changelog for v1.20
Update README.md
Finalize support for LLVM 10 (#3323)
Merge upstream stable (e274c8cbcc) (#3326)
Revert to strong importedModules ModuleInfo refs (#3347)
Prepare to release v1.20.1
Nicholas Lindsay Wilson (4):
fix SpecialCaseList
Fix CGFT
Fix future versions of LLVM9
Fix ctfe semantic analysis for dcompute
Nicholas Wilson (1):
Fix issue #3079 : Some (but not all) targets in this export set were already defined (#3151)
Roberto Rosmaninho (1):
Adapt to current LLVM 10 (#3257)
Stefanos Baziotis (3):
Add inbounds where possible
Add inbounds to static arrays and dynamic arrays
Disable dead code when an if/else if condition is constant (#3134)
I've hit a segfault in a non-main thread, dereferencing a global TLS static variable, that appears to have been GC'd.
A printf inside
scanTLSRangesconfirmed this.Linking against the
version(Shared)libphobos library does not have the same problem, asinheritLoadedLibrariesis called on each new thread entrypoint, which callsgetTLSRangeagain to get all thread-local ranges.Neither does this appear to affect other sections support, as they either get the addresses of the thread local
_tlstart/_tlsendbrackets, or callpthread_[get|set]specific(_tlsKey)to test and allocate a new per-thread array.Moving the initialization of
_tlsRangesfrom_d_dso_registry- which is only called once in the initialization of the main thread - toinitTLSRanges- which is called during the construction of every thread.