[PATCH] [lld][ELF] Add static TLS support.

Michael Spencer bigcheesegs at gmail.com
Wed Jan 30 14:00:59 PST 2013



================
Comment at: lib/ReaderWriter/ELF/X86_64/X86_64TargetHandler.cpp:92-94
@@ +91,5 @@
+    int32_t result = (int32_t)(targetVAddress - tlsEnd);
+    *reinterpret_cast<llvm::support::little32_t *>(location) =
+        result +
+        (int32_t) * reinterpret_cast<llvm::support::little32_t *>(location);
+    break;
----------------
Shankar Kalpathi Easwaran wrote:
> should this be result | instead of result + ?
No idea.

================
Comment at: lib/ReaderWriter/ELF/X86_64/X86_64TargetHandler.cpp:74-90
@@ +73,19 @@
+    // Get the start and end of the TLS segment.
+    auto tdata = _targetInfo.getTargetHandler<X86_64ELFType>().targetLayout()
+        .findOutputSection(".tdata");
+    auto tbss = _targetInfo.getTargetHandler<X86_64ELFType>().targetLayout()
+        .findOutputSection(".tbss");
+    uint64_t tlsStart = 0;
+    uint64_t tlsEnd = 0;
+    // HACK: The tdata and tbss sections end up together to from the TLS
+    // segment. This should actually use the TLS program header entry. And it
+    // shouldn't be looked up for each relocation.
+    if (tdata) {
+      tlsStart = tdata->virtualAddr();
+      tlsEnd = tdata->virtualAddr() + tdata->memSize();
+    }
+    if (tbss) {
+      tlsStart = std::min(tlsStart, tbss->virtualAddr());
+      tlsEnd = std::max(tlsEnd, tbss->virtualAddr() + tbss->memSize());
+    }
+    int32_t result = (int32_t)(targetVAddress - tlsEnd);
----------------
Shankar Kalpathi Easwaran wrote:
> Does it make sense to cache the value, because there is no need to compute this again and again.
Yeah, it should be cached. Really there should be a step after everything is laid out to initialize the relocation handler. As it will also need to know the location of the got and other such stuff.


http://llvm-reviews.chandlerc.com/D351



More information about the llvm-commits mailing list