Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes to support TLS access emitted in ILC (x64 win/linux) #429

Merged
merged 2 commits into from
Jun 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion llvm/include/llvm/MC/MCObjectFileInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ class MCObjectFileInfo {
}

MCSection *getTLSExtraDataSection() const { return TLSExtraDataSection; }
const MCSection *getTLSDataSection() const { return TLSDataSection; }
MCSection *getTLSDataSection() const { return TLSDataSection; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed? Could we just mark things const on the objwriter side? Changes to LLVM outside of tools/objwriter need to be ported every time we update LLVM so there's a lot of value in keeping them as minimal as possible.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we just mark things const on the objwriter side

I tried and propagating the const requires a lot of changes (const can be viral).
It is also inconsistent with the treatment other section accessors - i.e why getTLSDataSection is a const and getTLSBSSSection isn't?

I think the difference is unintentional. If we want const, we should make other sections accessors const as well.

Copy link
Member Author

@VSadov VSadov Jun 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One possibility is to keep getTLSDataSection() as const (for no reason) and just cast the const away in the object writer.

There is a danger that something may eventually make dependency on this being const and it would not be easily noticeable when updating.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cast the const away in the object writer

Such workaround stands out in the code and feels like a mildly dangerous hack.
I think we can do such change if removing the const becomes a burden when updating. It probably won't if upstream code does not change. It does not look like this part changes often.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to be sure - I have noted the concern, but any way to deal with this issue has a downside. Removing the 'const' seems not distinctly worse than other solutions.
We need to pick one way to move forward while decision is not binding, since it is an implementation detail that can be changed. I am going to merge what we have, but will keep an eye if this becomes an issue.

MCSection *getTLSBSSSection() const { return TLSBSSSection; }

MCSection *getStackMapSection() const { return StackMapSection; }
Expand Down
16 changes: 16 additions & 0 deletions llvm/tools/objwriter/objwriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -457,6 +461,18 @@ 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_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) {
Expand Down
3 changes: 3 additions & 0 deletions llvm/tools/objwriter/objwriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ enum class RelocType {
IMAGE_REL_BASED_RELPTR32 = 0x7C,
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
Expand Down