4 ms·
Obviously. How about more complex things like multi-threading APIs though? Can the Rust compiler determine that the subject program doesn't need TLS and produce
by oguz-ismail2 9mo ago
Obviously. How about more complex things like multi-threading APIs though? Can the Rust compiler determine that the subject program doesn't need TLS and produce a binary that doesn't set it up at all, for example?
- dwattttt 9mo agoOptimising out TLS isn't going to be a good example of compiler capability. Whether another thread exists is a global property of a process, and beyond that the system that process operates in. The compiler isn't going to know for instance that an LD_PRELOAD variable won't be set that would create a thread.
- oguz-ismail2 9mo ago> Whether another thread exists is a global property of a process, and beyond that the system that process operates in. TLS is a language feature. Whether another thread exists doesn't mean it has to use the same facilities as the main program. > The compiler isn't going to know for instance that an LD_PRELOAD variable won't be set that would create a thread. Say the program is not dynamically linked. Still no?
- dwattttt 9mo ago> Say the program is not dynamically linked. Still no? Whether the program has dynamic dependencies does not dictate whether a thread can be created, that's a property of the OS. Windows has CreateRemoteThread, and I'd be shocked if similar capabilities didn't exist elsewhere. If I mark something as thread-local, I want it to be thread-local.
- steveklabnik 9mo agoI mean, it’s not that obvious, your parent asked about it directly, and you could easily imagine calling it libc for this. I beehive the answer to your question is “yes” because no-std binaries can be mere bytes in size, but I suspect that more complex programs will almost always have some dependency somewhere (possibly even the standard library, but I don’t know offhand) that uses TLS somewhere in it.