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

Shankar Kalpathi Easwaran shankarke at gmail.com
Wed Jan 30 13:33:07 PST 2013



================
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);
----------------
Does it make sense to cache the value, because there is no need to compute this again and again.

================
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;
----------------
should this be result | instead of result + ?


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



More information about the llvm-commits mailing list