From da38b2949163e2e5b798e980a15bab6cb7319516 Mon Sep 17 00:00:00 2001 From: vsadov <8218165+VSadov@users.noreply.github.com> Date: Thu, 8 Jun 2023 11:32:59 -0700 Subject: [PATCH 1/2] tls support --- llvm/include/llvm/MC/MCObjectFileInfo.h | 2 +- llvm/tools/objwriter/objwriter.cpp | 8 ++++++++ llvm/tools/objwriter/objwriter.h | 1 + 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/llvm/include/llvm/MC/MCObjectFileInfo.h b/llvm/include/llvm/MC/MCObjectFileInfo.h index 3c1d10c4e62f1..be5c768cf0a54 100644 --- a/llvm/include/llvm/MC/MCObjectFileInfo.h +++ b/llvm/include/llvm/MC/MCObjectFileInfo.h @@ -344,7 +344,7 @@ class MCObjectFileInfo { } MCSection *getTLSExtraDataSection() const { return TLSExtraDataSection; } - const MCSection *getTLSDataSection() const { return TLSDataSection; } + MCSection *getTLSDataSection() const { return TLSDataSection; } MCSection *getTLSBSSSection() const { return TLSBSSSection; } MCSection *getStackMapSection() const { return StackMapSection; } diff --git a/llvm/tools/objwriter/objwriter.cpp b/llvm/tools/objwriter/objwriter.cpp index 27ac94aa0e88d..ff39f959d25f4 100644 --- a/llvm/tools/objwriter/objwriter.cpp +++ b/llvm/tools/objwriter/objwriter.cpp @@ -222,6 +222,10 @@ MCSection *ObjectWriter::GetSection(const char *SectionName, Section = ObjFileInfo->getReadOnlySection(); } else if (strcmp(SectionName, "xdata") == 0) { Section = ObjFileInfo->getXDataSection(); + } else if (strcmp(SectionName, "tdata") == 0) { + Section = ObjFileInfo->getTLSDataSection(); + } else if (strcmp(SectionName, "tbss") == 0) { + Section = ObjFileInfo->getTLSBSSSection(); } else if (strcmp(SectionName, "bss") == 0) { if (OutContext->getObjectFileType() == MCContext::IsMachO) { Section = ObjFileInfo->getDataBSSSection(); @@ -457,6 +461,10 @@ int ObjectWriter::EmitSymbolRef(const char *SymbolName, case RelocType::IMAGE_REL_BASED_DIR64: Size = 8; break; + case RelocType::IMAGE_REL_SECREL: + Kind = MCSymbolRefExpr::VK_SECREL; + Size = 4; + break; case RelocType::IMAGE_REL_BASED_REL32: if (OutContext->getObjectFileType() == MCContext::IsMachO && OutContext->getTargetTriple().getArch() == Triple::aarch64) { diff --git a/llvm/tools/objwriter/objwriter.h b/llvm/tools/objwriter/objwriter.h index 860312f92a13e..78e885d573c74 100644 --- a/llvm/tools/objwriter/objwriter.h +++ b/llvm/tools/objwriter/objwriter.h @@ -57,6 +57,7 @@ enum class RelocType { IMAGE_REL_BASED_THUMB_BRANCH24 = 0x13, IMAGE_REL_BASED_ARM64_BRANCH26 = 0x15, IMAGE_REL_BASED_RELPTR32 = 0x7C, + IMAGE_REL_SECREL = 0x80, IMAGE_REL_BASED_ARM64_PAGEBASE_REL21 = 0x81, IMAGE_REL_BASED_ARM64_PAGEOFFSET_12A = 0x82, }; From 36ce724aa5d18e235d52cb854e4b75b800c144ed Mon Sep 17 00:00:00 2001 From: vsadov <8218165+VSadov@users.noreply.github.com> Date: Thu, 8 Jun 2023 21:35:06 -0700 Subject: [PATCH 2/2] more operators --- llvm/tools/objwriter/objwriter.cpp | 8 ++++++++ llvm/tools/objwriter/objwriter.h | 4 +++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/llvm/tools/objwriter/objwriter.cpp b/llvm/tools/objwriter/objwriter.cpp index ff39f959d25f4..beea87c043af7 100644 --- a/llvm/tools/objwriter/objwriter.cpp +++ b/llvm/tools/objwriter/objwriter.cpp @@ -465,6 +465,14 @@ int ObjectWriter::EmitSymbolRef(const char *SymbolName, Kind = MCSymbolRefExpr::VK_SECREL; Size = 4; break; + case RelocType::IMAGE_REL_TLSGD: + Kind = MCSymbolRefExpr::VK_TLSGD; + Size = 4; + break; + case RelocType::IMAGE_REL_TPOFF: + Kind = MCSymbolRefExpr::VK_TPOFF; + Size = 4; + break; case RelocType::IMAGE_REL_BASED_REL32: if (OutContext->getObjectFileType() == MCContext::IsMachO && OutContext->getTargetTriple().getArch() == Triple::aarch64) { diff --git a/llvm/tools/objwriter/objwriter.h b/llvm/tools/objwriter/objwriter.h index 78e885d573c74..80aa61703b6cf 100644 --- a/llvm/tools/objwriter/objwriter.h +++ b/llvm/tools/objwriter/objwriter.h @@ -57,9 +57,11 @@ enum class RelocType { IMAGE_REL_BASED_THUMB_BRANCH24 = 0x13, IMAGE_REL_BASED_ARM64_BRANCH26 = 0x15, IMAGE_REL_BASED_RELPTR32 = 0x7C, - IMAGE_REL_SECREL = 0x80, IMAGE_REL_BASED_ARM64_PAGEBASE_REL21 = 0x81, IMAGE_REL_BASED_ARM64_PAGEOFFSET_12A = 0x82, + IMAGE_REL_SECREL = 0x104, + IMAGE_REL_TLSGD = 0x105, + IMAGE_REL_TPOFF = 0x106, }; enum class SymbolRefFlags